Skip to content

Commit

Permalink
Handle type annotations on method reference qualifiers
Browse files Browse the repository at this point in the history
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: 577228869
  • Loading branch information
cushon authored and google-java-format Team committed Oct 30, 2023
1 parent 295e7a4 commit 6295f5d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,6 @@ public boolean visitEnumDeclaration(ClassTree node) {

@Override
public Void visitMemberReference(MemberReferenceTree node, Void unused) {
sync(node);
builder.open(plusFour);
scan(node.getQualifierExpression(), null);
builder.breakOp();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class C {
@A(0x14)
int f(Object o) {
@A(0x40)
int local;
try (@A(0x41)
JarFile jarFile = new JarFile("hello.jar")) {
} catch (
@A(0x42)
IOException e) {
}
if (o instanceof @A(0x43) String) {}
new @A(0x44) ArrayList<>();
Supplier<List<?>> a = @A(0x45) ArrayList::new;
Supplier<List<?>> b = @A(0x46) ImmutableList::of;
String s = (@A(0x47) String) o;
List<?> xs = new ArrayList<@A(0x48) String>();
xs = ImmutableList.<@A(0x49) String>of();
Supplier<List<?>> c = ArrayList<@A(0x4A) String>::new;
Supplier<List<?>> d = ImmutableList::<@A(0x4B) String>of;
return 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class C {
@A(0x14)
int f(Object o) {
@A(0x40)
int local;
try (@A(0x41)
JarFile jarFile = new JarFile("hello.jar")) {
} catch (
@A(0x42)
IOException e) {
}
if (o instanceof @A(0x43) String) {}
new @A(0x44) ArrayList<>();
Supplier<List<?>> a = @A(0x45) ArrayList::new;
Supplier<List<?>> b = @A(0x46) ImmutableList::of;
String s = (@A(0x47) String) o;
List<?> xs = new ArrayList<@A(0x48) String>();
xs = ImmutableList.<@A(0x49) String>of();
Supplier<List<?>> c = ArrayList<@A(0x4A) String>::new;
Supplier<List<?>> d = ImmutableList::<@A(0x4B) String>of;
return 0;
}
}

0 comments on commit 6295f5d

Please sign in to comment.