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 02:43:27 UTC
groovy git commit: GROOVY-8426 Fix line and column numbers assigned
to BlockStatements generated out of method definitions(closes #650)
Repository: groovy
Updated Branches:
refs/heads/GROOVY_2_5_X 8c914e67e -> 7e6511107
GROOVY-8426 Fix line and column numbers assigned to BlockStatements generated out of method definitions(closes #650)
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/7e651110
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/7e651110
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/7e651110
Branch: refs/heads/GROOVY_2_5_X
Commit: 7e651110712a04fa3cdef0c89aaf257e155e8b74
Parents: 8c914e6
Author: Marcin Erdmann <er...@gmail.com>
Authored: Thu Dec 28 11:19:56 2017 +0000
Committer: sunlan <su...@apache.org>
Committed: Sun Dec 31 10:42:56 2017 +0800
----------------------------------------------------------------------
.../groovy/antlr/AntlrParserPlugin.java | 13 ++++++++++---
.../groovy/antlr/AntlrParserPluginTest.groovy | 20 ++++++++++++++++++++
2 files changed, 30 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/7e651110/src/main/java/org/codehaus/groovy/antlr/AntlrParserPlugin.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/antlr/AntlrParserPlugin.java b/src/main/java/org/codehaus/groovy/antlr/AntlrParserPlugin.java
index 37a105f..2af9882 100644
--- a/src/main/java/org/codehaus/groovy/antlr/AntlrParserPlugin.java
+++ b/src/main/java/org/codehaus/groovy/antlr/AntlrParserPlugin.java
@@ -1414,18 +1414,25 @@ public class AntlrParserPlugin extends ASTHelper implements ParserPlugin, Groovy
}
protected Statement statementList(AST code) {
- return statementListNoChild(code.getFirstChild(), code);
+ BlockStatement block = siblingsToBlockStatement(code.getFirstChild());
+ configureAST(block, code);
+ return block;
}
protected Statement statementListNoChild(AST node, AST alternativeConfigureNode) {
- BlockStatement block = new BlockStatement();
+ BlockStatement block = siblingsToBlockStatement(node);
// alternativeConfigureNode is used only to set the source position
if (node != null) {
configureAST(block, node);
} else {
configureAST(block, alternativeConfigureNode);
}
- for (; node != null; node = node.getNextSibling()) {
+ return block;
+ }
+
+ private BlockStatement siblingsToBlockStatement(AST firstSiblingNode) {
+ BlockStatement block = new BlockStatement();
+ for (AST node = firstSiblingNode; node != null; node = node.getNextSibling()) {
block.addStatement(statement(node));
}
return block;
http://git-wip-us.apache.org/repos/asf/groovy/blob/7e651110/src/test/org/codehaus/groovy/antlr/AntlrParserPluginTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/antlr/AntlrParserPluginTest.groovy b/src/test/org/codehaus/groovy/antlr/AntlrParserPluginTest.groovy
index 2ecc9a7..98bd59d 100644
--- a/src/test/org/codehaus/groovy/antlr/AntlrParserPluginTest.groovy
+++ b/src/test/org/codehaus/groovy/antlr/AntlrParserPluginTest.groovy
@@ -19,6 +19,7 @@
package org.codehaus.groovy.antlr
import org.codehaus.groovy.ast.builder.AstBuilder
+import org.codehaus.groovy.ast.stmt.BlockStatement
import org.codehaus.groovy.ast.stmt.Statement
import org.codehaus.groovy.ast.*
import static org.codehaus.groovy.control.CompilePhase.CONVERSION
@@ -76,4 +77,23 @@ class AntlrParserPluginTest extends GroovyTestCase {
assert statement.lastColumnNumber == 34
assert statement.statementLabel == 'label'
}
+
+ 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
+ }
+
}