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.
333
334
335
336
337
338
339
340
341
342
343
|
# File 'lib/mirah/ast/structure.rb', line 333
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.
328
329
330
|
# File 'lib/mirah/ast/structure.rb', line 328
def runtime
@runtime
end
|
#values ⇒ Object
Returns the value of attribute values.
327
328
329
|
# File 'lib/mirah/ast/structure.rb', line 327
def values
@values
end
|
Instance Method Details
#[](name) ⇒ Object
357
358
359
|
# File 'lib/mirah/ast/structure.rb', line 357
def [](name)
@values[name]
end
|
#[]=(name, value) ⇒ Object
353
354
355
|
# File 'lib/mirah/ast/structure.rb', line 353
def []=(name, value)
@values[name] = value
end
|
#annotation_value(node, typer) ⇒ Object
373
374
375
376
377
378
379
380
381
382
383
384
385
|
# File 'lib/mirah/ast/structure.rb', line 373
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
361
362
363
364
365
366
367
368
369
370
371
|
# File 'lib/mirah/ast/structure.rb', line 361
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
345
346
347
|
# File 'lib/mirah/ast/structure.rb', line 345
def name
@name
end
|
#type ⇒ Object
349
350
351
|
# File 'lib/mirah/ast/structure.rb', line 349
def type
BiteScript::ASM::Type.getObjectType(@name.tr('.', '/'))
end
|