Skip to content

Commit

Permalink
enhance test coverage for Token class
Browse files Browse the repository at this point in the history
  • Loading branch information
jmgrassau committed Nov 13, 2023
1 parent bf3e0af commit 9914319
Show file tree
Hide file tree
Showing 3 changed files with 312 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ public class PadResourceResolver implements IPadFileResolver {
// only to differentiate keywords from identifiers.
//
// To update the resource to the latest ABAP grammar,
// - download the grammar file, e.g. from https://ldcier1.wdf.sap.corp:44300/sap/bc/adt/abapsource/parsers/rnd/grammar
// (if required, adjust system ID '...er1' in this link)
// - download the current grammar file
// - update \com.sap.adt.abapcleaner\resources\grammar.txt from that file (keeping the name), and
// - adjust the release number returned by getRelease() below

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ public final Token insertRightSibling(Token newToken, boolean moveFollowingLines
// ensure newToken is not placed behind a comment
if (isComment() && newToken.lineBreaks == 0) {
if (next == null) {
newToken.setWhitespace(1, parentCommand.getIndent() + ABAP.INDENT_STEP);
throw new IntegrityBrokenException(this, "cannot insert a right sibling after the final comment in a command");
} else {
newToken.copyWhitespaceFrom(next);
if (newToken.isComment()) {
Expand Down Expand Up @@ -1089,7 +1089,7 @@ public final void insertRightSibling(Term newTerm, boolean moveFollowingLinesRig
// ensure newTerm is not placed behind a comment
if (isComment() && newTerm.firstToken.lineBreaks == 0) {
if (next == null) {
newTerm.firstToken.setWhitespace(1, parentCommand.getIndent() + ABAP.INDENT_STEP);
throw new IntegrityBrokenException(this, "cannot insert a right sibling after the final comment in a command");
} else {
newTerm.firstToken.copyWhitespaceFrom(next);
if (newTerm.lastToken.isComment()) {
Expand Down Expand Up @@ -1132,7 +1132,7 @@ public final void insertRightSibling(Term newTerm, boolean moveFollowingLinesRig
newTerm.getPrev().next = newTerm.firstToken;

if (moveFollowingLinesRight)
parentCommand.addIndent(newTerm.firstToken.spacesLeft + newTermWidth, oldStartIndex);
parentCommand.addIndent(newTerm.firstToken.spacesLeft + newTermWidth, oldStartIndex, newTerm.lastToken, null);

parentCommand.onTermInserted(newTerm);
parentCommand.testReferentialIntegrity(true);
Expand Down Expand Up @@ -1319,7 +1319,7 @@ final ColorType getMainColorType() {
}
}

private final boolean isDeclarationKeyword() {
public final boolean isDeclarationKeyword() {
if (!isKeyword())
return false;

Expand Down Expand Up @@ -1452,6 +1452,8 @@ public final int getMaxIndexInLine(Token endToken) {
}

public final int getLineInCommand() {
if (this == parentCommand.firstToken)
return 0;
Token token = parentCommand.firstToken.next;
int line = 0; // (token.lineBreaks == 0) ? 0 : -1;
while (token != null && token != this) {
Expand Down Expand Up @@ -1603,14 +1605,14 @@ public final Token getNextTokenOfTypes(TokenType... tokenTypes) {
}

public final Token getNextSiblingOfType(TokenType tokenType) {
Token result = next;
Token result = nextSibling;
while (result != null && result.type != tokenType)
result = result.nextSibling;
return result;
}

public final Token getNextSiblingOfTypeAndText(TokenType tokenType, String... texts) {
Token result = next;
Token result = nextSibling;
while (result != null) {
if (result.type == tokenType && result.textEqualsAny(texts)) {
return result;
Expand All @@ -1628,7 +1630,7 @@ public final Token getPrevTokenOfType(TokenType tokenType) {
}

public final Token getPrevSiblingOfType(TokenType tokenType) {
Token result = prev;
Token result = prevSibling;
while (result != null && result.type != tokenType)
result = result.prevSibling;
return result;
Expand Down
Loading

0 comments on commit 9914319

Please sign in to comment.