Skip to content

Commit a268700

Browse files
committed
Don't format annotations as block-like constructs
Resolves google#159 MOE_MIGRATED_REVID=191358990
1 parent dac314e commit a268700

File tree

10 files changed

+158
-144
lines changed

10 files changed

+158
-144
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,7 @@ public Void visitAnnotation(AnnotationTree node, Void unused) {
12251225
token("@");
12261226
scan(node.getAnnotationType(), null);
12271227
if (!node.getArguments().isEmpty()) {
1228-
builder.open(plusTwo);
1228+
builder.open(plusFour);
12291229
token("(");
12301230
builder.breakOp();
12311231
boolean first = true;
@@ -1250,9 +1250,8 @@ public Void visitAnnotation(AnnotationTree node, Void unused) {
12501250
}
12511251
first = false;
12521252
}
1253-
builder.breakOp(UNIFIED, "", minusTwo, /* optionalTag= */ Optional.absent());
1253+
token(")");
12541254
builder.close();
1255-
token(")", plusTwo);
12561255
builder.close();
12571256
return null;
12581257

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

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -98,44 +98,40 @@ class Test {
9898
Object var;
9999

100100
@Deprecated(
101-
x = 42,
102-
y = {
103-
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX,
104-
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX,
105-
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX,
106-
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
107-
}
108-
)
101+
x = 42,
102+
y = {
103+
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX,
104+
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX,
105+
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX,
106+
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
107+
})
109108
Object var;
110109

111110
@Deprecated(
112-
y = {
113-
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX,
114-
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX,
115-
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX,
116-
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
117-
}
118-
)
111+
y = {
112+
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX,
113+
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX,
114+
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX,
115+
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
116+
})
119117
Object var;
120118
}
121119

122120
@Frozzle({
123121
@Mirror(in = edu.oswego.cs.dl.util.concurrent.F.class, methods = "foo"),
124122
@Mirror(in = edu.oswego.cs.dl.util.concurrent.F.class, methods = "foo"),
125123
@Mirror(
126-
in = edu.oswego.cs.dl.util.concurrent.F.class,
127-
enable = false,
128-
methods = {
129-
"foo", "foo", "foo", "foo", "foo",
130-
"foo", "foo", "foo", "foo", "foo",
131-
"foo", "foo", "foo", "foo", "foo",
132-
}
133-
),
124+
in = edu.oswego.cs.dl.util.concurrent.F.class,
125+
enable = false,
126+
methods = {
127+
"foo", "foo", "foo", "foo", "foo",
128+
"foo", "foo", "foo", "foo", "foo",
129+
"foo", "foo", "foo", "foo", "foo",
130+
}),
134131
@Mirror(
135-
in = edu.oswego.cs.dl.util.concurrent.F.class,
136-
enable = false,
137-
methods = {"foo", "foo", "foo", "foo", "foo", "foo", "foo", "foo", "foo", "foo", "foo"}
138-
),
132+
in = edu.oswego.cs.dl.util.concurrent.F.class,
133+
enable = false,
134+
methods = {"foo", "foo", "foo", "foo", "foo", "foo", "foo", "foo", "foo", "foo", "foo"}),
139135
@Mirror(in = edu.oswego.cs.dl.util.concurrent.F.class, methods = "foo"),
140136
})
141137
class C {}
Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
@BugPattern(category = GUAVA, severity = NOT_A_PROBLEM, maturity = EXPERIMENTAL)
22
@BugPattern(
3-
name = "AsyncFunctionReturnsImmediate",
4-
summary = SIMPLIFY,
5-
category = GUAVA,
6-
severity = NOT_A_PROBLEM,
7-
maturity = EXPERIMENTAL
8-
)
3+
name = "AsyncFunctionReturnsImmediate",
4+
summary = SIMPLIFY,
5+
category = GUAVA,
6+
severity = NOT_A_PROBLEM,
7+
maturity = EXPERIMENTAL)
98
@BugPattern(
10-
name = "AsyncFunctionReturnsImmediate",
11-
summary = SIMPLIFY,
12-
explanation =
13-
"If an AsyncFunction always returns immediateFuture() and never throws, it can "
14-
+ "be replaced with a Function.",
15-
category = GUAVA,
16-
severity = NOT_A_PROBLEM,
17-
maturity = EXPERIMENTAL
18-
)
9+
name = "AsyncFunctionReturnsImmediate",
10+
summary = SIMPLIFY,
11+
explanation =
12+
"If an AsyncFunction always returns immediateFuture() and never throws, it can "
13+
+ "be replaced with a Function.",
14+
category = GUAVA,
15+
severity = NOT_A_PROBLEM,
16+
maturity = EXPERIMENTAL)
1917
class Test {}

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@ class B21305044 {
1616
List<
1717
? super
1818
@Crazy(
19-
key = value,
20-
other =
21-
@Crazier({
22-
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20
23-
})
24-
)
19+
key = value,
20+
other =
21+
@Crazier({
22+
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20
23+
}))
2524
Object>
2625
c;
2726
}

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

