This commit is contained in:
2026-07-07 04:50:18 +02:00
parent a7bf07e8b2
commit 9a5f122bd2
6 changed files with 165 additions and 21 deletions

View File

@@ -31,7 +31,7 @@ class DynamicClasspathResolverTest {
.filter(arg -> arg.startsWith("-Dmdep.outputFile="))
.findFirst()
.orElseThrow();
Path outputFile = Path.of(outputFileArg.substring("-Dmdep.outputFile=".length()));
Path outputFile = pb.directory().toPath().resolve(outputFileArg.substring("-Dmdep.outputFile=".length()));
Files.writeString(outputFile, cp);
}

View File

@@ -1036,4 +1036,47 @@ class HeuristicCallGraphEngineCoreTest {
org.assertj.core.api.Assertions.assertThat(chains).hasSize(1);
org.assertj.core.api.Assertions.assertThat(chains.get(0).getTriggerPoint().getPolymorphicEvents()).containsExactlyInAnyOrder("REACTIVE_EVENT");
}
@Test
void shouldExtractEventFromSwitchExpressionAndParentheses(@TempDir Path tempDir) throws IOException {
String source = """
package com.example;
public class SwitchOrderService {
public void processOrder(int type) {
String e = (((switch(type) {
case 1 -> "PAY";
default -> { yield "CANCEL"; }
})));
sendEvent(e);
}
public void sendEvent(String event) {
}
}
""";
Files.writeString(tempDir.resolve("SwitchOrderService.java"), source);
CodebaseContext context = new CodebaseContext();
context.scan(tempDir);
HeuristicCallGraphEngine builder = new HeuristicCallGraphEngine(context);
EntryPoint entryPoint = EntryPoint.builder()
.className("com.example.SwitchOrderService")
.methodName("processOrder")
.build();
TriggerPoint trigger = TriggerPoint.builder()
.className("com.example.SwitchOrderService")
.methodName("sendEvent")
.event("event")
.build();
List<CallChain> chains = builder.findChains(List.of(entryPoint), List.of(trigger));
assertThat(chains).hasSize(1);
System.out.println("POLY EVENTS: " + chains.get(0).getTriggerPoint().getPolymorphicEvents());
assertThat(chains.get(0).getTriggerPoint().getPolymorphicEvents())
.containsExactlyInAnyOrder("PAY", "CANCEL");
}
}