groovy git commit: Refine error messages
Repository: groovy Updated Branches: refs/heads/master a4306dcb7 -> 18de060f6 Refine error messages (cherry picked from commit a4306dc) Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/18de060f Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/18de060f Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/18de060f Branch: refs/heads/master Commit: 18de060f66dc10298fee39fab9c653add463e0c7 Parents: a4306dc Author: sunlanAuthored: Thu Oct 5 13:59:04 2017 +0800 Committer: sunlan Committed: Thu Oct 5 13:59:04 2017 +0800 -- src/test/gls/generics/GenericsTest.groovy | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/18de060f/src/test/gls/generics/GenericsTest.groovy -- diff --git a/src/test/gls/generics/GenericsTest.groovy b/src/test/gls/generics/GenericsTest.groovy index 2a57ec5..0f8df3b 100644 --- a/src/test/gls/generics/GenericsTest.groovy +++ b/src/test/gls/generics/GenericsTest.groovy @@ -427,11 +427,11 @@ import java.util.concurrent.atomic.AtomicInteger shouldFailCompilationWithMessage """ def List () -""", "Unexpected input: 'def List
history = new ArrayList
groovy git commit: Refine error messages
Repository: groovy Updated Branches: refs/heads/GROOVY_2_6_X e9294f56f -> 0b9db15f7 Refine error messages (cherry picked from commit a4306dc) Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/0b9db15f Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/0b9db15f Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/0b9db15f Branch: refs/heads/GROOVY_2_6_X Commit: 0b9db15f7073659b998b8ae12b21fd0c228fe5a5 Parents: e9294f5 Author: sunlanAuthored: Thu Oct 5 13:28:25 2017 +0800 Committer: sunlan Committed: Thu Oct 5 13:29:06 2017 +0800 -- src/test/gls/generics/GenericsTest.groovy | 2 +- src/test/groovy/bugs/Groovy5318Bug.groovy | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/0b9db15f/src/test/gls/generics/GenericsTest.groovy -- diff --git a/src/test/gls/generics/GenericsTest.groovy b/src/test/gls/generics/GenericsTest.groovy index 3fe0e69..2a57ec5 100644 --- a/src/test/gls/generics/GenericsTest.groovy +++ b/src/test/gls/generics/GenericsTest.groovy @@ -398,7 +398,7 @@ import java.util.concurrent.atomic.AtomicInteger } else { shouldFailCompilationWithMessage """ def list1 = new ArrayList
groovy git commit: Refine error messages
Repository: groovy Updated Branches: refs/heads/master 35ae8e484 -> a4306dcb7 Refine error messages Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/a4306dcb Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/a4306dcb Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/a4306dcb Branch: refs/heads/master Commit: a4306dcb76579907f4d054e2ea630d16c148de05 Parents: 35ae8e4 Author: sunlanAuthored: Thu Oct 5 13:28:25 2017 +0800 Committer: sunlan Committed: Thu Oct 5 13:28:25 2017 +0800 -- src/test/gls/generics/GenericsTest.groovy | 2 +- src/test/groovy/bugs/Groovy5318Bug.groovy | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/a4306dcb/src/test/gls/generics/GenericsTest.groovy -- diff --git a/src/test/gls/generics/GenericsTest.groovy b/src/test/gls/generics/GenericsTest.groovy index 3fe0e69..2a57ec5 100644 --- a/src/test/gls/generics/GenericsTest.groovy +++ b/src/test/gls/generics/GenericsTest.groovy @@ -398,7 +398,7 @@ import java.util.concurrent.atomic.AtomicInteger } else { shouldFailCompilationWithMessage """ def list1 = new ArrayList
groovy git commit: Treat conditional statement as expression
Repository: groovy Updated Branches: refs/heads/GROOVY_2_6_X d91eb131d -> e9294f56f Treat conditional statement as expression (cherry picked from commit 35ae8e4) Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/e9294f56 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/e9294f56 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/e9294f56 Branch: refs/heads/GROOVY_2_6_X Commit: e9294f56f62b2db6c275e923928aeba7e8ff1695 Parents: d91eb13 Author: sunlanAuthored: Thu Oct 5 12:47:10 2017 +0800 Committer: sunlan Committed: Thu Oct 5 12:49:40 2017 +0800 -- src/antlr/GroovyParser.g4 | 1 + .../apache/groovy/parser/antlr4/AstBuilder.java | 18 .../parser/antlr4/GroovyParserTest.groovy | 4 + .../ConditionalStatementAsExpression_01x.groovy | 91 4 files changed, 114 insertions(+) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/e9294f56/src/antlr/GroovyParser.g4 -- diff --git a/src/antlr/GroovyParser.g4 b/src/antlr/GroovyParser.g4 index 700344b..85580e1 100644 --- a/src/antlr/GroovyParser.g4 +++ b/src/antlr/GroovyParser.g4 @@ -817,6 +817,7 @@ expressionListElement[boolean canSpread] enhancedStatementExpression : statementExpression | standardLambdaExpression +| conditionalStatement// treat conditional statement as expression ; /** http://git-wip-us.apache.org/repos/asf/groovy/blob/e9294f56/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 7dfef2a..4ec1589 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 @@ -2001,6 +2001,24 @@ public class AstBuilder extends GroovyParserBaseVisitor implements Groov expression = ((ExpressionStatement) this.visit(ctx.statementExpression())).getExpression(); } else if (asBoolean(ctx.standardLambdaExpression())) { expression = this.visitStandardLambdaExpression(ctx.standardLambdaExpression()); +} else if (asBoolean(ctx.conditionalStatement())) { +expression = +configureAST( +createCallMethodCallExpression( +configureAST( +new ClosureExpression( +Parameter.EMPTY_ARRAY, +configureAST( + this.createBlockStatement(this.visitConditionalStatement(ctx.conditionalStatement())), +ctx +) +), +ctx +), +new ArgumentListExpression() +), +ctx +); } else { throw createParsingFailedException("Unsupported enhanced statement expression: " + ctx.getText(), ctx); } http://git-wip-us.apache.org/repos/asf/groovy/blob/e9294f56/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy -- diff --git a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy index 1e3e0e2..7fcc6a0 100644 --- a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy +++ b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy @@ -381,6 +381,10 @@ class GroovyParserTest extends GroovyTestCase { doRunAndTest('core/SafeChainOperator.groovy'); } +void "test groovy core - ConditionalStatementAsExpression"() { +doRunAndTest('core/ConditionalStatementAsExpression_01x.groovy'); +} + void "test groovy core - BUG"() { doRunAndTest('bugs/BUG-GROOVY-4757.groovy'); doRunAndTest('bugs/BUG-GROOVY-5652.groovy'); http://git-wip-us.apache.org/repos/asf/groovy/blob/e9294f56/subprojects/parser-antlr4/src/test/resources/core/ConditionalStatementAsExpression_01x.groovy
groovy git commit: Treat conditional statement as expression
Repository: groovy Updated Branches: refs/heads/master 1783be3ae -> 35ae8e484 Treat conditional statement as expression Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/35ae8e48 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/35ae8e48 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/35ae8e48 Branch: refs/heads/master Commit: 35ae8e484020f2d11b2dd9c7efa3740ee527fa70 Parents: 1783be3 Author: sunlanAuthored: Thu Oct 5 12:47:10 2017 +0800 Committer: sunlan Committed: Thu Oct 5 12:47:10 2017 +0800 -- src/antlr/GroovyParser.g4 | 1 + .../apache/groovy/parser/antlr4/AstBuilder.java | 18 .../parser/antlr4/GroovyParserTest.groovy | 4 + .../ConditionalStatementAsExpression_01x.groovy | 91 4 files changed, 114 insertions(+) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/35ae8e48/src/antlr/GroovyParser.g4 -- diff --git a/src/antlr/GroovyParser.g4 b/src/antlr/GroovyParser.g4 index 23e7e7a..dd0bcfb 100644 --- a/src/antlr/GroovyParser.g4 +++ b/src/antlr/GroovyParser.g4 @@ -784,6 +784,7 @@ expressionListElement[boolean canSpread] enhancedStatementExpression : statementExpression | standardLambdaExpression +| conditionalStatement// treat conditional statement as expression ; /** http://git-wip-us.apache.org/repos/asf/groovy/blob/35ae8e48/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 157a5be..c69cf3c 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 @@ -1979,6 +1979,24 @@ public class AstBuilder extends GroovyParserBaseVisitor implements Groov expression = ((ExpressionStatement) this.visit(ctx.statementExpression())).getExpression(); } else if (asBoolean(ctx.standardLambdaExpression())) { expression = this.visitStandardLambdaExpression(ctx.standardLambdaExpression()); +} else if (asBoolean(ctx.conditionalStatement())) { +expression = +configureAST( +createCallMethodCallExpression( +configureAST( +new ClosureExpression( +Parameter.EMPTY_ARRAY, +configureAST( + this.createBlockStatement(this.visitConditionalStatement(ctx.conditionalStatement())), +ctx +) +), +ctx +), +new ArgumentListExpression() +), +ctx +); } else { throw createParsingFailedException("Unsupported enhanced statement expression: " + ctx.getText(), ctx); } http://git-wip-us.apache.org/repos/asf/groovy/blob/35ae8e48/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy -- diff --git a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy index fd65344..abadf5f 100644 --- a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy +++ b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy @@ -373,6 +373,10 @@ class GroovyParserTest extends GroovyTestCase { doRunAndTest('core/SafeChainOperator.groovy'); } +void "test groovy core - ConditionalStatementAsExpression"() { +doRunAndTest('core/ConditionalStatementAsExpression_01x.groovy'); +} + void "test groovy core - BUG"() { doRunAndTest('bugs/BUG-GROOVY-4757.groovy'); doRunAndTest('bugs/BUG-GROOVY-5652.groovy'); http://git-wip-us.apache.org/repos/asf/groovy/blob/35ae8e48/subprojects/parser-antlr4/src/test/resources/core/ConditionalStatementAsExpression_01x.groovy --
groovy git commit: Minor refactoring: conditionalStatement
Repository: groovy Updated Branches: refs/heads/GROOVY_2_6_X 0f6bd3eb7 -> d91eb131d Minor refactoring: conditionalStatement (cherry picked from commit 1783be3) Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/d91eb131 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/d91eb131 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/d91eb131 Branch: refs/heads/GROOVY_2_6_X Commit: d91eb131d12d170cbd3ca68cb3cbfc7a2203484d Parents: 0f6bd3e Author: sunlanAuthored: Thu Oct 5 02:27:04 2017 +0800 Committer: sunlan Committed: Thu Oct 5 02:27:46 2017 +0800 -- src/antlr/GroovyParser.g4 | 8 ++-- .../apache/groovy/parser/antlr4/AstBuilder.java | 20 +--- 2 files changed, 19 insertions(+), 9 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/d91eb131/src/antlr/GroovyParser.g4 -- diff --git a/src/antlr/GroovyParser.g4 b/src/antlr/GroovyParser.g4 index 0d7b5db..700344b 100644 --- a/src/antlr/GroovyParser.g4 +++ b/src/antlr/GroovyParser.g4 @@ -630,6 +630,11 @@ variableNames : LPAREN variableDeclaratorId (COMMA variableDeclaratorId)+ rparen ; +conditionalStatement +: ifElseStatement +| switchStatement +; + ifElseStatement : IF expressionInPar nls tb=statement ((nls | sep) ELSE nls fb=statement)? ; @@ -693,12 +698,11 @@ locals[ String footprint = "" ] statement : block #blockStmtAlt -| ifElseStatement #ifElseStmtAlt +| conditionalStatement #conditionalStmtAlt | loopStatement #loopStmtAlt | tryCatchStatement #tryCatchStmtAlt -| switchStatement #switchStmtAlt | SYNCHRONIZED expressionInPar nls block #synchronizedStmtAlt | RETURN expression? #returnStmtAlt | THROW expression #throwStmtAlt http://git-wip-us.apache.org/repos/asf/groovy/blob/d91eb131/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 28e4e73..7dfef2a 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 @@ -391,8 +391,19 @@ public class AstBuilder extends GroovyParserBaseVisitor implements Groov } @Override -public IfStatement visitIfElseStmtAlt(IfElseStmtAltContext ctx) { -return configureAST(this.visitIfElseStatement(ctx.ifElseStatement()), ctx); +public Statement visitConditionalStmtAlt(ConditionalStmtAltContext ctx) { +return configureAST(this.visitConditionalStatement(ctx.conditionalStatement()), ctx); +} + +@Override +public Statement visitConditionalStatement(ConditionalStatementContext ctx) { +if (asBoolean(ctx.ifElseStatement())) { +return configureAST(this.visitIfElseStatement(ctx.ifElseStatement()), ctx); +} else if (asBoolean(ctx.switchStatement())) { +return configureAST(this.visitSwitchStatement(ctx.switchStatement()), ctx); +} + +throw createParsingFailedException("Unsupported conditional statement", ctx); } @Override @@ -686,11 +697,6 @@ public class AstBuilder extends GroovyParserBaseVisitor implements Groov } @Override -public SwitchStatement visitSwitchStmtAlt(SwitchStmtAltContext ctx) { -return configureAST(this.visitSwitchStatement(ctx.switchStatement()), ctx); -} - -@Override public SwitchStatement visitSwitchStatement(SwitchStatementContext ctx) { List statementList = new LinkedList<>(); for (SwitchBlockStatementGroupContext c : ctx.switchBlockStatementGroup()) {
groovy git commit: Minor refactoring: conditionalStatement
Repository: groovy Updated Branches: refs/heads/master b384a3923 -> 1783be3ae Minor refactoring: conditionalStatement Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/1783be3a Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/1783be3a Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/1783be3a Branch: refs/heads/master Commit: 1783be3aed8697d30bf1a0374e577a0ea20de197 Parents: b384a39 Author: sunlanAuthored: Thu Oct 5 02:27:04 2017 +0800 Committer: sunlan Committed: Thu Oct 5 02:27:04 2017 +0800 -- src/antlr/GroovyParser.g4 | 8 ++-- .../apache/groovy/parser/antlr4/AstBuilder.java | 20 +--- 2 files changed, 19 insertions(+), 9 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/1783be3a/src/antlr/GroovyParser.g4 -- diff --git a/src/antlr/GroovyParser.g4 b/src/antlr/GroovyParser.g4 index ad504e1..23e7e7a 100644 --- a/src/antlr/GroovyParser.g4 +++ b/src/antlr/GroovyParser.g4 @@ -597,6 +597,11 @@ variableNames : LPAREN variableDeclaratorId (COMMA variableDeclaratorId)+ rparen ; +conditionalStatement +: ifElseStatement +| switchStatement +; + ifElseStatement : IF expressionInPar nls tb=statement ((nls | sep) ELSE nls fb=statement)? ; @@ -660,12 +665,11 @@ locals[ String footprint = "" ] statement : block #blockStmtAlt -| ifElseStatement #ifElseStmtAlt +| conditionalStatement #conditionalStmtAlt | loopStatement #loopStmtAlt | tryCatchStatement #tryCatchStmtAlt -| switchStatement #switchStmtAlt | SYNCHRONIZED expressionInPar nls block #synchronizedStmtAlt | RETURN expression? #returnStmtAlt | THROW expression #throwStmtAlt http://git-wip-us.apache.org/repos/asf/groovy/blob/1783be3a/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 226d200..157a5be 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 @@ -387,8 +387,19 @@ public class AstBuilder extends GroovyParserBaseVisitor implements Groov } @Override -public IfStatement visitIfElseStmtAlt(IfElseStmtAltContext ctx) { -return configureAST(this.visitIfElseStatement(ctx.ifElseStatement()), ctx); +public Statement visitConditionalStmtAlt(ConditionalStmtAltContext ctx) { +return configureAST(this.visitConditionalStatement(ctx.conditionalStatement()), ctx); +} + +@Override +public Statement visitConditionalStatement(ConditionalStatementContext ctx) { +if (asBoolean(ctx.ifElseStatement())) { +return configureAST(this.visitIfElseStatement(ctx.ifElseStatement()), ctx); +} else if (asBoolean(ctx.switchStatement())) { +return configureAST(this.visitSwitchStatement(ctx.switchStatement()), ctx); +} + +throw createParsingFailedException("Unsupported conditional statement", ctx); } @Override @@ -670,11 +681,6 @@ public class AstBuilder extends GroovyParserBaseVisitor implements Groov } @Override -public SwitchStatement visitSwitchStmtAlt(SwitchStmtAltContext ctx) { -return configureAST(this.visitSwitchStatement(ctx.switchStatement()), ctx); -} - -@Override public SwitchStatement visitSwitchStatement(SwitchStatementContext ctx) { List statementList = ctx.switchBlockStatementGroup().stream()
groovy git commit: Minor refactoring: if-else
Repository: groovy Updated Branches: refs/heads/GROOVY_2_6_X a47e3d094 -> 0f6bd3eb7 Minor refactoring: if-else (cherry picked from commit b384a39) Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/0f6bd3eb Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/0f6bd3eb Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/0f6bd3eb Branch: refs/heads/GROOVY_2_6_X Commit: 0f6bd3eb73317de945b648b6821399491e3de2ed Parents: a47e3d0 Author: sunlanAuthored: Thu Oct 5 02:03:53 2017 +0800 Committer: sunlan Committed: Thu Oct 5 02:05:39 2017 +0800 -- src/antlr/GroovyParser.g4 | 6 +- .../main/java/org/apache/groovy/parser/antlr4/AstBuilder.java | 7 +++ 2 files changed, 12 insertions(+), 1 deletion(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/0f6bd3eb/src/antlr/GroovyParser.g4 -- diff --git a/src/antlr/GroovyParser.g4 b/src/antlr/GroovyParser.g4 index c4ad1be..0d7b5db 100644 --- a/src/antlr/GroovyParser.g4 +++ b/src/antlr/GroovyParser.g4 @@ -630,6 +630,10 @@ variableNames : LPAREN variableDeclaratorId (COMMA variableDeclaratorId)+ rparen ; +ifElseStatement +: IF expressionInPar nls tb=statement ((nls | sep) ELSE nls fb=statement)? +; + switchStatement locals[ String footprint = "" ] : SWITCH expressionInPar nls LBRACE nls switchBlockStatementGroup* nls RBRACE @@ -689,7 +693,7 @@ locals[ String footprint = "" ] statement : block #blockStmtAlt -| IF expressionInPar nls tb=statement ((nls | sep) ELSE nls fb=statement)?#ifElseStmtAlt +| ifElseStatement #ifElseStmtAlt | loopStatement #loopStmtAlt | tryCatchStatement #tryCatchStmtAlt http://git-wip-us.apache.org/repos/asf/groovy/blob/0f6bd3eb/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 70a3fd0..28e4e73 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 @@ -392,6 +392,11 @@ public class AstBuilder extends GroovyParserBaseVisitor implements Groov @Override public IfStatement visitIfElseStmtAlt(IfElseStmtAltContext ctx) { +return configureAST(this.visitIfElseStatement(ctx.ifElseStatement()), ctx); +} + +@Override +public IfStatement visitIfElseStatement(IfElseStatementContext ctx) { Expression conditionExpression = this.visitExpressionInPar(ctx.expressionInPar()); BooleanExpression booleanExpression = configureAST( @@ -409,6 +414,7 @@ public class AstBuilder extends GroovyParserBaseVisitor implements Groov return configureAST(new IfStatement(booleanExpression, ifBlock, elseBlock), ctx); } + @Override public Statement visitLoopStmtAlt(LoopStmtAltContext ctx) { return configureAST((Statement) this.visit(ctx.loopStatement()), ctx); @@ -684,6 +690,7 @@ public class AstBuilder extends GroovyParserBaseVisitor implements Groov return configureAST(this.visitSwitchStatement(ctx.switchStatement()), ctx); } +@Override public SwitchStatement visitSwitchStatement(SwitchStatementContext ctx) { List statementList = new LinkedList<>(); for (SwitchBlockStatementGroupContext c : ctx.switchBlockStatementGroup()) {
groovy git commit: Minor refactoring: if-else
Repository: groovy Updated Branches: refs/heads/master 93bfa40f3 -> b384a3923 Minor refactoring: if-else Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/b384a392 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/b384a392 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/b384a392 Branch: refs/heads/master Commit: b384a3923484f03f8c8dab761f7928727634cce7 Parents: 93bfa40 Author: sunlanAuthored: Thu Oct 5 02:03:53 2017 +0800 Committer: sunlan Committed: Thu Oct 5 02:03:53 2017 +0800 -- src/antlr/GroovyParser.g4 | 6 +- .../main/java/org/apache/groovy/parser/antlr4/AstBuilder.java | 7 +++ 2 files changed, 12 insertions(+), 1 deletion(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/b384a392/src/antlr/GroovyParser.g4 -- diff --git a/src/antlr/GroovyParser.g4 b/src/antlr/GroovyParser.g4 index 59a6f4c..ad504e1 100644 --- a/src/antlr/GroovyParser.g4 +++ b/src/antlr/GroovyParser.g4 @@ -597,6 +597,10 @@ variableNames : LPAREN variableDeclaratorId (COMMA variableDeclaratorId)+ rparen ; +ifElseStatement +: IF expressionInPar nls tb=statement ((nls | sep) ELSE nls fb=statement)? +; + switchStatement locals[ String footprint = "" ] : SWITCH expressionInPar nls LBRACE nls switchBlockStatementGroup* nls RBRACE @@ -656,7 +660,7 @@ locals[ String footprint = "" ] statement : block #blockStmtAlt -| IF expressionInPar nls tb=statement ((nls | sep) ELSE nls fb=statement)?#ifElseStmtAlt +| ifElseStatement #ifElseStmtAlt | loopStatement #loopStmtAlt | tryCatchStatement #tryCatchStmtAlt http://git-wip-us.apache.org/repos/asf/groovy/blob/b384a392/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 29cd49e..226d200 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 @@ -388,6 +388,11 @@ public class AstBuilder extends GroovyParserBaseVisitor implements Groov @Override public IfStatement visitIfElseStmtAlt(IfElseStmtAltContext ctx) { +return configureAST(this.visitIfElseStatement(ctx.ifElseStatement()), ctx); +} + +@Override +public IfStatement visitIfElseStatement(IfElseStatementContext ctx) { Expression conditionExpression = this.visitExpressionInPar(ctx.expressionInPar()); BooleanExpression booleanExpression = configureAST( @@ -405,6 +410,7 @@ public class AstBuilder extends GroovyParserBaseVisitor implements Groov return configureAST(new IfStatement(booleanExpression, ifBlock, elseBlock), ctx); } + @Override public Statement visitLoopStmtAlt(LoopStmtAltContext ctx) { return configureAST((Statement) this.visit(ctx.loopStatement()), ctx); @@ -668,6 +674,7 @@ public class AstBuilder extends GroovyParserBaseVisitor implements Groov return configureAST(this.visitSwitchStatement(ctx.switchStatement()), ctx); } +@Override public SwitchStatement visitSwitchStatement(SwitchStatementContext ctx) { List statementList = ctx.switchBlockStatementGroup().stream()