This commit is contained in:
Clément Fournier
2019-12-16 09:28:05 +01:00
parent 99cc1afd1b
commit 0d0a45c7ac
3 changed files with 27 additions and 11 deletions

View File

@ -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 <iostream>\n" + "#include <string>\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());
}

View File

@ -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;

View File

@ -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());
}