groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From emil...@apache.org
Subject [groovy] 02/02: minor edits
Date Tue, 17 Dec 2019 02:40:28 GMT
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

commit 8fe41a2feff9960a6b9bcd62a1077b32ccde839b
Author: Eric Milles <eric.milles@thomsonreuters.com>
AuthorDate: Mon Dec 16 20:22:50 2019 -0600

    minor edits
---
 .../java/org/codehaus/groovy/ast/ClassHelper.java  | 27 ++++++++++------------
 .../org/codehaus/groovy/ast/VariableScope.java     |  3 +--
 .../groovy/classgen/asm/InvocationWriter.java      |  7 +++---
 .../groovy/control/ParserPluginFactory.java        |  2 +-
 .../codehaus/groovy/control/ResolveVisitor.java    |  3 ++-
 .../groovy/transform/ASTTransformationVisitor.java |  4 ++--
 6 files changed, 21 insertions(+), 25 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/ast/ClassHelper.java b/src/main/java/org/codehaus/groovy/ast/ClassHelper.java
index 0a659d2..17bcc8d 100644
--- a/src/main/java/org/codehaus/groovy/ast/ClassHelper.java
+++ b/src/main/java/org/codehaus/groovy/ast/ClassHelper.java
@@ -68,7 +68,6 @@ import java.math.BigInteger;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.Objects;
 import java.util.regex.Pattern;
 
 /**
@@ -408,38 +407,36 @@ public class ClassHelper {
         return false;
     }
 
-    /**
-     * Check if the type is a generated function, i.e. closure/lambda
-     * @param type the type to check
-     * @return the check result
-     * @since 3.0.0
-     */
-    public static boolean isGeneratedFunction(ClassNode type) {
-        Objects.requireNonNull(type, "type should not be null");
-        return type.implementsAnyInterfaces(GENERATED_CLOSURE_Type, GENERATED_LAMBDA_TYPE);
-    }
-
     static class ClassHelperCache {
         static ManagedConcurrentMap<Class, SoftReference<ClassNode>> classCache
= new ManagedConcurrentMap<Class, SoftReference<ClassNode>>(ReferenceBundle.getWeakBundle());
     }
 
