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 3c5182c5b088441c0b27350e23880e17ee6d17e3
Author: Eric Milles <eric.mil...@thomsonreuters.com>
AuthorDate: Fri Feb 14 13:35:06 2020 -0600

    minor edits
    
    (cherry picked from commit ff7b13e9ef3fbde05dda4f12f63adece71b04bba)
---
 .../groovy/ast/expr/PropertyExpression.java        |  89 ++++++-----
 .../codehaus/groovy/ast/expr/TupleExpression.java  |  66 ++++----
 .../codehaus/groovy/ast/tools/GeneralUtils.java    | 178 +++++++++------------
 3 files changed, 154 insertions(+), 179 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/ast/expr/PropertyExpression.java 
b/src/main/java/org/codehaus/groovy/ast/expr/PropertyExpression.java
index bfc6638..7bfaf84 100644
--- a/src/main/java/org/codehaus/groovy/ast/expr/PropertyExpression.java
+++ b/src/main/java/org/codehaus/groovy/ast/expr/PropertyExpression.java
@@ -27,44 +27,38 @@ public class PropertyExpression extends Expression {
 
     private Expression objectExpression;
     private final Expression property;
-    private boolean spreadSafe = false;
-    private boolean safe = false;
-    private boolean isStatic = false;
+    private boolean safe;
+    private boolean spreadSafe;
+    private boolean isStatic;
+    private boolean implicitThis;
 
-    private boolean implicitThis = false;
-
-    public boolean isStatic() {
-        return isStatic;
+    public PropertyExpression(final Expression objectExpression, final String 
propertyName) {
+        this(objectExpression, new ConstantExpression(propertyName), false);
     }
 
-    public PropertyExpression(Expression objectExpression, String property) {
-        this(objectExpression, new ConstantExpression(property), false);
-    }
-    
-    public PropertyExpression(Expression objectExpression, Expression 
property) {
+    public PropertyExpression(final Expression objectExpression, final 
Expression property) {
         this(objectExpression, property, false);
     }
 
-    public PropertyExpression(Expression objectExpression, Expression 
property, boolean safe) {
+    public PropertyExpression(final Expression objectExpression, final 
Expression property, final boolean safe) {
         this.objectExpression = objectExpression;
         this.property = property;
         this.safe = safe;
     }
 
-    public void visit(GroovyCodeVisitor visitor) {
+    public void visit(final GroovyCodeVisitor visitor) {
         visitor.visitPropertyExpression(this);
     }
 
-    public boolean isDynamic() {
-        return true;
-    }
-
-    public Expression transformExpression(ExpressionTransformer transformer) {
-        PropertyExpression ret = new 
PropertyExpression(transformer.transform(objectExpression),
-                transformer.transform(property), safe);
+    public Expression transformExpression(final ExpressionTransformer 
transformer) {
+        PropertyExpression ret = new PropertyExpression(
+                transformer.transform(objectExpression),
+                transformer.transform(property),
+                safe
+        );
+        ret.setImplicitThis(implicitThis);
         ret.setSpreadSafe(spreadSafe);
         ret.setStatic(isStatic);
-        ret.setImplicitThis(implicitThis);
         ret.setSourcePosition(this);
         ret.copyNodeMetaData(this);
         return ret;
@@ -74,17 +68,16 @@ public class PropertyExpression extends Expression {
         return objectExpression;
     }
 
-    public void setObjectExpression(Expression exp) {
-        objectExpression=exp;
-    }    
-    
+    public void setObjectExpression(final Expression objectExpression) {
+        this.objectExpression = objectExpression;
+    }
+
     public Expression getProperty() {
         return property;
     }
-    
+
     public String getPropertyAsString() {
-        if (property==null) return null;
-        if (! (property instanceof ConstantExpression)) return null;
+        if (!(property instanceof ConstantExpression)) return null;
         ConstantExpression constant = (ConstantExpression) property;
         return constant.getText();
     }
@@ -97,9 +90,21 @@ public class PropertyExpression extends Expression {
         return object + spread + safe + "." + text;
     }
 
+    public boolean isDynamic() {
+        return true;
+    }
+
+    public boolean isImplicitThis() {
+        return implicitThis;
+    }
+
+    public void setImplicitThis(final boolean implicitThis) {
+        this.implicitThis  = implicitThis;
+    }
+
     /**
-     * @return is this a safe navigation, i.e. if true then if the source 
object is null
-     * then this navigation will return null
+     * @return is this a safe navigation, i.e. if true then if the source 
object
+     * is null then this navigation will return null
      */
     public boolean isSafe() {
         return safe;
@@ -109,23 +114,19 @@ public class PropertyExpression extends Expression {
         return spreadSafe;
     }
 
-    public void setSpreadSafe(boolean value) {
-        spreadSafe = value;
+    public void setSpreadSafe(final boolean spreadSafe) {
+        this.spreadSafe = spreadSafe;
     }
 
-    public String toString() {
-        return super.toString() + "[object: " + objectExpression + " property: 
" + property + "]";
+    public boolean isStatic() {
+        return isStatic;
     }
 
-    public void setStatic(boolean aStatic) {
-        this.isStatic = aStatic;
-    }
-    
-    public boolean isImplicitThis(){
-        return implicitThis;
+    public void setStatic(final boolean isStatic) {
+        this.isStatic = isStatic;
     }
-    
-    public void setImplicitThis(boolean it) {
-        implicitThis  = it;
+
+    public String toString() {
+        return super.toString() + "[object: " + objectExpression + " property: 
" + property + "]";
     }
 }
diff --git a/src/main/java/org/codehaus/groovy/ast/expr/TupleExpression.java 
b/src/main/java/org/codehaus/groovy/ast/expr/TupleExpression.java
index 022b7ae..62c5d0b 100644
--- a/src/main/java/org/codehaus/groovy/ast/expr/TupleExpression.java
+++ b/src/main/java/org/codehaus/groovy/ast/expr/TupleExpression.java
@@ -21,87 +21,89 @@ package org.codehaus.groovy.ast.expr;
 import org.codehaus.groovy.ast.GroovyCodeVisitor;
 
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 
-/**
- * Represents a tuple expression {1, 2, 3} which creates an immutable List
- */
 public class TupleExpression extends Expression implements 
Iterable<Expression> {
+
     private final List<Expression> expressions;
 
     public TupleExpression() {
         this(0);
     }
 
-    public TupleExpression(Expression expr) {
+    public TupleExpression(final Expression expr) {
         this(1);
         addExpression(expr);
     }
 
-    public TupleExpression(Expression expr1, Expression expr2) {
+    public TupleExpression(final Expression expr1, final Expression expr2) {
         this(2);
         addExpression(expr1);
         addExpression(expr2);
     }
 
-    public TupleExpression(Expression expr1, Expression expr2, Expression 
expr3) {
+    public TupleExpression(final Expression expr1, final Expression expr2, 
final Expression expr3) {
         this(3);
         addExpression(expr1);
         addExpression(expr2);
         addExpression(expr3);
     }
-    
-    public TupleExpression(int length) {
-        this.expressions = new ArrayList<Expression>(length);
+
+    public TupleExpression(final int capacity) {
+        this.expressions = new ArrayList<>(capacity);
     }
-    
-    public TupleExpression(List<Expression> expressions) {
+
+    public TupleExpression(final List<Expression> expressions) {
         this.expressions = expressions;
     }
-    
-    public TupleExpression(Expression[] expressionArray) {
-        this();
-        expressions.addAll(Arrays.asList(expressionArray));
+
+    public TupleExpression(final Expression[] expressionArray) {
+        this(expressionArray.length);
+        for (Expression e : expressionArray) expressions.add(e);
     }
 
-    public TupleExpression addExpression(Expression expression) {
+    public TupleExpression addExpression(final Expression expression) {
         expressions.add(expression);
         return this;
     }
-    
+
+    public Expression getExpression(final int i) {
+        return expressions.get(i);
+    }
+
     public List<Expression> getExpressions() {
         return expressions;
+        // TODO: return Collections.unmodifiableList(expressions);
+        // see also 
org.codehaus.groovy.ast.expr.MethodCallExpression.NO_ARGUMENTS
     }
 
-    public void visit(GroovyCodeVisitor visitor) {
+    public Iterator<Expression> iterator() {
+        // TODO: return getExpressions().iterator();
+        return Collections.unmodifiableList(expressions).iterator();
+    }
+
+    public void visit(final GroovyCodeVisitor visitor) {
         visitor.visitTupleExpression(this);
     }
 
-    public Expression transformExpression(ExpressionTransformer transformer) {
-        Expression ret = new 
TupleExpression(transformExpressions(getExpressions(), transformer)); 
+    public Expression transformExpression(final ExpressionTransformer 
transformer) {
+        Expression ret = new 
TupleExpression(transformExpressions(getExpressions(), transformer));
         ret.setSourcePosition(this);
         ret.copyNodeMetaData(this);
         return ret;
     }
 
-    public Expression getExpression(int i) {
-        return expressions.get(i);
-    }
-
     public String getText() {
         StringBuilder buffer = new StringBuilder("(");
         boolean first = true;
-        for (Expression expression : expressions) {
+        for (Expression expression : getExpressions()) {
             if (first) {
                 first = false;
-            }
-            else {
+            } else {
                 buffer.append(", ");
             }
-            
             buffer.append(expression.getText());
         }
         buffer.append(")");
@@ -109,10 +111,6 @@ public class TupleExpression extends Expression implements 
Iterable<Expression>
     }
 
     public String toString() {
-        return super.toString() + expressions;
-    }
-
-    public Iterator<Expression> iterator() {
-        return Collections.unmodifiableList(expressions).iterator();
+        return super.toString() + getExpressions();
     }
 }
diff --git a/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java 
b/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java
index bf212d8..0d850ce 100644
--- a/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java
+++ b/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java
@@ -70,6 +70,7 @@ import org.objectweb.asm.MethodVisitor;
 
 import java.lang.reflect.Modifier;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.LinkedHashSet;
 import java.util.List;
@@ -78,7 +79,6 @@ import java.util.Set;
 import java.util.function.Consumer;
 
 import static org.apache.groovy.util.BeanUtils.capitalize;
-import static org.codehaus.groovy.syntax.Types.COMPARE_NOT_IDENTICAL;
 
 /**
  * Handy methods when working with the Groovy AST
@@ -87,7 +87,7 @@ public class GeneralUtils {
     public static final Token ASSIGN = Token.newSymbol(Types.ASSIGN, -1, -1);
     public static final Token EQ = Token.newSymbol(Types.COMPARE_EQUAL, -1, 
-1);
     public static final Token NE = Token.newSymbol(Types.COMPARE_NOT_EQUAL, 
-1, -1);
-    public static final Token NOT_IDENTICAL = 
Token.newSymbol(COMPARE_NOT_IDENTICAL, -1, -1);
+    public static final Token NOT_IDENTICAL = 
Token.newSymbol(Types.COMPARE_NOT_IDENTICAL, -1, -1);
     public static final Token LT = Token.newSymbol(Types.COMPARE_LESS_THAN, 
-1, -1);
     public static final Token AND = Token.newSymbol(Types.LOGICAL_AND, -1, -1);
     public static final Token OR = Token.newSymbol(Types.LOGICAL_OR, -1, -1);
@@ -97,37 +97,33 @@ public class GeneralUtils {
     private static final Token INDEX = Token.newSymbol("[", -1, -1);
 
     public static BinaryExpression andX(final Expression lhv, final Expression 
rhv) {
-        return new BinaryExpression(lhv, AND, rhv);
+        return binX(lhv, AND, rhv);
     }
 
     public static ArgumentListExpression args(final Expression... expressions) 
{
-        List<Expression> args = new ArrayList<Expression>();
-        Collections.addAll(args, expressions);
-        return new ArgumentListExpression(args);
+        List<Expression> list = new ArrayList<>(expressions.length);
+        Collections.addAll(list, expressions);
+        return args(list);
     }
 
     public static ArgumentListExpression args(final List<Expression> 
expressions) {
         return new ArgumentListExpression(expressions);
     }
 
-    public static ArgumentListExpression args(final Parameter[] parameters) {
+    public static ArgumentListExpression args(final Parameter... parameters) {
         return new ArgumentListExpression(parameters);
     }
 
     public static ArgumentListExpression args(final String... names) {
-        List<Expression> vars = new ArrayList<Expression>();
-        for (String name : names) {
-            vars.add(varX(name));
-        }
-        return new ArgumentListExpression(vars);
+        return 
args(Arrays.stream(names).map(GeneralUtils::varX).toArray(Expression[]::new));
     }
 
     public static Statement assignS(final Expression target, final Expression 
value) {
-        return new ExpressionStatement(assignX(target, value));
+        return stmt(assignX(target, value));
     }
 
     public static Expression assignX(final Expression target, final Expression 
value) {
-        return new BinaryExpression(target, ASSIGN, value);
+        return binX(target, ASSIGN, value);
     }
 
     public static Expression attrX(final Expression oe, final Expression prop) 
{
@@ -138,18 +134,18 @@ public class GeneralUtils {
         return new BinaryExpression(left, token, right);
     }
 
-    public static BlockStatement block(final VariableScope varScope, final 
Statement... stmts) {
+    public static BlockStatement block(final VariableScope scope, final 
Statement... stmts) {
         BlockStatement block = new BlockStatement();
-        block.setVariableScope(varScope);
+        block.setVariableScope(scope);
         for (Statement stmt : stmts) {
             block.addStatement(stmt);
         }
         return block;
     }
 
-    public static BlockStatement block(final VariableScope varScope, final 
List<Statement> stmts) {
+    public static BlockStatement block(final VariableScope scope, final 
List<Statement> stmts) {
         BlockStatement block = new BlockStatement();
-        block.setVariableScope(varScope);
+        block.setVariableScope(scope);
         for (Statement stmt : stmts) {
             block.addStatement(stmt);
         }
@@ -164,8 +160,8 @@ public class GeneralUtils {
         return block;
     }
 
-    public static BooleanExpression boolX(final Expression boolExpr) {
-        return new BooleanExpression(boolExpr);
+    public static BooleanExpression boolX(final Expression expr) {
+        return new BooleanExpression(expr);
     }
 
     public static BytecodeExpression bytecodeX(final Consumer<MethodVisitor> 
writer) {
@@ -255,7 +251,7 @@ public class GeneralUtils {
      * @return the expression comparing two values
      */
     public static BinaryExpression cmpX(final Expression lhv, final Expression 
rhv) {
-        return new BinaryExpression(lhv, CMP, rhv);
+        return binX(lhv, CMP, rhv);
     }
 
     public static ConstantExpression constX(final Object val) {
@@ -271,7 +267,7 @@ public class GeneralUtils {
     }
 
     public static ConstructorCallExpression ctorX(final ClassNode type) {
-        return new ConstructorCallExpression(type, 
ArgumentListExpression.EMPTY_ARGUMENTS);
+        return ctorX(type, ArgumentListExpression.EMPTY_ARGUMENTS);
     }
 
     public static Statement ctorSuperS(final Expression args) {
@@ -303,11 +299,11 @@ public class GeneralUtils {
     }
 
     public static BinaryExpression eqX(final Expression lhv, final Expression 
rhv) {
-        return new BinaryExpression(lhv, EQ, rhv);
+        return binX(lhv, EQ, rhv);
     }
 
     public static BooleanExpression equalsNullX(final Expression argExpr) {
-        return new BooleanExpression(eqX(argExpr, new 
ConstantExpression(null)));
+        return boolX(eqX(argExpr, nullX()));
     }
 
     public static FieldExpression fieldX(final FieldNode fieldNode) {
@@ -319,12 +315,12 @@ public class GeneralUtils {
     }
 
     public static Expression findArg(final String argName) {
-        return new PropertyExpression(new VariableExpression("args"), argName);
+        return propX(varX("args"), argName);
     }
 
     public static List<MethodNode> getAllMethods(final ClassNode type) {
         ClassNode node = type;
-        List<MethodNode> result = new ArrayList<MethodNode>();
+        List<MethodNode> result = new ArrayList<>();
         while (node != null) {
             result.addAll(node.getMethods());
             node = node.getSuperClass();
@@ -334,7 +330,7 @@ public class GeneralUtils {
 
     public static List<PropertyNode> getAllProperties(final ClassNode type) {
         ClassNode node = type;
-        List<PropertyNode> result = new ArrayList<PropertyNode>();
+        List<PropertyNode> result = new ArrayList<>();
         while (node != null) {
             result.addAll(node.getProperties());
             node = node.getSuperClass();
@@ -343,7 +339,7 @@ public class GeneralUtils {
     }
 
     public static List<FieldNode> getInstanceNonPropertyFields(final ClassNode 
cNode) {
-        List<FieldNode> result = new ArrayList<FieldNode>();
+        List<FieldNode> result = new ArrayList<>();
         for (FieldNode fNode : cNode.getFields()) {
             if (!fNode.isStatic() && cNode.getProperty(fNode.getName()) == 
null) {
                 result.add(fNode);
@@ -354,7 +350,7 @@ public class GeneralUtils {
 
     public static List<String> getInstanceNonPropertyFieldNames(final 
ClassNode cNode) {
         List<FieldNode> fList = getInstanceNonPropertyFields(cNode);
-        List<String> result = new ArrayList<String>(fList.size());
+        List<String> result = new ArrayList<>(fList.size());
         for (FieldNode fNode : fList) {
             result.add(fNode.getName());
         }
@@ -362,7 +358,7 @@ public class GeneralUtils {
     }
 
     public static List<PropertyNode> getInstanceProperties(final ClassNode 
cNode) {
-        List<PropertyNode> result = new ArrayList<PropertyNode>();
+        List<PropertyNode> result = new ArrayList<>();
         for (PropertyNode pNode : cNode.getProperties()) {
             if (!pNode.isStatic()) {
                 result.add(pNode);
@@ -373,7 +369,7 @@ public class GeneralUtils {
 
     public static List<String> getInstancePropertyNames(final ClassNode cNode) 
{
         List<PropertyNode> pList = BeanUtils.getAllProperties(cNode, false, 
false, true);
-        List<String> result = new ArrayList<String>(pList.size());
+        List<String> result = new ArrayList<>(pList.size());
         for (PropertyNode pNode : pList) {
             result.add(pNode.getName());
         }
@@ -381,7 +377,7 @@ public class GeneralUtils {
     }
 
     public static List<FieldNode> getInstancePropertyFields(final ClassNode 
cNode) {
-        List<FieldNode> result = new ArrayList<FieldNode>();
+        List<FieldNode> result = new ArrayList<>();
         for (PropertyNode pNode : cNode.getProperties()) {
             if (!pNode.isStatic()) {
                 result.add(pNode.getField());
@@ -391,7 +387,7 @@ public class GeneralUtils {
     }
 
     public static Set<ClassNode> getInterfacesAndSuperInterfaces(final 
ClassNode type) {
-        Set<ClassNode> res = new LinkedHashSet<ClassNode>();
+        Set<ClassNode> res = new LinkedHashSet<>();
         if (type.isInterface()) {
             res.add(type);
             return res;
@@ -407,7 +403,7 @@ public class GeneralUtils {
     public static List<FieldNode> getSuperNonPropertyFields(final ClassNode 
cNode) {
         List<FieldNode> result;
         if (cNode == ClassHelper.OBJECT_TYPE) {
-            result = new ArrayList<FieldNode>();
+            result = new ArrayList<>();
         } else {
             result = getSuperNonPropertyFields(cNode.getSuperClass());
         }
@@ -422,7 +418,7 @@ public class GeneralUtils {
     public static List<FieldNode> getSuperPropertyFields(final ClassNode 
cNode) {
         List<FieldNode> result;
         if (cNode == ClassHelper.OBJECT_TYPE) {
-            result = new ArrayList<FieldNode>();
+            result = new ArrayList<>();
         } else {
             result = getSuperPropertyFields(cNode.getSuperClass());
         }
@@ -445,7 +441,7 @@ public class GeneralUtils {
     public static List<PropertyNode> getAllProperties(final Set<String> names, 
final ClassNode origType, final ClassNode cNode, final boolean 
includeProperties,
                                                       final boolean 
includeFields, final boolean includePseudoGetters, final boolean 
includePseudoSetters,
                                                       final boolean 
traverseSuperClasses, final boolean skipReadonly, final boolean reverse, final 
boolean allNames, final boolean includeStatic) {
-        List<PropertyNode> result = new ArrayList<PropertyNode>();
+        List<PropertyNode> result = new ArrayList<>();
         if (cNode != ClassHelper.OBJECT_TYPE && traverseSuperClasses && 
!reverse) {
             result.addAll(getAllProperties(names, origType, 
cNode.getSuperClass(), includeProperties, includeFields, includePseudoGetters, 
includePseudoSetters, true, skipReadonly));
         }
@@ -500,7 +496,7 @@ public class GeneralUtils {
         if (annotatedNode.equals(owner)) {
             return callThisX(getterName(annotatedNode, pNode));
         }
-        return propX(new VariableExpression("this"), pNode.getName());
+        return propX(varX("this"), pNode.getName());
     }
 
     /**
@@ -549,46 +545,42 @@ public class GeneralUtils {
 
     public static Statement ifElseS(final Expression cond, final Statement 
thenStmt, final Statement elseStmt) {
         return new IfStatement(
-                cond instanceof BooleanExpression ? (BooleanExpression) cond : 
new BooleanExpression(cond),
+                cond instanceof BooleanExpression ? (BooleanExpression) cond : 
boolX(cond),
                 thenStmt,
                 elseStmt
         );
     }
 
     public static Statement ifS(final Expression cond, final Expression 
trueExpr) {
-        return ifS(cond, new ExpressionStatement(trueExpr));
+        return ifElseS(cond, stmt(trueExpr), EmptyStatement.INSTANCE);
     }
 
     public static Statement ifS(final Expression cond, final Statement 
trueStmt) {
-        return new IfStatement(
-                cond instanceof BooleanExpression ? (BooleanExpression) cond : 
new BooleanExpression(cond),
-                trueStmt,
-                EmptyStatement.INSTANCE
-        );
+        return ifElseS(cond, trueStmt, EmptyStatement.INSTANCE);
     }
 
     public static Expression indexX(final Expression target, final Expression 
value) {
-        return new BinaryExpression(target, INDEX, value);
+        return binX(target, INDEX, value);
     }
 
     public static BooleanExpression isInstanceOfX(final Expression 
objectExpression, final ClassNode cNode) {
-        return new BooleanExpression(new BinaryExpression(objectExpression, 
INSTANCEOF, classX(cNode)));
+        return boolX(binX(objectExpression, INSTANCEOF, classX(cNode)));
     }
 
     public static BooleanExpression isNullX(final Expression expr) {
-        return new BooleanExpression(new BinaryExpression(expr, EQ, new 
ConstantExpression(null)));
+        return boolX(binX(expr, EQ, nullX()));
     }
 
     public static BooleanExpression isOneX(final Expression expr) {
-        return new BooleanExpression(new BinaryExpression(expr, EQ, new 
ConstantExpression(1)));
+        return boolX(binX(expr, EQ, constX(1)));
     }
 
     public static BooleanExpression isTrueX(final Expression argExpr) {
-        return new BooleanExpression(new BinaryExpression(argExpr, EQ, new 
ConstantExpression(Boolean.TRUE)));
+        return boolX(binX(argExpr, EQ, constX(Boolean.TRUE)));
     }
 
     public static BooleanExpression isZeroX(final Expression expr) {
-        return new BooleanExpression(new BinaryExpression(expr, EQ, new 
ConstantExpression(0)));
+        return boolX(binX(expr, EQ, constX(0)));
     }
 
     public static ListExpression listX(final List<Expression> args) {
@@ -598,7 +590,7 @@ public class GeneralUtils {
     public static ListExpression list2args(final List<? extends Object> args) {
         ListExpression result = new ListExpression();
         for (Object o : args) {
-            result.addExpression(new ConstantExpression(o));
+            result.addExpression(constX(o));
         }
         return result;
     }
@@ -606,25 +598,25 @@ public class GeneralUtils {
     public static ListExpression classList2args(final List<String> args) {
         ListExpression result = new ListExpression();
         for (Object o : args) {
-            result.addExpression(new 
ClassExpression(ClassHelper.make(o.toString())));
+            result.addExpression(classX(ClassHelper.make(o.toString())));
         }
         return result;
     }
 
     public static VariableExpression localVarX(final String name) {
-        VariableExpression result = new VariableExpression(name);
+        VariableExpression result = varX(name);
         result.setAccessedVariable(result);
         return result;
     }
 
     public static VariableExpression localVarX(final String name, final 
ClassNode type) {
-        VariableExpression result = new VariableExpression(name, type);
+        VariableExpression result = varX(name, type);
         result.setAccessedVariable(result);
         return result;
     }
 
     public static BinaryExpression ltX(final Expression lhv, final Expression 
rhv) {
-        return new BinaryExpression(lhv, LT, rhv);
+        return binX(lhv, LT, rhv);
     }
 
     public static MapExpression mapX(final List<MapEntryExpression> 
expressions) {
@@ -632,27 +624,27 @@ public class GeneralUtils {
     }
 
     public static BinaryExpression neX(final Expression lhv, final Expression 
rhv) {
-        return new BinaryExpression(lhv, NE, rhv);
+        return binX(lhv, NE, rhv);
     }
 
     public static BinaryExpression notIdenticalX(final Expression lhv, final 
Expression rhv) {
-        return new BinaryExpression(lhv, NOT_IDENTICAL, rhv);
+        return binX(lhv, NOT_IDENTICAL, rhv);
     }
 
     public static BooleanExpression notNullX(final Expression argExpr) {
-        return new BooleanExpression(new BinaryExpression(argExpr, NE, new 
ConstantExpression(null)));
+        return boolX(binX(argExpr, NE, nullX()));
     }
 
     public static NotExpression notX(final Expression expr) {
-        return new NotExpression(expr instanceof BooleanExpression ? expr : 
new BooleanExpression(expr));
+        return new NotExpression(expr instanceof BooleanExpression ? expr : 
boolX(expr));
     }
 
     public static ConstantExpression nullX() {
-        return new ConstantExpression(null);
+        return constX(null);
     }
 
     public static BinaryExpression orX(final Expression lhv, final Expression 
rhv) {
-        return new BinaryExpression(lhv, OR, rhv);
+        return binX(lhv, OR, rhv);
     }
 
     public static Parameter param(final ClassNode type, final String name) {
@@ -668,11 +660,11 @@ public class GeneralUtils {
     }
 
     public static Parameter[] params(final Parameter... params) {
-        return params != null ? params : Parameter.EMPTY_ARRAY;
+        return (params != null ? params : Parameter.EMPTY_ARRAY);
     }
 
     public static BinaryExpression plusX(final Expression lhv, final 
Expression rhv) {
-        return new BinaryExpression(lhv, PLUS, rhv);
+        return binX(lhv, PLUS, rhv);
     }
 
     public static PropertyExpression propX(final Expression owner, final 
String property) {
@@ -692,14 +684,11 @@ public class GeneralUtils {
     }
 
     public static Statement safeExpression(final Expression fieldExpr, final 
Expression expression) {
-        return new IfStatement(
-                equalsNullX(fieldExpr),
-                new ExpressionStatement(fieldExpr),
-                new ExpressionStatement(expression));
+        return new IfStatement(equalsNullX(fieldExpr), stmt(fieldExpr), 
stmt(expression));
     }
 
     public static BooleanExpression sameX(final Expression self, final 
Expression other) {
-        return new BooleanExpression(callX(self, "is", args(other)));
+        return boolX(callX(self, "is", args(other)));
     }
 
     public static Statement stmt(final Expression expr) {
@@ -708,7 +697,7 @@ public class GeneralUtils {
 
     public static TernaryExpression ternaryX(final Expression cond, final 
Expression trueExpr, final Expression elseExpr) {
         return new TernaryExpression(
-                cond instanceof BooleanExpression ? (BooleanExpression) cond : 
new BooleanExpression(cond),
+                cond instanceof BooleanExpression ? (BooleanExpression) cond : 
boolX(cond),
                 trueExpr,
                 elseExpr);
     }
@@ -745,14 +734,8 @@ public class GeneralUtils {
 
     
//--------------------------------------------------------------------------
 
-    public static Parameter[] cloneParams(final Parameter[] source) {
-        Parameter[] result = new Parameter[source.length];
-        for (int i = 0; i < source.length; i++) {
-            Parameter srcParam = source[i];
-            Parameter dstParam = new Parameter(srcParam.getOriginType(), 
srcParam.getName());
-            result[i] = dstParam;
-        }
-        return result;
+    public static Parameter[] cloneParams(final Parameter[] parameters) {
+        return Arrays.stream(parameters).map(p -> param(p.getOriginType(), 
p.getName())).toArray(Parameter[]::new);
     }
 
     /**
@@ -775,7 +758,6 @@ public class GeneralUtils {
     public static void copyAnnotatedNodeAnnotations(final AnnotatedNode 
annotatedNode, final List<AnnotationNode> copied, final List<AnnotationNode> 
notCopied, final boolean includeGenerated) {
         List<AnnotationNode> annotationList = annotatedNode.getAnnotations();
         for (AnnotationNode annotation : annotationList)  {
-
             List<AnnotationNode> annotations = 
annotation.getClassNode().getAnnotations(AbstractASTTransformation.RETENTION_CLASSNODE);
             if (annotations.isEmpty()) continue;
 
@@ -793,13 +775,9 @@ public class GeneralUtils {
             if (!(valueExpression instanceof PropertyExpression)) continue;
 
             PropertyExpression propertyExpression = (PropertyExpression) 
valueExpression;
-            boolean processAnnotation =
-                    propertyExpression.getProperty() instanceof 
ConstantExpression &&
-                            (
-                                    "RUNTIME".equals(((ConstantExpression) 
(propertyExpression.getProperty())).getValue()) ||
-                                            
"CLASS".equals(((ConstantExpression) 
(propertyExpression.getProperty())).getValue())
-                            );
-
+            boolean processAnnotation = propertyExpression.getProperty() 
instanceof ConstantExpression
+                    && ("RUNTIME".equals(((ConstantExpression) 
(propertyExpression.getProperty())).getValue())
+                        || "CLASS".equals(((ConstantExpression) 
(propertyExpression.getProperty())).getValue()));
             if (processAnnotation)  {
                 AnnotationNode newAnnotation = new 
AnnotationNode(annotation.getClassNode());
                 for (Map.Entry<String, Expression> member : 
annotation.getMembers().entrySet())  {
@@ -818,7 +796,7 @@ public class GeneralUtils {
         final Expression fieldExpr = propX(varX("this"), name);
         Expression initExpr = fNode.getInitialValueExpression();
         Statement assignInit;
-        if (initExpr == null || (initExpr instanceof ConstantExpression && 
((ConstantExpression)initExpr).isNullExpression())) {
+        if (initExpr == null || (initExpr instanceof ConstantExpression && 
((ConstantExpression) initExpr).isNullExpression())) {
             if (ClassHelper.isPrimitiveType(fType)) {
                 assignInit = EmptyStatement.INSTANCE;
             } else {
@@ -833,9 +811,9 @@ public class GeneralUtils {
     }
 
     private static String getterName(final ClassNode annotatedNode, final 
PropertyNode pNode) {
-        String getterName = "get" + capitalize(pNode.getName());
-        boolean existingExplicitGetter = annotatedNode.getMethod(getterName, 
Parameter.EMPTY_ARRAY) != null;
-        if (ClassHelper.boolean_TYPE.equals(pNode.getOriginType()) && 
!existingExplicitGetter) {
+        String getterName = getGetterName(pNode);
+        if (ClassHelper.boolean_TYPE.equals(pNode.getOriginType())
+                && annotatedNode.getMethod(getterName, Parameter.EMPTY_ARRAY) 
== null) {
             getterName = "is" + capitalize(pNode.getName());
         }
         return getterName;
@@ -863,7 +841,7 @@ public class GeneralUtils {
         if (expression == null) throw new IllegalArgumentException("Null: 
expression");
 
         StringBuilder result = new StringBuilder();
-        for (int x = expression.getLineNumber(); x <= 
expression.getLastLineNumber(); x++) {
+        for (int x = expression.getLineNumber(), y = 
expression.getLastLineNumber(); x <= y; x += 1) {
             String line = readerSource.getLine(x, null);
             if (line == null) {
                 throw new Exception(
@@ -880,7 +858,6 @@ public class GeneralUtils {
             result.append(line).append('\n');
         }
 
-
         String source = result.toString().trim();
 
         return source;
@@ -892,7 +869,7 @@ public class GeneralUtils {
         if (preCode instanceof BlockStatement) {
             BlockStatement block = (BlockStatement) preCode;
             List<Statement> statements = block.getStatements();
-            for (int i = 0; i < statements.size(); i++) {
+            for (int i = 0, n = statements.size(); i < n; i += 1) {
                 Statement statement = statements.get(i);
                 // adjust the first statement if it's a super call
                 if (i == 0 && statement instanceof ExpressionStatement) {
@@ -924,15 +901,14 @@ public class GeneralUtils {
                 if (typeClass != null && 
GeneratedClosure.class.isAssignableFrom(typeClass)) return true;
             }
         }
-
         return false;
     }
 
     public static boolean hasDeclaredMethod(final ClassNode cNode, final 
String name, final int argsCount) {
-        List<MethodNode> ms = cNode.getDeclaredMethods(name);
-        for (MethodNode m : ms) {
-            Parameter[] paras = m.getParameters();
-            if (paras != null && paras.length == argsCount) {
+        List<MethodNode> methods = cNode.getDeclaredMethods(name);
+        for (MethodNode method : methods) {
+            Parameter[] params = method.getParameters();
+            if (params != null && params.length == argsCount) {
                 return true;
             }
         }
@@ -942,15 +918,15 @@ public class GeneralUtils {
     public static boolean inSamePackage(final ClassNode first, final ClassNode 
second) {
         PackageNode firstPackage = first.getPackage();
         PackageNode secondPackage = second.getPackage();
-        return ((firstPackage == null && secondPackage == null) ||
-                        firstPackage != null && secondPackage != null && 
firstPackage.getName().equals(secondPackage.getName()));
+        return ((firstPackage == null && secondPackage == null)
+                || firstPackage != null && secondPackage != null && 
firstPackage.getName().equals(secondPackage.getName()));
     }
 
     public static boolean inSamePackage(final Class<?> first, final Class<?> 
second) {
         Package firstPackage = first.getPackage();
         Package secondPackage = second.getPackage();
-        return ((firstPackage == null && secondPackage == null) ||
-                        firstPackage != null && secondPackage != null && 
firstPackage.getName().equals(secondPackage.getName()));
+        return ((firstPackage == null && secondPackage == null)
+                || firstPackage != null && secondPackage != null && 
firstPackage.getName().equals(secondPackage.getName()));
     }
 
     public static boolean isDefaultVisibility(final int modifiers) {

Reply via email to