Class: Mirah::JVM::Types::TypeDefinition
- Inherits:
-
Type
- Object
- Type
- Mirah::JVM::Types::TypeDefinition
show all
- Defined in:
- lib/mirah/jvm/types/type_definition.rb,
lib/mirah/jvm/types/methods.rb
Constant Summary
Logging::Logged::VLEVELS
Instance Attribute Summary collapse
Attributes inherited from Type
#inner_class, #type_system
Instance Method Summary
collapse
-
#abstract? ⇒ Boolean
-
#constructor(*types) ⇒ Object
-
#constructors ⇒ Object
(also: #declared_constructors)
-
#declare_field(name, type, static) ⇒ Object
-
#declare_method(name, arguments, type, exceptions) ⇒ Object
-
#declare_static_method(name, arguments, type, exceptions) ⇒ Object
-
#declared_class_methods(name = nil) ⇒ Object
-
#declared_fields ⇒ Object
-
#declared_instance_methods(name = nil) ⇒ Object
-
#define(builder) ⇒ Object
-
#field_getter(name) ⇒ Object
-
#field_setter(name) ⇒ Object
-
#getDeclaredField(name) ⇒ Object
-
#getDeclaredFields ⇒ Object
-
#hasStaticField(name) ⇒ Object
-
#initialize(types, scope, name, node) ⇒ TypeDefinition
constructor
A new instance of TypeDefinition.
-
#instance_methods ⇒ Object
-
#interface? ⇒ Boolean
-
#interfaces(include_parent = true) ⇒ Object
-
#java_method(name, *types) ⇒ Object
-
#java_static_method(name, *types) ⇒ Object
-
#meta ⇒ Object
-
#name ⇒ Object
-
#static_methods ⇒ Object
-
#superclass ⇒ Object
Methods inherited from Type
#add_compiled_macro, #add_enumerable_macros, #add_intrinsics, #add_method, #add_method_listener, #aload, #ancestors_and_interfaces, #array?, #array_type, #assignableFrom, #assignable_from?, #astore, #basic_type, #class_id, #compatible?, #component_type, #declared_intrinsics, #declared_macros, #dynamic?, #error?, #expand_each, #find_callable_macros, #find_callable_macros2, #find_callable_methods, #find_callable_methods2, #find_callable_static_methods, #flags, #full_name, #generic, #generic?, #getAsmType, #get_method, #include, #init_value, #inner_class?, #inner_class_getter, #inspect, #internal_name, #intrinsics, #isAnnotation, #isArray, #isBlock, #isEnum, #isError, #isGeneric, #isMeta, #isPrimitive, #is_parent, #iterable?, #jvm_type, #load, #load_extensions, #macro, #macros, #matchesAnything, #meta?, #method_listeners, #method_updated, #newarray, #pop, #prefix, #primitive?, #read_macrodef_annotation, #retention, #return, #store, #to_s, #type_parameters, #ungeneric, #unmeta, #void?, #wide?, #widen
#error, #info, #log, #logger, #logger_name, #logging?, #vlog, #warning
#each_is_exact, #each_is_exact_or_subtype_or_convertible, #field_lookup, #find_jls, #find_jls2, #find_method, #find_method2, #inner_class, #is_more_specific?, #phase1, #phase2, #phase3, #primitive_convertible?
Constructor Details
#initialize(types, scope, name, node) ⇒ TypeDefinition
Returns a new instance of TypeDefinition.
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/mirah/jvm/types/type_definition.rb', line 8
def initialize(types, scope, name, node)
raise ArgumentError, "Bad name #{name}" if name[0,1] == '.'
raise ArgumentError, "Bad name #{name}" if name.include? ?/
@type_system = types
@scope = scope
@name = name
@node = node
@fields = {}
raise ArgumentError, "Bad type #{name}" if self.name =~ /Java::/
end
|
Instance Attribute Details
#node ⇒ Object
Returns the value of attribute node.
6
7
8
|
# File 'lib/mirah/jvm/types/type_definition.rb', line 6
def node
@node
end
|
#scope ⇒ Object
Returns the value of attribute scope.
6
7
8
|
# File 'lib/mirah/jvm/types/type_definition.rb', line 6
def scope
@scope
end
|
Instance Method Details
#abstract? ⇒ Boolean
47
48
49
|
# File 'lib/mirah/jvm/types/type_definition.rb', line 47
def abstract?
node && (node.kind_of?(InterfaceDeclaration) || node.annotated_abstract?)
end
|
#constructor(*types) ⇒ Object
801
802
803
804
805
|
# File 'lib/mirah/jvm/types/methods.rb', line 801
def constructor(*types)
constructor = first_matching constructors, types
return constructor if constructor
raise NameError, "No constructor #{name}(#{types.join ', '})"
end
|
#constructors ⇒ Object
Also known as:
declared_constructors
815
816
817
818
819
820
821
822
|
# File 'lib/mirah/jvm/types/methods.rb', line 815
def constructors
if @constructors.nil?
@constructors = []
declare_method('initialize', [], self, [])
@have_default_constructor = true
end
@constructors
end
|
#declare_field(name, type, static) ⇒ Object
850
851
852
853
854
855
856
|
# File 'lib/mirah/jvm/types/methods.rb', line 850
def declare_field(name, type, static)
if type.isError
declared_fields.delete(name)
return
end
declared_fields[name] ||= MirahMember.new(self, name, [], type, static, [])
end
|
#declare_method(name, arguments, type, exceptions) ⇒ Object
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
|
# File 'lib/mirah/jvm/types/methods.rb', line 858
def declare_method(name, arguments, type, exceptions)
raise "Bad args" unless arguments.all?
if type.isError
instance_methods.delete(name)
method_updated(name)
return
end
member = MirahMember.new(self, name, arguments, type, false, exceptions)
if name == 'initialize'
if constructors.size == 1 && @have_default_constructor
constructors.clear
@have_default_constructor = false
elsif constructors.size > 1 && @have_default_constructor
raise "Invalid state: default constructor but #{constructors.size} constructors"
end
constructors << JavaConstructor.new(@type_system, member)
else
instance_methods[name] << JavaMethod.new(@type_system, member)
end
method_updated(name)
end
|
#declare_static_method(name, arguments, type, exceptions) ⇒ Object
882
883
884
885
886
887
888
889
890
|
# File 'lib/mirah/jvm/types/methods.rb', line 882
def declare_static_method(name, arguments, type, exceptions)
if type.isError
static_methods.delete(name)
else
member = MirahMember.new(self, name, arguments, type, true, exceptions)
static_methods[name] << JavaStaticMethod.new(@type_system, member)
end
method_updated(name)
end
|
#declared_class_methods(name = nil) ⇒ Object
811
812
813
|
# File 'lib/mirah/jvm/types/methods.rb', line 811
def declared_class_methods(name=nil)
declared_methods meta, static_methods, name
end
|
#declared_fields ⇒ Object
846
847
848
|
# File 'lib/mirah/jvm/types/methods.rb', line 846
def declared_fields
@fields ||= {}
end
|
#declared_instance_methods(name = nil) ⇒ Object
807
808
809
|
# File 'lib/mirah/jvm/types/methods.rb', line 807
def declared_instance_methods(name=nil)
declared_methods self, instance_methods, name
end
|
#define(builder) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/mirah/jvm/types/type_definition.rb', line 51
def define(builder)
class_name = name.tr('.', '/')
is_interface = node && node.kind_of?(InterfaceDeclaration)
@type ||= builder.define_class(
class_name,
:visibility => :public,
:abstract => abstract?,
:interface => is_interface,
:superclass => superclass,
:interfaces => interfaces)
end
|
#field_getter(name) ⇒ Object
896
897
898
|
# File 'lib/mirah/jvm/types/methods.rb', line 896
def field_getter(name)
nil
end
|
#field_setter(name) ⇒ Object
900
901
902
|
# File 'lib/mirah/jvm/types/methods.rb', line 900
def field_setter(name)
nil
end
|
#getDeclaredField(name) ⇒ Object
837
838
839
|
# File 'lib/mirah/jvm/types/methods.rb', line 837
def getDeclaredField(name)
@fields[name]
end
|
#getDeclaredFields ⇒ Object
833
834
835
|
# File 'lib/mirah/jvm/types/methods.rb', line 833
def getDeclaredFields
@fields.values.to_java(JVMMethod)
end
|
#hasStaticField(name) ⇒ Object
841
842
843
844
|
# File 'lib/mirah/jvm/types/methods.rb', line 841
def hasStaticField(name)
f = getDeclaredField(name)
f && f.static?
end
|
#instance_methods ⇒ Object
825
826
827
|
# File 'lib/mirah/jvm/types/methods.rb', line 825
def instance_methods
@instance_methods ||= Hash.new {|h, k| h[k] = []}
end
|
#interface? ⇒ Boolean
892
893
894
|
# File 'lib/mirah/jvm/types/methods.rb', line 892
def interface?
false
end
|
#interfaces(include_parent = true) ⇒ Object
39
40
41
42
43
44
45
|
# File 'lib/mirah/jvm/types/type_definition.rb', line 39
def interfaces(include_parent=true)
if node
node.interfaces.map {|n| @type_system.get(scope, n.typeref).resolve}
else
[]
end
end
|
#java_method(name, *types) ⇒ Object
785
786
787
788
789
790
791
|
# File 'lib/mirah/jvm/types/methods.rb', line 785
def java_method(name, *types)
method = first_matching instance_methods[name], 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
793
794
795
796
797
798
799
|
# File 'lib/mirah/jvm/types/methods.rb', line 793
def java_static_method(name, *types)
method = first_matching static_methods[name], types
return method if method
intrinsic = meta.intrinsics[name][types]
return intrinsic if intrinsic
raise NameError, "No method #{self.name}.#{name}(#{types.join ', '})"
end
|
63
64
65
|
# File 'lib/mirah/jvm/types/type_definition.rb', line 63
def meta
@meta ||= TypeDefMeta.new(self)
end
|
#name ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/mirah/jvm/types/type_definition.rb', line 19
def name
if @type
@type.name.tr('/', '.')
else
if !@name.include?(?.) && scope.package
"#{scope.package}.#{@name}"
else
@name
end
end
end
|
#static_methods ⇒ Object
829
830
831
|
# File 'lib/mirah/jvm/types/methods.rb', line 829
def static_methods
@static_methods ||= Hash.new {|h, k| h[k] = []}
end
|
#superclass ⇒ Object
31
32
33
34
35
36
37
|
# File 'lib/mirah/jvm/types/type_definition.rb', line 31
def superclass
if node && node.superclass
@type_system.get(scope, node.superclass.typeref).resolve
else
@type_system.type(nil, 'java.lang.Object')
end
end
|