File tree Expand file tree Collapse file tree
core/src/test/java/com/google/errorprone/bugpatterns Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1616
1717package com .google .errorprone .bugpatterns ;
1818
19+ import static com .google .common .truth .TruthJUnit .assume ;
20+
1921import com .google .auto .value .processor .AutoValueProcessor ;
2022import com .google .errorprone .BugCheckerRefactoringTestHelper ;
2123import com .google .errorprone .CompilationTestHelper ;
@@ -176,6 +178,37 @@ Function<Void, Void> f() {
176178 .doTest ();
177179 }
178180
181+ @ Test
182+ public void lambdaExpressionTrees () {
183+ assume ().that (Runtime .version ().feature ()).isAtLeast (22 );
184+ testHelper
185+ .addInputLines (
186+ "Test.java" ,
187+ """
188+ import java.util.List;
189+
190+ class Test {
191+ void withParens(List<String> list) {
192+ list.forEach((_) -> System.out.println());
193+ list.forEach((unused) -> System.out.println());
194+ list.forEach((String unused) -> System.out.println());
195+ }
196+
197+ void withoutParens(List<String> list) {
198+ list.forEach(_ -> System.out.println());
199+ list.forEach(unused -> System.out.println());
200+ }
201+ }
202+ """ )
203+ // TODO(kak): we probably should remove unnecessary parentheses from LambdaExpressionTrees.
204+ // Note that the parentheses are not a ParenthesizedTree node: In the AST, when you have
205+ // (_) -> ..., the (_) is not represented as a ParenthesizedTree node wrapping an
206+ // expression. Instead, the parentheses are just syntactical tokens that are part of the
207+ // LambdaExpressionTree node itself.
208+ .expectUnchanged ()
209+ .doTest ();
210+ }
211+
179212 @ Test
180213 public void unaryPostFixParenthesesNotNeeded () {
181214 testHelper
You can’t perform that action at this time.
0 commit comments