Repository: groovy Updated Branches: refs/heads/parrot 5a773a8a6 -> 8025ca3b9
Minor refactoring Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/8025ca3b Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/8025ca3b Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/8025ca3b Branch: refs/heads/parrot Commit: 8025ca3b97e1159e95425df85825b7f812c8d409 Parents: 5a773a8 Author: sunlan <[email protected]> Authored: Sat Jan 28 15:33:26 2017 +0800 Committer: sunlan <[email protected]> Committed: Sat Jan 28 15:33:26 2017 +0800 ---------------------------------------------------------------------- .../apache/groovy/parser/antlr4/AstBuilder.java | 60 +++++++++++--------- 1 file changed, 34 insertions(+), 26 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/groovy/blob/8025ca3b/subprojects/groovy-parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java ---------------------------------------------------------------------- diff --git a/subprojects/groovy-parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java b/subprojects/groovy-parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java index 522ca5b..68c5f3a 100644 --- a/subprojects/groovy-parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java +++ b/subprojects/groovy-parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java @@ -1351,8 +1351,7 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov return this.configureAST(this.visitVariableDeclaration(ctx.variableDeclaration()), ctx); } - @Override - public DeclarationListStatement visitVariableDeclaration(VariableDeclarationContext ctx) { + private ModifierManager createModifierManager(VariableDeclarationContext ctx) { List<ModifierNode> modifierNodeList = Collections.emptyList(); if (asBoolean(ctx.variableModifiers())) { @@ -1365,32 +1364,41 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov modifierNodeList = this.visitModifiersOpt(ctx.modifiersOpt()); } - ModifierManager modifierManager = new ModifierManager(modifierNodeList); + return new ModifierManager(modifierNodeList); + } - if (asBoolean(ctx.typeNamePairs())) { // e.g. def (int a, int b) = [1, 2] - if (!modifierManager.contains(DEF)) { - throw createParsingFailedException("keyword def is required to declare tuple, e.g. def (int a, int b) = [1, 2]", ctx); - } + private DeclarationListStatement createMultiAssignmentDeclarationListStatement(VariableDeclarationContext ctx, ModifierManager modifierManager) { + if (!modifierManager.contains(DEF)) { + throw createParsingFailedException("keyword def is required to declare tuple, e.g. def (int a, int b) = [1, 2]", ctx); + } - return this.configureAST( - new DeclarationListStatement( - this.configureAST( - modifierManager.attachAnnotations( - new DeclarationExpression( - new ArgumentListExpression( - this.visitTypeNamePairs(ctx.typeNamePairs()).stream() - .peek(e -> modifierManager.processVariableExpression((VariableExpression) e)) - .collect(Collectors.toList()) - ), - this.createGroovyTokenByType(ctx.ASSIGN().getSymbol(), Types.ASSIGN), - this.visitVariableInitializer(ctx.variableInitializer()) - ) - ), - ctx - ) - ), - ctx - ); + return this.configureAST( + new DeclarationListStatement( + this.configureAST( + modifierManager.attachAnnotations( + new DeclarationExpression( + new ArgumentListExpression( + this.visitTypeNamePairs(ctx.typeNamePairs()).stream() + .peek(e -> modifierManager.processVariableExpression((VariableExpression) e)) + .collect(Collectors.toList()) + ), + this.createGroovyTokenByType(ctx.ASSIGN().getSymbol(), Types.ASSIGN), + this.visitVariableInitializer(ctx.variableInitializer()) + ) + ), + ctx + ) + ), + ctx + ); + } + + @Override + public DeclarationListStatement visitVariableDeclaration(VariableDeclarationContext ctx) { + ModifierManager modifierManager = this.createModifierManager(ctx); + + if (asBoolean(ctx.typeNamePairs())) { // e.g. def (int a, int b) = [1, 2] + return this.createMultiAssignmentDeclarationListStatement(ctx, modifierManager); } ClassNode variableType = this.visitType(ctx.type());
