Skip to content

Commit

Permalink
Fix handling of type-annotated varargs
Browse files Browse the repository at this point in the history
MOE_MIGRATED_REVID=197703737
  • Loading branch information
ingop authored and cushon committed May 24, 2018
1 parent eb181b2 commit 5174180
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
10 changes: 8 additions & 2 deletions core/src/main/java/com/google/googlejavaformat/OpsBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,15 @@ public final void close() {

/** Return the text of the next {@link Input.Token}, or absent if there is none. */
public final Optional<String> peekToken() {
return peekToken(0);
}

/** Return the text of an upcoming {@link Input.Token}, or absent if there is none. */
public final Optional<String> peekToken(int skip) {
ImmutableList<? extends Input.Token> tokens = input.getTokens();
return tokenI < tokens.size()
? Optional.of(tokens.get(tokenI).getTok().getOriginalText())
int idx = tokenI + skip;
return idx < tokens.size()
? Optional.of(tokens.get(idx).getTok().getOriginalText())
: Optional.absent();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3324,6 +3324,9 @@ private void maybeAddDims(
lastWasAnnotation = false;
break;
case ".":
if (!builder.peekToken().get().equals(".") || !builder.peekToken(1).get().equals(".")) {
return;
}
if (lastWasAnnotation) {
builder.breakToFill(" ");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ public class ArrayVsVarargs {
void i(String @B... arg) {}
void j(String @C [] @D [] arg) {}
void k(String @E [] @F... arg) {}

Class<?> c = byte[].class;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ public class ArrayVsVarargs {
void j(String @C [] @D [] arg) {}

void k(String @E [] @F ... arg) {}

Class<?> c = byte[].class;
}

0 comments on commit 5174180

Please sign in to comment.