Skip to content

Commit

Permalink
fix: FlowPath Analysis with chained lambda expressions (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
amishra-u authored Dec 7, 2024
1 parent 2fa4437 commit 190153b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static Option<Cursor> findCallableBlockCursor(Cursor start) {
Object next = nextCursor.getValue();
if (next instanceof J.Block) {
methodDeclarationBlockCursor = nextCursor;
if (J.Block.isStaticOrInitBlock(nextCursor)) {
if (J.Block.isStaticOrInitBlock(nextCursor) || nextCursor.getParentTreeCursor().getValue() instanceof J.Lambda) {
return Option.some(nextCursor);
}
} else if (next instanceof J.MethodDeclaration) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,47 @@ void test() {
)
);
}

@Test
void flowPathDetectionWithChainedLambdas() {
//language=java
rewriteRun(
spec -> spec.expectedCyclesThatMakeChanges(1).cycles(1),
java(
"""
import java.util.List;
import java.util.stream.Stream;
class Test {
void test() {
List<Integer> list = Stream.of(1, 2, 3).peek(i -> {
System.out.println("Number " + i);
}).peek(i -> {
int n = 42;
int o = n;
System.out.println(o);
int p = o;
}).toList();
}
}
""", """
import java.util.List;
import java.util.stream.Stream;
class Test {
void test() {
List<Integer> list = Stream.of(1, 2, 3).peek(i -> {
System.out.println("Number " + i);
}).peek(i -> {
int n = /*~~>*/42;
int o = /*~~>*/n;
System.out.println(/*~~>*/o);
int p = /*~~>*/o;
}).toList();
}
}
"""
)
);
}
}

0 comments on commit 190153b

Please sign in to comment.