[apex] Fix line/column numbering
This commit is contained in:
@ -15,4 +15,27 @@ public class ASTExpressionStatement extends AbstractApexNode<ExpressionStatement
|
||||
public Object jjtAccept(ApexParserVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
|
||||
private int beginColumnDiff = -1;
|
||||
|
||||
@Override
|
||||
public int getBeginColumn() {
|
||||
if (beginColumnDiff > -1) {
|
||||
return super.getBeginColumn() - beginColumnDiff;
|
||||
}
|
||||
|
||||
if (jjtGetNumChildren() > 0 && jjtGetChild(0) instanceof ASTMethodCallExpression) {
|
||||
ASTMethodCallExpression methodCallExpression = (ASTMethodCallExpression) jjtGetChild(0);
|
||||
|
||||
int fullLength = methodCallExpression.getFullMethodName().length();
|
||||
int nameLength = methodCallExpression.getMethodName().length();
|
||||
if (fullLength > nameLength) {
|
||||
beginColumnDiff = fullLength - nameLength;
|
||||
} else {
|
||||
beginColumnDiff = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return super.getBeginColumn() - beginColumnDiff;
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ import net.sourceforge.pmd.lang.apex.ApexJorjeLogging;
|
||||
import net.sourceforge.pmd.lang.apex.ApexParserOptions;
|
||||
import net.sourceforge.pmd.lang.ast.ParseException;
|
||||
|
||||
import apex.jorje.data.Locations;
|
||||
import apex.jorje.semantic.ast.compilation.Compilation;
|
||||
import apex.jorje.semantic.ast.compilation.UserClass;
|
||||
import apex.jorje.semantic.ast.compilation.UserEnum;
|
||||
@ -41,6 +42,7 @@ public class ApexParser {
|
||||
public Compilation parseApex(final String sourceCode) throws ParseException {
|
||||
|
||||
TopLevelVisitor visitor = new TopLevelVisitor();
|
||||
Locations.useIndexFactory();
|
||||
CompilerService.INSTANCE.visitAstFromString(sourceCode, visitor);
|
||||
|
||||
Compilation astRoot = visitor.getTopLevel();
|
||||
|
@ -6,6 +6,7 @@ package net.sourceforge.pmd.lang.apex.ast;
|
||||
|
||||
import static net.sourceforge.pmd.lang.apex.ast.ApexParserTestHelpers.parse;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
@ -76,6 +77,7 @@ public class ApexParserTest {
|
||||
|
||||
// BlockStatement - the whole method body
|
||||
Node blockStatement = method1.jjtGetChild(1);
|
||||
assertTrue(((ASTBlockStatement) blockStatement).hasCurlyBrace());
|
||||
assertPosition(blockStatement, 2, 27, 5, 5);
|
||||
|
||||
// the expression ("System.out...")
|
||||
@ -130,7 +132,7 @@ public class ApexParserTest {
|
||||
Assert.assertNotNull(rootNode);
|
||||
|
||||
int count = visitPosition(rootNode, 0);
|
||||
Assert.assertEquals(489, count);
|
||||
Assert.assertEquals(427, count);
|
||||
}
|
||||
|
||||
private int visitPosition(Node node, int count) {
|
||||
|
Reference in New Issue
Block a user