From c79f8af02f10beac85c5759334848b1121252807 Mon Sep 17 00:00:00 2001 From: Eric Milles Date: Thu, 10 Mar 2022 12:39:17 -0600 Subject: [PATCH] GROOVY-10525: add test case --- .../transform/stc/GenericsSTCTest.groovy | 79 ++++++++++++------- 1 file changed, 51 insertions(+), 28 deletions(-) diff --git a/src/test/groovy/transform/stc/GenericsSTCTest.groovy b/src/test/groovy/transform/stc/GenericsSTCTest.groovy index a372aa372f7..089871fc881 100644 --- a/src/test/groovy/transform/stc/GenericsSTCTest.groovy +++ b/src/test/groovy/transform/stc/GenericsSTCTest.groovy @@ -1292,11 +1292,11 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase { test { Class clazz -> clazz.newInstance() } ''' + File parentDir = File.createTempDir() config.with { targetDirectory = File.createTempDir() - jointCompilationOptions = [stubDir: File.createTempDir()] + jointCompilationOptions = [memStub: true] } - File parentDir = File.createTempDir() try { def a = new File(parentDir, 'Face.java') a.write ''' @@ -1333,7 +1333,6 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase { } finally { parentDir.deleteDir() config.targetDirectory.deleteDir() - config.jointCompilationOptions.stubDir.deleteDir() } } @@ -1522,6 +1521,16 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase { 'Cannot call A#(java.lang.Class, java.lang.Class) with arguments [java.lang.Class, java.lang.Class]' } + void testMethodCallWithMapParameterUnbounded() { + assertScript """ + import static ${this.class.name}.isEmpty + class C { + Map map = new HashMap() + } + assert isEmpty(new C().map) + """ + } + // GROOVY-9460 void testMethodCallWithClassParameterUnbounded() { assertScript ''' @@ -1529,15 +1538,27 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase { static void baz(Class target) { } } - class Foo { // cannot be "T" because that matches type parameter in Class - void test(Class param) { - Bar.baz(param) // Cannot call Bar#baz(java.lang.Class) with arguments [java.lang.Class] + class Foo { // cannot be "T" because that matches type parameter in Class + void test(Class c) { + Bar.baz(c) // Cannot call Bar#baz(Class) with arguments [Class] } } new Foo().test(String.class) ''' } + // GROOVY-10525 + void testMethodCallWithClassParameterUnbounded2() { + assertScript ''' + @Grab('javax.validation:validation-api:1.1.0.Final') + import javax.validation.Validator + + void test(Object bean, List> types, Validator validator) { + validator.validate(bean, types as Class[]) + } + ''' + } + void testConstructorCallWithClassParameterUsingClassLiteralArg() { assertScript ''' class A {} @@ -1886,11 +1907,11 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase { // GROOVY-8409, GROOVY-9902 void testShouldUseMethodGenericType11() { + File parentDir = File.createTempDir() config.with { targetDirectory = File.createTempDir() - jointCompilationOptions = [stubDir: File.createTempDir()] + jointCompilationOptions = [memStub: true] } - File parentDir = File.createTempDir() try { def a = new File(parentDir, 'Main.groovy') a.write ''' @@ -1925,7 +1946,6 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase { } finally { parentDir.deleteDir() config.targetDirectory.deleteDir() - config.jointCompilationOptions.stubDir.deleteDir() } } @@ -2694,7 +2714,7 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase { File parentDir = File.createTempDir() config.with { targetDirectory = File.createTempDir() - jointCompilationOptions = [stubDir: File.createTempDir()] + jointCompilationOptions = [memStub: true] } try { def a = new File(parentDir, 'aJavaClass.java') @@ -2731,7 +2751,6 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase { } finally { parentDir.deleteDir() config.targetDirectory.deleteDir() - config.jointCompilationOptions.stubDir.deleteDir() } } @@ -3093,11 +3112,11 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase { ''' // GROOVY-9822 + File parentDir = File.createTempDir() config.with { targetDirectory = File.createTempDir() jointCompilationOptions = [memStub: true] } - File parentDir = File.createTempDir() try { def a = new File(parentDir, 'Types.java') a.write ''' @@ -3796,7 +3815,7 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase { File parentDir = File.createTempDir() config.with { targetDirectory = File.createTempDir() - jointCompilationOptions = [stubDir: File.createTempDir()] + jointCompilationOptions = [memStub: true] } try { def a = new File(parentDir, 'Bean.java') @@ -3821,7 +3840,6 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase { } finally { parentDir.deleteDir() config.targetDirectory.deleteDir() - config.jointCompilationOptions.stubDir.deleteDir() } } @@ -4026,11 +4044,11 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase { // GROOVY-9821 ['.', '?.', '*.'].each { op -> + File parentDir = File.createTempDir() config.with { targetDirectory = File.createTempDir() jointCompilationOptions = [memStub: true] } - File parentDir = File.createTempDir() try { def a = new File(parentDir, 'Types.java') a.write ''' @@ -4092,11 +4110,11 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase { // + File parentDir = File.createTempDir() config.with { targetDirectory = File.createTempDir() jointCompilationOptions = [memStub: true] } - File parentDir = File.createTempDir() try { def a = new File(parentDir, 'Pojo.java') a.write ''' @@ -4131,11 +4149,11 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase { // GROOVY-10234 void testSelfReferentialTypeParameter() { + File parentDir = File.createTempDir() config.with { targetDirectory = File.createTempDir() jointCompilationOptions = [memStub: true] } - File parentDir = File.createTempDir() try { def a = new File(parentDir, 'Main.groovy') a.write ''' @@ -4221,26 +4239,31 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase { ''' } - static class MyList extends LinkedList {} + //-------------------------------------------------------------------------- + + static class MyList + extends LinkedList { + } - public static class ClassA { - public Class foo(Class classType) { + static class ClassA { + def Class foo(Class classType) { return classType; } - - public Class bar(Class classType) { + def Class bar(Class classType) { return null; } } - public static class JavaClassSupport { - public static class Container { + static class JavaClassSupport { + static class Container { } - - public static class StringContainer extends Container { + static class StringContainer extends Container { } - - public static List unwrap(Collection> list) { + static List unwrap(Collection> list) { } } + + static boolean isEmpty(Map map) { + map == null || map.isEmpty() + } }