You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by em...@apache.org on 2022/03/10 19:12:28 UTC
[groovy] branch GROOVY_3_0_X updated: GROOVY-10525: add test case
This is an automated email from the ASF dual-hosted git repository.
emilles pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY_3_0_X by this push:
new 9a7b54c GROOVY-10525: add test case
9a7b54c is described below
commit 9a7b54c1fb0b2b6a01bc190d4aceb0e9c79df286
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Thu Mar 10 12:39:17 2022 -0600
GROOVY-10525: add test case
---
.../groovy/transform/stc/GenericsSTCTest.groovy | 66 +++++++++++++++-------
1 file changed, 46 insertions(+), 20 deletions(-)
diff --git a/src/test/groovy/transform/stc/GenericsSTCTest.groovy b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
index 7cbf0b2..06b1918 100644
--- a/src/test/groovy/transform/stc/GenericsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
@@ -634,6 +634,16 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase {
''', 'Cannot call A <String, Integer>#<init>(java.lang.Class <String>, java.lang.Class <Integer>) with arguments [java.lang.Class <java.lang.Integer>, java.lang.Class <java.lang.String>]'
}
+ void testMethodCallWithMapParameterUnbounded() {
+ assertScript """
+ import static ${this.class.name}.isEmpty
+ class C {
+ Map<String, ?> map = new HashMap()
+ }
+ assert isEmpty(new C().map)
+ """
+ }
+
// GROOVY-9460
void testMethodCallWithClassParameterUnbounded() {
assertScript '''
@@ -641,15 +651,27 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase {
static void baz(Class<?> target) {
}
}
- class Foo<D> { // cannot be "T" because that matches type parameter in Class
- void test(Class<D> param) {
- Bar.baz(param) // Cannot call Bar#baz(java.lang.Class<?>) with arguments [java.lang.Class<D>]
+ class Foo<X> { // cannot be "T" because that matches type parameter in Class
+ void test(Class<X> c) {
+ Bar.baz(c) // Cannot call Bar#baz(Class<?>) with arguments [Class<X>]
}
}
new Foo<String>().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<Class<?>> types, Validator validator) {
+ validator.validate(bean, types as Class<?>[])
+ }
+ '''
+ }
+
void testConstructorCallWithClassParameterUsingClassLiteralArg() {
assertScript '''
class A {}
@@ -1536,7 +1558,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')
@@ -1573,7 +1595,6 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase {
} finally {
parentDir.deleteDir()
config.targetDirectory.deleteDir()
- config.jointCompilationOptions.stubDir.deleteDir()
}
}
@@ -1851,11 +1872,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 '''
@@ -2639,11 +2660,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 '''
@@ -2705,11 +2726,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 '''
@@ -2744,11 +2765,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 '''
@@ -2807,26 +2828,31 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase {
'''
}
- static class MyList extends LinkedList<String> {}
+ //--------------------------------------------------------------------------
- public static class ClassA<T> {
- public <X> Class<X> foo(Class<X> classType) {
+ static class MyList
+ extends LinkedList<String> {
+ }
+
+ static class ClassA<T> {
+ def <X> Class<X> foo(Class<X> classType) {
return classType;
}
-
- public <X> Class<X> bar(Class<T> classType) {
+ def <X> Class<X> bar(Class<T> classType) {
return null;
}
}
- public static class JavaClassSupport {
- public static class Container<T> {
+ static class JavaClassSupport {
+ static class Container<T> {
}
-
- public static class StringContainer extends Container<String> {
+ static class StringContainer extends Container<String> {
}
-
- public static <T> List<T> unwrap(Collection<? extends Container<T>> list) {
+ static <T> List<T> unwrap(Collection<? extends Container<T>> list) {
}
}
+
+ static boolean isEmpty(Map<?,?> map) {
+ map == null || map.isEmpty()
+ }
}