You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2020/04/25 08:55:37 UTC

[groovy] branch GROOVY-9526 created (now ab4147a)

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

sunlan pushed a change to branch GROOVY-9526
in repository https://gitbox.apache.org/repos/asf/groovy.git.


      at ab4147a  GROOVY-9526: Failed to reload classes with generic parameters

This branch includes the following new commits:

     new ab4147a  GROOVY-9526: Failed to reload classes with generic parameters

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[groovy] 01/01: GROOVY-9526: Failed to reload classes with generic parameters

Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch GROOVY-9526
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit ab4147ae562c443dcb09f73597166a0891470d6c
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sat Apr 25 16:54:25 2020 +0800

    GROOVY-9526: Failed to reload classes with generic parameters
---
 src/main/java/groovy/util/GroovyScriptEngine.java | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/src/main/java/groovy/util/GroovyScriptEngine.java b/src/main/java/groovy/util/GroovyScriptEngine.java
index 7afd183..3a13407 100644
--- a/src/main/java/groovy/util/GroovyScriptEngine.java
+++ b/src/main/java/groovy/util/GroovyScriptEngine.java
@@ -24,7 +24,9 @@ import groovy.lang.GroovyCodeSource;
 import groovy.lang.GroovyResourceLoader;
 import groovy.lang.Script;
 import org.codehaus.groovy.GroovyBugError;
+import org.codehaus.groovy.ast.ClassHelper;
 import org.codehaus.groovy.ast.ClassNode;
+import org.codehaus.groovy.ast.GenericsType;
 import org.codehaus.groovy.classgen.GeneratorContext;
 import org.codehaus.groovy.control.ClassNodeResolver;
 import org.codehaus.groovy.control.CompilationFailedException;
@@ -49,6 +51,7 @@ import java.net.URLConnection;
 import java.security.AccessController;
 import java.security.CodeSource;
 import java.security.PrivilegedAction;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
@@ -199,6 +202,18 @@ public class GroovyScriptEngine implements ResourceConnector {
                             }
                             if (clazz != null) {
                                 ClassNode cn = new ClassNode(clazz);
+                                cn.setGenericsTypes(
+                                        Arrays.stream(clazz.getTypeParameters())
+                                                .map(e -> {
+                                                    ClassNode type = ClassHelper.makeWithoutCaching(e.getName());
+                                                    type.setRedirect(ClassHelper.OBJECT_TYPE);
+                                                    return new GenericsType(
+                                                            type,
+                                                            null,
+                                                            null
+                                                    );
+                                                }).toArray(GenericsType[]::new)
+                                );
                                 return new LookupResult(null, cn);
                             }
                         } catch (ResourceException re) {