Skip to content

Commit 1eb4e5b

Browse files
authored
Merge pull request #66 from openjavaformat/member-reference-type-annotation
Accept a type annotation on the qualifier of a method reference
2 parents 30fa1cc + af4b138 commit 1eb4e5b

3 files changed

Lines changed: 48 additions & 1 deletion

File tree

‎open-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,8 @@ public boolean visitEnumDeclaration(ClassTree node) {
928928

929929
@Override
930930
public Void visitMemberReference(MemberReferenceTree node, Void unused) {
931-
sync(node);
931+
// No sync(node): javac's start position for a member reference leaves out a type annotation on its
932+
// qualifier ("@A ArrayList::new"), so syncing to it would report the annotation as never generated.
932933
builder.open(OpenOp.builder()
933934
.plusIndent(plusFour)
934935
.debugName("methodReference")
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)