Class: Mirah::AST::Annotation
- Inherits:
-
Node
- Object
- Node
- Mirah::AST::Annotation
show all
- Defined in:
- lib/mirah/ast/structure.rb
Instance Attribute Summary collapse
Attributes inherited from Node
#children, #inferred_type, #newline, #parent, #position
Instance Method Summary
collapse
Methods inherited from 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(parent, position, name = nil, &block) ⇒ Annotation
Returns a new instance of Annotation.
300
301
302
303
304
305
306
307
308
309
310
|
# File 'lib/mirah/ast/structure.rb', line 300
def initialize(parent, position, name=nil, &block)
super(parent, position, &block)
if name
@name = if name.respond_to?(:class_name)
name.class_name
else
name.name
end
end
@values = {}
end
|
Instance Attribute Details
#runtime ⇒ Object
Also known as:
runtime?
Returns the value of attribute runtime.
295
296
297
|
# File 'lib/mirah/ast/structure.rb', line 295
def runtime
@runtime
end
|
#values ⇒ Object
Returns the value of attribute values.
294
295
296
|
# File 'lib/mirah/ast/structure.rb', line 294
def values
@values
end
|
Instance Method Details
#[](name) ⇒ Object
324
325
326
|
# File 'lib/mirah/ast/structure.rb', line 324
def [](name)
@values[name]
end
|
#[]=(name, value) ⇒ Object
320
321
322
|
# File 'lib/mirah/ast/structure.rb', line 320
def []=(name, value)
@values[name] = value
end
|
#annotation_value(node, typer) ⇒ Object
340
341
342
343
344
345
346
347
348
349
350
351
352
|
# File 'lib/mirah/ast/structure.rb', line 340
def annotation_value(node, typer)
case node
when String
java.lang.String.new(node.literal)
when Fixnum
java.lang.Integer.new(node.literal)
when Array
node.children.map {|node| annotation_value(node, typer)}
else
raise "Unsupported Annotation Value Type"
end
end
|
#infer(typer, expression) ⇒ Object
328
329
330
331
332
333
334
335
336
337
338
|
# File 'lib/mirah/ast/structure.rb', line 328
def infer(typer, expression)
@inferred ||= begin
@name = name_node.type_reference(typer).name if name_node
@values.each do |name, value|
if Node === value
@values[name] = annotation_value(value, typer)
end
end
true
end
end
|
#name ⇒ Object
312
313
314
|
# File 'lib/mirah/ast/structure.rb', line 312
def name
@name
end
|
#type ⇒ Object
316
317
318
|
# File 'lib/mirah/ast/structure.rb', line 316
def type
BiteScript::ASM::Type.getObjectType(@name.tr('.', '/'))
end
|