Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiline tokens in GJF-core #1091

Merged
merged 1 commit into from
Apr 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions core/src/main/java/com/google/googlejavaformat/Doc.java
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,10 @@ boolean isReal() {
private final Indent plusIndentCommentsBefore;
private final Optional<Indent> breakAndIndentTrailingComment;

private Input.Tok tok() {
return token.getTok();
}

private Token(
Input.Token token,
RealOrImaginary realOrImaginary,
Expand Down Expand Up @@ -465,7 +469,8 @@ public void add(DocBuilder builder) {

@Override
int computeWidth() {
return token.getTok().length();
int idx = Newlines.firstBreak(tok().getOriginalText());
return (idx >= 0) ? MAX_LINE_WIDTH : tok().length();
}

@Override
Expand All @@ -480,8 +485,7 @@ Range<Integer> computeRange() {

@Override
public State computeBreaks(CommentsHelper commentsHelper, int maxWidth, State state) {
String text = token.getTok().getOriginalText();
return state.withColumn(state.column + text.length());
return state.withColumn(state.column + computeWidth());
}

@Override
Expand Down