groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From emil...@apache.org
Subject [groovy] 01/02: add wildcard support to isUsingUncheckedGenerics and missesGenericsTypes
Date Sun, 22 Dec 2019 19:31:06 GMT
This is an automated email from the ASF dual-hosted git repository.

emilles pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit d443bb0cc9b1087aa9f8c23b8d799faf7446df37
Author: Eric Milles <eric.milles@thomsonreuters.com>
AuthorDate: Sun Dec 22 13:14:09 2019 -0600

    add wildcard support to isUsingUncheckedGenerics and missesGenericsTypes
---
 .../transform/stc/StaticTypeCheckingSupport.java   | 34 ++++++++++++++--------
 1 file changed, 22 insertions(+), 12 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
index 0184a83..5f2e6a6 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
@@ -1007,21 +1007,22 @@ public abstract class StaticTypeCheckingSupport {
      */
     public static boolean isUsingUncheckedGenerics(final ClassNode node) {
         if (node.isArray()) return isUsingUncheckedGenerics(node.getComponentType());
-        if (node.isUsingGenerics()) {
-            GenericsType[] genericsTypes = node.getGenericsTypes();
-            if (genericsTypes != null) {
-                for (GenericsType genericsType : genericsTypes) {
-                    if (genericsType.isPlaceholder()) {
-                        return true;
-                    } else {
-                        if (isUsingUncheckedGenerics(genericsType.getType())) {
-                            return true;
-                        }
+        GenericsType[] genericsTypes = node.getGenericsTypes();
+        if (genericsTypes != null) {
+            for (GenericsType genericsType : genericsTypes) {
+                if (genericsType.isPlaceholder()) return true;
+                if (genericsType.isWildcard()) {
+                    ClassNode lowerBound = genericsType.getLowerBound();
+                    ClassNode[] upperBounds = genericsType.getUpperBounds();
+                    if (lowerBound != null) {
+                        if (lowerBound.isGenericsPlaceHolder() || isUsingUncheckedGenerics(lowerBound))
return true;
+                    } else if (upperBounds != null) {
+                        if (upperBounds[0].isGenericsPlaceHolder() || isUsingUncheckedGenerics(upperBounds[0]))
return true;
                     }
+                } else {
+                    if (isUsingUncheckedGenerics(genericsType.getType())) return true;
                 }
             }
-        } else {
-            return false;
         }
         return false;
     }
@@ -2146,6 +2147,15 @@ public abstract class StaticTypeCheckingSupport {
         if (cnTypes != null) {
             for (GenericsType genericsType : cnTypes) {
                 if (genericsType.isPlaceholder()) return true;
+                if (genericsType.isWildcard()) {
+                    ClassNode lowerBound = genericsType.getLowerBound();
+                    ClassNode[] upperBounds = genericsType.getUpperBounds();
+                    if (lowerBound != null) {
+                        if (lowerBound.isGenericsPlaceHolder() || missesGenericsTypes(lowerBound))
return true;
+                    } else if (upperBounds != null) {
+                        if (upperBounds[0].isGenericsPlaceHolder() || missesGenericsTypes(upperBounds[0]))
return true;
+                    }
+                }
             }
         }
         return false;


Mime
View raw message