Skip to content

Commit eb181b2

Browse files
committed
Add horizontal whitespace between varargs specifiers and type annotations
e.g. ``` -void f(int @nullable... xs) {} +void f(int @nullable ... xs) {} ``` For consistency with the handling of type annotated arrays. Fixes #282 MOE_MIGRATED_REVID=197644300
1 parent 588b108 commit eb181b2

File tree

5 files changed

+39
-26
lines changed

5 files changed

+39
-26
lines changed

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

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -943,9 +943,7 @@ void visitVariables(
943943
annotationDirection,
944944
Optional.of(fragment.getModifiers()),
945945
fragment.getType(),
946-
VarArgsOrNot.fromVariable(fragment),
947-
/* varargsAnnotations= */ ImmutableList.of(),
948-
fragment.getName(),
946+
/* name= */ fragment.getName(),
949947
"",
950948
"=",
951949
Optional.fromNullable(fragment.getInitializer()),
@@ -1838,9 +1836,7 @@ public Void visitTry(TryTree node, Void unused) {
18381836
fieldAnnotationDirection(variableTree.getModifiers()),
18391837
Optional.of(variableTree.getModifiers()),
18401838
variableTree.getType(),
1841-
VarArgsOrNot.NO,
1842-
/* varargsAnnotations= */ ImmutableList.of(),
1843-
variableTree.getName(),
1839+
/* name= */ variableTree.getName(),
18441840
"",
18451841
"=",
18461842
Optional.fromNullable(variableTree.getInitializer()),
@@ -2283,9 +2279,7 @@ private void visitUnionType(VariableTree declaration) {
22832279
Direction.HORIZONTAL,
22842280
/* modifiers= */ Optional.absent(),
22852281
last,
2286-
VarArgsOrNot.NO,
2287-
/* varargsAnnotations= */ ImmutableList.of(),
2288-
declaration.getName(),
2282+
/* name= */ declaration.getName(),
22892283
/* op= */ "",
22902284
"=",
22912285
Optional.fromNullable(declaration.getInitializer()),
@@ -2329,9 +2323,7 @@ private void visitFormals(
23292323
Direction.HORIZONTAL,
23302324
Optional.of(receiver.get().getModifiers()),
23312325
receiver.get().getType(),
2332-
VarArgsOrNot.NO,
2333-
/* varargsAnnotations= */ ImmutableList.of(),
2334-
receiver.get().getName(),
2326+
/* name= */ receiver.get().getName(),
23352327
"",
23362328
"",
23372329
/* initializer= */ Optional.absent(),
@@ -2520,16 +2512,11 @@ private void visitToDeclare(
25202512
String equals,
25212513
Optional<String> trailing) {
25222514
sync(node);
2523-
boolean varargs = VarArgsOrNot.fromVariable(node).isYes();
2524-
List<? extends AnnotationTree> varargsAnnotations = ImmutableList.of();
2525-
Tree type = node.getType();
25262515
declareOne(
25272516
kind,
25282517
annotationsDirection,
25292518
Optional.of(node.getModifiers()),
2530-
type,
2531-
VarArgsOrNot.valueOf(varargs),
2532-
varargsAnnotations,
2519+
node.getType(),
25332520
node.getName(),
25342521
"",
25352522
equals,
@@ -3183,8 +3170,6 @@ int declareOne(
31833170
Direction annotationsDirection,
31843171
Optional<ModifiersTree> modifiers,
31853172
Tree type,
3186-
VarArgsOrNot isVarargs,
3187-
List<? extends AnnotationTree> varargsAnnotations,
31883173
Name name,
31893174
String op,
31903175
String equals,
@@ -3236,10 +3221,6 @@ int declareOne(
32363221
} else {
32373222
scan(type, null);
32383223
}
3239-
if (isVarargs.isYes()) {
3240-
visitAnnotations(varargsAnnotations, BreakOrNot.YES, BreakOrNot.YES);
3241-
builder.op("...");
3242-
}
32433224
}
32443225
builder.close();
32453226

@@ -3342,6 +3323,15 @@ private void maybeAddDims(
33423323
token("]");
33433324
lastWasAnnotation = false;
33443325
break;
3326+
case ".":
3327+
if (lastWasAnnotation) {
3328+
builder.breakToFill(" ");
3329+
} else {
3330+
builder.breakToFill();
3331+
}
3332+
builder.op("...");
3333+
lastWasAnnotation = false;
3334+
break;
33453335
default:
33463336
return;
33473337
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class B38203081 {
22
void f(int @A []... xs) {}
33

4-
void g(int @A [] @B... xs) {}
4+
void g(int @A [] @B ... xs) {}
55
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
public class ArrayVsVarargs {
2+
3+
void f(String[] arg) {}
4+
void g(String... arg) {}
5+
void h(String @A [] arg) {}
6+
void i(String @B... arg) {}
7+
void j(String @C [] @D [] arg) {}
8+
void k(String @E [] @F... arg) {}
9+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
public class ArrayVsVarargs {
2+
3+
void f(String[] arg) {}
4+
5+
void g(String... arg) {}
6+
7+
void h(String @A [] arg) {}
8+
9+
void i(String @B ... arg) {}
10+
11+
void j(String @C [] @D [] arg) {}
12+
13+
void k(String @E [] @F ... arg) {}
14+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
class I95 {
2-
public void format2(Object @Nullable... a2) {}
2+
public void format2(Object @Nullable ... a2) {}
33
}

0 commit comments

Comments
 (0)