Module: Mirah::JavaSource::Helper
- Included in:
- ClassBuilder, JsniMethodBuilder, MethodBuilder
- Defined in:
- lib/mirah/jvm/source_generator/builder.rb
Instance Method Summary collapse
- #annotate(annotations) ⇒ Object
- #annotation_value(value) ⇒ Object
- #block(line = '') ⇒ Object
- #dedent ⇒ Object
- #indent ⇒ Object
- #init_value(type) ⇒ Object
- #print(*args) ⇒ Object
- #puts(*args) ⇒ Object
Instance Method Details
#annotate(annotations) ⇒ Object
152 153 154 155 156 |
# File 'lib/mirah/jvm/source_generator/builder.rb', line 152 def annotate(annotations) annotations.each do |annotation| puts annotation_value(annotation) end end |
#annotation_value(value) ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/mirah/jvm/source_generator/builder.rb', line 158 def annotation_value(value) case value when Java::JavaLang::Integer value.to_s when Java::JavaLang::String, String value.to_s.inspect when Array values = value.map{|x|annotation_value(x)}.join(", ") "{#{values}}" when BiteScript::ASM::Type value.getClassName.gsub("$", ".") when Mirah::AST::Annotation name = value.name.gsub("$", ".") values = value.values.map {|n, v| "#{n}=#{annotation_value(v)}"} "@#{name}(#{values.join ', '})" else raise "Unsupported annotation value #{value.inspect}" end end |
#block(line = '') ⇒ Object
132 133 134 135 136 137 138 |
# File 'lib/mirah/jvm/source_generator/builder.rb', line 132 def block(line='') puts line + " {" indent yield dedent puts "}" end |
#dedent ⇒ Object
128 129 130 |
# File 'lib/mirah/jvm/source_generator/builder.rb', line 128 def dedent @out.dedent end |
#indent ⇒ Object
124 125 126 |
# File 'lib/mirah/jvm/source_generator/builder.rb', line 124 def indent @out.indent end |
#init_value(type) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/mirah/jvm/source_generator/builder.rb', line 140 def init_value(type) # TODO move this to types? case type when JVMTypes::Boolean 'false' when JVMTypes::PrimitiveType, JVMTypes::NarrowingType '0' else 'null' end end |
#print(*args) ⇒ Object
120 121 122 |
# File 'lib/mirah/jvm/source_generator/builder.rb', line 120 def print(*args) @out.print(*args) end |
#puts(*args) ⇒ Object
116 117 118 |
# File 'lib/mirah/jvm/source_generator/builder.rb', line 116 def puts(*args) @out.puts(*args) end |