diff --git a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/AbstractEcmascriptNode.java b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/AbstractEcmascriptNode.java index c7832b567d..748dff098d 100644 --- a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/AbstractEcmascriptNode.java +++ b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/AbstractEcmascriptNode.java @@ -7,7 +7,6 @@ package net.sourceforge.pmd.lang.ecmascript.ast; import org.mozilla.javascript.ast.AstNode; import net.sourceforge.pmd.lang.ast.AstVisitor; -import net.sourceforge.pmd.lang.ast.SourceCodePositioner; import net.sourceforge.pmd.lang.ast.impl.AbstractNode; import net.sourceforge.pmd.util.document.FileLocation; import net.sourceforge.pmd.util.document.TextDocument; @@ -18,6 +17,7 @@ abstract class AbstractEcmascriptNode extends AbstractNode extends AbstractNode EcmascriptNode build(T astNode) { EcmascriptNode node = buildInternal(astNode); - calculateLineNumbers(node); + calculateLineNumbers(node, astNode.getAbsolutePosition()); // Set all the trailing comma nodes for (AbstractEcmascriptNode trailingCommaNode : parseProblemToNode.values()) { @@ -231,7 +231,7 @@ final class EcmascriptTreeBuilder implements NodeVisitor { if (trailingCommaLocalizedMessage.equals(parseProblem.getMessage())) { // Report on the shortest code block containing the // problem (i.e. inner most code in nested structures). - AbstractEcmascriptNode currentNode = (AbstractEcmascriptNode) parseProblemToNode.get(parseProblem); + AbstractEcmascriptNode currentNode = parseProblemToNode.get(parseProblem); if (currentNode == null || node.node.getLength() < currentNode.node.getLength()) { parseProblemToNode.put(parseProblem, node); } @@ -241,7 +241,11 @@ final class EcmascriptTreeBuilder implements NodeVisitor { } } - private void calculateLineNumbers(EcmascriptNode node) { - node.descendantsOrSelf().forEach(n -> ((AbstractEcmascriptNode) n).calculateLineNumbers(textDocument)); + private void calculateLineNumbers(EcmascriptNode node, int parentAbsPos) { + int absPos = ((AbstractEcmascriptNode) node).calculateAbsolutePos(textDocument, parentAbsPos); + + for (EcmascriptNode child : node.children()) { + ((AbstractEcmascriptNode) child).calculateAbsolutePos(textDocument, absPos); + } } }