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/02/22 03:22:49 UTC

[groovy] branch danielsun/tweak-resolving-further updated (9786373 -> 090ac11)

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

sunlan pushed a change to branch danielsun/tweak-resolving-further
in repository https://gitbox.apache.org/repos/asf/groovy.git.


 discard 9786373  Try to address the bug - 6
 discard 3183317  Try to address the bug - 5
 discard 18746ac  Try to address the bug - 4
 discard b2e4dc6  Try to address the bug - 3
 discard d44cd85  Try to address the bug - 2
 discard 07ef71e  Try to address the bug - 1
 discard 2f608f3  GROOVY-9416: Avoid unnecessary looking up non default import classes when resolving types
     new 090ac11  GROOVY-9416: Avoid unnecessary looking up non default import classes when resolving types

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (9786373)
            \
             N -- N -- N   refs/heads/danielsun/tweak-resolving-further (090ac11)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

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.


Summary of changes:
 .github/workflows/gradle.yml                                 |  4 ++--
 .../java/org/codehaus/groovy/control/ResolveVisitor.java     | 12 +++++-------
 src/main/java/org/codehaus/groovy/vmplugin/VMPlugin.java     | 12 ++++++++++++
 src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java     | 11 +++++++----
 .../org/codehaus/groovy/vmplugin/v9/ClassFinderTest.groovy   |  6 ++++++
 5 files changed, 32 insertions(+), 13 deletions(-)


[groovy] 01/01: GROOVY-9416: Avoid unnecessary looking up non default import classes when resolving types

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

sunlan pushed a commit to branch danielsun/tweak-resolving-further
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 090ac119e9bfffa46335aa0108ccf452a92b6fbf
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sat Feb 22 11:22:36 2020 +0800

    GROOVY-9416: Avoid unnecessary looking up non default import classes when resolving types
---
 .../java/org/codehaus/groovy/control/ResolveVisitor.java     |  5 +++--
 src/main/java/org/codehaus/groovy/vmplugin/VMPlugin.java     | 12 ++++++++++++
 src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java     |  7 +++++++
 .../org/codehaus/groovy/vmplugin/v9/ClassFinderTest.groovy   |  6 ++++++
 4 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java b/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
index 4395dc8..de43cf9 100644
--- a/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
+++ b/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
@@ -621,9 +621,10 @@ public class ResolveVisitor extends ClassCodeExpressionTransformer {
                 }
             }
 
-            if (resolveFromDefaultImports(type, DEFAULT_IMPORTS)) {
+            if (VMPluginFactory.getPlugin().resolveFromDefaultImports(this, type)) {
                 return true;
             }
+
             if (BIGINTEGER_STR.equals(typeName)) {
                 type.setRedirect(ClassHelper.BigInteger_TYPE);
                 return true;
@@ -642,7 +643,7 @@ public class ResolveVisitor extends ClassCodeExpressionTransformer {
         DEFAULT_IMPORT_CLASS_AND_PACKAGES_CACHE.putAll(defaultImportClasses);
     }
 
-    protected boolean resolveFromDefaultImports(final ClassNode type, final String[] packagePrefixes) {
+    public boolean resolveFromDefaultImports(final ClassNode type, final String[] packagePrefixes) {
         String typeName = type.getName();
 
         for (String packagePrefix : packagePrefixes) {
diff --git a/src/main/java/org/codehaus/groovy/vmplugin/VMPlugin.java b/src/main/java/org/codehaus/groovy/vmplugin/VMPlugin.java
index 7ef1065..7165bdd 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/VMPlugin.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/VMPlugin.java
@@ -23,6 +23,7 @@ import groovy.lang.MetaMethod;
 import org.codehaus.groovy.ast.AnnotationNode;
 import org.codehaus.groovy.ast.ClassNode;
 import org.codehaus.groovy.ast.CompileUnit;
+import org.codehaus.groovy.control.ResolveVisitor;
 
 import java.lang.reflect.AccessibleObject;
 import java.lang.reflect.Method;
@@ -125,4 +126,15 @@ public interface VMPlugin {
     default Map<String, Set<String>> getDefaultImportClasses(String[] packageNames) {
         return Collections.emptyMap();
     }
+
+    /**
+     * Resolve types from default imported packages
+     *
+     * @param resolveVisitor the resolve visitor
+     * @param type the type to resolve
+     * @return resolved or not
+     */
+    default boolean resolveFromDefaultImports(ResolveVisitor resolveVisitor, final ClassNode type) {
+        return resolveVisitor.resolveFromDefaultImports(type, ResolveVisitor.DEFAULT_IMPORTS);
+    }
 }
diff --git a/src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java b/src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java
index 60b354d..e3097b9 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java
@@ -25,6 +25,8 @@ import groovy.lang.MetaMethod;
 import groovy.lang.Tuple;
 import groovy.lang.Tuple2;
 import org.codehaus.groovy.GroovyBugError;
+import org.codehaus.groovy.ast.ClassNode;
+import org.codehaus.groovy.control.ResolveVisitor;
 import org.codehaus.groovy.reflection.CachedClass;
 import org.codehaus.groovy.reflection.CachedMethod;
 import org.codehaus.groovy.reflection.ReflectionUtils;
@@ -106,6 +108,11 @@ public class Java9 extends Java8 {
         return result;
     }
 
+    @Override
+    public boolean resolveFromDefaultImports(ResolveVisitor resolveVisitor, final ClassNode type) {
+        return false;
+    }
+
     private static class LookupHolder {
         private static final Method PRIVATE_LOOKUP;
         private static final Constructor<MethodHandles.Lookup> LOOKUP_Constructor;
diff --git a/src/test/org/codehaus/groovy/vmplugin/v9/ClassFinderTest.groovy b/src/test/org/codehaus/groovy/vmplugin/v9/ClassFinderTest.groovy
index 37ee4b0..f12a8e2 100644
--- a/src/test/org/codehaus/groovy/vmplugin/v9/ClassFinderTest.groovy
+++ b/src/test/org/codehaus/groovy/vmplugin/v9/ClassFinderTest.groovy
@@ -46,6 +46,12 @@ class ClassFinderTest {
     }
 
     @Test
+    void findGroovyClass4() {
+        Map<String, Set<String>> result = ClassFinder.find(ConfigSlurper.location.toURI(), "groovy/util")
+        assert ["groovy/util"] == result.get("ConfigSlurper")?.toList()
+    }
+
+    @Test
     void findGroovyClassRecursive() {
         Map<String, Set<String>> result = ClassFinder.find(GroovySystem.location.toURI(), "groovy/lang", true)
         assert ["groovy/lang"] == result.get("GString")?.toList()