Module: BiteScript::Annotatable

Included in:
ClassBuilder, MethodBuilder
Defined in:
lib/bitescript/builder.rb,
lib/bitescript/asm3/builder.rb

Instance Method Summary collapse

Instance Method Details

#annotate(cls, runtime = nil) {|annotation| ... } ⇒ Object

Yields:

  • (annotation)


64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/bitescript/builder.rb', line 64

def annotate(cls, runtime=nil)
  if runtime.nil?
    retention = find_retention(cls)
    return if retention == 'SOURCE'
    runtime = retention == 'RUNTIME'
  end

  annotation = visit_annotation(Signature.ci(cls), runtime)
  annotation.extend AnnotationBuilder

  yield annotation
  annotation.visit_end
end

#find_retention(cls) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/bitescript/builder.rb', line 78

def find_retention(cls)
  if cls.kind_of?(BiteScript::ASM::ClassMirror)
    retention = cls.getDeclaredAnnotation('java.lang.annotation.Retention')
  elsif cls.kind_of?(BiteScript::ASM::Type)
    mirror = BiteScript::ASM::ClassMirror.for_name(cls.class_name) rescue nil
    return find_retention(mirror) if mirror
  elsif Java::JavaClass === cls
    retention = cls.annotation(Retention.java_class)
  else
    retention = cls.java_class.annotation(Retention.java_class)
  end
  return 'CLASS' if retention.nil?
  return retention.value.name
end