groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From emil...@apache.org
Subject [groovy] 01/02: sync with groovy-eclipse
Date Thu, 31 Oct 2019 13:45:54 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 37c2db46c7b7a96d95a6cd33178f4c5d44c167dc
Author: Eric Milles <eric.milles@thomsonreuters.com>
AuthorDate: Thu Oct 31 08:38:13 2019 -0500

    sync with groovy-eclipse
---
 .../groovy/grape/GrabAnnotationTransformation.java |  11 +-
 .../java/org/codehaus/groovy/ast/CompileUnit.java  |  22 +--
 .../org/codehaus/groovy/ast/GroovyCodeVisitor.java |  10 +-
 .../java/org/codehaus/groovy/ast/ImportNode.java   |   5 +-
 .../java/org/codehaus/groovy/ast/MethodNode.java   |   3 +-
 .../java/org/codehaus/groovy/ast/ModuleNode.java   |  98 ++++++-------
 .../java/org/codehaus/groovy/ast/Parameter.java    |  21 ++-
 .../classgen/asm/sc/StaticInvocationWriter.java    |  30 ++--
 .../groovy/control/CompilerConfiguration.java      | 151 +++++----------------
 9 files changed, 128 insertions(+), 223 deletions(-)

diff --git a/src/main/java/groovy/grape/GrabAnnotationTransformation.java b/src/main/java/groovy/grape/GrabAnnotationTransformation.java
index eac9e2c..d30430a 100644
--- a/src/main/java/groovy/grape/GrabAnnotationTransformation.java
+++ b/src/main/java/groovy/grape/GrabAnnotationTransformation.java
@@ -58,6 +58,7 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -201,9 +202,9 @@ public class GrabAnnotationTransformation extends ClassCodeVisitorSupport
implem
             }
         }
 
-        List<Map<String,Object>> grabMaps = new ArrayList<Map<String,Object>>();
-        List<Map<String,Object>> grabMapsInit = new ArrayList<Map<String,Object>>();
-        List<Map<String,Object>> grabExcludeMaps = new ArrayList<Map<String,Object>>();
+        Collection<Map<String,Object>> grabMaps = new LinkedHashSet<>();
+        Collection<Map<String,Object>> grabMapsInit = new ArrayList<>();
+        Collection<Map<String,Object>> grabExcludeMaps = new ArrayList<>();
 
         for (ClassNode classNode : sourceUnit.getAST().getClasses()) {
             grabAnnotations = new ArrayList<AnnotationNode>();
@@ -387,7 +388,7 @@ public class GrabAnnotationTransformation extends ClassCodeVisitorSupport
implem
         }
     }
 
