mirah 0.1.4-java → 0.2.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +0 -0
  3. data/CODE_OF_CONDUCT.md +74 -0
  4. data/History.txt +531 -0
  5. data/README.md +23 -10
  6. data/Rakefile +239 -156
  7. data/TODO.md +71 -10
  8. data/bin/mirah +1 -1
  9. data/bin/mirahc +1 -1
  10. data/dist/mirahc.jar +0 -0
  11. data/examples/bintrees.mirah +2 -2
  12. data/examples/construction.mirah +2 -2
  13. data/examples/fields.mirah +1 -1
  14. data/examples/fractal.mirah +1 -1
  15. data/examples/fractal.rb +70 -0
  16. data/examples/interfaces.mirah +1 -1
  17. data/examples/java_thing.mirah +1 -1
  18. data/examples/macros/square.mirah +3 -3
  19. data/examples/macros/square_int.mirah +3 -3
  20. data/examples/macros/string_each_char.mirah +6 -6
  21. data/examples/rosettacode/100-doors.mirah +0 -2
  22. data/examples/rosettacode/count-occurrences-of-a-substring.mirah +3 -3
  23. data/examples/rosettacode/empty-string.mirah +1 -1
  24. data/examples/rosettacode/fizz-buzz.mirah +4 -4
  25. data/examples/rosettacode/is-string-numeric.mirah +7 -7
  26. data/examples/rosettacode/palindrome.mirah +2 -2
  27. data/examples/rosettacode/reverse-a-string.mirah +1 -1
  28. data/examples/rosettacode/rot-13.mirah +1 -1
  29. data/examples/{edb.mirah → rosettacode/simple_character_math.mirah} +13 -4
  30. data/examples/rosettacode/string-case.mirah +2 -2
  31. data/examples/rosettacode/string-length.mirah +1 -1
  32. data/examples/swing.mirah +9 -14
  33. data/extensions_and_macros.md +117 -0
  34. data/lib/mirah.rb +1 -1
  35. data/lib/mirah/errors.rb +3 -1
  36. data/lib/mirah/transform/ast_ext.rb +3 -2
  37. data/lib/mirah/util/process_errors.rb +1 -2
  38. data/lib/mirah/version.rb +1 -1
  39. data/test/A.class +0 -0
  40. data/test/core/util/jvm_version_test.rb +10 -0
  41. data/test/core/util/mirah_arguments_test.rb +51 -4
  42. data/test/fixtures/cp1251_test.mirah +7 -0
  43. data/test/fixtures/org/foo/AbstractExecutorJava8.java +30 -0
  44. data/test/fixtures/org/foo/ClassWithSelfReferencingTypeParameter.java +24 -0
  45. data/test/fixtures/org/foo/InnerInterfaceClass.java +12 -0
  46. data/test/fixtures/org/foo/IntAnno.class +0 -0
  47. data/test/fixtures/org/foo/TypeFixtureJava8.java +10 -0
  48. data/test/fixtures/utf8_test.mirah +7 -0
  49. data/test/jvm/access_levels_test.rb +31 -0
  50. data/test/jvm/annotations_test.rb +3 -6
  51. data/test/jvm/blocks_test.rb +303 -120
  52. data/test/jvm/cast_test.rb +123 -50
  53. data/test/jvm/closure_test.rb +242 -0
  54. data/test/jvm/constructors_test.rb +1 -3
  55. data/test/jvm/example_test.rb +6 -2
  56. data/test/jvm/extensions/array_extensions_test.rb +181 -0
  57. data/test/jvm/extensions/collection_extensions_test.rb +195 -0
  58. data/test/jvm/{enumerable_test.rb → extensions/enumerable_test.rb} +81 -13
  59. data/test/jvm/extensions/hash_extensions_test.rb +56 -0
  60. data/test/jvm/extensions/list_extensions_test.rb +143 -0
  61. data/test/jvm/extensions/lock_extensions_test.rb +43 -0
  62. data/test/jvm/{numeric_extensions_test.rb → extensions/numeric_extensions_test.rb} +0 -0
  63. data/test/jvm/extensions/numeric_operators_test.rb +86 -0
  64. data/test/jvm/extensions/object_extensions_test.rb +122 -0
  65. data/test/jvm/{string_builder_extensions_test.rb → extensions/string_builder_extensions_test.rb} +0 -0
  66. data/test/jvm/{string_extensions_test.rb → extensions/string_extensions_test.rb} +57 -4
  67. data/test/jvm/generics_test.rb +14 -6
  68. data/test/jvm/import_test.rb +38 -1
  69. data/test/jvm/interface_test.rb +17 -0
  70. data/test/jvm/jvm_commands_test.rb +9 -0
  71. data/test/jvm/jvm_compiler_test.rb +568 -43
  72. data/test/jvm/macros_test.rb +343 -19
  73. data/test/jvm/main_method_test.rb +1 -3
  74. data/test/jvm/new_backend_test_helper.rb +54 -7
  75. data/test/jvm/rescue_test.rb +20 -5
  76. data/test/jvm/static_fields_test.rb +52 -10
  77. data/test/jvm/{mirror_compilation_test_helper.rb → string_test.rb} +10 -9
  78. data/test/jvm/varargs_test.rb +6 -16
  79. data/test/mirrors/base_type_test.rb +20 -7
  80. data/test/mirrors/bytecode_mirror_test.rb +8 -3
  81. data/test/mirrors/generics_test.rb +89 -10
  82. data/test/mirrors/member_test.rb +1 -1
  83. data/test/mirrors/method_lookup_test.rb +10 -3
  84. data/test/mirrors/mirrors_test.rb +20 -20
  85. data/test/mirrors/simple_async_mirror_loader_test.rb +1 -1
  86. data/test/mirrors/simple_mirror_loader_test.rb +1 -1
  87. data/test/newMirahClass$Closure2.class +0 -0
  88. data/test/newMirahClass.class +0 -0
  89. data/test/test_helper.rb +8 -1
  90. metadata +31 -16
  91. data/bin/bundler +0 -16
  92. data/bin/rake +0 -16
  93. data/examples/ant/example-build.xml~ +0 -7
  94. data/examples/test.edb +0 -9
  95. data/lib/mirah/compiler.rb +0 -67
  96. data/lib/mirah/parser.rb +0 -224
  97. data/lib/mirah/util/delegate.rb +0 -65
  98. data/test/jvm/list_extensions_test.rb +0 -23
