Skip to content

Commit 1fe6789

Browse files
cushongoogle-java-format Team
authored andcommitted
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 #959 PiperOrigin-RevId: 564710136
1 parent d0e44e5 commit 1fe6789

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1250,7 +1250,10 @@ public Void visitLambdaExpression(LambdaExpressionTree node, Void unused) {
12501250
token(",");
12511251
builder.breakOp(" ");
12521252
}
1253-
scan(parameter, null);
1253+
visitVariables(
1254+
ImmutableList.of(parameter),
1255+
DeclarationKind.NONE,
1256+
fieldAnnotationDirection(parameter.getModifiers()));
12541257
first = false;
12551258
}
12561259
if (parens) {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class I959 {
2+
public void test() {
3+
new File(".").listFiles((final var dir, final var name) -> true);
4+
}
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class I959 {
2+
public void test() {
3+
new File(".").listFiles((final var dir, final var name) -> true);
4+
}
5+
}

0 commit comments

Comments
 (0)