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


The following commit(s) were added to refs/heads/master by this push:
     new 92ec881  GROOVY-3945, GROOVY-7490, GROOVY-8389: remove redundant 
transformation
92ec881 is described below

commit 92ec8815c72a2cf9e6e2153cf5eb3f37b89c8990
Author: Eric Milles <[email protected]>
AuthorDate: Mon Oct 25 13:33:07 2021 -0500

    GROOVY-3945, GROOVY-7490, GROOVY-8389: remove redundant transformation
---
 .../groovy/control/StaticImportVisitor.java        |  8 -----
 src/test/groovy/StaticImportTest.groovy            | 38 +++++++++++++++++++---
 2 files changed, 33 insertions(+), 13 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/control/StaticImportVisitor.java 
b/src/main/java/org/codehaus/groovy/control/StaticImportVisitor.java
index 8ef0b70..4c257f9 100644
--- a/src/main/java/org/codehaus/groovy/control/StaticImportVisitor.java
+++ b/src/main/java/org/codehaus/groovy/control/StaticImportVisitor.java
@@ -254,14 +254,6 @@ public class StaticImportVisitor extends 
ClassCodeExpressionTransformer {
                     setSourcePosition(result, mce);
                     return result;
                 }
-                if (name != null && !inLeftExpression) { // maybe a closure 
field
-                    result = 
findStaticFieldOrPropertyAccessorImportFromModule(name);
-                    if (result != null) {
-                        result = new MethodCallExpression(result, "call", 
args);
-                        result.setSourcePosition(mce);
-                        return result;
-                    }
-                }
             }
         } else if (currentMethod != null && currentMethod.isStatic() && 
isSuperExpression(object)) {
             Expression result = new MethodCallExpression(new 
ClassExpression(currentClass.getSuperClass()), method, args);
diff --git a/src/test/groovy/StaticImportTest.groovy 
b/src/test/groovy/StaticImportTest.groovy
index 445f86d..465bc9a 100644
--- a/src/test/groovy/StaticImportTest.groovy
+++ b/src/test/groovy/StaticImportTest.groovy
@@ -26,12 +26,10 @@ import static junit.framework.Assert.format
 import static junit.framework.Assert.assertEquals
 import static groovy.StaticImportTarget.x
 import static groovy.StaticImportTarget.z // do not remove
-import static groovy.StaticImportTarget.getCl
 import static java.lang.Math.*
 import static java.util.Calendar.getInstance as now
 import static groovy.API.*
 import static groovy.StaticImportChild.*
-import static groovy.bugs.Groovy4145.foo4145
 import static groovy.Outer1.*
 import static groovy.Outer2.Inner2
 import static groovy.Outer2.Inner2 as InnerAlias2
@@ -418,13 +416,43 @@ final class StaticImportTest extends 
groovy.test.GroovyTestCase {
     }
 
     // GROOVY-3945
-    void testStaticImportOfAClosureProperty() {
-        assert cl() == 'StaticImportTarget#static closure called'
+    void testStaticImportOfClosureProperty() {
+        assertScript '''
+            import static groovy.StaticImportTarget.cl
+            String result = cl()
+            assert result == 'StaticImportTarget#static closure called'
+        '''
+    }
+
+    // GROOVY-7490
+    void testStaticImportOfCallableProperty() {
+        assertScript '''
+            class WithCall {
+                String call(String input) {
+                    return input
+                }
+            }
+            class Pogo {
+                static final WithCall callable_property = new WithCall()
+            }
+
+            import static Pogo.callable_property
+
+            @groovy.transform.CompileStatic
+            def usage() {
+                callable_property('works')
+            }
+            String result = usage()
+            assert result == 'works'
+        '''
     }
 
     // GROOVY-4145
     void testStaticPropertyImportedImplementedAsGetter() {
-        assert foo4145 == 3
+        assertScript '''
+            import static groovy.bugs.Groovy4145.foo4145
+            assert foo4145 == 3
+        '''
     }
 
     void 
testMethodCallExpressionInStaticContextWithInstanceVariableShouldFail() { 
//GROOVY-4228

Reply via email to