@@ -8,8 +8,6 @@ class MainMethodTest < Test::Unit::TestCase
8
8
 
9
9
  main_class, = compile code, :name => 'with_main'
10
10
 
11
- assert_output "bar\n" do
12
- main_class.main(nil)
13
- end
11
+ assert_run_output("bar\n", main_class)
14
12
  end
15
13
  end
@@ -17,6 +17,7 @@ require 'test_helper'
17
17
  module JVMCompiler
18
18
  java_import 'org.mirah.tool.RunCommand'
19
19
  java_import 'org.mirah.util.SimpleDiagnostics'
20
+
20
21
  System = java.lang.System
21
22
  JVM_VERSION = ENV['MIRAH_TEST_JVM_VERSION'] || '1.7'
22
23
 
@@ -24,7 +25,22 @@ module JVMCompiler
24
25
  java_import 'java.util.Locale'
25
26
  def report(diagnostic)
26
27
  if diagnostic.kind.name == "ERROR"
27
- raise Mirah::MirahError, diagnostic.getMessage(Locale.getDefault)
28
+ source = if diagnostic.source
29
+
30
+ line_no = [0, diagnostic.getLineNumber - diagnostic.source.initial_line].max
31
+ line = diagnostic.source.contents.lines.to_a[line_no]
32
+ start_col = if line_no == 0
33
+ diagnostic.column_number - diagnostic.source.initial_column
34
+ else
35
+ diagnostic.column_number - 1
36
+ end
37
+ end_col = [start_col + (diagnostic.end_position - diagnostic.start_position),
38
+ line.size - 1].min
39
+ line[start_col..end_col]
40
+ else
41
+ "<unknown>"
42
+ end
43
+ raise Mirah::MirahError.new(diagnostic.getMessage(Locale.getDefault), source, diagnostic)
28
44
  end
29
45
  super
30
46
  end
