Repository: groovy Updated Branches: refs/heads/master 1f2ca648a -> 0d7b0bcc5
Minor refactoring Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/0d7b0bcc Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/0d7b0bcc Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/0d7b0bcc Branch: refs/heads/master Commit: 0d7b0bcc5b1f9f5b2219e92b1879413aa79f4818 Parents: 1f2ca64 Author: sunlan <[email protected]> Authored: Thu Sep 7 20:25:33 2017 +0800 Committer: sunlan <[email protected]> Committed: Thu Sep 7 20:25:33 2017 +0800 ---------------------------------------------------------------------- .../org/codehaus/groovy/ast/expr/Expression.java | 2 +- .../apache/groovy/parser/antlr4/AstBuilder.java | 17 +++++++---------- 2 files changed, 8 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/groovy/blob/0d7b0bcc/src/main/org/codehaus/groovy/ast/expr/Expression.java ---------------------------------------------------------------------- diff --git a/src/main/org/codehaus/groovy/ast/expr/Expression.java b/src/main/org/codehaus/groovy/ast/expr/Expression.java index 1109528..6ffa3f2 100644 --- a/src/main/org/codehaus/groovy/ast/expr/Expression.java +++ b/src/main/org/codehaus/groovy/ast/expr/Expression.java @@ -32,7 +32,7 @@ import org.codehaus.groovy.GroovyBugError; * @author <a href="mailto:[email protected]">James Strachan</a> */ public abstract class Expression extends AnnotatedNode { - + public static final Expression[] EMPTY_ARRAY = new Expression[0]; private ClassNode type=ClassHelper.DYNAMIC_TYPE; /** http://git-wip-us.apache.org/repos/asf/groovy/blob/0d7b0bcc/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java ---------------------------------------------------------------------- diff --git a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java index 8d15e54..a833973 100644 --- a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java +++ b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java @@ -441,7 +441,7 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov if (asBoolean(ctx.localVariableDeclaration())) { DeclarationListStatement declarationListStatement = this.visitLocalVariableDeclaration(ctx.localVariableDeclaration()); - List<?> declarationExpressionList = declarationListStatement.getDeclarationExpressions(); + List<? extends Expression> declarationExpressionList = declarationListStatement.getDeclarationExpressions(); if (declarationExpressionList.size() == 1) { return this.configureAST((Expression) declarationExpressionList.get(0), ctx); @@ -2218,7 +2218,7 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov @Override public ClassNode[] visitTypeList(TypeListContext ctx) { if (!asBoolean(ctx)) { - return new ClassNode[0]; + return ClassNode.EMPTY_ARRAY; } return ctx.type().stream() @@ -2849,7 +2849,7 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov empties = new Expression[emptyDimList.size()]; Arrays.setAll(empties, i -> ConstantExpression.EMPTY_EXPRESSION); } else { - empties = new Expression[0]; + empties = Expression.EMPTY_ARRAY; } arrayExpression = @@ -3585,7 +3585,7 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov } if (asBoolean(ctx.LT())) { // e.g. <> - return new GenericsType[0]; + return GenericsType.EMPTY_ARRAY; } throw createParsingFailedException("Unsupported type arguments or diamond: " + ctx.getText(), ctx); @@ -4129,11 +4129,8 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov private boolean isInsideParentheses(NodeMetaDataHandler nodeMetaDataHandler) { Integer insideParenLevel = nodeMetaDataHandler.getNodeMetaData(INSIDE_PARENTHESES_LEVEL); - if (null != insideParenLevel) { - return insideParenLevel > 0; - } + return null != insideParenLevel && insideParenLevel > 0; - return false; } private void addEmptyReturnStatement() { @@ -4238,9 +4235,9 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov } if (0 == newLineCnt) { - return new Pair<Integer, Integer>(token.getLine(), token.getCharPositionInLine() + 1 + token.getText().length()); + return new Pair<>(token.getLine(), token.getCharPositionInLine() + 1 + token.getText().length()); } else { // e.g. GStringEnd contains newlines, we should fix the location info - return new Pair<Integer, Integer>(token.getLine() + newLineCnt, stopTextLength - stopText.lastIndexOf('\n')); + return new Pair<>(token.getLine() + newLineCnt, stopTextLength - stopText.lastIndexOf('\n')); } }
