Repository: groovy Updated Branches: refs/heads/GROOVY_2_6_X 6fd3f95e4 -> e7676ec75
Minor refactoring (cherry picked from commit 0d7b0bc) Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/e7676ec7 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/e7676ec7 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/e7676ec7 Branch: refs/heads/GROOVY_2_6_X Commit: e7676ec754d92b709613bac2baee7fb1f1665f4b Parents: 6fd3f95 Author: sunlan <sun...@apache.org> Authored: Thu Sep 7 20:25:33 2017 +0800 Committer: sunlan <sun...@apache.org> Committed: Thu Sep 7 20:56:08 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/e7676ec7/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:ja...@coredevelopers.net">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/e7676ec7/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 9cd91c8..b2d0c47 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 @@ -446,7 +446,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); @@ -2238,7 +2238,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; } List<ClassNode> list = new ArrayList<>(); @@ -2878,7 +2878,7 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov empties[i] = ConstantExpression.EMPTY_EXPRESSION; } } else { - empties = new Expression[0]; + empties = Expression.EMPTY_ARRAY; } List<Expression> sizes = new LinkedList<>(); @@ -3645,7 +3645,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); @@ -4209,11 +4209,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() { @@ -4318,9 +4315,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')); } }