-    private void callGrabAsStaticInitIfNeeded(ClassNode classNode, ClassNode grapeClassNode,
List<Map<String,Object>> grabMapsInit, List<Map<String, Object>> grabExcludeMaps)
{
+    private void callGrabAsStaticInitIfNeeded(ClassNode classNode, ClassNode grapeClassNode,
Collection<Map<String,Object>> grabMapsInit, Collection<Map<String, Object>>
grabExcludeMaps) {
         List<Statement> grabInitializers = new ArrayList<Statement>();
         MapExpression basicArgs = new MapExpression();
         if (autoDownload != null)  {
@@ -400,7 +401,7 @@ public class GrabAnnotationTransformation extends ClassCodeVisitorSupport
implem
 
         if (systemProperties != null && !systemProperties.isEmpty()) {
             BlockStatement block = new BlockStatement();
-            for(Map.Entry e : systemProperties.entrySet()) {
+            for(Map.Entry<String, String> e : systemProperties.entrySet()) {
                 block.addStatement(stmt(callX(SYSTEM_CLASSNODE, "setProperty", args(constX(e.getKey()),
constX(e.getValue())))));
             }
             StaticMethodCallExpression enabled = callX(SYSTEM_CLASSNODE, "getProperty", args(constX("groovy.grape.enable"),
constX("true")));
diff --git a/src/main/java/org/codehaus/groovy/ast/CompileUnit.java b/src/main/java/org/codehaus/groovy/ast/CompileUnit.java
index 656cc23..4344b46 100644
--- a/src/main/java/org/codehaus/groovy/ast/CompileUnit.java
+++ b/src/main/java/org/codehaus/groovy/ast/CompileUnit.java
@@ -24,8 +24,6 @@ import org.codehaus.groovy.control.CompilerConfiguration;
 import org.codehaus.groovy.control.SourceUnit;
 import org.codehaus.groovy.control.messages.SyntaxErrorMessage;
 import org.codehaus.groovy.syntax.SyntaxException;
-import org.codehaus.groovy.util.ListHashMap;
-import org.objectweb.asm.Opcodes;
 
 import java.security.CodeSource;
 import java.util.ArrayList;
@@ -55,7 +53,7 @@ public class CompileUnit implements NodeMetaDataHandler {
     private final Map<String, SourceUnit> classNameToSource = new LinkedHashMap<>();
     private final Map<String, InnerClassNode> generatedInnerClasses = new LinkedHashMap<>();
     private final Map<String, ConstructedOuterNestedClassNode> classesToResolve = new
LinkedHashMap<>();
-    private Map metaDataMap = null;
+    private Map metaDataMap;
 
     public CompileUnit(GroovyClassLoader classLoader, CompilerConfiguration config) {
         this(classLoader, null, config);
@@ -214,8 +212,8 @@ public class CompileUnit implements NodeMetaDataHandler {
     }
 
     @Override
-    public ListHashMap getMetaDataMap() {
-        return (ListHashMap) metaDataMap;
+    public Map<?, ?> getMetaDataMap() {
+        return metaDataMap;
     }
 
     @Override
@@ -224,7 +222,9 @@ public class CompileUnit implements NodeMetaDataHandler {
     }
 
     /**
-     * Represents a resolved type as a placeholder, SEE GROOVY-7812
+     * Represents a resolved type as a placeholder.
+     *
+     * @see GROOVY-7812
      */
     @Internal
     public static class ConstructedOuterNestedClassNode extends ClassNode {
@@ -232,11 +232,15 @@ public class CompileUnit implements NodeMetaDataHandler {
         private final List<BiConsumer<ConstructedOuterNestedClassNode, ClassNode>>
setRedirectListenerList = new ArrayList<>();
 
         public ConstructedOuterNestedClassNode(ClassNode outer, String innerClassName) {
-            super(innerClassName, Opcodes.ACC_PUBLIC, ClassHelper.OBJECT_TYPE);
+            super(innerClassName, ACC_PUBLIC, ClassHelper.OBJECT_TYPE);
             this.enclosingClassNode = outer;
             this.isPrimaryNode = false;
         }
 
+        public ClassNode getEnclosingClassNode() {
+            return enclosingClassNode;
+        }
+
         @Override
         public void setRedirect(ClassNode cn) {
             for (BiConsumer<ConstructedOuterNestedClassNode, ClassNode> setRedirectListener
: setRedirectListenerList) {
@@ -245,10 +249,6 @@ public class CompileUnit implements NodeMetaDataHandler {
             super.setRedirect(cn);
         }
 
-        public ClassNode getEnclosingClassNode() {
-            return enclosingClassNode;
-        }
-
         public void addSetRedirectListener(BiConsumer<ConstructedOuterNestedClassNode,
ClassNode> setRedirectListener) {
             setRedirectListenerList.add(setRedirectListener);
         }
diff --git a/src/main/java/org/codehaus/groovy/ast/GroovyCodeVisitor.java b/src/main/java/org/codehaus/groovy/ast/GroovyCodeVisitor.java
index d807e60..be45610 100644
--- a/src/main/java/org/codehaus/groovy/ast/GroovyCodeVisitor.java
+++ b/src/main/java/org/codehaus/groovy/ast/GroovyCodeVisitor.java
@@ -199,14 +199,6 @@ public interface GroovyCodeVisitor {
     default void visitEmptyExpression(EmptyExpression expression) {}
 
     default void visitListOfExpressions(List<? extends Expression> list) {
-        if (list == null) return;
-        for (Expression expression : list) {
-            if (expression instanceof SpreadExpression) {
-                Expression spread = ((SpreadExpression) expression).getExpression();
-                spread.visit(this);
-            } else {
-                expression.visit(this);
-            }
-        }
+        if (list != null) list.forEach(expr -> expr.visit(this));
     }
 }
diff --git a/src/main/java/org/codehaus/groovy/ast/ImportNode.java b/src/main/java/org/codehaus/groovy/ast/ImportNode.java
index b011104..df249bb 100644
--- a/src/main/java/org/codehaus/groovy/ast/ImportNode.java
+++ b/src/main/java/org/codehaus/groovy/ast/ImportNode.java
@@ -28,7 +28,6 @@ public class ImportNode extends AnnotatedNode implements Opcodes {
     private final ClassNode type;
     private final String alias;
     private final String fieldName;
-    // TODO use PackageNode instead here?
     private final String packageName;
     private final boolean isStar;
     private final boolean isStatic;
@@ -104,12 +103,12 @@ public class ImportNode extends AnnotatedNode implements Opcodes {
             return "import static " + typeName + ".*";
         }
         if (isStatic) {
-            if (alias != null && alias.length() != 0 && !alias.equals(fieldName))
{
+            if (alias != null && !alias.isEmpty() && !alias.equals(fieldName))
{
                 return "import static " + typeName + "." + fieldName + " as " + alias;
             }
             return "import static " + typeName + "." + fieldName;
         }
-        if (alias == null || alias.length() == 0) {
+        if (alias == null || alias.isEmpty()) {
             return "import " + typeName;
         }
         return "import " + typeName + " as " + alias;
diff --git a/src/main/java/org/codehaus/groovy/ast/MethodNode.java b/src/main/java/org/codehaus/groovy/ast/MethodNode.java
index b05888b..a9da877 100644
--- a/src/main/java/org/codehaus/groovy/ast/MethodNode.java
+++ b/src/main/java/org/codehaus/groovy/ast/MethodNode.java
@@ -27,7 +27,7 @@ import java.util.List;
 import java.util.Optional;
 
 /**
- * Represents a method declaration
+ * Represents a method declaration.
  */
 public class MethodNode extends AnnotatedNode implements Opcodes {
 
@@ -103,6 +103,7 @@ public class MethodNode extends AnnotatedNode implements Opcodes {
     public void setParameters(Parameter[] parameters) {
         invalidateCachedData();
         VariableScope scope = new VariableScope();
+        this.hasDefaultValue = false;
         this.parameters = parameters;
         if (parameters != null && parameters.length > 0) {
             for (Parameter para : parameters) {
diff --git a/src/main/java/org/codehaus/groovy/ast/ModuleNode.java b/src/main/java/org/codehaus/groovy/ast/ModuleNode.java
index 54f7e16..7033169 100644
--- a/src/main/java/org/codehaus/groovy/ast/ModuleNode.java
+++ b/src/main/java/org/codehaus/groovy/ast/ModuleNode.java
@@ -37,6 +37,7 @@ import java.io.File;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
@@ -51,21 +52,21 @@ import java.util.Map;
  */
 public class ModuleNode extends ASTNode implements Opcodes {
 
-    private final BlockStatement statementBlock = new BlockStatement();
-    List<ClassNode> classes = new LinkedList<ClassNode>();
-    private final List<MethodNode> methods = new ArrayList<MethodNode>();
-    private final Map<String, ImportNode> imports = new HashMap<String, ImportNode>();
-    private final List<ImportNode> starImports = new ArrayList<ImportNode>();
-    private final Map<String, ImportNode> staticImports = new LinkedHashMap<String,
ImportNode>();
-    private final Map<String, ImportNode> staticStarImports = new LinkedHashMap<String,
ImportNode>();
+    private List<ClassNode> classes = new LinkedList<>();
+    private final List<MethodNode> methods = new ArrayList<>();
+    private final Map<String, ImportNode> imports = new HashMap<>();
+    private final List<ImportNode> starImports = new ArrayList<>();
+    private final Map<String, ImportNode> staticImports = new LinkedHashMap<>();
+    private final Map<String, ImportNode> staticStarImports = new LinkedHashMap<>();
     private CompileUnit unit;
     private PackageNode packageNode;
     private String description;
     private boolean createClassForStatements = true;
     private transient SourceUnit context;
-    private boolean importsResolved = false;
+    private boolean importsResolved;
     private ClassNode scriptDummy;
-    private String mainClassName = null;
+    private String mainClassName;
+    private final BlockStatement statementBlock = new BlockStatement();
     private final Parameter[] SCRIPT_CONTEXT_CTOR = {new Parameter(ClassHelper.BINDING_TYPE,
"context")};
 
     public ModuleNode (SourceUnit context ) {
@@ -87,7 +88,7 @@ public class ModuleNode extends ASTNode implements Opcodes {
     public List<ClassNode> getClasses() {
         if (createClassForStatements && (!statementBlock.isEmpty() || !methods.isEmpty()
|| isPackageInfo())) {
             ClassNode mainClass = createStatementsClass();
-            mainClassName = mainClass.getName(); 
+            mainClassName = mainClass.getName();
             createClassForStatements = false;
             classes.add(0, mainClass);
             mainClass.setModule(this);
@@ -101,7 +102,7 @@ public class ModuleNode extends ASTNode implements Opcodes {
     }
 
     public List<ImportNode> getImports() {
-        return new ArrayList<ImportNode>(imports.values());
+        return new ArrayList<>(imports.values());
     }
 
     public List<ImportNode> getStarImports() {
@@ -126,7 +127,7 @@ public class ModuleNode extends ASTNode implements Opcodes {
     }
 
     public void addImport(String alias, ClassNode type) {
-        addImport(alias, type, new ArrayList<AnnotationNode>());
+        addImport(alias, type, new ArrayList<>());
     }
 
     public void addImport(String alias, ClassNode type, List<AnnotationNode> annotations)
{
@@ -137,7 +138,7 @@ public class ModuleNode extends ASTNode implements Opcodes {
     }
 
     public void addStarImport(String packageName) {
-        addStarImport(packageName, new ArrayList<AnnotationNode>());
+        addStarImport(packageName, Collections.emptyList());
     }
 
     public void addStarImport(String packageName, List<AnnotationNode> annotations)
{
@@ -147,6 +148,32 @@ public class ModuleNode extends ASTNode implements Opcodes {
         storeLastAddedImportNode(importNode);
     }
 
+    public void addStaticImport(ClassNode type, String fieldName, String alias) {
+        addStaticImport(type, fieldName, alias, Collections.emptyList());
+    }
+
+    public void addStaticImport(ClassNode type, String fieldName, String alias, List<AnnotationNode>
annotations) {
+        ImportNode node = new ImportNode(type, fieldName, alias);
+        node.addAnnotations(annotations);
+        ImportNode prev = staticImports.put(alias, node);
+        if (prev != null) {
+            staticImports.put(prev.toString(), prev);
+            staticImports.put(alias, staticImports.remove(alias));
+        }
+        storeLastAddedImportNode(node);
+    }
+
+    public void addStaticStarImport(String name, ClassNode type) {
+        addStaticStarImport(name, type, Collections.emptyList());
+    }
+
+    public void addStaticStarImport(String name, ClassNode type, List<AnnotationNode>
annotations) {
+        ImportNode node = new ImportNode(type);
+        node.addAnnotations(annotations);
+        staticStarImports.put(name, node);
+        storeLastAddedImportNode(node);
+    }
+
     public void addStatement(Statement node) {
         statementBlock.addStatement(node);
     }
@@ -206,12 +233,9 @@ public class ModuleNode extends ASTNode implements Opcodes {
      * @return the underlying character stream description
      */
     public String getDescription() {
-        if( context != null )
-        {
+        if (context != null) {
             return context.getName();
-        }
-        else
-        {
+        } else {
             return this.description;
         }
     }
@@ -233,7 +257,7 @@ public class ModuleNode extends ASTNode implements Opcodes {
             setScriptBaseClassFromConfig(scriptDummy);
             return scriptDummy;
         }
-        
+
         String name = getPackageName();
         if (name == null) {
             name = "";
@@ -273,13 +297,13 @@ public class ModuleNode extends ASTNode implements Opcodes {
             }
         }
     }
-    
+
     protected ClassNode createStatementsClass() {
         ClassNode classNode = getScriptClassDummy();
         if (classNode.getName().endsWith("package-info")) {
             return classNode;
         }
-        
+
         handleMainMethodIfPresent(methods);
 
         // return new Foo(new ShellContext(args)).run()
@@ -346,7 +370,7 @@ public class ModuleNode extends ASTNode implements Opcodes {
     }
 
     /*
-     * If a main method is provided by user, account for it under run() as scripts generate
their own 'main' so they can run.  
+     * If a main method is provided by user, account for it under run() as scripts generate
their own 'main' so they can run.
      */
     private void handleMainMethodIfPresent(List methods) {
         boolean found = false;
@@ -360,7 +384,7 @@ public class ModuleNode extends ASTNode implements Opcodes {
 
                     argTypeMatches = (argType.equals(ClassHelper.OBJECT_TYPE) || argType.getName().contains("String[]"));
                     retTypeMatches = (retType == ClassHelper.VOID_TYPE || retType == ClassHelper.OBJECT_TYPE);
-                    
+
                     if(retTypeMatches && argTypeMatches) {
                         if(found) {
                             throw new RuntimeException("Repetitive main method found.");
@@ -412,11 +436,11 @@ public class ModuleNode extends ASTNode implements Opcodes {
     public boolean isEmpty() {
         return classes.isEmpty() && statementBlock.getStatements().isEmpty();
     }
-    
+
     public void sortClasses(){
         if (isEmpty()) return;
         List<ClassNode> classes = getClasses();
-        LinkedList<ClassNode> sorted = new LinkedList<ClassNode>();
+        LinkedList<ClassNode> sorted = new LinkedList<>();
         int level=1;
         while (!classes.isEmpty()) {
             for (Iterator<ClassNode> cni = classes.iterator(); cni.hasNext();) {
@@ -448,32 +472,10 @@ public class ModuleNode extends ASTNode implements Opcodes {
         return staticStarImports;
     }
 
-    public void addStaticImport(ClassNode type, String fieldName, String alias) {
-        addStaticImport(type, fieldName, alias, new ArrayList<AnnotationNode>());
-    }
-
-    public void addStaticImport(ClassNode type, String fieldName, String alias, List<AnnotationNode>
annotations) {
-        ImportNode node = new ImportNode(type, fieldName, alias);
-        node.addAnnotations(annotations);
-        staticImports.put(alias, node);
-        storeLastAddedImportNode(node);
-    }
-
-    public void addStaticStarImport(String name, ClassNode type) {
-        addStaticStarImport(name, type, new ArrayList<AnnotationNode>());
-    }
-
-    public void addStaticStarImport(String name, ClassNode type, List<AnnotationNode>
annotations) {
-        ImportNode node = new ImportNode(type);
-        node.addAnnotations(annotations);
-        staticStarImports.put(name, node);
-        storeLastAddedImportNode(node);
-    }
-
     // This method only exists as a workaround for GROOVY-6094
     // In order to keep binary compatibility
     private void storeLastAddedImportNode(final ImportNode node) {
-        if (getNodeMetaData(ImportNode.class)==ImportNode.class) {
+        if (getNodeMetaData(ImportNode.class) == ImportNode.class) {
             putNodeMetaData(ImportNode.class, node);
         }
     }
diff --git a/src/main/java/org/codehaus/groovy/ast/Parameter.java b/src/main/java/org/codehaus/groovy/ast/Parameter.java
index b1fe29d..36d4967 100644
--- a/src/main/java/org/codehaus/groovy/ast/Parameter.java
+++ b/src/main/java/org/codehaus/groovy/ast/Parameter.java
@@ -20,7 +20,6 @@ package org.codehaus.groovy.ast;
 
 import org.codehaus.groovy.ast.expr.Expression;
 
-
 /**
  * Represents a parameter on a constructor or method call. The type name is
  * optional - it defaults to java.lang.Object if unknown.
@@ -31,13 +30,13 @@ public class Parameter extends AnnotatedNode implements Variable {
 
     private ClassNode type;
     private final String name;
+    private ClassNode originType;
     private boolean dynamicTyped;
+    private boolean closureShare;
     private Expression defaultValue;
     private boolean hasDefaultValue;
     private boolean inStaticContext;
-    private boolean closureShare=false;
     private int modifiers;
-    private ClassNode originType=ClassHelper.DYNAMIC_TYPE;
 
     public Parameter(ClassNode type, String name) {
         this.name = name;
@@ -45,7 +44,7 @@ public class Parameter extends AnnotatedNode implements Variable {
         this.originType = type;
         this.hasDefaultValue = false;
     }
-    
+
     public Parameter(ClassNode type, String name, Expression defaultValue) {
         this(type,name);
         this.defaultValue = defaultValue;
@@ -68,11 +67,11 @@ public class Parameter extends AnnotatedNode implements Variable {
         this.type = type;
         dynamicTyped |= type==ClassHelper.DYNAMIC_TYPE;
     }
-    
+
     public boolean hasInitialExpression() {
         return this.hasDefaultValue;
     }
-    
+
     /**
      * @return the default value expression for this parameter or null if
      * no default value is specified
@@ -80,16 +79,16 @@ public class Parameter extends AnnotatedNode implements Variable {
     public Expression getInitialExpression() {
         return defaultValue;
     }
-    
+
     public void setInitialExpression(Expression init) {
         defaultValue = init;
         hasDefaultValue = defaultValue != null;
     }
-    
+
     public boolean isInStaticContext() {
         return inStaticContext;
     }
-    
+
     public void setInStaticContext(boolean inStaticContext) {
         this.inStaticContext = inStaticContext;
     }
@@ -103,7 +102,7 @@ public class Parameter extends AnnotatedNode implements Variable {
     }
 
     public void setClosureSharedVariable(boolean inClosure) {
-        closureShare = inClosure;        
+        closureShare = inClosure;
     }
 
     public int getModifiers() {
@@ -113,7 +112,7 @@ public class Parameter extends AnnotatedNode implements Variable {
     public ClassNode getOriginType() {
         return originType;
     }
-    
+
     public void setOriginType(ClassNode cn) {
         originType = cn;
     }
diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java
b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java
index 1d0c6e7..42f2fa4 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java
@@ -456,17 +456,11 @@ public class StaticInvocationWriter extends InvocationWriter {
                 ) {
             int stackLen = operandStack.getStackLength() + argumentListSize;
             MethodVisitor mv = controller.getMethodVisitor();
-            //mv = new org.objectweb.asm.util.TraceMethodVisitor(mv);
             controller.setMethodVisitor(mv);
             // varg call
             // first parameters as usual
             for (int i = 0; i < para.length - 1; i++) {
-                Expression expression = argumentList.get(i);
-                expression.putNodeMetaData(PARAMETER_TYPE, para[i].getType());
-                expression.visit(acg);
-                if (!isNullConstant(expression)) {
-                    operandStack.doGroovyCast(para[i].getType());
-                }
+                visitArgument(argumentList.get(i), para[i].getType());
             }
             // last parameters wrapped in an array
             List<Expression> lastParams = new LinkedList<Expression>();
@@ -487,12 +481,7 @@ public class StaticInvocationWriter extends InvocationWriter {
             }
         } else if (argumentListSize == para.length) {
             for (int i = 0; i < argumentListSize; i++) {
-                Expression expression = argumentList.get(i);
-                expression.putNodeMetaData(PARAMETER_TYPE, para[i].getType());
-                expression.visit(acg);
-                if (!isNullConstant(expression)) {
-                    operandStack.doGroovyCast(para[i].getType());
-                }
+                visitArgument(argumentList.get(i), para[i].getType());
             }
         } else {
             // method call with default arguments
@@ -519,16 +508,19 @@ public class StaticInvocationWriter extends InvocationWriter {
                 }
             }
             for (int i = 0; i < arguments.length; i++) {
-                Expression expression = arguments[i];
-                expression.putNodeMetaData(PARAMETER_TYPE, para[i].getType());
-                expression.visit(acg);
-                if (!isNullConstant(expression)) {
-                    operandStack.doGroovyCast(para[i].getType());
-                }
+                visitArgument(arguments[i], para[i].getType());
             }
         }
     }
 
+    private void visitArgument(Expression argumentExpr, ClassNode parameterType) {
+        argumentExpr.putNodeMetaData(PARAMETER_TYPE, parameterType);
+        argumentExpr.visit(controller.getAcg());
+        if (!isNullConstant(argumentExpr)) {
+            controller.getOperandStack().doGroovyCast(parameterType);
+        }
+    }
+
     private static boolean isNullConstant(final Expression expression) {
         return (expression instanceof ConstantExpression && ((ConstantExpression)
expression).getValue() == null);
     }
diff --git a/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java b/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java
index 57d256e..d75c7ec 100644
--- a/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java
+++ b/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java
@@ -35,6 +35,7 @@ import java.util.LinkedHashSet;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 import java.util.Properties;
 import java.util.Set;
 import java.util.StringTokenizer;
@@ -55,30 +56,30 @@ public class CompilerConfiguration {
     /** This (<code>"runtimeGroovydoc"</code>) is the Optimization Option value
for enabling attaching {@link groovy.lang.Groovydoc} annotation. */
     public static final String RUNTIME_GROOVYDOC = "runtimeGroovydoc";
 
-    /** This (<code>"memStub"</code>) is the Joint Compilation Option value for
enabling generating stubs in memory. .*/
+    /** This (<code>"memStub"</code>) is the Joint Compilation Option value for
enabling generating stubs in memory. */
     public static final String MEM_STUB = "memStub";
 
-    /** This (<code>"1.4"</code>) is the value for targetBytecode to compile
for a JDK 1.4. **/
+    /** This (<code>"1.4"</code>) is the value for targetBytecode to compile
for a JDK 1.4. */
     public static final String JDK4 = "1.4";
-    /** This (<code>"1.5"</code>) is the value for targetBytecode to compile
for a JDK 1.5. **/
+    /** This (<code>"1.5"</code>) is the value for targetBytecode to compile
for a JDK 1.5. */
     public static final String JDK5 = "1.5";
-    /** This (<code>"1.6"</code>) is the value for targetBytecode to compile
for a JDK 1.6. **/
+    /** This (<code>"1.6"</code>) is the value for targetBytecode to compile
for a JDK 1.6. */
     public static final String JDK6 = "1.6";
-    /** This (<code>"1.7"</code>) is the value for targetBytecode to compile
for a JDK 1.7. **/
+    /** This (<code>"1.7"</code>) is the value for targetBytecode to compile
for a JDK 1.7. */
     public static final String JDK7 = "1.7";
-    /** This (<code>"1.8"</code>) is the value for targetBytecode to compile
for a JDK 1.8. **/
+    /** This (<code>"1.8"</code>) is the value for targetBytecode to compile
for a JDK 1.8. */
     public static final String JDK8 = "1.8";
-    /** This (<code>"9"</code>) is the value for targetBytecode to compile for
a JDK 9. **/
+    /** This (<code>"9"</code>) is the value for targetBytecode to compile for
a JDK 9. */
     public static final String JDK9 = "9";
-    /** This (<code>"10"</code>) is the value for targetBytecode to compile for
a JDK 10. **/
+    /** This (<code>"10"</code>) is the value for targetBytecode to compile for
a JDK 10. */
     public static final String JDK10 = "10";
-    /** This (<code>"11"</code>) is the value for targetBytecode to compile for
a JDK 11. **/
+    /** This (<code>"11"</code>) is the value for targetBytecode to compile for
a JDK 11. */
     public static final String JDK11 = "11";
-    /** This (<code>"12"</code>) is the value for targetBytecode to compile for
a JDK 12. **/
+    /** This (<code>"12"</code>) is the value for targetBytecode to compile for
a JDK 12. */
     public static final String JDK12 = "12";
-    /** This (<code>"13"</code>) is the value for targetBytecode to compile for
a JDK 13. **/
+    /** This (<code>"13"</code>) is the value for targetBytecode to compile for
a JDK 13. */
     public static final String JDK13 = "13";
-    /** This (<code>"14"</code>) is the value for targetBytecode to compile for
a JDK 14. **/
+    /** This (<code>"14"</code>) is the value for targetBytecode to compile for
a JDK 14. */
     public static final String JDK14 = "14";
 
     /**
@@ -86,7 +87,7 @@ public class CompilerConfiguration {
      * @deprecated
      */
     @Deprecated
-    public static final String POST_JDK5 = JDK5; // for backwards compatibility
+    public static final String POST_JDK5 = JDK5;
 
     /**
      * This constant is for comparing targetBytecode to ensure it is set to an earlier value
than JDK 1.5.
@@ -112,10 +113,8 @@ public class CompilerConfiguration {
             JDK14, Opcodes.V14
     );
 
-    private static final String[] EMPTY_STRING_ARRAY = new String[0];
-
-    /** An array of the valid targetBytecode values */
-    public static final String[] ALLOWED_JDKS = JDK_TO_BYTECODE_VERSION_MAP.keySet().toArray(EMPTY_STRING_ARRAY);
+    /** The valid targetBytecode values. */
+    public static final String[] ALLOWED_JDKS = JDK_TO_BYTECODE_VERSION_MAP.keySet().toArray(new
String[JDK_TO_BYTECODE_VERSION_MAP.size()]);
 
     /**
      * The default source encoding
@@ -126,7 +125,7 @@ public class CompilerConfiguration {
      *  A convenience for getting a default configuration.  Do not modify it!
      *  See {@link #CompilerConfiguration(Properties)} for an example on how to
      *  make a suitable copy to modify.  But if you're really starting from a
-     *  default context, then you probably just want <code>new CompilerConfiguration()</code>.

+     *  default context, then you probably just want <code>new CompilerConfiguration()</code>.
      */
     public static final CompilerConfiguration DEFAULT = new CompilerConfiguration() {
         @Override
@@ -280,7 +279,6 @@ public class CompilerConfiguration {
         }
     };
 
-
     /**
      * See {@link WarningMessage} for levels.
      */
@@ -319,7 +317,7 @@ public class CompilerConfiguration {
     /**
      * If true, generates metadata for reflection on method parameters
      */
-    private boolean parameters = false;
+    private boolean parameters;
 
     /**
      * The number of non-fatal errors to allow before bailing
@@ -923,7 +921,6 @@ public class CompilerConfiguration {
         return defaultScriptExtension;
     }
 
-
     public void setDefaultScriptExtension(String defaultScriptExtension) {
         this.defaultScriptExtension = defaultScriptExtension;
     }
@@ -945,8 +942,8 @@ public class CompilerConfiguration {
     }
 
     /**
-     * Allow setting the bytecode compatibility level. The parameter can take
-     * one of the values in {@link #ALLOWED_JDKS}.
+     * Sets the bytecode compatibility level. The parameter can take one of the values
+     * in {@link #ALLOWED_JDKS}.
      *
      * @param version the bytecode compatibility level
      */
@@ -961,9 +958,8 @@ public class CompilerConfiguration {
     }
 
     /**
-     * Retrieves the compiler bytecode compatibility level.
-     * Defaults to the minimum officially supported bytecode
-     * version for any particular Groovy version.
+     * Retrieves the compiler bytecode compatibility level. Defaults to the minimum
+     * officially supported bytecode version for any particular Groovy version.
      *
      * @return bytecode compatibility level
      */
@@ -1086,111 +1082,34 @@ public class CompilerConfiguration {
     }
 
     /**
-     * Check whether invoke dynamic enabled
-     * @return the result
+     * Checks if invoke dynamic is enabled.
      */
     public boolean isIndyEnabled() {
-        Boolean indyEnabled = this.getOptimizationOptions().get(INVOKEDYNAMIC);
-
-        if (null == indyEnabled) {
-            return false;
-        }
-
-        return indyEnabled;
+        Boolean indyEnabled = getOptimizationOptions().get(INVOKEDYNAMIC);
+        return Optional.ofNullable(indyEnabled).orElse(Boolean.FALSE).booleanValue();
     }
 
     /**
-     * Check whether groovydoc enabled
-     * @return the result
+     * Checks if groovydoc is enabled.
      */
     public boolean isGroovydocEnabled() {
-        Boolean groovydocEnabled = this.getOptimizationOptions().get(GROOVYDOC);
-
-        if (null == groovydocEnabled) {
-            return false;
-        }
-
-        return groovydocEnabled;
+        Boolean groovydocEnabled = getOptimizationOptions().get(GROOVYDOC);
+        return Optional.ofNullable(groovydocEnabled).orElse(Boolean.FALSE).booleanValue();
     }
 
     /**
-     * Check whether runtime groovydoc enabled
-     * @return the result
+     * Checks if runtime groovydoc is enabled.
      */
     public boolean isRuntimeGroovydocEnabled() {
-        Boolean runtimeGroovydocEnabled = this.getOptimizationOptions().get(RUNTIME_GROOVYDOC);
-
-        if (null == runtimeGroovydocEnabled) {
-            return false;
-        }
-
-        return runtimeGroovydocEnabled;
+        Boolean runtimeGroovydocEnabled = getOptimizationOptions().get(RUNTIME_GROOVYDOC);
+        return Optional.ofNullable(runtimeGroovydocEnabled).orElse(Boolean.FALSE).booleanValue();
     }
 
     /**
-     * Check whether mem stub enabled
-     * @return the result
+     * Checks if in-memory stub creation is enabled.
      */
     public boolean isMemStubEnabled() {
-        Object memStubEnabled = this.getJointCompilationOptions().get(MEM_STUB);
-
-        if (null == memStubEnabled) {
-            return false;
-        }
-
-        return "true".equals(memStubEnabled.toString());
-    }
-
-
-//       See http://groovy.329449.n5.nabble.com/What-the-static-compile-by-default-tt5750118.html
-//           https://issues.apache.org/jira/browse/GROOVY-8543
-//
-//    {
-//        // this object initializer assures that `enableCompileStaticByDefault` must be
invoked no matter which constructor called.
-//        if (getBooleanSafe("groovy.compile.static")) {
-//            enableCompileStaticByDefault();
-//        }
-//    }
-//
-//
-//    private void enableCompileStaticByDefault() {
-//        compilationCustomizers.add(
-//            new CompilationCustomizer(CompilePhase.CONVERSION) {
-//                @Override
-//                public void call(final SourceUnit source, GeneratorContext context, ClassNode
classNode) throws CompilationFailedException {
-//                    for (ClassNode cn : source.getAST().getClasses()) {
-//                        newClassCodeVisitor(source).visitClass(cn);
-//                    }
-//                }
-//
-//                private ClassCodeVisitorSupport newClassCodeVisitor(SourceUnit source)
{
-//                    return new ClassCodeVisitorSupport() {
-//                        @Override
-//                        public void visitClass(ClassNode node) {
-//                            enableCompileStatic(node);
-//                        }
-//
-//                        private void enableCompileStatic(ClassNode classNode) {
-//                            if (!classNode.getAnnotations(ClassHelper.make(GROOVY_TRANSFORM_COMPILE_STATIC)).isEmpty())
{
-//                                return;
-//                            }
-//                            if (!classNode.getAnnotations(ClassHelper.make(GROOVY_TRANSFORM_COMPILE_DYNAMIC)).isEmpty())
{
-//                                return;
-//                            }
-//
-//                            classNode.addAnnotation(new AnnotationNode(ClassHelper.make(GROOVY_TRANSFORM_COMPILE_STATIC)));
-//                        }
-//
-//                        @Override
-//                        protected SourceUnit getSourceUnit() {
-//                            return source;
-//                        }
-//
-//                        private static final String GROOVY_TRANSFORM_COMPILE_STATIC = "groovy.transform.CompileStatic";
-//                        private static final String GROOVY_TRANSFORM_COMPILE_DYNAMIC =
"groovy.transform.CompileDynamic";
-//                    };
-//                }
-//            }
-//        );
-//    }
+        Object memStubEnabled = getJointCompilationOptions().get(MEM_STUB);
+        return Optional.ofNullable(memStubEnabled).map(value -> "true".equals(value.toString())).orElse(Boolean.FALSE).booleanValue();
+    }
 }


Mime
View raw message