From 0d0a45c7ac8d18ec1702ab1c7da82f70e851baf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Mon, 16 Dec 2019 09:28:05 +0100 Subject: [PATCH] Cleanup --- .../sourceforge/pmd/cpd/CPPTokenizerTest.java | 4 +-- .../pmd/lang/java/ast/ASTExpression.java | 2 +- .../pmd/lang/java/ast/AbstractJavaNode.java | 32 ++++++++++++++----- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/pmd-cpp/src/test/java/net/sourceforge/pmd/cpd/CPPTokenizerTest.java b/pmd-cpp/src/test/java/net/sourceforge/pmd/cpd/CPPTokenizerTest.java index 21a224367a..c8caeb354e 100644 --- a/pmd-cpp/src/test/java/net/sourceforge/pmd/cpd/CPPTokenizerTest.java +++ b/pmd-cpp/src/test/java/net/sourceforge/pmd/cpd/CPPTokenizerTest.java @@ -41,7 +41,7 @@ public class CPPTokenizerTest { assertNotSame(TokenEntry.getEOF(), tokens.getTokens().get(0)); assertEquals(24, tokens.size()); } - + @Test public void testIgnoreBetweenSpecialComments() { String code = "#include \n" + "#include \n" + "\n" + "// CPD-OFF\n" @@ -155,7 +155,7 @@ public class CPPTokenizerTest { tokenizer.setProperties(properties); expectedException.expect(TokenMgrError.class); - expectedException.expectMessage("Lexical error in file issue-1559.cpp"); + expectedException.expectMessage("Lexical error in file issue-1559.cpp at"); tokenizer.tokenize(code, new Tokens()); } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTExpression.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTExpression.java index 201140bae9..f8ba6c0b57 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTExpression.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTExpression.java @@ -80,7 +80,7 @@ public interface ASTExpression extends JavaNode, TypeNode, ASTMemberValue { /** * Returns the constant value of this expression, if this is a constant expression. * Otherwise, or if some references couldn't be resolved, returns null. - * TODO implement that + * TODO implement that on other types */ default @Nullable Object getConstValue() { return null; diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AbstractJavaNode.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AbstractJavaNode.java index 4bb2ab6cce..3d90298a70 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AbstractJavaNode.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AbstractJavaNode.java @@ -31,6 +31,25 @@ abstract class AbstractJavaNode extends AbstractNode implements JavaNode { this.parser = parser; } + @Override + public int getBeginLine() { + return jjtGetFirstToken().getBeginLine(); + } + + @Override + public int getBeginColumn() { + return jjtGetFirstToken().getBeginColumn(); + } + + @Override + public int getEndLine() { + return jjtGetLastToken().getEndLine(); + } + + @Override + public int getEndColumn() { + return jjtGetLastToken().getEndColumn(); + } @Override public void jjtClose() { @@ -235,22 +254,19 @@ abstract class AbstractJavaNode extends AbstractNode implements JavaNode { */ void shiftTokens(int leftShift, int rightShift) { if (leftShift != 0) { - jjtSetFirstToken(findTokenSiblingInThisNode(this.jjtGetFirstToken(), leftShift)); + jjtSetFirstToken(findTokenSiblingInThisNode(jjtGetFirstToken(), leftShift)); } if (rightShift != 0) { - jjtSetLastToken(findTokenSiblingInThisNode(this.jjtGetLastToken(), rightShift)); + jjtSetLastToken(findTokenSiblingInThisNode(jjtGetLastToken(), rightShift)); } } - // these make the setter visible to the parser - private JavaccToken findTokenSiblingInThisNode(JavaccToken token, int shift) { - assert token != null : "Null token"; if (shift == 0) { return token; } else if (shift < 0) { // expects a positive shift - return TokenUtils.nthPrevious(this.jjtGetFirstToken(), token, -shift); + return TokenUtils.nthPrevious(jjtGetFirstToken(), token, -shift); } else { return TokenUtils.nthFollower(token, shift); } @@ -258,8 +274,8 @@ abstract class AbstractJavaNode extends AbstractNode implements JavaNode { void copyTextCoordinates(AbstractJavaNode copy) { - this.jjtSetFirstToken(copy.jjtGetFirstToken()); - this.jjtSetLastToken(copy.jjtGetLastToken()); + jjtSetFirstToken(copy.jjtGetFirstToken()); + jjtSetLastToken(copy.jjtGetLastToken()); }