@@ -38,13 +54,23 @@ module JVMCompiler
38
54
  def compile(code, options = {})
39
55
  name = options.fetch :name, tmp_script_name
40
56
 
41
- java_version = options.fetch :java_version, JVMCompiler::JVM_VERSION
42
57
  args = ["-d", TEST_DEST,
43
58
  "--vmodule", "org.mirah.jvm.compiler.ClassCompiler=OFF",
59
+ # "--verbose",
44
60
  "--classpath", Mirah::Env.encode_paths([FIXTURE_TEST_DEST, TEST_DEST]) ]
61
+
62
+ java_version = options.fetch :java_version, JVMCompiler::JVM_VERSION
45
63
  if java_version
46
64
  args += ["--jvm", java_version]
47
65
  end
66
+ if options[:verbose]
67
+ args << '--verbose'
68
+ end
69
+ if options[:separate_macro_dest]
70
+ macro_dest = TEST_DEST.sub('classes','macro_classes')
71
+ args += ["--macro-dest", macro_dest,
72
+ "--macroclasspath", Mirah::Env.encode_paths([macro_dest])]
73
+ end
48
74
 
49
75
  cmd = build_command name, code
50
76
  compile_or_raise cmd, args
@@ -56,7 +82,13 @@ module JVMCompiler
56
82
 
57
83
  def build_command(name, code)
58
84
  cmd = RunCommand.new
59
- cmd.addFakeFile(name, code)
85
+ if code.is_a?(Array)
86
+ code.each.with_index do |c,i|
87
+ cmd.addFakeFile("#{name}_#{i}", c)
88
+ end
89
+ else
90
+ cmd.addFakeFile(name, code)
91
+ end
60
92
  cmd.setDiagnostics(TestDiagnostics.new(false))
61
93
  cmd
62
94
  end
@@ -65,9 +97,6 @@ module JVMCompiler
65
97
  if 0 != cmd.compile(args)
66
98
  raise Mirah::MirahError, "Compilation failed"
67
99
  end
68
- rescue => e
69
- raise e.cause if e.respond_to?(:cause) && e.cause
70
- raise e
71
100
  end
72
101
 
73
102
  def compiler_name
@@ -76,7 +105,11 @@ module JVMCompiler
76
105
 
77
106
  def clean_tmp_files
78
107
  return unless @tmp_classes
79
- File.unlink(*@tmp_classes)
108
+ begin
109
+ File.unlink(*@tmp_classes)
110
+ rescue
111
+ JavaFile.unlink *@tmp_classes
112
+ end
80
113
  end
81
114
 
82
115
  def dump_class_files class_map
@@ -107,6 +140,20 @@ module JVMCompiler
107
140
  end
108
141
  ex
109
142
  end
143
+
144
+ class JavaFile
145
+ java_import 'java.io.File'
146
+
147
+ def self.unlink *files
148
+ files.each do |f|
149
+ jf = File.new(f)
150
+ unless jf.delete
151
+ jf.deleteOnExit
152
+ puts "\nwarn: locked #{jf}"
153
+ end
154
+ end
155
+ end
156
+ end
110
157
  end
111
158
 
112
159
  class Test::Unit::TestCase
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
1
+ # Copyright (c) 2015 The Mirah project authors. All Rights Reserved.
2
2
  # All contributing project authors may be found in the NOTICE file.
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,6 +15,23 @@
15
15
 
16
16
  class RescueTest < Test::Unit::TestCase
17
17
 
18
+ def test_rescue_with_import
19
+ cls, = compile(<<-EOF)
20
+ def foo
21
+ begin
22
+ raise "some error"
23
+ rescue Exception => e
24
+ import java.util.Collections
25
+ x = [3, 1, 2]
26
+ Collections.sort x
27
+ x
28
+ end
29
+ end
30
+ EOF
31
+
32
+ assert_equal [1, 2, 3], cls.foo.to_a
33
+ end
34
+
18
35
  def test_rescue_with_no_raise_runs_begin_and_not_rescue
19
36
  cls, = compile(<<-EOF)
20
37
  def foo
@@ -254,9 +271,7 @@ class RescueTest < Test::Unit::TestCase
254
271
  puts "else"
255
272
  end
256
273
  EOF
