Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
alingse committed Dec 5, 2024
1 parent 053944e commit 8a786f9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/src/main/java/thriftlabs/thriftfmt/FormatterUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

public final class FormatterUtil {
public static final int FAKE_NODE_LINE_NO = -1;
public static final int FAKE_TOKEN_INDEX = -1; // 用于 token

public static boolean isToken(ParseTree node, String text) {
return node instanceof TerminalNode && ((TerminalNode) node).getSymbol().getText().equals(text);
Expand All @@ -37,7 +38,7 @@ public static TerminalNode createFakeNode(int type, String text) {
CommonToken fakeToken = new CommonToken(type, text);
fakeToken.setLine(FAKE_NODE_LINE_NO);
fakeToken.setCharPositionInLine(FAKE_NODE_LINE_NO);
fakeToken.setTokenIndex(-1);
fakeToken.setTokenIndex(FAKE_TOKEN_INDEX);
return new TerminalNodeImpl(fakeToken);
}

Expand Down
6 changes: 3 additions & 3 deletions lib/src/main/java/thriftlabs/thriftfmt/ThriftFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,11 @@ protected String getCurrentLine() {
return "";
}

int lastNewLineIndex = this.out.lastIndexOf("\n");
if (lastNewLineIndex == -1) {
int index = this.out.lastIndexOf("\n");
if (index == -1) {
return this.out;
}
return this.out.substring(lastNewLineIndex + 1);
return this.out.substring(index + 1);
}

private void addTailComment() {
Expand Down

0 comments on commit 8a786f9

Please sign in to comment.