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/02/05 02:05:09 UTC

[groovy] branch GROOVY_2_5_X updated: GROOVY-10461: query `DecompiledClassNode` parameterized without resolve

This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/GROOVY_2_5_X by this push:
     new 267c55a  GROOVY-10461: query `DecompiledClassNode` parameterized without resolve
267c55a is described below

commit 267c55a3f3d06a165beb2ed39c90d7441c94eb70
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Fri Feb 4 19:13:27 2022 -0600

    GROOVY-10461: query `DecompiledClassNode` parameterized without resolve
    
    Conflicts:
    	src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java
---
 .../groovy/ast/decompiled/DecompiledClassNode.java |  7 ++++--
 .../codehaus/groovy/ast/tools/GenericsUtils.java   | 26 +++++++++++++---------
 2 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/ast/decompiled/DecompiledClassNode.java b/src/main/java/org/codehaus/groovy/ast/decompiled/DecompiledClassNode.java
index c18f0d0..22a41ef 100644
--- a/src/main/java/org/codehaus/groovy/ast/decompiled/DecompiledClassNode.java
+++ b/src/main/java/org/codehaus/groovy/ast/decompiled/DecompiledClassNode.java
@@ -167,6 +167,10 @@ public class DecompiledClassNode extends ClassNode {
         throw new UnsupportedOperationException();
     }
 
+    public boolean isParameterized() {
+        return (classData.signature != null && classData.signature.charAt(0) == '<');
+    }
+
     @Override
     public boolean isResolved() {
         return true;
@@ -273,5 +277,4 @@ public class DecompiledClassNode extends ClassNode {
         }
         return node;
     }
-
-}
\ No newline at end of file
+}
diff --git a/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java b/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java
index a5605e0..cdd3bb4 100644
--- a/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java
+++ b/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java
@@ -35,6 +35,7 @@ import org.codehaus.groovy.ast.GenericsType;
 import org.codehaus.groovy.ast.MethodNode;
 import org.codehaus.groovy.ast.ModuleNode;
 import org.codehaus.groovy.ast.Parameter;
+import org.codehaus.groovy.ast.decompiled.DecompiledClassNode;
 import org.codehaus.groovy.ast.stmt.EmptyStatement;
 import org.codehaus.groovy.control.CompilationUnit;
 import org.codehaus.groovy.control.ResolveVisitor;
@@ -271,19 +272,24 @@ public class GenericsUtils {
         genericsSpec = createGenericsSpec(targetRedirect, genericsSpec);
         extractSuperClassGenerics(hint, targetRedirect, genericsSpec);
         return correctToGenericsSpecRecurse(genericsSpec, targetRedirect);
-
     }
 
-    public static ClassNode nonGeneric(ClassNode type) {
-        if (type.isUsingGenerics()) {
-            final ClassNode nonGen = ClassHelper.makeWithoutCaching(type.getName());
-            nonGen.setRedirect(type);
-            nonGen.setGenericsTypes(null);
-            nonGen.setUsingGenerics(false);
-            return nonGen;
+    public static ClassNode nonGeneric(final ClassNode type) {
+        int dims = 0;
+        ClassNode temp = type;
+        while (temp.isArray()) { dims += 1;
+            temp = temp.getComponentType();
         }
-        if (type.isArray() && type.getComponentType().isUsingGenerics()) {
-            return type.getComponentType().getPlainNodeReference().makeArray();
+        if (temp instanceof DecompiledClassNode // GROOVY-10461: check without resolving supers
+                        ? ((DecompiledClassNode) temp).isParameterized() : temp.isUsingGenerics()) {
+            ClassNode result = ClassHelper.makeWithoutCaching(temp.getName());
+            result.setRedirect(temp);
+            result.setGenericsTypes(null);
+            result.setUsingGenerics(false);
+            while (dims > 0) { dims -= 1;
+                result = result.makeArray();
+            }
+            return result;
         }
         return type;
     }