257
- assert_output "else\n" do
258
- cls.main nil
259
- end
274
+ assert_run_output("else\n", cls)
260
275
  end
261
276
 
262
277
  def test_ensure
@@ -313,6 +328,6 @@ class RescueTest < Test::Unit::TestCase
313
328
  end
314
329
  EOF
315
330
 
316
- assert_output("a\nb\nc\nensure\n") { cls.main(nil) }
331
+ assert_run_output("a\nb\nc\nensure\n", cls)
317
332
  end
318
333
  end
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2014 The Mirah project authors. All Rights Reserved.
1
+ # Copyright (c) 2015 The Mirah project authors. All Rights Reserved.
2
2
  # All contributing project authors may be found in the NOTICE file.
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,9 +21,7 @@ class StaticFieldsTest < Test::Unit::TestCase
21
21
  puts GregorianCalendar.AM
22
22
  EOF
23
23
 
24
- assert_output "0\n" do
25
- cls.main(nil)
26
- end
24
+ assert_run_output("0\n", cls)
27
25
  end
28
26
 
29
27
  def test_static_field_inheritance_lookup_with_double_colon
@@ -34,9 +32,7 @@ class StaticFieldsTest < Test::Unit::TestCase
34
32
  puts GregorianCalendar::AM
35
33
  EOF
36
34
 
37
- assert_output "0\n" do
38
- cls.main(nil)
39
- end
35
+ assert_run_output("0\n", cls)
40
36
  }
41
37
  end
42
38
 
@@ -45,8 +41,54 @@ class StaticFieldsTest < Test::Unit::TestCase
45
41
  CONSTANT = 1
46
42
  puts CONSTANT
47
43
  EOF
48
- assert_output "1\n" do
49
- cls.main(nil)
50
- end
44
+ assert_run_output("1\n", cls)
45
+ end
46
+
47
+ def test_static_final_constant
48
+ cls, = compile(<<-EOF)
49
+ class Bar
50
+
51
+ static_final :serialVersionUID, -1234567890123456789
52
+
53
+ class << self
54
+ def reflect
55
+ field = Bar.class.getDeclaredField("serialVersionUID")
56
+ puts field.getModifiers
57
+ puts field.get(nil)
58
+ end
59
+ end
60
+ end
61
+
62
+ Bar.reflect
63
+ EOF
64
+ assert_run_output("26\n-1234567890123456789\n", cls)
65
+ end
66
+
67
+ def test_transient
68
+ cls, = compile(%q[
69
+ class Bar implements java::io::Serializable
70
+
71
+ static_final :serialVersionUID, -1234567890123456789
72
+
73
+ transient :b
74
+
75
+ def initialize(a:int,b:int)
76
+ @a = a
77
+ @b = b
78
+ end
79
+
80
+ def toString
81
+ "Bar(#{@a},#{@b})"
82
+ end
83
+ end
84
+
85
+ bout = java::io::ByteArrayOutputStream.new
86
+ oout = java::io::ObjectOutputStream.new(bout)
87
+ oout.writeObject(Bar.new(5,7))
88
+ oout.close
89
+ bin = java::io::ObjectInputStream.new(java::io::ByteArrayInputStream.new(bout.toByteArray))
90
+ puts Bar(bin.readObject)
91
+ ])
92
+ assert_run_output("Bar(5,0)\n", cls) # b=7 should be forgotten, because b is a transient field.
51
93
  end
52
94
  end
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
1
+ # Copyright (c) 2015 The Mirah project authors. All Rights Reserved.
2
2
  # All contributing project authors may be found in the NOTICE file.
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,13 +12,14 @@
12
12
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
- require 'new_backend_test_helper'
16
- require 'stringio'
17
- require 'fileutils'
18
15
 
19
- module JVMCompiler
20
- def type_system
21
- # TODO: classpath
22
- Java::OrgMirahJvmMirrors::MirrorTypeSystem.new
16
+ class StringTest < Test::Unit::TestCase
17
+
18
+ def test_string_interpolation_subsequence
19
+ cls, = compile(%q[
20
+ puts "#{begin; "a"; "b"; "c"; end}"
21
+ ])
22
+ assert_run_output("c\n", cls)
23
23
  end
