Class: Duby::JVM::Types::TypeDefinition
- Inherits:
-
Type
show all
- Defined in:
- lib/duby/jvm/types.rb,
lib/duby/jvm/types/methods.rb
Constant Summary
AST::TypeReference::BlockType, AST::TypeReference::ErrorType, AST::TypeReference::NoType, AST::TypeReference::NullType, AST::TypeReference::UnreachableType
Instance Attribute Summary collapse
Attributes inherited from Type
#inner_class
#array
Attributes inherited from AST::Node
#children, #inferred_type, #newline, #parent, #position
Instance Method Summary
collapse
Methods inherited from Type
#add_enumerable_macros, #add_intrinsics, #add_macro, #add_method, #aload, #array?, #array_type, #assignable_from?, #astore, #basic_type, #compatible?, #component_type, #declared_intrinsics, #dynamic?, #expand_each, #get_method, #init_value, #inner_class?, #inner_class_getter, #inspect, #intrinsics, #is_parent, #iterable?, #jvm_type, #load, #log, #meta?, #newarray, #prefix, #primitive?, #return, #store, #to_source, #unmeta, #void?, #wide?
#each_is_exact, #each_is_exact_or_subtype_or_convertible, #field_lookup, #find_jls, #find_method, #inner_class, #is_more_specific?, #log, #phase1, #phase2, #phase3, #primitive_convertible?
#==, #block?, #compatible?, #component_type, #eql?, #error?, #hash, #is_parent, #iterable?, #meta?, #narrow, #null?, #primitive?, #to_s, #unmeta, #unreachable?
Methods included from AST::Named
#to_s
Methods inherited from AST::Node
#<<, ===, #[], #_set_parent, child, child_name, #each, #empty?, #expr?, #initialize_copy, #insert, #inspect, #line_number, #log, #precompile, #resolve_if, #resolved!, #resolved?, #simple_name, #temp, #to_s
Constructor Details
Returns a new instance of TypeDefinition.
325
326
327
328
329
330
|
# File 'lib/duby/jvm/types.rb', line 325
def initialize(name, node)
raise ArgumentError, "Bad name #{name}" if name[0,1] == '.'
@name = name
@node = node
raise ArgumentError, "Bad type #{name}" if self.name =~ /Java::/
end
|
Instance Attribute Details
Returns the value of attribute node.
323
324
325
|
# File 'lib/duby/jvm/types.rb', line 323
def node
@node
end
|
Instance Method Details
#constructor(*types) ⇒ Object
514
515
516
517
518
|
# File 'lib/duby/jvm/types/methods.rb', line 514
def constructor(*types)
constructor = constructors.find {|c| c.argument_types == types}
return constructor if constructor
raise NameError, "No constructor #{name}(#{types.join ', '})"
end
|
#constructors ⇒ Object
540
541
542
|
# File 'lib/duby/jvm/types/methods.rb', line 540
def constructors
@constructors ||= []
end
|
#declare_method(name, arguments, type, exceptions) ⇒ Object
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
|
# File 'lib/duby/jvm/types/methods.rb', line 562
def declare_method(name, arguments, type, exceptions)
raise "Bad args" unless arguments.all?
member = DubyMember.new(self, name, arguments, type, false, exceptions)
if name == 'initialize'
if @default_constructor_added
unless arguments.empty?
raise "Can't add constructor #{member} after using the default."
end
else
constructors << JavaConstructor.new(member)
end
else
instance_methods[name] << JavaMethod.new(member)
end
end
|
#declare_static_method(name, arguments, type, exceptions) ⇒ Object
578
579
580
581
|
# File 'lib/duby/jvm/types/methods.rb', line 578
def declare_static_method(name, arguments, type, exceptions)
member = DubyMember.new(self, name, arguments, type, true, exceptions)
static_methods[name] << JavaStaticMethod.new(member)
end
|
#declared_class_methods(name = nil) ⇒ Object
528
529
530
531
532
533
534
|
# File 'lib/duby/jvm/types/methods.rb', line 528
def declared_class_methods(name=nil)
meta.declared_intrinsics(name) + if name.nil?
static_methods.values.flatten
else
static_methods[name]
end
end
|
#declared_constructors ⇒ Object
536
537
538
|
# File 'lib/duby/jvm/types/methods.rb', line 536
def declared_constructors
constructors
end
|
#declared_instance_methods(name = nil) ⇒ Object
520
521
522
523
524
525
526
|
# File 'lib/duby/jvm/types/methods.rb', line 520
def declared_instance_methods(name=nil)
declared_intrinsics(name) + if name.nil?
instance_methods.values.flatten
else
instance_methods[name]
end
end
|
#default_constructor ⇒ Object
544
545
546
547
548
549
550
551
552
|
# File 'lib/duby/jvm/types/methods.rb', line 544
def default_constructor
if constructors.empty?
declare_method('initialize', [], self, [])
@default_constructor_added = true
constructors[0]
else
constructor
end
end
|
#define(builder) ⇒ Object
352
353
354
355
|
# File 'lib/duby/jvm/types.rb', line 352
def define(builder)
class_name = @name.tr('.', '/')
@type ||= builder.public_class(class_name, superclass, *interfaces)
end
|
#field_getter(name) ⇒ Object
587
588
589
|
# File 'lib/duby/jvm/types/methods.rb', line 587
def field_getter(name)
nil
end
|
#field_setter(name) ⇒ Object
591
592
593
|
# File 'lib/duby/jvm/types/methods.rb', line 591
def field_setter(name)
nil
end
|
#instance_methods ⇒ Object
554
555
556
|
# File 'lib/duby/jvm/types/methods.rb', line 554
def instance_methods
@instance_methods ||= Hash.new {|h, k| h[k] = []}
end
|
583
584
585
|
# File 'lib/duby/jvm/types/methods.rb', line 583
def interface?
false
end
|
#interfaces ⇒ Object
344
345
346
347
348
349
350
|
# File 'lib/duby/jvm/types.rb', line 344
def interfaces
if node
node.interfaces
else
[]
end
end
|
#java_method(name, *types) ⇒ Object
498
499
500
501
502
503
504
|
# File 'lib/duby/jvm/types/methods.rb', line 498
def java_method(name, *types)
method = instance_methods[name].find {|m| m.argument_types == types}
return method if method
intrinsic = intrinsics[name][types]
return intrinsic if intrinsic
raise NameError, "No method #{self.name}.#{name}(#{types.join ', '})"
end
|
#java_static_method(name, *types) ⇒ Object
506
507
508
509
510
511
512
|
# File 'lib/duby/jvm/types/methods.rb', line 506
def java_static_method(name, *types)
method = static_methods[name].find {|m| m.argument_types == types}
return method if method
intrinsic = meta.intrinsics[name][types]
return intrinsic if intrinsic
raise NameError, "No method #{self.name}.#{name}(#{types.join ', '})"
end
|
357
358
359
|
# File 'lib/duby/jvm/types.rb', line 357
def meta
@meta ||= TypeDefMeta.new(self)
end
|
332
333
334
335
336
337
338
|
# File 'lib/duby/jvm/types.rb', line 332
def name
if @type
@type.name
else
@name
end
end
|
#static_methods ⇒ Object
558
559
560
|
# File 'lib/duby/jvm/types/methods.rb', line 558
def static_methods
@static_methods ||= Hash.new {|h, k| h[k] = []}
end
|
#superclass ⇒ Object
340
341
342
|
# File 'lib/duby/jvm/types.rb', line 340
def superclass
(node && node.superclass) || Object
end
|