-    public static boolean isSAMType(ClassNode type) {
+    public static boolean isSAMType(final ClassNode type) {
         return findSAM(type) != null;
     }
 
-    public static boolean isFunctionalInterface(ClassNode type) {
+    public static boolean isFunctionalInterface(final ClassNode type) {
         // Functional interface must be an interface at first, or the following exception
will occur:
         // java.lang.invoke.LambdaConversionException: Functional interface SamCallable is
not an interface
         return type.isInterface() && isSAMType(type);
     }
 
     /**
+     * Checks if the type is a generated function, i.e. closure or lambda.
+     *
+     * @since 3.0.0
+     */
+    public static boolean isGeneratedFunction(final ClassNode type) {
+        return type.implementsAnyInterfaces(GENERATED_CLOSURE_Type, GENERATED_LAMBDA_TYPE);
+    }
+
+    /**
      * Returns the single abstract method of a class node, if it is a SAM type, or null otherwise.
      *
      * @param type a type for which to search for a single abstract method
      * @return the method node if type is a SAM type, null otherwise
      */
-    public static MethodNode findSAM(ClassNode type) {
+    public static MethodNode findSAM(final ClassNode type) {
         if (!Modifier.isAbstract(type.getModifiers())) return null;
         if (type.isInterface()) {
             List<MethodNode> methods;
diff --git a/src/main/java/org/codehaus/groovy/ast/VariableScope.java b/src/main/java/org/codehaus/groovy/ast/VariableScope.java
index 4b0fbfc..942cfd5 100644
--- a/src/main/java/org/codehaus/groovy/ast/VariableScope.java
+++ b/src/main/java/org/codehaus/groovy/ast/VariableScope.java
@@ -27,7 +27,7 @@ import java.util.Map;
  * Records declared and referenced variabes for a given scope.  Helps determine
  * variable sharing across closure and method boundaries.
  */
-public class VariableScope implements Cloneable {
+public class VariableScope {
 
     private VariableScope parent;
     private ClassNode classScope;
@@ -186,7 +186,6 @@ public class VariableScope implements Cloneable {
 
     //
 
-    // TODO: implement Cloneable and override Object.clone()
     public VariableScope copy() {
         VariableScope that = new VariableScope(parent);
         that.classScope = this.classScope;
diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/InvocationWriter.java b/src/main/java/org/codehaus/groovy/classgen/asm/InvocationWriter.java
index 221361b..6848dab 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/InvocationWriter.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/InvocationWriter.java
@@ -51,6 +51,7 @@ import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Objects;
 import java.util.TreeMap;
 
 import static org.objectweb.asm.Opcodes.AALOAD;
@@ -187,10 +188,8 @@ public class InvocationWriter {
                     mv.visitTypeInsn(CHECKCAST, owner);
                 }
             } else if (target.isPublic()
-                    && (!Modifier.isPublic(declaringClass.getModifiers())
-                    && !receiverType.equals(declaringClass))
-                    && receiverType.isDerivedFrom(declaringClass)
-                    && !receiverType.getPackageName().equals(classNode.getPackageName()))
{
+                    && (!receiverType.equals(declaringClass) && !Modifier.isPublic(declaringClass.getModifiers()))
+                    && receiverType.isDerivedFrom(declaringClass) && !Objects.equals(receiverType.getPackageName(),
classNode.getPackageName())) {
                 // GROOVY-6962: package private class, public method
                 owner = BytecodeHelper.getClassInternalName(receiverType);
             }
diff --git a/src/main/java/org/codehaus/groovy/control/ParserPluginFactory.java b/src/main/java/org/codehaus/groovy/control/ParserPluginFactory.java
index cced8a9..ee09105 100644
--- a/src/main/java/org/codehaus/groovy/control/ParserPluginFactory.java
+++ b/src/main/java/org/codehaus/groovy/control/ParserPluginFactory.java
@@ -34,7 +34,7 @@ public abstract class ParserPluginFactory {
     }
 
     /**
-     * Previously, created the ANTLR 2.7 parser, now throws an exception.
+     * Creates the ANTLR 2 parser.
      *
      * @throws UnsupportedOperationException always
      */
diff --git a/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java b/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
index 30b3476..07c3c88 100644
--- a/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
+++ b/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
@@ -321,7 +321,7 @@ public class ResolveVisitor extends ClassCodeExpressionTransformer {
         genericParameterNames = oldPNames;
     }
 
-    private boolean resolveToInner(final ClassNode type) {
+    protected boolean resolveToInner(final ClassNode type) {
         // we do not do our name mangling to find an inner class
         // if the type is a ConstructedClassWithPackage, because in this case we
         // are resolving the name at a different place already
@@ -355,6 +355,7 @@ public class ResolveVisitor extends ClassCodeExpressionTransformer {
     // when resolving the outer class later, we set the resolved type of ConstructedOuterNestedClass
instance to the actual inner class node(SEE GROOVY-7812(#2))
     private boolean resolveToOuterNested(final ClassNode type) {
         CompileUnit compileUnit = currentClass.getCompileUnit();
+        if (compileUnit == null) return false;
         String typeName = type.getName();
 
         BiConsumer<ConstructedOuterNestedClassNode, ClassNode> setRedirectListener
= (s, c) -> type.setRedirect(s);
diff --git a/src/main/java/org/codehaus/groovy/transform/ASTTransformationVisitor.java b/src/main/java/org/codehaus/groovy/transform/ASTTransformationVisitor.java
index ea950a6..b8348c6 100644
--- a/src/main/java/org/codehaus/groovy/transform/ASTTransformationVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/ASTTransformationVisitor.java
@@ -332,10 +332,10 @@ public final class ASTTransformationVisitor extends ClassCodeVisitorSupport
{
                 if (ASTTransformation.class.isAssignableFrom(gTransClass)) {
                     ASTTransformation instance = (ASTTransformation) gTransClass.getDeclaredConstructor().newInstance();
                     if (instance instanceof CompilationUnitAware) {
-                        ((CompilationUnitAware)instance).setCompilationUnit(compilationUnit);
+                        ((CompilationUnitAware) instance).setCompilationUnit(compilationUnit);
                     }
                     CompilationUnit.ISourceUnitOperation suOp = source -> {
-                        instance.visit(new ASTNode[] {source.getAST()}, source);
+                        instance.visit(new ASTNode[]{source.getAST()}, source);
                     };
                     if (isFirstScan) {
                         compilationUnit.addPhaseOperation(suOp, transformAnnotation.phase().getPhaseNumber());


Mime
View raw message