Class: Duby::JVM::Types::TypeDefinition
- Inherits:
-
Type
show all
- Defined in:
- lib/duby/jvm/types.rb,
lib/duby/jvm/types/methods.rb
Constant Summary
MethodLookup::BOOLEAN, MethodLookup::BYTE, MethodLookup::CHAR, MethodLookup::DOUBLE, MethodLookup::FLOAT, MethodLookup::INT, MethodLookup::LONG, MethodLookup::PrimitiveConversions, MethodLookup::SHORT
AST::TypeReference::ErrorType, AST::TypeReference::NoType, AST::TypeReference::NullType, AST::TypeReference::UnreachableType
Instance Attribute Summary collapse
#array
Attributes inherited from AST::Node
#children, #inferred_type, #newline, #parent, #position
Instance Method Summary
collapse
Methods inherited from Type
#add_intrinsics, #add_method, #aload, #array?, #array_type, #assignable_from?, #astore, #basic_type, #compatible?, #component_type, #declared_intrinsics, #get_method, #init_value, #inspect, #interface?, #intrinsics, #is_parent, #iterable?, #jvm_type, #load, #meta?, #newarray, #prefix, #primitive?, #return, #store, #to_source, #unmeta, #void?, #wide?
#each_is_exact, #each_is_exact_or_subtype_or_convertible, #find_jls, #find_method, #is_more_specific?, #log, #phase1, #phase2, #phase3, #primitive_convertible?
#==, #compatible?, #component_type, #eql?, #error?, #hash, #is_parent, #iterable?, #meta?, #narrow, #primitive?, #to_s, #unmeta, #unreachable?
Methods included from AST::Named
#to_s
Methods inherited from AST::Node
#[], #each, #expr?, #inspect, #line_number, #log, #precompile, #resolve_if, #resolved!, #resolved?, #simple_name, #temp, #to_s
Constructor Details
Returns a new instance of TypeDefinition.
262
263
264
265
266
267
268
269
270
271
|
# File 'lib/duby/jvm/types.rb', line 262
def initialize(name, node)
if name.class_builder?
super(name)
else
raise ArgumentError, "Bad name #{name}" if name[0,1] == '.'
@name = name
end
@node = node
raise ArgumentError, "Bad type #{name}" if self.name =~ /Java::/
end
|
Instance Attribute Details
Returns the value of attribute node.
260
261
262
|
# File 'lib/duby/jvm/types.rb', line 260
def node
@node
end
|
Instance Method Details
#constructor(*types) ⇒ Object
286
287
288
289
290
|
# File 'lib/duby/jvm/types/methods.rb', line 286
def constructor(*types)
constructor = constructors.find {|c| c.argument_types == types}
return constructor if constructor
raise NameError, "No constructo #{name}(#{types.join ', '})"
end
|
#constructors ⇒ Object
300
301
302
|
# File 'lib/duby/jvm/types/methods.rb', line 300
def constructors
@constructors ||= []
end
|
#declare_method(name, arguments, type, exceptions) ⇒ Object
312
313
314
315
316
317
318
319
|
# File 'lib/duby/jvm/types/methods.rb', line 312
def declare_method(name, arguments, type, exceptions)
member = DubyMember.new(self, name, arguments, type, false, exceptions)
if name == 'initialize'
constructors << JavaConstructor.new(member)
else
instance_methods[name] << JavaMethod.new(member)
end
end
|
#declare_static_method(name, arguments, type, exceptions) ⇒ Object
321
322
323
324
|
# File 'lib/duby/jvm/types/methods.rb', line 321
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 ⇒ Object
296
297
298
|
# File 'lib/duby/jvm/types/methods.rb', line 296
def declared_class_methods
static_methods.values.flatten
end
|
#declared_instance_methods ⇒ Object
292
293
294
|
# File 'lib/duby/jvm/types/methods.rb', line 292
def declared_instance_methods
instance_methods.values.flatten
end
|
#define(builder) ⇒ Object
293
294
295
296
|
# File 'lib/duby/jvm/types.rb', line 293
def define(builder)
class_name = @name.tr('.', '/')
@type ||= builder.public_class(class_name, superclass, *interfaces)
end
|
#instance_methods ⇒ Object
304
305
306
|
# File 'lib/duby/jvm/types/methods.rb', line 304
def instance_methods
@instance_methods ||= Hash.new {|h, k| h[k] = []}
end
|
#interfaces ⇒ Object
285
286
287
288
289
290
291
|
# File 'lib/duby/jvm/types.rb', line 285
def interfaces
if node
node.interfaces
else
[]
end
end
|
#java_method(name, *types) ⇒ Object
274
275
276
277
278
|
# File 'lib/duby/jvm/types/methods.rb', line 274
def java_method(name, *types)
method = instance_methods[name].find {|m| m.argument_types == types}
return method if method
raise NameError, "No method #{self.name}.#{name}(#{types.join ', '})"
end
|
#java_static_method(name, *types) ⇒ Object
280
281
282
283
284
|
# File 'lib/duby/jvm/types/methods.rb', line 280
def java_static_method(name, *types)
method = static_methods[name].find {|m| m.argument_types == types}
return method if method
raise NameError, "No method #{self.name}.#{name}(#{types.join ', '})"
end
|
298
299
300
|
# File 'lib/duby/jvm/types.rb', line 298
def meta
@meta ||= TypeDefMeta.new(self)
end
|
273
274
275
276
277
278
279
|
# File 'lib/duby/jvm/types.rb', line 273
def name
if @type
@type.name
else
@name
end
end
|
#static_methods ⇒ Object
308
309
310
|
# File 'lib/duby/jvm/types/methods.rb', line 308
def static_methods
@static_methods ||= Hash.new {|h, k| h[k] = []}
end
|
#superclass ⇒ Object
281
282
283
|
# File 'lib/duby/jvm/types.rb', line 281
def superclass
(node && node.superclass) || Object
end
|