Class: BiteScript::ASM::ClassMirror
Defined Under Namespace
Classes: Builder
Instance Attribute Summary collapse
Attributes included from Modifiers
#flags
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Modifiers
add_modifier
Methods included from Annotated
#addAnnotation, #annotations, #declaredAnnotations, #getDeclaredAnnotation, #inspect_annotations
Constructor Details
#initialize(type, flags) ⇒ ClassMirror
Returns a new instance of ClassMirror.
171
172
173
174
175
176
177
178
179
|
# File 'lib/bitescript/mirror.rb', line 171
def initialize(type, flags)
super()
@type = type
@flags = flags
@methods = Hash.new {|h, k| h[k] = {}}
@constructors = {}
@fields = {}
@interfaces = []
end
|
Instance Attribute Details
#interfaces ⇒ Object
Returns the value of attribute interfaces.
168
169
170
|
# File 'lib/bitescript/mirror.rb', line 168
def interfaces
@interfaces
end
|
#superclass ⇒ Object
Returns the value of attribute superclass.
169
170
171
|
# File 'lib/bitescript/mirror.rb', line 169
def superclass
@superclass
end
|
#type ⇒ Object
Returns the value of attribute type.
168
169
170
|
# File 'lib/bitescript/mirror.rb', line 168
def type
@type
end
|
Class Method Details
.load(name_or_bytes) ⇒ Object
181
182
183
184
185
|
# File 'lib/bitescript/mirror.rb', line 181
def self.load(name_or_bytes)
builder = BiteScript::ASM::ClassMirror::Builder.new
BiteScript::ASM::ClassReader.new(name_or_bytes).accept(builder, 3)
builder.mirror
end
|
Instance Method Details
#addConstructor(constructor) ⇒ Object
196
197
198
|
# File 'lib/bitescript/mirror.rb', line 196
def addConstructor(constructor)
@constructors[constructor.parameters] = constructor
end
|
#addField(field) ⇒ Object
235
236
237
|
# File 'lib/bitescript/mirror.rb', line 235
def addField(field)
@fields[field.name] = field
end
|
#addMethod(method) ⇒ Object
215
216
217
218
219
220
221
222
223
224
225
|
# File 'lib/bitescript/mirror.rb', line 215
def addMethod(method)
return if method.synthetic?
type_names = method.argument_types.map {|type| type.descriptor}
if method.name == '<init>'
@constructors[type_names] = method
else
@methods[method.name][type_names] = method
end
end
|
#getConstructor(*arg_types) ⇒ Object
188
189
190
|
# File 'lib/bitescript/mirror.rb', line 188
def getConstructor(*arg_types)
@constructors[arg_types]
end
|
#getConstructors ⇒ Object
192
193
194
|
# File 'lib/bitescript/mirror.rb', line 192
def getConstructors
@constructors.values
end
|
#getDeclaredFields ⇒ Object
231
232
233
|
# File 'lib/bitescript/mirror.rb', line 231
def getDeclaredFields
@fields.values
end
|
#getDeclaredMethod(name, *args) ⇒ Object
200
201
202
203
204
205
|
# File 'lib/bitescript/mirror.rb', line 200
def getDeclaredMethod(name, *args)
if args[0].kind_of?(Array)
args = args[0]
end
@methods[name][args]
end
|
#getDeclaredMethods(name = nil) ⇒ Object
207
208
209
210
211
212
213
|
# File 'lib/bitescript/mirror.rb', line 207
def getDeclaredMethods(name=nil)
if name
@methods[name].values
else
@methods.values.map {|m| m.values}.flatten
end
end
|
#getField(name) ⇒ Object
227
228
229
|
# File 'lib/bitescript/mirror.rb', line 227
def getField(name)
@fields[name]
end
|
#inspect ⇒ Object
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
|
# File 'lib/bitescript/mirror.rb', line 239
def inspect
if annotation?
kind = "@interface"
elsif interface?
kind = "interface"
elsif enum?
kind = "enum"
else
kind = "class"
end
if superclass && !enum? && !interface?
extends = "extends #{superclass.getClassName} "
end
if self.interfaces && !self.interfaces.empty?
interfaces = self.interfaces.map{|i| i.class_name}.join(', ')
if interface?
extends = "extends #{interfaces} "
else
implements = "implements #{interfaces} "
end
end
result = "#{inspect_annotations}#{modifier_string}#{kind} "
result << "#{type.class_name} #{extends}{\n"
(getDeclaredFields + getConstructors + getDeclaredMethods).each do |f|
result << f.inspect << "\n"
end
result << "}"
end
|