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 2019/08/30 20:20:49 UTC

[groovy] branch danielsun1106-patch-1 updated (dda33b4 -> 6e387d0)

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

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


 discard dda33b4  GROOVY-9236: Avoid unnecessary resolving
     new 6e387d0  GROOVY-9236: Avoid unnecessary resolving

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   (dda33b4)
            \
             N -- N -- N   refs/heads/danielsun1106-patch-1 (6e387d0)

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:
 .../groovy/bugs/groovy9236/Groovy9236.groovy                 |  0
 .../groovy/bugs/groovy9236/Groovy9236SamePkg.groovy}         |  2 +-
 .../groovy/bugs/groovy9236/Main.groovy}                      | 12 ++++++++++--
 src/test/groovy/bugs/groovy9236/Groovy9236Bug.groovy         | 12 ++++++++----
 4 files changed, 19 insertions(+), 7 deletions(-)
 copy src/{test => test-resources}/groovy/bugs/groovy9236/Groovy9236.groovy (100%)
 copy src/{test/groovy/bugs/groovy9236/Groovy9236.groovy => test-resources/groovy/bugs/groovy9236/Groovy9236SamePkg.groovy} (96%)
 rename src/{test/groovy/bugs/groovy9236/Groovy9236.groovy => test-resources/groovy/bugs/groovy9236/Main.groovy} (81%)


[groovy] 01/01: GROOVY-9236: Avoid unnecessary resolving

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

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

commit 6e387d09b00663faccb8390a027e7e4d23a7a011
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sat Aug 31 04:19:53 2019 +0800

    GROOVY-9236: Avoid unnecessary resolving
---
 .../codehaus/groovy/control/ResolveVisitor.java    |   6 +-
 .../groovy/bugs/groovy9236/Groovy9236.groovy       |  23 ++++
 .../bugs/groovy9236/Groovy9236SamePkg.groovy       |  23 ++++
 .../groovy/bugs/groovy9236/Main.groovy             |  31 ++++++
 .../groovy/bugs/groovy9236/Groovy9236Bug.groovy    | 124 +++++++++++++++++++++
 5 files changed, 204 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java b/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
index 9f6cf24..0610f24 100644
--- a/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
+++ b/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
@@ -462,12 +462,12 @@ public class ResolveVisitor extends ClassCodeExpressionTransformer {
             return true;
         }
 
-        return resolveNestedClass(type) ||
+        return  resolveNestedClass(type) ||
                 resolveFromModule(type, testModuleImports) ||
                 resolveFromCompileUnit(type) ||
                 resolveFromDefaultImports(type, testDefaultImports) ||