Lines changed: 44 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,56 @@
11
@PluginInfo(
2-
shortName = "chromesuggestions",
3-
owner = "mathp",
4-
demoLink = "unspecified",
5-
modules = {
6-
BackendsModule.class,
7-
CommonBackendsModule.class,
8-
ChromeSuggestionsPlugin.ChromeSuggestionsModule.class
9-
}
10-
)
2+
shortName = "chromesuggestions",
3+
owner = "mathp",
4+
demoLink = "unspecified",
5+
modules = {
6+
BackendsModule.class,
7+
CommonBackendsModule.class,
8+
ChromeSuggestionsPlugin.ChromeSuggestionsModule.class
9+
})
1110
@Module(library = true, complete = false)
1211
@Module(
13-
library = true,
14-
complete = false,
15-
injects = {ClassInfoTracker.class, JslayoutMetaProto.class}
16-
)
12+
library = true,
13+
complete = false,
14+
injects = {ClassInfoTracker.class, JslayoutMetaProto.class})
1715
@Module(
18-
library = true,
19-
complete = false,
20-
injects = {
21-
ClassInfoTracker.class,
22-
JslayoutMetaProto.class,
23-
JslayoutMetaProto.class,
24-
JslayoutMeta.class
25-
}
26-
)
16+
library = true,
17+
complete = false,
18+
injects = {
19+
ClassInfoTracker.class,
20+
JslayoutMetaProto.class,
21+
JslayoutMetaProto.class,
22+
JslayoutMeta.class
23+
})
2724
@Module(
28-
library = true,
29-
complete = false,
30-
injects = {
31-
ClassInfoTracker.class,
32-
JslayoutMetaProto.class,
33-
JslayoutMetaProto.class,
34-
JslayoutMeta.class,
35-
JslayoutMeta.class
36-
}
37-
)
25+
library = true,
26+
complete = false,
27+
injects = {
28+
ClassInfoTracker.class,
29+
JslayoutMetaProto.class,
30+
JslayoutMetaProto.class,
31+
JslayoutMeta.class,
32+
JslayoutMeta.class
33+
})
3834
@Module(
39-
injects = {One.class, Two.class},
40-
includes = {Three.class, Four.class}
41-
)
35+
injects = {One.class, Two.class},
36+
includes = {Three.class, Four.class})
4237
@Module(
43-
library = true,
44-
complete = false,
45-
numbers = {1, 2, 3}
46-
)
38+
library = true,
39+
complete = false,
40+
numbers = {1, 2, 3})
4741
@Module(
48-
library = true,
49-
complete = false,
50-
numbers = {
51-
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26
52-
}
53-
)
42+
library = true,
43+
complete = false,
44+
numbers = {
45+
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26
46+
})
5447
@Module(
55-
library = true,
56-
complete = false,
57-
numbers = {
58-
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
59-
27, 28, 29, 30
60-
}
61-
)
48+
library = true,
49+
complete = false,
50+
numbers = {
51+
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
52+
27, 28, 29, 30
53+
})
6254
@Module({ClassInfoTracker.class, JslayoutMetaProto.class, JslayoutMetaProto.class})
6355
@Module({
6456
ClassInfoTracker.class,
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
class B22848286 {
22

33
@FxxxSxxx(
4-
xxxx = "xxxxxx_xxxxxxx_xxxxxxxxx_xxxx",
5-
xxxx = "Xxxxx xxxx xx xxxxxx xxxxxxx xxxxxxxxx."
6-
)
4+
xxxx = "xxxxxx_xxxxxxx_xxxxxxxxx_xxxx",
5+
xxxx = "Xxxxx xxxx xx xxxxxx xxxxxxx xxxxxxxxx.")
76
int x;
87

98
@FxxxGxxxxxxxx(
10-
xxxx = "Xxx xxxxxx xxxxxxxxy xxx xxx xxxxxxxxx, x.x. xxx xxxxxx xxxxxxxx xxxxxxxxy"
11-
)
9+
xxxx = "Xxx xxxxxx xxxxxxxxy xxx xxx xxxxxxxxx, x.x. xxx xxxxxx xxxxxxxx xxxxxxxxy")
1210
int y;
1311
}
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
class B30764810 {
22
@Foo(
3-
x = {0},
4-
y = 0
5-
// comment
6-
)
3+
x = {0},
4+
y = 0
5+
// comment
6+
)
77
int a;
88

