Class: BiteScript::ASM::ClassMirror
- Inherits:
-
Object
- Object
- BiteScript::ASM::ClassMirror
show all
- Includes:
- Annotated, Modifiers
- Defined in:
- lib/bitescript/mirror.rb,
lib/bitescript/asm3/mirror.rb
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.
172
173
174
175
176
177
178
179
180
|
# File 'lib/bitescript/mirror.rb', line 172
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.
169
170
171
|
# File 'lib/bitescript/mirror.rb', line 169
def interfaces
@interfaces
end
|
#signature ⇒ Object
Returns the value of attribute signature.
170
171
172
|
# File 'lib/bitescript/mirror.rb', line 170
def signature
@signature
end
|
#superclass ⇒ Object
Returns the value of attribute superclass.
170
171
172
|
# File 'lib/bitescript/mirror.rb', line 170
def superclass
@superclass
end
|
#type ⇒ Object
Returns the value of attribute type.
169
170
171
|
# File 'lib/bitescript/mirror.rb', line 169
def type
@type
end
|
Class Method Details
.for_name(name) ⇒ Object
195
196
197
|
# File 'lib/bitescript/mirror.rb', line 195
def self.for_name(name)
load(name)
end
|
.load(name_or_bytes) ⇒ Object
182
183
184
185
186
187
188
189
190
191
192
193
|
# File 'lib/bitescript/mirror.rb', line 182
def self.load(name_or_bytes)
builder = BiteScript::ASM::ClassMirror::Builder.new
if name_or_bytes.kind_of?(String)
classname = name_or_bytes.tr('.', '/') + ".class"
stream = JRuby.runtime.jruby_class_loader.getResourceAsStream(
classname)
raise NameError, "Class '#{name_or_bytes}' not found." unless stream
name_or_bytes = stream
end
BiteScript::ASM::ClassReader.new(name_or_bytes).accept(builder, 3)
builder.mirror
end
|
Instance Method Details
#addConstructor(constructor) ⇒ Object
207
208
209
|
# File 'lib/bitescript/mirror.rb', line 207
def addConstructor(constructor)
@constructors[constructor.parameters] = constructor
end
|
#addField(field) ⇒ Object
246
247
248
|
# File 'lib/bitescript/mirror.rb', line 246
def addField(field)
@fields[field.name] = field
end
|
#addMethod(method) ⇒ Object
226
227
228
229
230
231
232
233
234
235
236
|
# File 'lib/bitescript/mirror.rb', line 226
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
|
#generic_interfaces ⇒ Object
258
259
260
|
# File 'lib/bitescript/mirror.rb', line 258
def generic_interfaces
signature.interfaces if signature
end
|
#generic_superclass ⇒ Object
254
255
256
|
# File 'lib/bitescript/mirror.rb', line 254
def generic_superclass
signature.superclass if signature
end
|
#getConstructor(*arg_types) ⇒ Object
199
200
201
|
# File 'lib/bitescript/mirror.rb', line 199
def getConstructor(*arg_types)
@constructors[arg_types]
end
|
#getConstructors ⇒ Object
203
204
205
|
# File 'lib/bitescript/mirror.rb', line 203
def getConstructors
@constructors.values
end
|
#getDeclaredFields ⇒ Object
242
243
244
|
# File 'lib/bitescript/mirror.rb', line 242
def getDeclaredFields
@fields.values
end
|
#getDeclaredMethod(name, *args) ⇒ Object
211
212
213
214
215
216
|
# File 'lib/bitescript/mirror.rb', line 211
def getDeclaredMethod(name, *args)
if args[0].kind_of?(Array)
args = args[0]
end
@methods[name][args]
end
|
#getDeclaredMethods(name = nil) ⇒ Object
218
219
220
221
222
223
224
|
# File 'lib/bitescript/mirror.rb', line 218
def getDeclaredMethods(name=nil)
if name
@methods[name].values
else
@methods.values.map {|m| m.values}.flatten
end
end
|
#getField(name) ⇒ Object
238
239
240
|
# File 'lib/bitescript/mirror.rb', line 238
def getField(name)
@fields[name]
end
|
#inspect ⇒ Object
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
|
# File 'lib/bitescript/mirror.rb', line 262
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
|
#type_parameters ⇒ Object
250
251
252
|
# File 'lib/bitescript/mirror.rb', line 250
def type_parameters
signature.type_parameters is signature
end
|