groovy git commit: Refine arguments validation and the test of GROOVY-8542
Repository: groovy Updated Branches: refs/heads/GROOVY_2_6_X d862bdbdc -> e0026bb77 Refine arguments validation and the test of GROOVY-8542 (cherry picked from commit 322e862) Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/e0026bb7 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/e0026bb7 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/e0026bb7 Branch: refs/heads/GROOVY_2_6_X Commit: e0026bb779cd1031a006bf3a77556f54b39c266e Parents: d862bdb Author: danielsun1106 Authored: Thu Apr 12 22:19:58 2018 +0800 Committer: danielsun1106 Committed: Thu Apr 12 22:20:58 2018 +0800 -- .../apache/groovy/parser/antlr4/AstBuilder.java | 26 .../resources/core/NonStaticClass_01x.groovy| 10 +--- 2 files changed, 16 insertions(+), 20 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/e0026bb7/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 723f623..9b810f0 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 @@ -2319,25 +2319,19 @@ public class AstBuilder extends GroovyParserBaseVisitor implements Groov return configureAST(propertyExpression, ctx); } } -} - -if (asBoolean(ctx.creator())) { +} else if (asBoolean(ctx.creator())) { CreatorContext creatorContext = ctx.creator(); creatorContext.putNodeMetaData(ENCLOSING_INSTANCE_EXPRESSION, baseExpr); return configureAST(this.visitCreator(creatorContext), ctx); -} - -if (asBoolean(ctx.indexPropertyArgs())) { // e.g. list[1, 3, 5] +} else if (asBoolean(ctx.indexPropertyArgs())) { // e.g. list[1, 3, 5] Tuple2 tuple = this.visitIndexPropertyArgs(ctx.indexPropertyArgs()); boolean isSafeChain = isTrue(baseExpr, PATH_EXPRESSION_BASE_EXPR_SAFE_CHAIN); return configureAST( new BinaryExpression(baseExpr, createGroovyToken(tuple.getFirst()), tuple.getSecond(), isSafeChain || asBoolean(ctx.indexPropertyArgs().QUESTION())), ctx); -} - -if (asBoolean(ctx.namedPropertyArgs())) { // this is a special way to new instance, e.g. Person(name: 'Daniel.Sun', location: 'Shanghai') +} else if (asBoolean(ctx.namedPropertyArgs())) { // this is a special way to new instance, e.g. Person(name: 'Daniel.Sun', location: 'Shanghai') List mapEntryExpressionList = this.visitNamedPropertyArgs(ctx.namedPropertyArgs()); @@ -2364,9 +2358,7 @@ public class AstBuilder extends GroovyParserBaseVisitor implements Groov return configureAST( new BinaryExpression(baseExpr, createGroovyToken(ctx.namedPropertyArgs().LBRACK().getSymbol()), right), ctx); -} - -if (asBoolean(ctx.arguments())) { +} else if (asBoolean(ctx.arguments())) { Expression argumentsExpr = this.visitArguments(ctx.arguments()); configureAST(argumentsExpr, ctx); @@ -2435,9 +2427,7 @@ public class AstBuilder extends GroovyParserBaseVisitor implements Groov // e.g. 1(), 1.1(), ((int) 1 / 2)(1, 2), {a, b -> a + b }(1, 2), m()() return configureAST(createCallMethodCallExpression(baseExpr, argumentsExpr), ctx); -} - -if (asBoolean(ctx.closure())) { +} else if (asBoolean(ctx.closure())) { ClosureExpression closureExpression = this.visitClosure(ctx.closure()); if (baseExpr instanceof MethodCallExpression) { @@ -3191,8 +3181,12 @@ public class AstBuilder extends GroovyParserBaseVisitor implements Groov if (null != enclosingInstanceExpression) { if (arguments instanceof ArgumentListExpression) { ((ArgumentListExpression) arguments).getExpressions().add(0, enclosingInstanceExpression); -} else if (arguments instanceof TupleExpression || arguments instanceof NamedArgumentListExpression) { +} else if (arguments instanceof TupleExpression) { throw createParsingFailedException("Creating instance of non-static class does not support named parameters", arguments); +} else if (arguments instanceof NamedArgumentListExpression) { +thr
groovy git commit: Refine arguments validation and the test of GROOVY-8542
Repository: groovy Updated Branches: refs/heads/master 3f35148f9 -> 322e86274 Refine arguments validation and the test of GROOVY-8542 Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/322e8627 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/322e8627 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/322e8627 Branch: refs/heads/master Commit: 322e862749e9f38ff6108b3b1a94cdb533832fd0 Parents: 3f35148 Author: danielsun1106 Authored: Thu Apr 12 22:19:58 2018 +0800 Committer: danielsun1106 Committed: Thu Apr 12 22:19:58 2018 +0800 -- .../apache/groovy/parser/antlr4/AstBuilder.java | 26 .../resources/core/NonStaticClass_01x.groovy| 10 +--- 2 files changed, 16 insertions(+), 20 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/322e8627/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 2372d44..80988f6 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 @@ -2291,25 +2291,19 @@ public class AstBuilder extends GroovyParserBaseVisitor implements Groov return configureAST(propertyExpression, ctx); } } -} - -if (asBoolean(ctx.creator())) { +} else if (asBoolean(ctx.creator())) { CreatorContext creatorContext = ctx.creator(); creatorContext.putNodeMetaData(ENCLOSING_INSTANCE_EXPRESSION, baseExpr); return configureAST(this.visitCreator(creatorContext), ctx); -} - -if (asBoolean(ctx.indexPropertyArgs())) { // e.g. list[1, 3, 5] +} else if (asBoolean(ctx.indexPropertyArgs())) { // e.g. list[1, 3, 5] Tuple2 tuple = this.visitIndexPropertyArgs(ctx.indexPropertyArgs()); boolean isSafeChain = isTrue(baseExpr, PATH_EXPRESSION_BASE_EXPR_SAFE_CHAIN); return configureAST( new BinaryExpression(baseExpr, createGroovyToken(tuple.getFirst()), tuple.getSecond(), isSafeChain || asBoolean(ctx.indexPropertyArgs().QUESTION())), ctx); -} - -if (asBoolean(ctx.namedPropertyArgs())) { // this is a special way to new instance, e.g. Person(name: 'Daniel.Sun', location: 'Shanghai') +} else if (asBoolean(ctx.namedPropertyArgs())) { // this is a special way to new instance, e.g. Person(name: 'Daniel.Sun', location: 'Shanghai') List mapEntryExpressionList = this.visitNamedPropertyArgs(ctx.namedPropertyArgs()); @@ -2346,9 +2340,7 @@ public class AstBuilder extends GroovyParserBaseVisitor implements Groov return configureAST( new BinaryExpression(baseExpr, createGroovyToken(ctx.namedPropertyArgs().LBRACK().getSymbol()), right), ctx); -} - -if (asBoolean(ctx.arguments())) { +} else if (asBoolean(ctx.arguments())) { Expression argumentsExpr = this.visitArguments(ctx.arguments()); configureAST(argumentsExpr, ctx); @@ -2417,9 +2409,7 @@ public class AstBuilder extends GroovyParserBaseVisitor implements Groov // e.g. 1(), 1.1(), ((int) 1 / 2)(1, 2), {a, b -> a + b }(1, 2), m()() return configureAST(createCallMethodCallExpression(baseExpr, argumentsExpr), ctx); -} - -if (asBoolean(ctx.closure())) { +} else if (asBoolean(ctx.closure())) { ClosureExpression closureExpression = this.visitClosure(ctx.closure()); if (baseExpr instanceof MethodCallExpression) { @@ -3162,8 +3152,12 @@ public class AstBuilder extends GroovyParserBaseVisitor implements Groov if (null != enclosingInstanceExpression) { if (arguments instanceof ArgumentListExpression) { ((ArgumentListExpression) arguments).getExpressions().add(0, enclosingInstanceExpression); -} else if (arguments instanceof TupleExpression || arguments instanceof NamedArgumentListExpression) { +} else if (arguments instanceof TupleExpression) { throw createParsingFailedException("Creating instance of non-static class does not support named parameters", arguments); +} else if (arguments instanceof NamedArgumentListExpression) { +throw createParsingFailedException("Unexpected argum