Handle `final var` lambda variables The start position of `final` variable is apparently after the token for `final`, this works around that by inlining a call to `visitVariable` and dropping the `sync` call that asserts the start position of the current node matches the next token. Fixes https://github.com/google/google-java-format/issues/959 PiperOrigin-RevId: 564710136
diff --git a/core/src/main/java/com/google/googlejavaformat/java/JavaInputAstVisitor.java b/core/src/main/java/com/google/googlejavaformat/java/JavaInputAstVisitor.java index 394d396..89c944c 100644 --- a/core/src/main/java/com/google/googlejavaformat/java/JavaInputAstVisitor.java +++ b/core/src/main/java/com/google/googlejavaformat/java/JavaInputAstVisitor.java
@@ -1250,7 +1250,10 @@ token(","); builder.breakOp(" "); } - scan(parameter, null); + visitVariables( + ImmutableList.of(parameter), + DeclarationKind.NONE, + fieldAnnotationDirection(parameter.getModifiers())); first = false; } if (parens) {
diff --git a/core/src/test/resources/com/google/googlejavaformat/java/testdata/I959.input b/core/src/test/resources/com/google/googlejavaformat/java/testdata/I959.input new file mode 100644 index 0000000..0660079 --- /dev/null +++ b/core/src/test/resources/com/google/googlejavaformat/java/testdata/I959.input
@@ -0,0 +1,5 @@ +class I959 { + public void test() { + new File(".").listFiles((final var dir, final var name) -> true); + } +} \ No newline at end of file
diff --git a/core/src/test/resources/com/google/googlejavaformat/java/testdata/I959.output b/core/src/test/resources/com/google/googlejavaformat/java/testdata/I959.output new file mode 100644 index 0000000..76a07f4 --- /dev/null +++ b/core/src/test/resources/com/google/googlejavaformat/java/testdata/I959.output
@@ -0,0 +1,5 @@ +class I959 { + public void test() { + new File(".").listFiles((final var dir, final var name) -> true); + } +}