You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2017/12/31 06:49:39 UTC

[3/3] groovy git commit: GROOVY-8426: Fix line and column numbers assigned to BlockStatements generated out of method definitions(closes #649, closes #650, closes #651)

GROOVY-8426: Fix line and column numbers assigned to BlockStatements generated out of method definitions(closes #649, closes #650, closes #651)

(cherry picked from commit 0c34922)


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

Branch: refs/heads/GROOVY_2_6_X
Commit: 6e30b3fa9a65e0354bdad09ead1445f1b3beb0d1
Parents: ff291eb
Author: Marcin Erdmann <er...@gmail.com>
Authored: Thu Dec 28 19:19:56 2017 +0800
Committer: sunlan <su...@apache.org>
Committed: Sun Dec 31 14:49:32 2017 +0800

----------------------------------------------------------------------
 .../parser/antlr4/GroovyParserTest.groovy       |  3 ++
 .../groovy/parser/antlr4/TestUtils.groovy       | 12 +++++
 .../test/resources/bugs/BUG-GROOVY-8426.groovy  | 46 ++++++++++++++++++++
 3 files changed, 61 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/6e30b3fa/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 391b284..0937106 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
@@ -29,6 +29,7 @@ import org.codehaus.groovy.syntax.Token
 
 import static org.apache.groovy.parser.antlr4.TestUtils.doTest
 import static org.apache.groovy.parser.antlr4.TestUtils.doRunAndTest
+import static org.apache.groovy.parser.antlr4.TestUtils.doRunAndTestWithAntlr2
 
 /**
  * Some basic test cases for the new parser
@@ -388,5 +389,7 @@ class GroovyParserTest extends GroovyTestCase {
         doRunAndTest('bugs/BUG-GROOVY-8311.groovy')
         if (!jdk8orGreater) return
         doRunAndTest('bugs/GROOVY-8228.groovy')
+
+        doRunAndTestWithAntlr2('bugs/BUG-GROOVY-8426.groovy')
     }
 }

http://git-wip-us.apache.org/repos/asf/groovy/blob/6e30b3fa/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/TestUtils.groovy
----------------------------------------------------------------------
diff --git a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/TestUtils.groovy b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/TestUtils.groovy
index 02db2ad..19b0fd6 100644
--- a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/TestUtils.groovy
+++ b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/TestUtils.groovy
@@ -24,6 +24,7 @@ import org.apache.groovy.parser.Antlr2Parser
 import org.apache.groovy.parser.Antlr4Parser
 import org.apache.groovy.parser.antlr4.util.ASTComparatorCategory
 import org.apache.groovy.parser.antlr4.util.AstDumper
+import org.codehaus.groovy.antlr.AntlrParserPluginFactory
 import org.codehaus.groovy.ast.*
 import org.codehaus.groovy.ast.stmt.*
 import org.codehaus.groovy.control.CompilerConfiguration
@@ -226,6 +227,10 @@ class TestUtils {
         assert executeScript(path);
     }
 
+    static doRunAndTestWithAntlr2(String path) {
+        assert executeScript(createAntlr2Shell(), "$RESOURCES_PATH/$path")
+    }
+
     static executeScript(String path) {
         executeScript(createAntlr4Shell(), "$RESOURCES_PATH/$path")
     }
@@ -251,5 +256,12 @@ class TestUtils {
         return new GroovyShell(configuration);
     }
 
+    static createAntlr2Shell() {
+        CompilerConfiguration configuration = new CompilerConfiguration(CompilerConfiguration.DEFAULT)
+        configuration.pluginFactory = new AntlrParserPluginFactory()
+
+        return new GroovyShell(configuration);
+    }
+
     public static final List COMMON_IGNORE_CLASS_LIST = Collections.unmodifiableList([AssertStatement, BreakStatement, ConstructorNode, ContinueStatement, ExpressionStatement, FieldNode, ForStatement, GenericsType, IfStatement, MethodNode, PackageNode, Parameter, PropertyNode, ReturnStatement, ThrowStatement, Token, WhileStatement]);
 }

http://git-wip-us.apache.org/repos/asf/groovy/blob/6e30b3fa/subprojects/parser-antlr4/src/test/resources/bugs/BUG-GROOVY-8426.groovy
----------------------------------------------------------------------
diff --git a/subprojects/parser-antlr4/src/test/resources/bugs/BUG-GROOVY-8426.groovy b/subprojects/parser-antlr4/src/test/resources/bugs/BUG-GROOVY-8426.groovy
new file mode 100644
index 0000000..59404a4
--- /dev/null
+++ b/subprojects/parser-antlr4/src/test/resources/bugs/BUG-GROOVY-8426.groovy
@@ -0,0 +1,46 @@
+import org.codehaus.groovy.ast.ClassNode
+import org.codehaus.groovy.ast.MethodNode
+import org.codehaus.groovy.ast.builder.AstBuilder
+import org.codehaus.groovy.ast.stmt.BlockStatement
+import static org.codehaus.groovy.control.CompilePhase.CONVERSION
+
+/*
+ *  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 Groovy8426Test {
+    void testMethodBlockStatement() {
+        def result = new AstBuilder().buildFromString CONVERSION, false, '''
+            def method() {
+                'return value'
+                
+            }
+        '''
+
+        ClassNode classNode = result[1]
+        MethodNode method = classNode.getMethods('method')[0]
+        BlockStatement statement = method.code
+
+        assert statement.lineNumber == 2
+        assert statement.lastLineNumber == 5
+        assert statement.columnNumber == 26
+        assert statement.lastColumnNumber == 14
+    }
+}
+
+new Groovy8426Test().testMethodBlockStatement()