Skip to content

Commit 53390d9

Browse files
cushongoogle-java-format Team
authored andcommitted
Handle type annotations on method reference qualifiers
e.g. ``` Supplier<List<?>> a = @A(0x45) ArrayList::new; Supplier<List<?>> b = @A(0x46) ImmutableList::of; ``` The necessary logic is already there, but the start position information for the method reference doesn't include the leading type annotations, which was resulting in an assertion to fail. PiperOrigin-RevId: 577850593
1 parent 295e7a4 commit 53390d9

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,6 @@ public boolean visitEnumDeclaration(ClassTree node) {
930930

931931
@Override
932932
public Void visitMemberReference(MemberReferenceTree node, Void unused) {
933-
sync(node);
934933
builder.open(plusFour);
935934
scan(node.getQualifierExpression(), null);
936935
builder.breakOp();
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class C {
2+
@A(0x14)
3+
int f(Object o) {
4+
@A(0x40)
5+
int local;
6+
try (@A(0x41)
7+
JarFile jarFile = new JarFile("hello.jar")) {
8+
} catch (
9+
@A(0x42)
10+
IOException e) {
11+
}
12+
if (o instanceof @A(0x43) String) {}
13+
new @A(0x44) ArrayList<>();
14+
Supplier<List<?>> a = @A(0x45) ArrayList::new;
15+
Supplier<List<?>> b = @A(0x46) ImmutableList::of;
16+
String s = (@A(0x47) String) o;
17+
List<?> xs = new ArrayList<@A(0x48) String>();
18+
xs = ImmutableList.<@A(0x49) String>of();
19+
Supplier<List<?>> c = ArrayList<@A(0x4A) String>::new;
20+
Supplier<List<?>> d = ImmutableList::<@A(0x4B) String>of;
21+
return 0;
22+
}
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class C {
2+
@A(0x14)
3+
int f(Object o) {
4+
@A(0x40)
5+
int local;
6+
try (@A(0x41)
7+
JarFile jarFile = new JarFile("hello.jar")) {
8+
} catch (
9+
@A(0x42)
10+
IOException e) {
11+
}
12+
if (o instanceof @A(0x43) String) {}
13+
new @A(0x44) ArrayList<>();
14+
Supplier<List<?>> a = @A(0x45) ArrayList::new;
15+
Supplier<List<?>> b = @A(0x46) ImmutableList::of;
16+
String s = (@A(0x47) String) o;
17+
List<?> xs = new ArrayList<@A(0x48) String>();
18+
xs = ImmutableList.<@A(0x49) String>of();
19+
Supplier<List<?>> c = ArrayList<@A(0x4A) String>::new;
20+
Supplier<List<?>> d = ImmutableList::<@A(0x4B) String>of;
21+
return 0;
22+
}
23+
}

0 commit comments

Comments
 (0)