Class: Mirah::JVM::Types::ExtendedType

Inherits:
Type show all
Defined in:
lib/mirah/jvm/types/extensions.rb

Constant Summary

Constants inherited from AST::TypeReference

AST::TypeReference::BlockType, AST::TypeReference::ErrorType, AST::TypeReference::NoType, AST::TypeReference::NullType, AST::TypeReference::UnreachableType

Instance Attribute Summary

Attributes inherited from Type

#inner_class

Attributes inherited from AST::TypeReference

#array

Attributes included from AST::Named

#name

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, #constructor, #declared_constructors, #declared_intrinsics, #dynamic?, #expand_each, #field_getter, #field_setter, #full_name, #init_value, #inner_class?, #inner_class_getter, #inspect, #interface?, #interfaces, #intrinsics, #is_parent, #iterable?, #jvm_type, #load, #load_extensions, #log, #meta?, #newarray, #pop, #prefix, #primitive?, #return, #store, #superclass, #to_source, #void?, #wide?, #wrap_with_scoped_body

Methods included from MethodLookup

#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?

Methods inherited from AST::TypeReference

#==, #_dump, _load, #basic_type, #block?, #compatible?, #component_type, #eql?, #error?, #full_name, #hash, #is_parent, #iterable?, #meta?, #narrow, #null?, #primitive?, #to_s, #type_reference, #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

#initialize(*args) ⇒ ExtendedType

Returns a new instance of ExtendedType.



20
21
22
23
# File 'lib/mirah/jvm/types/extensions.rb', line 20

def initialize(*args)
  super
  @static_includes = []
end

Instance Method Details

#__combine_methods(basic_methods) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/mirah/jvm/types/extensions.rb', line 72

def __combine_methods(basic_methods)
  methods = {}
  basic_methods.each do |method|
    key = [method.name, method.parameter_types, method.return_type]
    methods[key] = method
  end
  @static_includes.each do |type|
    type.declared_class_methods.each do |method|
      key = [method.name, method.parameter_types, method.return_type]
      methods[key] ||= method
    end
  end
  methods.values
end

#__included_method(name, types) ⇒ Object



87
88
89
90
91
92
93
# File 'lib/mirah/jvm/types/extensions.rb', line 87

def __included_method(name, types)
  @static_includes.each do |type|
    method = type.meta.java_method(name, *types)
    return method if method
  end
  nil
end

#declared_class_methods(name = nil) ⇒ Object



68
69
70
# File 'lib/mirah/jvm/types/extensions.rb', line 68

def declared_class_methods(name=nil)
  __combine_methods(__getobj__.declared_class_methods)
end

#declared_instance_methods(name = nil) ⇒ Object



64
65
66
# File 'lib/mirah/jvm/types/extensions.rb', line 64

def declared_instance_methods(name=nil)
  __combine_methods(__getobj__.declared_instance_methods)
end

#get_method(name, args) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/mirah/jvm/types/extensions.rb', line 46

def get_method(name, args)
  method = __getobj__.get_method(name, args)
  return method if method
  @static_includes.each do |type|
    method = type.meta.get_method(name, args)
    return method if method
  end
  nil
end

#include(type) ⇒ Object



25
26
27
28
# File 'lib/mirah/jvm/types/extensions.rb', line 25

def include(type)
  @static_includes << type
  self
end

#java_method(name, *types) ⇒ Object



56
57
58
# File 'lib/mirah/jvm/types/extensions.rb', line 56

def java_method(name, *types)
  __getobj__.java_method(name, *types) || __included_method(name, types)
end

#java_static_method(name, *types) ⇒ Object



60
61
62
# File 'lib/mirah/jvm/types/extensions.rb', line 60

def java_static_method(name, *types)
  __getobj__.java_static_method(name, *types) || __included_method(name, types)
end

#metaObject



30
31
32
33
34
35
36
# File 'lib/mirah/jvm/types/extensions.rb', line 30

def meta
  if meta?
    self
  else
    __getobj__.meta
  end
end

#unmetaObject



38
39
40
41
42
43
44
# File 'lib/mirah/jvm/types/extensions.rb', line 38

def unmeta
  if meta?
    __getobj__.unmeta
  else
    self
  end
end