diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTExpressionStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTExpressionStatement.java index ceb6f59c40..43be0a3ad7 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTExpressionStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTExpressionStatement.java @@ -15,4 +15,27 @@ public class ASTExpressionStatement extends AbstractApexNode -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; + } } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexParser.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexParser.java index b71f438e12..f5a268f3a8 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexParser.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexParser.java @@ -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(); diff --git a/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/ast/ApexParserTest.java b/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/ast/ApexParserTest.java index 1e4498b82f..f6afa580bc 100644 --- a/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/ast/ApexParserTest.java +++ b/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/ast/ApexParserTest.java @@ -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) {