Skip to content

Commit 5174180

Browse files
ingopcushon
authored andcommitted
Fix handling of type-annotated varargs
MOE_MIGRATED_REVID=197703737
1 parent eb181b2 commit 5174180

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

core/src/main/java/com/google/googlejavaformat/OpsBuilder.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,15 @@ public final void close() {
266266

267267
/** Return the text of the next {@link Input.Token}, or absent if there is none. */
268268
public final Optional<String> peekToken() {
269+
return peekToken(0);
270+
}
271+
272+
/** Return the text of an upcoming {@link Input.Token}, or absent if there is none. */
273+
public final Optional<String> peekToken(int skip) {
269274
ImmutableList<? extends Input.Token> tokens = input.getTokens();
270-
return tokenI < tokens.size()
271-
? Optional.of(tokens.get(tokenI).getTok().getOriginalText())
275+
int idx = tokenI + skip;
276+
return idx < tokens.size()
277+
? Optional.of(tokens.get(idx).getTok().getOriginalText())
272278
: Optional.absent();
273279
}
274280

core/src/main/java/com/google/googlejavaformat/java/JavaInputAstVisitor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3324,6 +3324,9 @@ private void maybeAddDims(
33243324
lastWasAnnotation = false;
33253325
break;
33263326
case ".":
3327+
if (!builder.peekToken().get().equals(".") || !builder.peekToken(1).get().equals(".")) {
3328+
return;
3329+
}
33273330
if (lastWasAnnotation) {
33283331
builder.breakToFill(" ");
33293332
} else {

core/src/test/resources/com/google/googlejavaformat/java/testdata/i282.input

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ public class ArrayVsVarargs {
66
void i(String @B... arg) {}
77
void j(String @C [] @D [] arg) {}
88
void k(String @E [] @F... arg) {}
9+
10+
Class<?> c = byte[].class;
911
}

core/src/test/resources/com/google/googlejavaformat/java/testdata/i282.output

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ public class ArrayVsVarargs {
1111
void j(String @C [] @D [] arg) {}
1212

1313
void k(String @E [] @F ... arg) {}
14+
15+
Class<?> c = byte[].class;
1416
}

0 commit comments

Comments
 (0)