24
- end
24
+ end
25
+
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
1
+ # Copyright (c) 2015 The Mirah project authors. All Rights Reserved.
2
2
  # All contributing project authors may be found in the NOTICE file.
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -19,36 +19,28 @@ class VarargsTest < Test::Unit::TestCase
19
19
  cls, = compile(<<-EOF)
20
20
  puts String.format("%s %s's", "rocking", "banana")
21
21
  EOF
22
- assert_output "rocking banana's\n" do
23
- cls.main nil
24
- end
22
+ assert_run_output("rocking banana's\n", cls)
25
23
  end
26
24
 
27
25
  def test_varargs_method_with_passed_including_int_varargs
28
26
  cls, = compile(<<-EOF)
29
27
  puts String.format("%s %d's", "rocking", 3)
30
28
  EOF
31
- assert_output "rocking 3's\n" do
32
- cls.main nil
33
- end
29
+ assert_run_output("rocking 3's\n", cls)
34
30
  end
35
31
 
36
32
  def test_varargs_method_with_passed_including_integer_varargs
37
33
  cls, = compile(<<-EOF)
38
34
  puts String.format("%s %d's", "rocking", Integer.valueOf(3))
39
35
  EOF
40
- assert_output "rocking 3's\n" do
41
- cls.main nil
42
- end
36
+ assert_run_output("rocking 3's\n", cls)
43
37
  end
44
38
 
45
39
  def test_varargs_method_lookup_without_passed_varargs
46
40
  cls, = compile(<<-EOF)
47
41
  puts String.format("rocking with no args")
48
42
  EOF
49
- assert_output "rocking with no args\n" do
50
- cls.main nil
51
- end
43
+ assert_run_output("rocking with no args\n", cls)
52
44
  end
53
45
 
54
46
  def test_varargs_method_lookup_when_passed_array
@@ -57,9 +49,7 @@ class VarargsTest < Test::Unit::TestCase
57
49
  args[0] = "an array"
58
50
  puts String.format("rocking with %s", args)
59
51
  EOF
60
- assert_output "rocking with an array\n" do
61
- cls.main nil
62
- end
52
+ assert_run_output("rocking with an array\n", cls)
63
53
  end
64
54
 
65
55
  end
@@ -13,14 +13,13 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
 
16
- require 'test/unit'
17
- require 'java'
18
- require 'dist/mirahc.jar'
16
+ require 'test_helper'
19
17
 
20
18
  class BaseTypeTest < Test::Unit::TestCase
21
19
  java_import 'org.objectweb.asm.Type'
22
20
  java_import 'org.objectweb.asm.Opcodes'
23
21
  java_import 'org.mirah.jvm.mirrors.BaseType'
22
+ java_import 'org.mirah.jvm.mirrors.VoidType'
24
23
  java_import 'org.mirah.jvm.mirrors.Member'
25
24
  java_import 'org.mirah.jvm.mirrors.MirrorTypeSystem'
26
25
  java_import 'org.mirah.jvm.types.MemberKind'
@@ -29,7 +28,7 @@ class BaseTypeTest < Test::Unit::TestCase
29
28
  def setup
30
29
  @types = MirrorTypeSystem.new
31
30
  @type = BaseType.new(@types.context, Type.getType("LFooBar;"), 0, nil)
32
- @void = BaseType.new(@types.context, Type.getType("V"), 0, nil)
31
+ @void = VoidType.new
33
32
  end
34
33
 
35
34
  def type(name)
@@ -89,9 +88,23 @@ class BaseTypeTest < Test::Unit::TestCase
89
88
  assert_equal(object, map.widen(int))
90
89
  end
91
90
 
92
- def test_widen_error
91
+ def test_widen_void_to_map_is_error
93
92
  map = type('java.util.Map')
94
- assert(@void.widen(map).isError)
95
- assert(map.widen(@void).isError)
93
+ assert(@void.widen(map).isError, @void.widen(map).to_s)
94
+ end
95
+
96
+ def test_widen_to_void_is_error
97
+ map = type('java.util.Map')
98
+ assert(map.widen(@void).isError, map.widen(@void).to_s)
99
+ end
100
+
101
+ def test_void_assignable_from_map
102
+ map = type('java.util.Map')
103
+ refute(@void.assignableFrom(map))
104
+ end
105
+
106
+ def test_map_assignable_from_void
107
+ map = type('java.util.Map')
108
+ refute(map.assignableFrom(@void))
96
109
  end
