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 <realblue...@hotmail.com>
Authored: Thu Apr 12 22:19:58 2018 +0800
Committer: danielsun1106 <realblue...@hotmail.com>
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<Object> 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<Token, Expression> 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<MapEntryExpression> mapEntryExpressionList =
                     this.visitNamedPropertyArgs(ctx.namedPropertyArgs());
 
@@ -2346,9 +2340,7 @@ public class AstBuilder extends 
GroovyParserBaseVisitor<Object> 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<Object> 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<Object> 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 arguments", 
arguments);
+                } else {
+                    throw createParsingFailedException("Unsupported 
arguments", arguments); // should never reach here
                 }
             }
 

http://git-wip-us.apache.org/repos/asf/groovy/blob/322e8627/subprojects/parser-antlr4/src/test/resources/core/NonStaticClass_01x.groovy
----------------------------------------------------------------------
diff --git 
a/subprojects/parser-antlr4/src/test/resources/core/NonStaticClass_01x.groovy 
b/subprojects/parser-antlr4/src/test/resources/core/NonStaticClass_01x.groovy
index 007978a..4b70e29 100644
--- 
a/subprojects/parser-antlr4/src/test/resources/core/NonStaticClass_01x.groovy
+++ 
b/subprojects/parser-antlr4/src/test/resources/core/NonStaticClass_01x.groovy
@@ -16,7 +16,6 @@
  *  specific language governing permissions and limitations
  *  under the License.
  */
-
 public class Y {
     public class X {
         def name
@@ -47,13 +46,16 @@ public class Y {
                         new X('Daniel')
                                         .name
     }
-}
 
-def createY() {
-    return new Y()
+    public static String getXName3() {
+        return createY().
+                new X('Daniel')
+                                .getName()
+    }
 }
 
 assert 'Daniel' == Y.createX(new Y()).name
 assert 'Daniel' == Y.createX().name
 assert 'Daniel' == Y.getXName()
 assert 'Daniel' == Y.getXName2()
+assert 'Daniel' == Y.getXName3()

Reply via email to