You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2017/06/03 08:43:02 UTC

[1/2] groovy git commit: Validate method declaration

Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_6_X ca30386c7 -> f3d87bcd6


Validate method declaration


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/2d5dcd34
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/2d5dcd34
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/2d5dcd34

Branch: refs/heads/GROOVY_2_6_X
Commit: 2d5dcd34e5398daf77b4472bde9c382fd6e041f5
Parents: ca30386
Author: sunlan <su...@apache.org>
Authored: Tue May 30 15:14:21 2017 +0800
Committer: paulk <pa...@asert.com.au>
Committed: Sat Jun 3 18:21:51 2017 +1000

----------------------------------------------------------------------
 .../apache/groovy/parser/antlr4/AstBuilder.java | 13 +++++++++---
 .../groovy/parser/antlr4/ModifierManager.java   |  4 ++++
 .../groovy/parser/antlr4/SyntaxErrorTest.groovy |  1 +
 .../resources/fail/ClassDeclaration_02x.groovy  | 22 ++++++++++++++++++++
 4 files changed, 37 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/2d5dcd34/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 2feec71..ec1020b 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
@@ -896,7 +896,6 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
                                 modifiers,
                                 ClassHelper.OBJECT_TYPE);
             }
-
         }
 
         this.configureAST(classNode, ctx);
@@ -1364,12 +1363,19 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
         String className = classNode.getNodeMetaData(CLASS_NAME);
         int modifiers = modifierManager.getClassMemberModifiersOpValue();
 
