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

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

Instance Method Summary collapse

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, name) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/mirah/jvm/types/extensions.rb', line 80

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

#__included_method(name, types) ⇒ Object



96
97
98
99
100
101
102
# File 'lib/mirah/jvm/types/extensions.rb', line 96

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, name)
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, name)
end

#find_callable_methods(name, include_interfaces = false) ⇒ Object



72
73
74
# File 'lib/mirah/jvm/types/extensions.rb', line 72

def find_callable_methods(name, include_interfaces=false)
  __combine_methods(__getobj__.find_callable_methods(name, include_interfaces), name)
end

#find_callable_static_methods(name) ⇒ Object



76
77
78
# File 'lib/mirah/jvm/types/extensions.rb', line 76

def find_callable_static_methods(name)
  __combine_methods(__getobj__.find_callable_static_methods(name), name)
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