97
110
  end
@@ -13,9 +13,7 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
 
16
- require 'test/unit'
17
- require 'java'
18
- require 'dist/mirahc.jar'
16
+ require 'test_helper'
19
17
 
20
18
  class BytecodeMirrorTest < Test::Unit::TestCase
21
19
  java_import 'org.objectweb.asm.Type'
@@ -83,6 +81,13 @@ class BytecodeMirrorTest < Test::Unit::TestCase
83
81
  assert_equal('FIELD_ACCESS', field.kind.name)
84
82
  end
85
83
 
84
+ def test_declared_field_signature
85
+ mirror = load(Type.getType("Ljava/lang/String;"))
86
+ field = mirror.getDeclaredField 'CASE_INSENSITIVE_ORDER'
87
+
88
+ assert_equal('Ljava/util/Comparator<Ljava/lang/String;>;', field.signature)
89
+ end
90
+
86
91
  def test_array
87
92
  mirror = load(Type.getType("[Ljava/lang/Object;"))
88
93
  assert(JVMTypeUtils.isArray(mirror))
@@ -16,26 +16,30 @@
16
16
  require 'java'
17
17
  require 'test/unit'
18
18
  require 'java'
19
- require 'dist/mirahc.jar'
19
+ require ENV.fetch('MIRAHC_JAR',File.expand_path("../../../dist/mirahc.jar",__FILE__))
20
+ require File.expand_path("../../jvm/new_backend_test_helper",__FILE__)
20
21
 
21
22
  class GenericsTest < Test::Unit::TestCase
22
23
  java_import 'java.util.HashSet'
24
+ java_import 'javax.lang.model.util.Types'
25
+ java_import 'org.objectweb.asm.Type'
26
+
27
+ java_import 'org.mirah.jvm.mirrors.BaseType'
23
28
  java_import 'org.mirah.jvm.mirrors.generics.Constraints'
24
29
  java_import 'org.mirah.jvm.mirrors.generics.LubFinder'
30
+ java_import 'org.mirah.jvm.mirrors.generics.TypeInvocation'
31
+ java_import 'org.mirah.jvm.mirrors.generics.TypeInvoker'
25
32
  java_import 'org.mirah.jvm.mirrors.generics.TypeParameterInference'
26
33
  java_import 'org.mirah.jvm.mirrors.generics.TypeVariable'
27
- java_import 'org.mirah.jvm.mirrors.generics.TypeInvocation'
28
34
  java_import 'org.mirah.jvm.mirrors.generics.Wildcard'
29
- java_import 'org.mirah.jvm.mirrors.BaseType'
30
- java_import 'org.mirah.jvm.mirrors.NullType'
31
35
  java_import 'org.mirah.jvm.mirrors.MirrorTypeSystem'
36
+ java_import 'org.mirah.jvm.mirrors.NullType'
32
37
  java_import 'org.mirah.jvm.model.Cycle'
33
38
  java_import 'org.mirah.jvm.model.IntersectionType'
34
39
  java_import 'org.mirah.typer.BaseTypeFuture'
35
- java_import 'org.objectweb.asm.Type'
36
- java_import 'javax.lang.model.util.Types'
37
40
 
38
41
  def setup
42
+ super
39
43
  @types = MirrorTypeSystem.new
40
44
  @type_utils = @types.context.get(Types.java_class)
41
45
  @tpi = TypeParameterInference.new(@type_utils)
@@ -57,7 +61,7 @@ class GenericsTest < Test::Unit::TestCase
57
61
  def g(name, params)
58
62
  klass = future(name)
59
63
  params = params.map {|x| future(x)}
60
- @types.parameterize(klass, params).resolve
64
+ @types.parameterize(klass, params, {}).resolve
61
65
  end
62
66
 
63
67
  def future(x)
@@ -310,7 +314,7 @@ class GenericsTest < Test::Unit::TestCase
310
314
  assert_nil(@tpi.findMatchingSupertype(string, abstract_list))
