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/12/23 00:34:21 UTC

[groovy] branch GROOVY_3_0_X updated (6779bd5 -> 98964b8)

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

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


    from 6779bd5  Update javadoc
     new 9d6b245  add wildcard support to isUsingUncheckedGenerics and missesGenericsTypes
     new d61ec94  remove repeat call to findSAM(ClassNode)
     new aa4e233  minor edits
     new 045b512  Remove redundant fields and reduce the visibility of lazy nodes
     new 98964b8  Tweak test

The 5 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/ast/decompiled/LazyConstructorNode.java |  7 ++---
 .../groovy/ast/decompiled/LazyFieldNode.java       |  7 ++---
 .../groovy/ast/decompiled/LazyMethodNode.java      |  7 ++---
 .../transform/stc/StaticTypeCheckingSupport.java   | 34 ++++++++++++++--------
 .../transform/stc/StaticTypeCheckingVisitor.java   | 32 ++++++++++----------
 .../test/groovy/groovy/ant/Groovy9352Test.groovy   | 20 ++++++++++++-
 6 files changed, 64 insertions(+), 43 deletions(-)


[groovy] 04/05: Remove redundant fields and reduce the visibility of lazy nodes

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

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

commit 045b512a399d3dbebe1e7792170a5606b5b6d8c4
Author: Daniel.Sun <re...@hotmail.com>
AuthorDate: Mon Dec 23 08:03:29 2019 +0800

    Remove redundant fields and reduce the visibility of lazy nodes
    
    (cherry picked from commit 0820faeba736a376194cd9a80835f8d6813026f9)
---
 .../org/codehaus/groovy/ast/decompiled/LazyConstructorNode.java    | 7 ++-----
 .../java/org/codehaus/groovy/ast/decompiled/LazyFieldNode.java     | 7 ++-----
 .../java/org/codehaus/groovy/ast/decompiled/LazyMethodNode.java    | 7 ++-----
 3 files changed, 6 insertions(+), 15 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/ast/decompiled/LazyConstructorNode.java b/src/main/java/org/codehaus/groovy/ast/decompiled/LazyConstructorNode.java
index a4b08b4..50bef15 100644
--- a/src/main/java/org/codehaus/groovy/ast/decompiled/LazyConstructorNode.java
+++ b/src/main/java/org/codehaus/groovy/ast/decompiled/LazyConstructorNode.java
@@ -41,23 +41,20 @@ import java.util.function.Supplier;
  *
  * @since 2.5.9
  */
