Skip to content

Accept a type annotation on the qualifier of a method reference - #66

Merged
abashev merged 1 commit into
mainfrom
member-reference-type-annotation
Sep 25, 2026
Merged

abashev merged 1 commit into
mainfrom
member-reference-type-annotation

Conversation

@abashev

@abashev abashev commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator

Brings over google/google-java-format#984, a fix from google-java-format 1.19.

The bug

Supplier<List<?>> a = @A ArrayList::new; failed with error: did not generate token "@". The printing of a type annotation on a method reference's qualifier was already in place, but visitMemberReference first synced to the tree's start position, and javac's start position for a member reference leaves out the annotation, so the sync reported the annotation's tokens as never generated.

From upstream, with the author kept

Checked

  • The golden fails on main and passes with the change. Long method references still break at :: exactly as before.
  • ./gradlew :open-java-format:test on JDK 21: 1501 tests, all green.
  • The 15,747 files of the JDK 21 sources format exactly as before.

"Supplier<List<?>> a = @A ArrayList::new;" failed with 'did not
generate token "@"'. The printing of a type annotation on a method
reference's qualifier was already in place, but visitMemberReference
first synced to the tree's start position, and javac's start position
for a member reference leaves out the annotation, so the sync reported
the annotation's tokens as never generated.

This ports google/google-java-format#984 by Liam Miller-Cushon:
visitMemberReference no longer syncs to the start position. The golden
B308157568 comes from upstream, with the expected output in this
project's style.

The 15,747 files of the JDK 21 sources format exactly as before.
@abashev
abashev merged commit 1eb4e5b into main Sep 25, 2026
15 checks passed
@abashev
abashev deleted the member-reference-type-annotation branch September 25, 2026 07:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants