Class: Mirah::JVM::Types::TypeDefinition
- Inherits:
-
Type
show all
- Defined in:
- lib/mirah/jvm/types/type_definition.rb,
lib/mirah/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_compiled_macro, #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, #full_name, #get_method, #include, #init_value, #inner_class?, #inner_class_getter, #inspect, #intrinsics, #is_parent, #iterable?, #jvm_type, #load, #load_extensions, #log, #meta?, #newarray, #pop, #prefix, #primitive?, #return, #store, #to_source, #unmeta, #void?, #wide?, #wrap_with_scoped_body
#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?
#==, #_dump, _load, #basic_type, #block?, #compatible?, #component_type, #eql?, #error?, #full_name, #hash, #is_parent, #iterable?, #meta?, #narrow, #null?, #primitive?, #to_s, #type_reference, #unmeta, #unreachable?, #void?
Methods included from AST::Named
#string_value, #to_s, #validate_name
Methods inherited from AST::Node
#<<, ===, #[], #[]=, #_dump, _load, #_set_parent, child, child_name, #child_nodes, #each, #empty?, #expr?, #inferred_type!, #initialize_copy, #insert, #inspect, #inspect_children, #line_number, #log, #precompile, #resolve_if, #resolved!, #resolved?, #simple_name, #string_value, #temp, #to_s, #top_level?, #validate_child, #validate_children
Constructor Details
Returns a new instance of TypeDefinition.
7
8
9
10
11
12
13
|
# File 'lib/mirah/jvm/types/type_definition.rb', line 7
def initialize(name, node)
raise ArgumentError, "Bad name #{name}" if name[0,1] == '.'
raise ArgumentError, "Bad name #{name}" if name.include? ?/
@name = name
@node = node
raise ArgumentError, "Bad type #{name}" if self.name =~ /Java::/
end
|
Instance Attribute Details
Returns the value of attribute node.
5
6
7
|
# File 'lib/mirah/jvm/types/type_definition.rb', line 5
def node
@node
end
|
Instance Method Details
#constructor(*types) ⇒ Object
523
524
525
526
527
|
# File 'lib/mirah/jvm/types/methods.rb', line 523
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
549
550
551
|
# File 'lib/mirah/jvm/types/methods.rb', line 549
def constructors
@constructors ||= []
end
|
#declare_method(name, arguments, type, exceptions) ⇒ Object
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
|
# File 'lib/mirah/jvm/types/methods.rb', line 571
def declare_method(name, arguments, type, exceptions)
raise "Bad args" unless arguments.all?
member = MirahMember.new(self, name, arguments, type, false, exceptions)
if name == 'initialize'
if @default_constructor_added
if arguments.empty?
@default_constructor_added = false
else
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
589
590
591
592
|
# File 'lib/mirah/jvm/types/methods.rb', line 589
def declare_static_method(name, arguments, type, exceptions)
member = MirahMember.new(self, name, arguments, type, true, exceptions)
static_methods[name] << JavaStaticMethod.new(member)
end
|
#declared_class_methods(name = nil) ⇒ Object
537
538
539
540
541
542
543
|
# File 'lib/mirah/jvm/types/methods.rb', line 537
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
545
546
547
|
# File 'lib/mirah/jvm/types/methods.rb', line 545
def declared_constructors
constructors
end
|
#declared_instance_methods(name = nil) ⇒ Object
529
530
531
532
533
534
535
|
# File 'lib/mirah/jvm/types/methods.rb', line 529
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
553
554
555
556
557
558
559
560
561
|
# File 'lib/mirah/jvm/types/methods.rb', line 553
def default_constructor
if constructors.empty?
declare_method('initialize', [], self, [])
@default_constructor_added = true
constructors[0]
else
constructor
end
end
|
#define(builder) ⇒ Object
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/mirah/jvm/types/type_definition.rb', line 35
def define(builder)
class_name = @name.tr('.', '/')
abstract = node && node.abstract
@type ||= builder.define_class(
class_name,
:visibility => :public,
:abstract => abstract,
:superclass => superclass,
:interfaces => interfaces)
end
|
#field_getter(name) ⇒ Object
598
599
600
|
# File 'lib/mirah/jvm/types/methods.rb', line 598
def field_getter(name)
nil
end
|
#field_setter(name) ⇒ Object
602
603
604
|
# File 'lib/mirah/jvm/types/methods.rb', line 602
def field_setter(name)
nil
end
|
#instance_methods ⇒ Object
563
564
565
|
# File 'lib/mirah/jvm/types/methods.rb', line 563
def instance_methods
@instance_methods ||= Hash.new {|h, k| h[k] = []}
end
|
594
595
596
|
# File 'lib/mirah/jvm/types/methods.rb', line 594
def interface?
false
end
|
#interfaces ⇒ Object
27
28
29
30
31
32
33
|
# File 'lib/mirah/jvm/types/type_definition.rb', line 27
def interfaces
if node
node.interfaces
else
[]
end
end
|
#java_method(name, *types) ⇒ Object
507
508
509
510
511
512
513
|
# File 'lib/mirah/jvm/types/methods.rb', line 507
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
515
516
517
518
519
520
521
|
# File 'lib/mirah/jvm/types/methods.rb', line 515
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
|
46
47
48
|
# File 'lib/mirah/jvm/types/type_definition.rb', line 46
def meta
@meta ||= TypeDefMeta.new(self)
end
|
15
16
17
18
19
20
21
|
# File 'lib/mirah/jvm/types/type_definition.rb', line 15
def name
if @type
@type.name.tr('/', '.')
else
@name
end
end
|
#static_methods ⇒ Object
567
568
569
|
# File 'lib/mirah/jvm/types/methods.rb', line 567
def static_methods
@static_methods ||= Hash.new {|h, k| h[k] = []}
end
|
#superclass ⇒ Object
23
24
25
|
# File 'lib/mirah/jvm/types/type_definition.rb', line 23
def superclass
(node && node.superclass) || Object
end
|