-public class LazyConstructorNode extends ConstructorNode {
+class LazyConstructorNode extends ConstructorNode {
     private final Supplier<ConstructorNode> constructorNodeSupplier;
     private ConstructorNode delegate;
-    private boolean initialized;
 
     public LazyConstructorNode(Supplier<ConstructorNode> constructorNodeSupplier) {
         this.constructorNodeSupplier = constructorNodeSupplier;
     }
 
     private void init() {
-        if (initialized) return;
+        if (null != delegate) return;
         delegate = constructorNodeSupplier.get();
 
         ClassNode declaringClass = super.getDeclaringClass();
         if (null != declaringClass) delegate.setDeclaringClass(declaringClass);
-
-        initialized = true;
     }
 
     @Override
diff --git a/src/main/java/org/codehaus/groovy/ast/decompiled/LazyFieldNode.java b/src/main/java/org/codehaus/groovy/ast/decompiled/LazyFieldNode.java
index 4dea774..94d2ed5 100644
--- a/src/main/java/org/codehaus/groovy/ast/decompiled/LazyFieldNode.java
+++ b/src/main/java/org/codehaus/groovy/ast/decompiled/LazyFieldNode.java
@@ -38,10 +38,9 @@ import java.util.function.Supplier;
  *
  * @since 2.5.9
  */
-public class LazyFieldNode extends FieldNode {
+class LazyFieldNode extends FieldNode {
     private final Supplier<FieldNode> fieldNodeSupplier;
     private FieldNode delegate;
-    private boolean initialized;
 
     private String name;
 
@@ -51,7 +50,7 @@ public class LazyFieldNode extends FieldNode {
     }
 
     private void init() {
-        if (initialized) return;
+        if (null != delegate) return;
         delegate = fieldNodeSupplier.get();
 
         ClassNode declaringClass = super.getDeclaringClass();
@@ -59,8 +58,6 @@ public class LazyFieldNode extends FieldNode {
 
         ClassNode owner = super.getOwner();
         if (null != owner) delegate.setOwner(owner);
-
-        initialized = true;
     }
 
     @Override
diff --git a/src/main/java/org/codehaus/groovy/ast/decompiled/LazyMethodNode.java b/src/main/java/org/codehaus/groovy/ast/decompiled/LazyMethodNode.java
index 2cd8fd0..11f12da 100644
--- a/src/main/java/org/codehaus/groovy/ast/decompiled/LazyMethodNode.java
+++ b/src/main/java/org/codehaus/groovy/ast/decompiled/LazyMethodNode.java
@@ -41,10 +41,9 @@ import java.util.function.Supplier;
  *
  * @since 2.5.9
  */
-public class LazyMethodNode extends MethodNode {
+class LazyMethodNode extends MethodNode {
     private final Supplier<MethodNode> methodNodeSupplier;
     private MethodNode delegate;
-    private boolean initialized;
 
     private String name;
 
@@ -54,13 +53,11 @@ public class LazyMethodNode extends MethodNode {
     }
 
     private void init() {
-        if (initialized) return;
+        if (null != delegate) return;
         delegate = methodNodeSupplier.get();
 
         ClassNode declaringClass = super.getDeclaringClass();
         if (null != declaringClass) delegate.setDeclaringClass(declaringClass);
-
-        initialized = true;
     }
 
     @Override


[groovy] 02/05: remove repeat call to findSAM(ClassNode)

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

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

commit d61ec94046261589e5dec4302958636ef03eeff0
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Sun Dec 22 13:17:49 2019 -0600

    remove repeat call to findSAM(ClassNode)
    
    (cherry picked from commit 7f1ef57ff967441cc98c1c1ff925aaf4f7979626)
---
 .../groovy/transform/stc/StaticTypeCheckingVisitor.java        | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
index fea37f6..4abb7f3 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -4166,17 +4166,19 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
         Expression leftExpression = expr.getLeftExpression();
         Expression rightExpression = expr.getRightExpression();
 
-        if (op == ASSIGN || op == ASSIGNMENT_OPERATOR || op == ELVIS_EQUAL) {
-            if (rightRedirect.isDerivedFrom(CLOSURE_TYPE) && isSAMType(leftRedirect)) {
+        if (op == EQUAL || op == ELVIS_EQUAL) {
+            if (rightRedirect.isDerivedFrom(CLOSURE_TYPE)) {
                 ClosureExpression closureExpression = null;
                 if (rightExpression instanceof ClosureExpression) {
                     closureExpression = (ClosureExpression) rightExpression;
                 } else if (rightExpression instanceof MethodReferenceExpression) {
                     closureExpression = rightExpression.getNodeMetaData(CONSTRUCTED_LAMBDA_EXPRESSION);
                 }
-
                 if (closureExpression != null) {
-                    return inferSAMTypeGenericsInAssignment(left, findSAM(left), right, closureExpression);
+                    MethodNode abstractMethod = findSAM(left);
+                    if (abstractMethod != null) {
+                        return inferSAMTypeGenericsInAssignment(left, abstractMethod, right, closureExpression);
+                    }
                 }
             }
 


[groovy] 05/05: Tweak test

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

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

commit 98964b8e1a459e7645c7857793548f261b761db2
Author: Daniel.Sun <re...@hotmail.com>
AuthorDate: Mon Dec 23 08:04:06 2019 +0800

    Tweak test
    
    (cherry picked from commit b73e9398b7d55e65d6862412fa3f198893cdbec8)
---
 .../src/test/groovy/groovy/ant/Groovy9352Test.groovy | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/subprojects/groovy-ant/src/test/groovy/groovy/ant/Groovy9352Test.groovy b/subprojects/groovy-ant/src/test/groovy/groovy/ant/Groovy9352Test.groovy
index 566f86e..a53b60f 100644
--- a/subprojects/groovy-ant/src/test/groovy/groovy/ant/Groovy9352Test.groovy
+++ b/subprojects/groovy-ant/src/test/groovy/groovy/ant/Groovy9352Test.groovy
@@ -51,12 +51,15 @@ class Groovy9352Test extends AntTestCase {
                            private Gson gson;
                            private Gson gson2 = new SubGson();
                            private List<Gson> gsonList;
+                           @GsonAnnotation
                            private List<? extends Gson> gsonList2 = new ArrayList<SubGson>();
                            
+                           @GsonAnnotation
                            private Producer(Gson p) {}
                            private Producer(int p) throws Gson {}
                            private Producer() { gson = new Gson(); }
                            
+                           @GsonAnnotation
                            private void bar(Gson p) {}
                            private Gson bar() { return null;}
                            private void bar(int p) throws Gson {}
@@ -73,6 +76,18 @@ class Groovy9352Test extends AntTestCase {
                         class SubGson extends Gson {
                         }
                     ''')
+                    'GsonAnnotation.java'('''
+                        package p2;
+                        import java.lang.annotation.ElementType;
+                        import java.lang.annotation.Retention;
+                        import java.lang.annotation.RetentionPolicy;
+                        import java.lang.annotation.Target;
+                        
+                        @Target({ElementType.TYPE, ElementType.ANNOTATION_TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.CONSTRUCTOR})
+                        @Retention(RetentionPolicy.RUNTIME)
+                        @interface GsonAnnotation {
+                        }
+                    ''')
                 }
             }
 
@@ -84,11 +99,14 @@ class Groovy9352Test extends AntTestCase {
                 javac()
             }
 
-            // 2) delete `Gson` and `SubGson` related files: "Gson.java", "Gson.class", "SubGson.java" and "SubGson.class"
+            // 2) delete `Gson`, `SubGson`, `GsonAnnotation` related files:
+            // "Gson.java", "Gson.class", "SubGson.java", "SubGson.class", "GsonAnnotation.java", "GsonAnnotation.class"
             assert new File(ant.project.baseDir,"src/p2/Gson.java").delete()
             assert new File(ant.project.baseDir,"build/p2/Gson.class").delete()
             assert new File(ant.project.baseDir,"src/p2/SubGson.java").delete()
             assert new File(ant.project.baseDir,"build/p2/SubGson.class").delete()
+            assert new File(ant.project.baseDir,"src/p2/GsonAnnotation.java").delete()
+            assert new File(ant.project.baseDir,"build/p2/GsonAnnotation.class").delete()
 
             // 3) compile the Groovy source code
             ant.groovyc(srcdir: 'src', destdir: 'build', includes: 'p1/*')


[groovy] 03/05: minor edits

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

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

commit aa4e2337482298aa3e73b6c3a1c2fbe8e049fe67
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Sun Dec 22 13:47:43 2019 -0600

    minor edits
    
    (cherry picked from commit d51f5aae39b8a897ba04658d8ace4ec4c930643f)
---
 .../transform/stc/StaticTypeCheckingVisitor.java   | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
index 4abb7f3..659597a 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -4312,30 +4312,30 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
         return null;
     }
 
-    private ClassNode inferSAMTypeGenericsInAssignment(final ClassNode samUsage, final MethodNode sam, final ClassNode closureType, final ClosureExpression closureExpression) {
+    private ClassNode inferSAMTypeGenericsInAssignment(final ClassNode samType, final MethodNode abstractMethod, final ClassNode closureType, final ClosureExpression closureExpression) {
         // if the sam type or closure type do not provide generics information,
         // we cannot infer anything, thus we simply return the provided samUsage
-        GenericsType[] samGt = samUsage.getGenericsTypes();
-        GenericsType[] closureGt = closureType.getGenericsTypes();
-        if (samGt == null || closureGt == null) return samUsage;
+        GenericsType[] samTypeGenerics = samType.getGenericsTypes();
+        GenericsType[] closureGenerics = closureType.getGenericsTypes();
+        if (samTypeGenerics == null || closureGenerics == null) return samType;
 
         // extract the generics from the return type
         Map<GenericsTypeName, GenericsType> connections = new HashMap<>();
-        extractGenericsConnections(connections, getInferredReturnType(closureExpression), sam.getReturnType());
+        extractGenericsConnections(connections, getInferredReturnType(closureExpression), abstractMethod.getReturnType());
 
         // next we get the block parameter types and set the generics
         // information just like before
         // TODO: add vargs handling
         if (closureExpression.isParameterSpecified()) {
             Parameter[] closureParams = closureExpression.getParameters();
-            Parameter[] methodParams = sam.getParameters();
-            for (int i = 0; i < closureParams.length; i++) {
-                ClassNode fromClosure = closureParams[i].getType();
-                ClassNode fromMethod = methodParams[i].getType();
-                extractGenericsConnections(connections, fromClosure, fromMethod);
+            Parameter[] methodParams = abstractMethod.getParameters();
+            for (int i = 0, n = closureParams.length; i < n; i += 1) {
+                ClassNode closureParamType = closureParams[i].getType();
+                ClassNode methodParamType = methodParams[i].getType();
+                extractGenericsConnections(connections, closureParamType, methodParamType);
             }
         }
-        return applyGenericsContext(connections, samUsage.redirect());
+        return applyGenericsContext(connections, samType.redirect());
     }
 
     protected static ClassNode getGroupOperationResultType(final ClassNode a, final ClassNode b) {


[groovy] 01/05: add wildcard support to isUsingUncheckedGenerics and missesGenericsTypes

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

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

commit 9d6b24573408300f9755769f934faeb7a4f81d40
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Sun Dec 22 13:14:09 2019 -0600

    add wildcard support to isUsingUncheckedGenerics and missesGenericsTypes
    
    (cherry picked from commit d443bb0cc9b1087aa9f8c23b8d799faf7446df37)
---
 .../transform/stc/StaticTypeCheckingSupport.java   | 34 ++++++++++++++--------
 1 file changed, 22 insertions(+), 12 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
index 0184a83..5f2e6a6 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
@@ -1007,21 +1007,22 @@ public abstract class StaticTypeCheckingSupport {
      */
     public static boolean isUsingUncheckedGenerics(final ClassNode node) {
         if (node.isArray()) return isUsingUncheckedGenerics(node.getComponentType());
-        if (node.isUsingGenerics()) {
-            GenericsType[] genericsTypes = node.getGenericsTypes();
-            if (genericsTypes != null) {
-                for (GenericsType genericsType : genericsTypes) {
-                    if (genericsType.isPlaceholder()) {
-                        return true;
-                    } else {
-                        if (isUsingUncheckedGenerics(genericsType.getType())) {
-                            return true;
-                        }
+        GenericsType[] genericsTypes = node.getGenericsTypes();
+        if (genericsTypes != null) {
+            for (GenericsType genericsType : genericsTypes) {
+                if (genericsType.isPlaceholder()) return true;
+                if (genericsType.isWildcard()) {
+                    ClassNode lowerBound = genericsType.getLowerBound();
+                    ClassNode[] upperBounds = genericsType.getUpperBounds();
+                    if (lowerBound != null) {
+                        if (lowerBound.isGenericsPlaceHolder() || isUsingUncheckedGenerics(lowerBound)) return true;
+                    } else if (upperBounds != null) {
+                        if (upperBounds[0].isGenericsPlaceHolder() || isUsingUncheckedGenerics(upperBounds[0])) return true;
                     }
+                } else {
+                    if (isUsingUncheckedGenerics(genericsType.getType())) return true;
                 }
             }
-        } else {
-            return false;
         }
         return false;
     }
@@ -2146,6 +2147,15 @@ public abstract class StaticTypeCheckingSupport {
         if (cnTypes != null) {
             for (GenericsType genericsType : cnTypes) {
                 if (genericsType.isPlaceholder()) return true;
+                if (genericsType.isWildcard()) {
+                    ClassNode lowerBound = genericsType.getLowerBound();
+                    ClassNode[] upperBounds = genericsType.getUpperBounds();
+                    if (lowerBound != null) {
+                        if (lowerBound.isGenericsPlaceHolder() || missesGenericsTypes(lowerBound)) return true;
+                    } else if (upperBounds != null) {
+                        if (upperBounds[0].isGenericsPlaceHolder() || missesGenericsTypes(upperBounds[0])) return true;
+                    }
+                }
             }
         }
         return false;