-                resolveFromStaticInnerClasses(type, testStaticInnerClasses) ||
-                resolveToOuter(type);
+                resolveToOuter(type) ||
+                resolveFromStaticInnerClasses(type, testStaticInnerClasses);
     }
 
     private boolean resolveNestedClass(ClassNode type) {
diff --git a/src/test-resources/groovy/bugs/groovy9236/Groovy9236.groovy b/src/test-resources/groovy/bugs/groovy9236/Groovy9236.groovy
new file mode 100644
index 0000000..ef1a1ac
--- /dev/null
+++ b/src/test-resources/groovy/bugs/groovy9236/Groovy9236.groovy
@@ -0,0 +1,23 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package groovy.bugs.groovy9236
+
+interface Groovy9236 {
+
+}
\ No newline at end of file
diff --git a/src/test-resources/groovy/bugs/groovy9236/Groovy9236SamePkg.groovy b/src/test-resources/groovy/bugs/groovy9236/Groovy9236SamePkg.groovy
new file mode 100644
index 0000000..69a5f56
--- /dev/null
+++ b/src/test-resources/groovy/bugs/groovy9236/Groovy9236SamePkg.groovy
@@ -0,0 +1,23 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package groovy.bugs.groovy9236
+
+class Groovy9236SamePkg {
+
+}
\ No newline at end of file
diff --git a/src/test-resources/groovy/bugs/groovy9236/Main.groovy b/src/test-resources/groovy/bugs/groovy9236/Main.groovy
new file mode 100644
index 0000000..e1767b4
--- /dev/null
+++ b/src/test-resources/groovy/bugs/groovy9236/Main.groovy
@@ -0,0 +1,31 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package groovy.bugs.groovy9236
+
+class Outer {
+    static class Groovy9236 {}
+
+    def test() {
+        assert new Groovy9236()
+        assert new Outer.Groovy9236()
+        assert new Groovy9236SamePkg()
+    }
+}
+
+new Outer().test()
diff --git a/src/test/groovy/bugs/groovy9236/Groovy9236Bug.groovy b/src/test/groovy/bugs/groovy9236/Groovy9236Bug.groovy
new file mode 100644
index 0000000..0ad30d0
--- /dev/null
+++ b/src/test/groovy/bugs/groovy9236/Groovy9236Bug.groovy
@@ -0,0 +1,124 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package groovy.bugs.groovy9236
+
+import org.codehaus.groovy.tools.GroovyStarter
+
+class Groovy9236Bug extends GroovyTestCase {
+    /* groovy-3.0.0-beta-3 will try to guess and load the following classes:
+Script1$_p_lambda1BeanInfo
+Script1$_p_lambda1Customizer
+Script1BeanInfo
+Script1Customizer
+groovy$transform$CompileStatic
+groovy.lang.GroovyObject$Collectors
+groovy.lang.GroovyObject$CompileStatic
+groovy.lang.GroovyObject$groovy$transform$CompileStatic
+groovy.lang.GroovyObject$java$util$stream$Collectors
+groovy.lang.GroovyObject$java$util$stream$Stream
+groovy.lang.groovy$transform$CompileStatic
+groovy.lang.java$util$stream$Collectors
+groovy.lang.java$util$stream$Stream
+groovy.transform$CompileStatic
+groovy.util.groovy$transform$CompileStatic
+groovy.util.java$util$stream$Collectors
+groovy.util.java$util$stream$Stream
+java$util$stream$Collectors
+java$util$stream$Stream
+java.io.groovy$transform$CompileStatic
+java.io.java$util$stream$Collectors
+java.io.java$util$stream$Stream
+java.lang.groovy$transform$CompileStatic
+java.lang.java$util$stream$Collectors
+java.lang.java$util$stream$Stream
+java.net.groovy$transform$CompileStatic
+java.net.java$util$stream$Collectors
+java.net.java$util$stream$Stream
+java.util$stream$Collectors
+java.util$stream$Stream
+java.util.groovy$transform$CompileStatic
+java.util.java$util$stream$Collectors
+java.util.java$util$stream$Stream
+java.util.stream$Collectors
+java.util.stream$Stream
+     */
+    void testAvoidUnnecessaryResolving() {
+        def cl = new Groovy9236ClassLoader()
+        def gs = new GroovyShell(cl)
+        gs.evaluate('''
+                import groovy.transform.CompileStatic
+                import java.util.stream.Collectors
+                import java.util.stream.Stream
+                
+                @CompileStatic
+                void p() {
+                    assert [2, 3, 4] == [1, 2, 3].stream().map(e -> e.plus 1).collect(Collectors.toList())
+                }
+                
+                p()
+        ''')
+
+        final classNamesShouldAvoidToGuess = ['java.lang.java$util$stream$Collectors',
+                                              'java.util.java$util$stream$Collectors',
+                                              'java.io.java$util$stream$Collectors',
+                                              'java.net.java$util$stream$Collectors',
+                                              'groovy.lang.java$util$stream$Collectors',
+                                              'groovy.util.java$util$stream$Collectors',
+                                              'java$util$stream$Collectors',
+                                              'java.util$stream$Collectors',
+                                              'java.util.stream$Collectors',
+                                              'java.lang.groovy$transform$CompileStatic',
+                                              'java.util.groovy$transform$CompileStatic',
+                                              'java.io.groovy$transform$CompileStatic',
+                                              'java.net.groovy$transform$CompileStatic',
+                                              'groovy.lang.groovy$transform$CompileStatic',
+                                              'groovy.util.groovy$transform$CompileStatic',
+                                              'groovy$transform$CompileStatic',
+                                              'groovy.transform$CompileStatic',
+                                              'java.lang.java$util$stream$Stream',
+                                              'java.util.java$util$stream$Stream',
+                                              'java.io.java$util$stream$Stream',
+                                              'java.net.java$util$stream$Stream',
+                                              'groovy.lang.java$util$stream$Stream',
+                                              'groovy.util.java$util$stream$Stream',
+                                              'java$util$stream$Stream',
+                                              'java.util$stream$Stream',
+                                              'java.util.stream$Stream']
+
+        assert cl.guessedClassNameList.every(n -> !classNamesShouldAvoidToGuess.contains(n))
+    }
+
+    void testResolvingPrecedence() {
+        def mainScriptPath = new File(this.getClass().getResource('/groovy/bugs/groovy9236/Main.groovy').toURI()).absolutePath
+        runScript(mainScriptPath)
+    }
+
+    static void runScript(String path) {
+        GroovyStarter.main(new String[] { "--main", "groovy.ui.GroovyMain", path })
+    }
+
+    private static class Groovy9236ClassLoader extends GroovyClassLoader {
+        def guessedClassNameList = []
+
+        protected Class<?> findClass(final String name) throws ClassNotFoundException {
+            guessedClassNameList << name
+            super.findClass(name)
+        }
+    }
+}