Class: Mirah::AST::Annotation

Inherits:
Node
  • Object
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.



297
298
299
300
301
302
303
304
305
306
307
# File 'lib/mirah/ast/structure.rb', line 297

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

#runtimeObject Also known as: runtime?

Returns the value of attribute runtime.



292
293
294
# File 'lib/mirah/ast/structure.rb', line 292

def runtime
  @runtime
end

#valuesObject (readonly)

Returns the value of attribute values.



291
292
293
# File 'lib/mirah/ast/structure.rb', line 291

def values
  @values
end

Instance Method Details

#[](name) ⇒ Object



321
322
323
# File 'lib/mirah/ast/structure.rb', line 321

def [](name)
  @values[name]
end

#[]=(name, value) ⇒ Object



317
318
319
# File 'lib/mirah/ast/structure.rb', line 317

def []=(name, value)
  @values[name] = value
end

#annotation_value(node, typer) ⇒ Object



337
338
339
340
341
342
343
344
345
346
347
348
349
# File 'lib/mirah/ast/structure.rb', line 337

def annotation_value(node, typer)
  case node
  when String
    java.lang.String.new(node.literal)
  when Array
    node.children.map {|node| annotation_value(node, typer)}
  else
    # TODO Support other types
    ref = value.type_refence(typer)
    desc = BiteScript::Signature.class_id(ref)
    BiteScript::ASM::Type.getType(desc)
  end
end

#infer(typer, expression) ⇒ Object



325
326
327
328
329
330
331
332
333
334
335
# File 'lib/mirah/ast/structure.rb', line 325

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

#nameObject



309
310
311
# File 'lib/mirah/ast/structure.rb', line 309

def name
  @name
end

#typeObject



313
314
315
# File 'lib/mirah/ast/structure.rb', line 313

def type
  BiteScript::ASM::Type.getObjectType(@name.tr('.', '/'))
end