-        if (!asBoolean(ctx.returnType())
-                && asBoolean(ctx.methodBody())
+        boolean hasReturnType = asBoolean(ctx.returnType());
+        boolean hasMethodBody = asBoolean(ctx.methodBody());
+
+        if (!hasReturnType
+                && hasMethodBody
                 && methodName.equals(className)) { // constructor declaration
 
             methodNode = createConstructorNodeForClass(methodName, parameters, exceptions, code, classNode, modifiers);
         } else { // class memeber method declaration
+            if (!hasReturnType && hasMethodBody && (0 == modifierManager.getModifierCount())) {
+                throw createParsingFailedException("Invalid method declaration: " + methodName, ctx);
+            }
+
             methodNode = createMethodNodeForClass(ctx, modifierManager, methodName, returnType, parameters, exceptions, code, classNode, modifiers);
         }
 
@@ -2831,6 +2837,7 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
 
         anonymousInnerClass.setUsingGenerics(false);
         anonymousInnerClass.setAnonymous(true);
+        anonymousInnerClass.putNodeMetaData(CLASS_NAME, fullName);
         this.configureAST(anonymousInnerClass, ctx);
 
         classNodeStack.push(anonymousInnerClass);

http://git-wip-us.apache.org/repos/asf/groovy/blob/2d5dcd34/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/ModifierManager.java
----------------------------------------------------------------------
diff --git a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/ModifierManager.java b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/ModifierManager.java
index 22d6d69..4032938 100644
--- a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/ModifierManager.java
+++ b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/ModifierManager.java
@@ -59,6 +59,10 @@ class ModifierManager {
         this.modifierNodeList = Collections.unmodifiableList(asBoolean((Object) modifierNodeList) ? modifierNodeList : Collections.<ModifierNode>emptyList());
     }
 
+    public int getModifierCount() {
+        return modifierNodeList.size();
+    }
+
     private void validate(List<ModifierNode> modifierNodeList) {
         Map<ModifierNode, Integer> modifierNodeCounter = new LinkedHashMap<>(modifierNodeList.size());
         int visibilityModifierCnt = 0;

http://git-wip-us.apache.org/repos/asf/groovy/blob/2d5dcd34/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy
----------------------------------------------------------------------
diff --git a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy
index 67a68f8..f311642 100644
--- a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy
+++ b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy
@@ -143,6 +143,7 @@ class SyntaxErrorTest extends GroovyTestCase {
 
     void "test groovy core - ClassDeclaration"() {
         TestUtils.doRunAndShouldFail('fail/ClassDeclaration_01x.groovy');
+        TestUtils.doRunAndShouldFail('fail/ClassDeclaration_02x.groovy');
     }
 
     void "test groovy core - MethodDeclaration"() {

http://git-wip-us.apache.org/repos/asf/groovy/blob/2d5dcd34/subprojects/parser-antlr4/src/test/resources/fail/ClassDeclaration_02x.groovy
----------------------------------------------------------------------
diff --git a/subprojects/parser-antlr4/src/test/resources/fail/ClassDeclaration_02x.groovy b/subprojects/parser-antlr4/src/test/resources/fail/ClassDeclaration_02x.groovy
new file mode 100644
index 0000000..662642d
--- /dev/null
+++ b/subprojects/parser-antlr4/src/test/resources/fail/ClassDeclaration_02x.groovy
@@ -0,0 +1,22 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+class Foo {}
+new Foo() {
+    Foo() {}
+}


[2/2] groovy git commit: GROOVY-8216: invalid octal split into two arguments

Posted by pa...@apache.org.
GROOVY-8216: invalid octal split into two arguments


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/f3d87bcd
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/f3d87bcd
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/f3d87bcd

Branch: refs/heads/GROOVY_2_6_X
Commit: f3d87bcd6d2cd61678d97f7b0dda2d9b195b67ec
Parents: 2d5dcd3
Author: sunlan <su...@apache.org>
Authored: Fri Jun 2 23:34:46 2017 +0800
Committer: paulk <pa...@asert.com.au>
Committed: Sat Jun 3 18:22:05 2017 +1000

----------------------------------------------------------------------
 .../apache/groovy/parser/antlr4/GroovyLexer.g4   |  4 ++++
 .../groovy/parser/antlr4/SyntaxErrorTest.groovy  |  1 +
 .../test/resources/bugs/BUG-GROOVY-8216.groovy   | 19 +++++++++++++++++++
 3 files changed, 24 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/f3d87bcd/subprojects/parser-antlr4/src/main/antlr4/org/apache/groovy/parser/antlr4/GroovyLexer.g4
----------------------------------------------------------------------
diff --git a/subprojects/parser-antlr4/src/main/antlr4/org/apache/groovy/parser/antlr4/GroovyLexer.g4 b/subprojects/parser-antlr4/src/main/antlr4/org/apache/groovy/parser/antlr4/GroovyLexer.g4
index 7bcec42..bc7131c 100644
--- a/subprojects/parser-antlr4/src/main/antlr4/org/apache/groovy/parser/antlr4/GroovyLexer.g4
+++ b/subprojects/parser-antlr4/src/main/antlr4/org/apache/groovy/parser/antlr4/GroovyLexer.g4
@@ -52,6 +52,7 @@ options {
 @members {
     private long tokenIndex     = 0;
     private int  lastTokenType  = 0;
+    private int  invalidDigitCount = 0;
 
     /**
      * Record the index and token type of the current token while emitting tokens.
@@ -444,6 +445,9 @@ IntegerLiteral
     |   HexIntegerLiteral
     |   OctalIntegerLiteral
     |   BinaryIntegerLiteral
+
+    // !!! Error Alternative !!!
+    |   '0' ([0-9] { invalidDigitCount++; })+ { require(false, "Invalid octal number", -(invalidDigitCount + 1), true); } IntegerTypeSuffix?
     ;
 
 fragment

http://git-wip-us.apache.org/repos/asf/groovy/blob/f3d87bcd/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy
----------------------------------------------------------------------
diff --git a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy
index f311642..03ba016 100644
--- a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy
+++ b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy
@@ -121,6 +121,7 @@ class SyntaxErrorTest extends GroovyTestCase {
     void "test groovy core - BUGs"() {
         TestUtils.doRunAndShouldFail('bugs/BUG-GROOVY-5318.groovy');
         TestUtils.doRunAndShouldFail('bugs/BUG-GROOVY-8150.groovy');
+        TestUtils.doRunAndShouldFail('bugs/BUG-GROOVY-8216.groovy');
     }
 
     void "test groovy core - DoWhile"() {

http://git-wip-us.apache.org/repos/asf/groovy/blob/f3d87bcd/subprojects/parser-antlr4/src/test/resources/bugs/BUG-GROOVY-8216.groovy
----------------------------------------------------------------------
diff --git a/subprojects/parser-antlr4/src/test/resources/bugs/BUG-GROOVY-8216.groovy b/subprojects/parser-antlr4/src/test/resources/bugs/BUG-GROOVY-8216.groovy
new file mode 100644
index 0000000..431d54c
--- /dev/null
+++ b/subprojects/parser-antlr4/src/test/resources/bugs/BUG-GROOVY-8216.groovy
@@ -0,0 +1,19 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+​println 09​
\ No newline at end of file