99
@Foo(
10-
x = {0},
11-
y = 0
12-
/* comment
13-
*/
14-
)
10+
x = {0},
11+
y = 0
12+
/* comment
13+
*/
14+
)
1515
int b;
1616
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@BugPattern(
2+
name = "AsyncFunctionReturnsImmediate",
3+
summary = SIMPLIFY,
4+
category = GUAVA,
5+
severity = NOT_A_PROBLEM,
6+
maturity = EXPERIMENTAL
7+
)
8+
@BugPattern(
9+
name = "AsyncFunctionReturnsImmediate",
10+
summary = SIMPLIFY,
11+
explanation =
12+
"If an AsyncFunction always returns immediateFuture() and never throws, it can "
13+
+ "be replaced with a Function.",
14+
category = GUAVA,
15+
severity = NOT_A_PROBLEM,
16+
maturity = EXPERIMENTAL)
17+
class Test {}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
@BugPattern(
2+
name = "AsyncFunctionReturnsImmediate",
3+
summary = SIMPLIFY,
4+
category = GUAVA,
5+
severity = NOT_A_PROBLEM,
6+
maturity = EXPERIMENTAL)
7+
@BugPattern(
8+
name = "AsyncFunctionReturnsImmediate",
9+
summary = SIMPLIFY,
10+
explanation =
11+
"If an AsyncFunction always returns immediateFuture() and never throws, it can "
12+
+ "be replaced with a Function.",
13+
category = GUAVA,
14+
severity = NOT_A_PROBLEM,
15+
maturity = EXPERIMENTAL)
16+
class Test {}

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

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,32 @@ package com.google.googlejavaformat.java.test;
33
/** Tests for NameQualifiedTypes, Names, NormalAnnotations, NullLiterals, and NumberLiterals. */
44
class N {
55
@NormalAnnotation(
6-
a = 1,
7-
b = 2,
8-
c = 3,
9-
d = 4,
10-
e = 5,
11-
f = 6,
12-
g = 7,
13-
h = 8,
14-
i = 9,
15-
j = 10,
16-
k = 11,
17-
l = 12,
18-
m = 13,
19-
n = 14,
20-
o = 15,
21-
p = 16,
22-
q = 17,
23-
r = 18,
24-
s = 19,
25-
t = 20,
26-
u = 21,
27-
v = 22,
28-
w = 23,
29-
x = 24,
30-
y = 25,
31-
z = 26
32-
)
6+
a = 1,
7+
b = 2,
8+
c = 3,
9+
d = 4,
10+
e = 5,
11+
f = 6,
12+
g = 7,
13+
h = 8,
14+
i = 9,
15+
j = 10,
16+
k = 11,
17+
l = 12,
18+
m = 13,
19+
n = 14,
20+
o = 15,
21+
p = 16,
22+
q = 17,
23+
r = 18,
24+
s = 19,
25+
t = 20,
26+
u = 21,
27+
v = 22,
28+
w = 23,
29+
x = 24,
30+
y = 25,
31+
z = 26)
3332
void f() {
3433
assert 00 == 0 && 0x0 == 0 && 1.0e0f == 1.00e0f && 0.2D == .2D;
3534
java.lang./* @MarkerAnnotation */ String s = null;

0 commit comments

Comments
 (0)