bitescript 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +26 -0
- data/Rakefile +1 -2
- data/bitescript.gemspec +1 -1
- data/lib/bitescript.rb +15 -1
- data/lib/bitescript/asm3/builder.rb +27 -2
- data/lib/bitescript/asm3/bytecode.rb +1 -0
- data/lib/bitescript/asm3/mirror.rb +42 -13
- data/lib/bitescript/builder.rb +28 -4
- data/lib/bitescript/mirror.rb +40 -18
- data/test/test_builder.rb +1 -2
- data/test/test_generics.rb +8 -0
- data/test/test_mirror.rb +19 -0
- metadata +5 -3
data/History.txt
CHANGED
@@ -1,3 +1,29 @@
|
|
1
|
+
=== 0.1.2 / 2013-02-24
|
2
|
+
|
3
|
+
3ff2e52 ensure that frame setting is updated when bytecode version is
|
4
|
+
24e8363 add aliases for h_* opcodes for asm3 support
|
5
|
+
67e22e6 fix up test for 1.7
|
6
|
+
1e7add0 oops there's no assert_false
|
7
|
+
83d5862 clean up rake file
|
8
|
+
8a72f8e add varargs support to mirrors
|
9
|
+
a8e2b4d ignore parameter annotations instead of blowing up when building a mirror
|
10
|
+
|
11
|
+
=== 0.1.1 / 2012-11-02
|
12
|
+
|
13
|
+
ba61804 Fixes for printing generics
|
14
|
+
99176d7 Fix another typo
|
15
|
+
c92f2a1 Fix generics typo
|
16
|
+
0a44001 Fix using ClassMirrors as an annotation type
|
17
|
+
fc7b508 Fix typo in generics
|
18
|
+
3fdbf72 Modify asm3 stuff to configure frame/stack computation too.
|
19
|
+
f473192 Allow configuring frame and stack computation.
|
20
|
+
79efa1e Update history again for 0.1.0.
|
21
|
+
e47bf31 port the to_widen functionality to asm3
|
22
|
+
7e51ec9 Merge remote-tracking branch 'origin'
|
23
|
+
e8eb48e Update history again for 0.1.0.
|
24
|
+
8db7cc8 Merge branch 'master' of github.com:headius/bitescript
|
25
|
+
b26d74a Add support for overriding getCommonSuperClass for writing frames
|
26
|
+
|
1
27
|
=== 0.1.0 / 2011-11-10
|
2
28
|
|
3
29
|
be71f3f Re-add old ASM3 versions of everything for backward compat.
|
data/Rakefile
CHANGED
data/bitescript.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{bitescript}
|
5
|
-
s.version = "0.1.
|
5
|
+
s.version = "0.1.2"
|
6
6
|
s.authors = ["Charles Oliver Nutter", "Ryan Brown"]
|
7
7
|
s.date = Time.now.strftime('%Y-%m-%d')
|
8
8
|
s.description = %q{BiteScript is a Ruby DSL for generating Java bytecode and classes.}
|
data/lib/bitescript.rb
CHANGED
@@ -22,10 +22,24 @@ module BiteScript
|
|
22
22
|
JAVA1_8 = defined?(Opcodes::V1_8) ? Opcodes::V1_8 : Opcodes::V1_7
|
23
23
|
|
24
24
|
class << self
|
25
|
-
|
25
|
+
attr_reader :bytecode_version
|
26
|
+
attr_accessor :compute_frames
|
27
|
+
attr_accessor :compute_maxs
|
28
|
+
|
29
|
+
def bytecode_version= version
|
30
|
+
case version
|
31
|
+
when JAVA1_4, JAVA1_5, JAVA1_6
|
32
|
+
BiteScript.compute_frames = false
|
33
|
+
else
|
34
|
+
BiteScript.compute_frames = true
|
35
|
+
end
|
36
|
+
@bytecode_version = version
|
37
|
+
end
|
26
38
|
|
27
39
|
# Default to JVM version we're running on
|
28
40
|
spec_version = ENV_JAVA['java.specification.version']
|
29
41
|
BiteScript.bytecode_version = BiteScript.const_get("JAVA#{spec_version.gsub('.', '_')}")
|
42
|
+
|
43
|
+
BiteScript.compute_maxs = true
|
30
44
|
end
|
31
45
|
end
|
@@ -126,6 +126,7 @@ module BiteScript
|
|
126
126
|
|
127
127
|
def define_class(class_name, opts, &block)
|
128
128
|
pkg = opts[:package] || @package.dup || []
|
129
|
+
opts[:widen] ||= @widen_proc
|
129
130
|
|
130
131
|
class_name = pkg.empty? ? class_name : "#{pkg.join('/')}/#{class_name}"
|
131
132
|
class_builder = ClassBuilder.new(self, class_name, @file_name, opts)
|
@@ -141,6 +142,10 @@ module BiteScript
|
|
141
142
|
return class_builder
|
142
143
|
end
|
143
144
|
end
|
145
|
+
|
146
|
+
def to_widen(&block)
|
147
|
+
@widen_proc = block
|
148
|
+
end
|
144
149
|
|
145
150
|
def public_class(class_name, superclass = java.lang.Object, *interfaces, &block)
|
146
151
|
define_class(class_name, :visibility => :public, :superclass => superclass, :interfaces => interfaces, &block)
|
@@ -202,6 +207,22 @@ module BiteScript
|
|
202
207
|
end
|
203
208
|
end
|
204
209
|
|
210
|
+
|
211
|
+
class CustomClassWriter < BiteScript::ASM::ClassWriter
|
212
|
+
def initialize(*args, &block)
|
213
|
+
super(*args)
|
214
|
+
@widen_proc = block
|
215
|
+
end
|
216
|
+
def getCommonSuperClass(a, b)
|
217
|
+
if @widen_proc
|
218
|
+
result = @widen_proc.call(a, b)
|
219
|
+
result
|
220
|
+
else
|
221
|
+
super
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
205
226
|
class ClassBuilder
|
206
227
|
include Util
|
207
228
|
include QuickTypes
|
@@ -232,7 +253,11 @@ module BiteScript
|
|
232
253
|
flags = Opcodes::ACC_INTERFACE | Opcodes::ACC_ABSTRACT
|
233
254
|
end
|
234
255
|
|
235
|
-
@class_writer =
|
256
|
+
@class_writer = CustomClassWriter.new(
|
257
|
+
0 |
|
258
|
+
(BiteScript.compute_frames ? ClassWriter::COMPUTE_FRAMES : 0) |
|
259
|
+
(BiteScript.compute_maxs ? ClassWriter::COMPUTE_MAXS : 0),
|
260
|
+
&opts[:widen])
|
236
261
|
|
237
262
|
interface_paths = []
|
238
263
|
(@interfaces).each {|interface| interface_paths << path(interface)}
|
@@ -594,7 +619,7 @@ module BiteScript
|
|
594
619
|
visit k, v
|
595
620
|
end
|
596
621
|
def annotation(name, cls)
|
597
|
-
if Java::JavaClass === cls || BiteScript::ASM::Type === cls
|
622
|
+
if Java::JavaClass === cls || BiteScript::ASM::Type === cls || BiteScript::ClassMirror === cls
|
598
623
|
java_class = cls
|
599
624
|
else
|
600
625
|
java_class = cls.java_class
|
@@ -289,6 +289,7 @@ module BiteScript
|
|
289
289
|
def #{const_down}(cls, name, *call_sig)
|
290
290
|
MethodHandle.new(Opcodes::#{const_name}, path(cls), name, sig(*call_sig))
|
291
291
|
end
|
292
|
+
alias #{const_down[1..-1]} #{const_down}
|
292
293
|
", b, __FILE__, line
|
293
294
|
OpcodeInstructions[const_name] = const_down
|
294
295
|
when "F_FULL", "ACC_ENUM", "ACC_SYNTHETIC", "ACC_INTERFACE", "ACC_PUBLIC",
|
@@ -113,6 +113,20 @@ module BiteScript::ASM
|
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
116
|
+
module Generics
|
117
|
+
def inspect_type(type)
|
118
|
+
if type.kind_of?(BiteScript::ASM::Type)
|
119
|
+
type.class_name
|
120
|
+
else
|
121
|
+
type.to_s
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def inspect_generic(type, generic_type)
|
126
|
+
inspect_type(generic_type || type)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
116
130
|
module Annotated
|
117
131
|
def annotations
|
118
132
|
@annotations ||= {}
|
@@ -154,6 +168,8 @@ module BiteScript::ASM
|
|
154
168
|
code << "modifiers << '#{name.downcase} ' if #{name.downcase}?\n"
|
155
169
|
end
|
156
170
|
|
171
|
+
add_modifier 'varargs'
|
172
|
+
|
157
173
|
class_eval <<-EOF
|
158
174
|
def modifier_string
|
159
175
|
modifiers = ''
|
@@ -166,6 +182,7 @@ module BiteScript::ASM
|
|
166
182
|
class ClassMirror
|
167
183
|
include Annotated
|
168
184
|
include Modifiers
|
185
|
+
include Generics
|
169
186
|
|
170
187
|
attr_reader :type, :interfaces
|
171
188
|
attr_accessor :superclass, :signature
|
@@ -249,7 +266,7 @@ module BiteScript::ASM
|
|
249
266
|
end
|
250
267
|
|
251
268
|
def type_parameters
|
252
|
-
signature.type_parameters
|
269
|
+
signature.type_parameters if signature
|
253
270
|
end
|
254
271
|
|
255
272
|
def generic_superclass
|
@@ -271,10 +288,12 @@ module BiteScript::ASM
|
|
271
288
|
kind = "class"
|
272
289
|
end
|
273
290
|
if superclass && !enum? && !interface?
|
274
|
-
extends = "extends #{superclass
|
291
|
+
extends = "extends #{inspect_generic(superclass, generic_superclass)} "
|
275
292
|
end
|
276
293
|
if self.interfaces && !self.interfaces.empty?
|
277
|
-
interfaces = self.interfaces.map
|
294
|
+
interfaces = (self.generic_interfaces || self.interfaces).map do |i|
|
295
|
+
inspect_type(i)
|
296
|
+
end.join(', ')
|
278
297
|
if interface?
|
279
298
|
extends = "extends #{interfaces} "
|
280
299
|
else
|
@@ -282,7 +301,8 @@ module BiteScript::ASM
|
|
282
301
|
end
|
283
302
|
end
|
284
303
|
result = "#{inspect_annotations}#{modifier_string}#{kind} "
|
285
|
-
|
304
|
+
typevars = "<#{type_parameters.map{|p| p.to_s}.join ', '}>" if type_parameters && type_parameters.size != 0
|
305
|
+
result << "#{type.class_name}#{typevars} #{extends}{\n"
|
286
306
|
(getDeclaredFields + getConstructors + getDeclaredMethods).each do |f|
|
287
307
|
result << f.inspect << "\n"
|
288
308
|
end
|
@@ -321,6 +341,8 @@ module BiteScript::ASM
|
|
321
341
|
builder
|
322
342
|
end
|
323
343
|
|
344
|
+
def visitParameterAnnotation(paramIndex, desc, visible);end
|
345
|
+
|
324
346
|
def visitField(flags, name, desc, signature, value)
|
325
347
|
signature = GenericTypeBuilder.read(signature)
|
326
348
|
@current = FieldMirror.new(@class.type, flags, name, Type.getType(desc), signature, value)
|
@@ -350,6 +372,7 @@ module BiteScript::ASM
|
|
350
372
|
|
351
373
|
class FieldMirror
|
352
374
|
include Modifiers
|
375
|
+
include Generics
|
353
376
|
include Annotated
|
354
377
|
|
355
378
|
attr_reader :declaring_class, :name, :type, :value, :signature
|
@@ -367,13 +390,15 @@ module BiteScript::ASM
|
|
367
390
|
end
|
368
391
|
|
369
392
|
def inspect
|
370
|
-
|
393
|
+
typename = inspect_generic(type, signature)
|
394
|
+
inspect_annotations + "#{modifier_string}#{typename} #{name};"
|
371
395
|
end
|
372
396
|
end
|
373
397
|
|
374
398
|
class MethodMirror
|
375
399
|
include Modifiers
|
376
400
|
include Annotated
|
401
|
+
include Generics
|
377
402
|
|
378
403
|
attr_reader :declaring_class, :name, :return_type
|
379
404
|
attr_reader :argument_types, :exception_types, :signature
|
@@ -385,6 +410,7 @@ module BiteScript::ASM
|
|
385
410
|
@return_type = return_type
|
386
411
|
@argument_types = parameters
|
387
412
|
@exception_types = exceptions
|
413
|
+
@signature = signature
|
388
414
|
end
|
389
415
|
|
390
416
|
def generic_parameter_types
|
@@ -400,16 +426,18 @@ module BiteScript::ASM
|
|
400
426
|
end
|
401
427
|
|
402
428
|
def type_parameters
|
403
|
-
signature.type_parameters
|
429
|
+
signature.type_parameters if signature
|
404
430
|
end
|
405
431
|
|
406
432
|
def inspect
|
407
|
-
"
|
433
|
+
typevars = "<#{type_parameters.map{|p| p.to_s}.join ', '}> " if type_parameters && type_parameters.size != 0
|
434
|
+
"%s%s%s%s %s(%s);" % [
|
408
435
|
inspect_annotations,
|
409
436
|
modifier_string,
|
410
|
-
|
437
|
+
typevars,
|
438
|
+
inspect_generic(return_type, generic_return_type),
|
411
439
|
name,
|
412
|
-
argument_types.map {|x| x
|
440
|
+
(generic_parameter_types || argument_types).map {|x| inspect_type(x)}.join(', '),
|
413
441
|
]
|
414
442
|
end
|
415
443
|
end
|
@@ -474,6 +502,7 @@ module BiteScript::ASM
|
|
474
502
|
end
|
475
503
|
|
476
504
|
class GenericTypeMirror
|
505
|
+
include Generics
|
477
506
|
def array?
|
478
507
|
false
|
479
508
|
end
|
@@ -529,11 +558,11 @@ module BiteScript::ASM
|
|
529
558
|
def wildcard?
|
530
559
|
true
|
531
560
|
end
|
532
|
-
def to_s
|
561
|
+
def to_s
|
533
562
|
if lower_bound
|
534
|
-
"? super #{lower_bound}"
|
563
|
+
"? super #{inspect_type(lower_bound)}"
|
535
564
|
elsif upper_bound
|
536
|
-
"? extends #{upper_bound}"
|
565
|
+
"? extends #{inspect_type(upper_bound)}"
|
537
566
|
else
|
538
567
|
"?"
|
539
568
|
end
|
@@ -646,4 +675,4 @@ module BiteScript::ASM
|
|
646
675
|
end
|
647
676
|
end
|
648
677
|
end
|
649
|
-
end
|
678
|
+
end
|
data/lib/bitescript/builder.rb
CHANGED
@@ -126,6 +126,7 @@ module BiteScript
|
|
126
126
|
|
127
127
|
def define_class(class_name, opts, &block)
|
128
128
|
pkg = opts[:package] || @package.dup || []
|
129
|
+
opts[:widen] ||= @widen_proc
|
129
130
|
|
130
131
|
class_name = pkg.empty? ? class_name : "#{pkg.join('/')}/#{class_name}"
|
131
132
|
class_builder = ClassBuilder.new(self, class_name, @file_name, opts)
|
@@ -141,7 +142,11 @@ module BiteScript
|
|
141
142
|
return class_builder
|
142
143
|
end
|
143
144
|
end
|
144
|
-
|
145
|
+
|
146
|
+
def to_widen(&block)
|
147
|
+
@widen_proc = block
|
148
|
+
end
|
149
|
+
|
145
150
|
def public_class(class_name, superclass = java.lang.Object, *interfaces, &block)
|
146
151
|
define_class(class_name, :visibility => :public, :superclass => superclass, :interfaces => interfaces, &block)
|
147
152
|
end
|
@@ -201,7 +206,22 @@ module BiteScript
|
|
201
206
|
false
|
202
207
|
end
|
203
208
|
end
|
204
|
-
|
209
|
+
|
210
|
+
class CustomClassWriter < BiteScript::ASM::ClassWriter
|
211
|
+
def initialize(*args, &block)
|
212
|
+
super(*args)
|
213
|
+
@widen_proc = block
|
214
|
+
end
|
215
|
+
def getCommonSuperClass(a, b)
|
216
|
+
if @widen_proc
|
217
|
+
result = @widen_proc.call(a, b)
|
218
|
+
result
|
219
|
+
else
|
220
|
+
super
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
205
225
|
class ClassBuilder
|
206
226
|
include Util
|
207
227
|
include QuickTypes
|
@@ -232,7 +252,11 @@ module BiteScript
|
|
232
252
|
flags = Opcodes::ACC_INTERFACE | Opcodes::ACC_ABSTRACT
|
233
253
|
end
|
234
254
|
|
235
|
-
@class_writer =
|
255
|
+
@class_writer = CustomClassWriter.new(
|
256
|
+
0 |
|
257
|
+
(BiteScript.compute_frames ? ClassWriter::COMPUTE_FRAMES : 0) |
|
258
|
+
(BiteScript.compute_maxs ? ClassWriter::COMPUTE_MAXS : 0),
|
259
|
+
&opts[:widen])
|
236
260
|
|
237
261
|
interface_paths = []
|
238
262
|
(@interfaces).each {|interface| interface_paths << path(interface)}
|
@@ -604,7 +628,7 @@ module BiteScript
|
|
604
628
|
visit k, v
|
605
629
|
end
|
606
630
|
def annotation(name, cls)
|
607
|
-
if Java::JavaClass === cls || BiteScript::ASM::Type === cls
|
631
|
+
if Java::JavaClass === cls || BiteScript::ASM::Type === cls || BiteScript::ClassMirror === cls
|
608
632
|
java_class = cls
|
609
633
|
else
|
610
634
|
java_class = cls.java_class
|
data/lib/bitescript/mirror.rb
CHANGED
@@ -112,6 +112,20 @@ module BiteScript::ASM
|
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
|
+
module Generics
|
116
|
+
def inspect_type(type)
|
117
|
+
if type.kind_of?(BiteScript::ASM::Type)
|
118
|
+
type.class_name
|
119
|
+
else
|
120
|
+
type.to_s
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def inspect_generic(type, generic_type)
|
125
|
+
inspect_type(generic_type || type)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
115
129
|
module Annotated
|
116
130
|
def annotations
|
117
131
|
@annotations ||= {}
|
@@ -153,6 +167,8 @@ module BiteScript::ASM
|
|
153
167
|
code << "modifiers << '#{name.downcase} ' if #{name.downcase}?\n"
|
154
168
|
end
|
155
169
|
|
170
|
+
add_modifier 'varargs'
|
171
|
+
|
156
172
|
class_eval <<-EOF
|
157
173
|
def modifier_string
|
158
174
|
modifiers = ''
|
@@ -165,6 +181,7 @@ module BiteScript::ASM
|
|
165
181
|
class ClassMirror
|
166
182
|
include Annotated
|
167
183
|
include Modifiers
|
184
|
+
include Generics
|
168
185
|
|
169
186
|
attr_reader :type, :interfaces
|
170
187
|
attr_accessor :superclass, :signature
|
@@ -248,7 +265,7 @@ module BiteScript::ASM
|
|
248
265
|
end
|
249
266
|
|
250
267
|
def type_parameters
|
251
|
-
signature.type_parameters
|
268
|
+
signature.type_parameters if signature
|
252
269
|
end
|
253
270
|
|
254
271
|
def generic_superclass
|
@@ -270,22 +287,18 @@ module BiteScript::ASM
|
|
270
287
|
kind = "class"
|
271
288
|
end
|
272
289
|
if superclass && !enum? && !interface?
|
273
|
-
extends = "extends #{superclass
|
290
|
+
extends = "extends #{inspect_generic(superclass, generic_superclass)} "
|
274
291
|
end
|
275
292
|
if self.interfaces && !self.interfaces.empty?
|
276
|
-
interfaces = self.interfaces.map
|
293
|
+
interfaces = (self.generic_interfaces || self.interfaces).map do |i|
|
294
|
+
inspect_type(i)
|
295
|
+
end.join(', ')
|
277
296
|
if interface?
|
278
297
|
extends = "extends #{interfaces} "
|
279
298
|
else
|
280
299
|
implements = "implements #{interfaces} "
|
281
300
|
end
|
282
301
|
end
|
283
|
-
result = "#{inspect_annotations}#{modifier_string}#{kind} "
|
284
|
-
result << "#{type.class_name} #{extends}{\n"
|
285
|
-
(getDeclaredFields + getConstructors + getDeclaredMethods).each do |f|
|
286
|
-
result << f.inspect << "\n"
|
287
|
-
end
|
288
|
-
result << "}"
|
289
302
|
end
|
290
303
|
|
291
304
|
class Builder < BiteScript::ASM::ClassVisitor
|
@@ -321,6 +334,8 @@ module BiteScript::ASM
|
|
321
334
|
builder
|
322
335
|
end
|
323
336
|
|
337
|
+
def visitParameterAnnotation(paramIndex, desc, visible);end
|
338
|
+
|
324
339
|
def visitField(flags, name, desc, signature, value)
|
325
340
|
signature = GenericTypeBuilder.read(signature)
|
326
341
|
mirror = FieldMirror.new(@class.type, flags, name, Type.getType(desc), signature, value)
|
@@ -350,6 +365,7 @@ module BiteScript::ASM
|
|
350
365
|
|
351
366
|
class FieldMirror
|
352
367
|
include Modifiers
|
368
|
+
include Generics
|
353
369
|
include Annotated
|
354
370
|
|
355
371
|
attr_reader :declaring_class, :name, :type, :value, :signature
|
@@ -367,7 +383,8 @@ module BiteScript::ASM
|
|
367
383
|
end
|
368
384
|
|
369
385
|
def inspect
|
370
|
-
|
386
|
+
typename = inspect_generic(type, signature)
|
387
|
+
inspect_annotations + "#{modifier_string}#{typename} #{name};"
|
371
388
|
end
|
372
389
|
|
373
390
|
class Builder < BiteScript::ASM::FieldVisitor
|
@@ -389,6 +406,7 @@ module BiteScript::ASM
|
|
389
406
|
class MethodMirror
|
390
407
|
include Modifiers
|
391
408
|
include Annotated
|
409
|
+
include Generics
|
392
410
|
|
393
411
|
attr_reader :declaring_class, :name, :return_type
|
394
412
|
attr_reader :argument_types, :exception_types, :signature
|
@@ -400,6 +418,7 @@ module BiteScript::ASM
|
|
400
418
|
@return_type = return_type
|
401
419
|
@argument_types = parameters
|
402
420
|
@exception_types = exceptions
|
421
|
+
@signature = signature
|
403
422
|
end
|
404
423
|
|
405
424
|
def generic_parameter_types
|
@@ -415,16 +434,18 @@ module BiteScript::ASM
|
|
415
434
|
end
|
416
435
|
|
417
436
|
def type_parameters
|
418
|
-
signature.type_parameters
|
437
|
+
signature.type_parameters if signature
|
419
438
|
end
|
420
439
|
|
421
440
|
def inspect
|
422
|
-
"
|
441
|
+
typevars = "<#{type_parameters.map{|p| p.to_s}.join ', '}> " if type_parameters && type_parameters.size != 0
|
442
|
+
"%s%s%s%s %s(%s);" % [
|
423
443
|
inspect_annotations,
|
424
444
|
modifier_string,
|
425
|
-
|
445
|
+
typevars,
|
446
|
+
inspect_generic(return_type, generic_return_type),
|
426
447
|
name,
|
427
|
-
argument_types.map {|x| x
|
448
|
+
(generic_parameter_types || argument_types).map {|x| inspect_type(x)}.join(', '),
|
428
449
|
]
|
429
450
|
end
|
430
451
|
|
@@ -506,6 +527,7 @@ module BiteScript::ASM
|
|
506
527
|
end
|
507
528
|
|
508
529
|
class GenericTypeMirror
|
530
|
+
include Generics
|
509
531
|
def array?
|
510
532
|
false
|
511
533
|
end
|
@@ -561,11 +583,11 @@ module BiteScript::ASM
|
|
561
583
|
def wildcard?
|
562
584
|
true
|
563
585
|
end
|
564
|
-
def to_s
|
586
|
+
def to_s
|
565
587
|
if lower_bound
|
566
|
-
"? super #{lower_bound}"
|
588
|
+
"? super #{inspect_type(lower_bound)}"
|
567
589
|
elsif upper_bound
|
568
|
-
"? extends #{upper_bound}"
|
590
|
+
"? extends #{inspect_type(upper_bound)}"
|
569
591
|
else
|
570
592
|
"?"
|
571
593
|
end
|
@@ -678,4 +700,4 @@ module BiteScript::ASM
|
|
678
700
|
end
|
679
701
|
end
|
680
702
|
end
|
681
|
-
end
|
703
|
+
end
|
data/test/test_builder.rb
CHANGED
@@ -296,8 +296,7 @@ class TestBuilder < Test::Unit::TestCase
|
|
296
296
|
dummy_constructor(cb)
|
297
297
|
obj = load_and_construct(@class_name, cb);
|
298
298
|
|
299
|
-
|
300
|
-
assert_raises(NativeException) {obj.yoohoo}
|
299
|
+
assert_raises(Java::JavaLang::UnsatisfiedLinkError) {obj.yoohoo}
|
301
300
|
end
|
302
301
|
|
303
302
|
def test_fields
|
data/test/test_generics.rb
CHANGED
@@ -124,4 +124,12 @@ class TestGenerics < Test::Unit::TestCase
|
|
124
124
|
assert_equal "java.lang.Comparable<T>", t.bounds[0].to_s
|
125
125
|
assert_equal "java.lang.Iterable<T>", t.bounds[1].to_s
|
126
126
|
end
|
127
|
+
|
128
|
+
def test_generic_parameter_types
|
129
|
+
mirror = BiteScript::ClassMirror.load('java.util.ArrayList')
|
130
|
+
method = mirror.getDeclaredMethods('add')[0]
|
131
|
+
assert_not_nil method.generic_parameter_types
|
132
|
+
puts method.generic_parameter_types
|
133
|
+
|
134
|
+
end
|
127
135
|
end
|
data/test/test_mirror.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'bitescript/mirror'
|
3
|
+
|
4
|
+
class TestMirror < Test::Unit::TestCase
|
5
|
+
include BiteScript
|
6
|
+
|
7
|
+
def test_varargs_true_on_varargs_method
|
8
|
+
cmirror = ClassMirror.load 'java.lang.String'
|
9
|
+
mmirror = cmirror.getDeclaredMethods('format').first
|
10
|
+
assert mmirror.varargs?
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_varargs_false_on_non_varargs_method
|
14
|
+
cmirror = ClassMirror.load 'java.lang.String'
|
15
|
+
mmirror = cmirror.getDeclaredMethods('copyValueOf').first
|
16
|
+
assert !mmirror.varargs?
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: bitescript
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Charles Oliver Nutter
|
@@ -11,7 +11,7 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date:
|
14
|
+
date: 2013-02-25 00:00:00 Z
|
15
15
|
dependencies: []
|
16
16
|
|
17
17
|
description: BiteScript is a Ruby DSL for generating Java bytecode and classes.
|
@@ -58,6 +58,7 @@ files:
|
|
58
58
|
- test/test_bytecode.rb
|
59
59
|
- test/test_generics.rb
|
60
60
|
- test/test_java_class.rb
|
61
|
+
- test/test_mirror.rb
|
61
62
|
- test/test_signature.rb
|
62
63
|
- History.txt
|
63
64
|
- LICENSE.txt
|
@@ -88,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
89
|
requirements: []
|
89
90
|
|
90
91
|
rubyforge_project: jruby-extras
|
91
|
-
rubygems_version: 1.8.
|
92
|
+
rubygems_version: 1.8.24
|
92
93
|
signing_key:
|
93
94
|
specification_version: 3
|
94
95
|
summary: BiteScript is a Ruby DSL for generating Java bytecode.
|
@@ -98,4 +99,5 @@ test_files:
|
|
98
99
|
- test/test_bytecode.rb
|
99
100
|
- test/test_generics.rb
|
100
101
|
- test/test_java_class.rb
|
102
|
+
- test/test_mirror.rb
|
101
103
|
- test/test_signature.rb
|