311
315
 
312
316
  array_list = @types.loadNamedType('java.util.ArrayList').resolve
313
- assert_equal(abstract_list, @tpi.findMatchingSupertype(array_list, abstract_list))
317
+ assert_equal(abstract_list.name, @tpi.findMatchingSupertype(array_list, abstract_list).name)
314
318
  end
315
319
 
316
320
  def test_equal_variable
@@ -666,7 +670,7 @@ class GenericsTest < Test::Unit::TestCase
666
670
  a = @types.getArrayType(s)
667
671
  assert_equal('java.util.Set<java.lang.String>[]', a.toString)
668
672
  supertypes = a.directSupertypes
669
- assert_equal('[java.util.Set[], java.util.Collection<java.lang.String>[]]',
673
+ assert_equal('[java.lang.Object, java.util.Set[], java.util.Collection<java.lang.String>[]]',
670
674
  supertypes.toString)
671
675
 
672
676
  end
@@ -782,4 +786,79 @@ class GenericsTest < Test::Unit::TestCase
782
786
  assert_equal(["java.lang.Comparable<java.lang.String>"],
783
787
  interfaces.grep(/Comparable/))
784
788
  end
785
- end
789
+
790
+ def test_type_invoker_simple_signature
791
+ invoker = invoker_for_signature('Ljava/lang/Object;')
792
+ assert_equal(0,invoker.getFormalTypeParameters.size)
793
+ end
794
+
795
+ def test_type_invoker_array_as_type_parameter_signature
796
+ invoker = invoker_for_signature('<T:Ljava/lang/Object;>Ljava/lang/Class<[TT;>;')
797
+ assert_equal(1,invoker.getFormalTypeParameters.size)
798
+ end
799
+
800
+ def test_type_invoker_class_with_self_referential_bounds
801
+ invoker = invoker_for_signature('<P:LAnotherClassWithSelfReferencingTypeParameter<TP;>;>Ljava/lang/Object;')
802
+ assert_equal(1,invoker.getFormalTypeParameters.size)
803
+ end
804
+
805
+ def test_ClassWithSelfReferencingTypeParameter
806
+ cls, = compile(%q[
807
+ import org.foo.ClassWithSelfReferencingTypeParameter
808
+
809
+ ClassWithSelfReferencingTypeParameter.new.foo.bar.baz
810
+ ])
811
+ assert_run_output("baz\n", cls)
812
+ end
813
+
814
+ def test_issue_417_npe
815
+ omit_if JVMCompiler::JVM_VERSION.to_f < 1.8
816
+ pend "fix NPE in generic inference" do
817
+ cls, = compile(%q[
818
+ import org.foo.TypeFixtureJava8
819
+ import java.util.function.BiConsumer
820
+ import java.util.Map
821
+ import java.util.List
822
+
823
+ class Issue417Test
824
+
825
+ def initialize(filters:List, flags:int)
826
+ @filters = filters
827
+ @flags = flags
828
+ @loader = TypeFixtureJava8.new
829
+ @future = nil
830
+ end
831
+
832
+ def run():void
833
+ @future = @loader.load(@filters, @flags)
834
+ end
835
+
836
+ def handle(block:BiConsumer):Issue417Test
837
+ @future.whenComplete(block)
838
+ self
839
+ end
840
+
841
+ def join():void
842
+ @future.join
843
+ end
844
+
845
+ end
846
+ ])
847
+ end
848
+ end
849
+
850
+ def test_type_invoker_recursive_reference_signature
851
+ omit_if JVMCompiler::JVM_VERSION.to_f < 1.8
852
+ # Stream API is needed here
853
+ invoker = invoker_for_signature('<T:Ljava/lang/Object;S::Ljava/util/stream/BaseStream<TT;TS;>;>Ljava/lang/Object;Ljava/lang/AutoCloseable;')
854
+ assert_equal(2,invoker.getFormalTypeParameters.size)
855
+ end
856
+
857
+ def invoker_for_signature(signature)
858
+ context = @types.context
859
+ invoker = TypeInvoker.new(context, nil, [], {})
860
+ invoker.read(signature)
861
+ invoker
862
+ end
863
+ end
864
+