This commit is contained in:
2026-07-06 18:54:58 +02:00
parent e041cb9a80
commit 6472f01026
5 changed files with 51 additions and 0 deletions

View File

@@ -20,7 +20,13 @@ public class HeuristicCallGraphEngine extends AbstractCallGraphEngine {
super(context);
}
@SuppressWarnings("unchecked")
protected Map<String, List<CallEdge>> buildCallGraph() {
Map<String, List<CallEdge>> cached = (Map<String, List<CallEdge>>) context.getCache().get("heuristicCallGraph");
if (cached != null) {
this.graph = cached;
return cached;
}
graph = new HashMap<>();
for (CompilationUnit cu : context.getCompilationUnits()) {
cu.accept(new ASTVisitor() {
@@ -131,6 +137,7 @@ public class HeuristicCallGraphEngine extends AbstractCallGraphEngine {
}
});
}
context.getCache().put("heuristicCallGraph", graph);
return graph;
}

View File

@@ -24,7 +24,13 @@ public class JdtCallGraphEngine extends AbstractCallGraphEngine {
this.injectionAnalyzer = injectionAnalyzer;
}
@SuppressWarnings("unchecked")
protected Map<String, List<CallEdge>> buildCallGraph() {
Map<String, List<CallEdge>> cached = (Map<String, List<CallEdge>>) context.getCache().get("jdtCallGraph");
if (cached != null) {
this.graph = cached;
return cached;
}
graph = new HashMap<>();
for (CompilationUnit cu : context.getCompilationUnits()) {
cu.accept(new ASTVisitor() {
@@ -131,6 +137,7 @@ public class JdtCallGraphEngine extends AbstractCallGraphEngine {
}
});
}
context.getCache().put("jdtCallGraph", graph);
return graph;
}

View File

@@ -29,6 +29,8 @@ public class JdtIntelligenceProvider implements CodebaseIntelligenceProvider {
private final LifecycleDetector lifecycleDetector;
private final InterceptorDetector interceptorDetector;
private final SpringComponentDetector componentDetector;
private List<TriggerPoint> cachedTriggers;
private List<EntryPoint> cachedEntryPoints;
public JdtIntelligenceProvider(CodebaseContext context, Path rootDir) {
this.context = context;
@@ -54,6 +56,9 @@ public class JdtIntelligenceProvider implements CodebaseIntelligenceProvider {
@Override
public List<TriggerPoint> findTriggerPoints() {
if (cachedTriggers != null) {
return cachedTriggers;
}
List<TriggerPoint> allTriggers = new ArrayList<>();
var cus = context.getCompilationUnits();
log.info("JdtIntelligenceProvider scanning {} compilation units for triggers", cus.size());
@@ -62,11 +67,15 @@ public class JdtIntelligenceProvider implements CodebaseIntelligenceProvider {
allTriggers.addAll(lifecycleDetector.detect(cu));
}
log.info("Found {} triggers (including lifecycle) in total", allTriggers.size());
cachedTriggers = allTriggers;
return allTriggers;
}
@Override
public List<EntryPoint> findEntryPoints() {
if (cachedEntryPoints != null) {
return cachedEntryPoints;
}
List<EntryPoint> allEntryPoints = new ArrayList<>();
var cus = context.getCompilationUnits();
log.info("JdtIntelligenceProvider scanning {} compilation units for entry points", cus.size());
@@ -77,6 +86,7 @@ public class JdtIntelligenceProvider implements CodebaseIntelligenceProvider {
allEntryPoints.addAll(componentDetector.detect(cu));
}
log.info("Found {} entry points (including interceptors and listeners) in total", allEntryPoints.size());
cachedEntryPoints = allEntryPoints;
return allEntryPoints;
}

View File

@@ -41,6 +41,11 @@ public class CodebaseContext {
private List<LibraryHint> libraryHints = new ArrayList<>();
private final ObjectMapper objectMapper = new ObjectMapper();
private Path projectRoot;
private final Map<String, Object> cache = new HashMap<>();
public Map<String, Object> getCache() {
return cache;
}
public void setProjectRoot(Path root) {
this.projectRoot = root;

View File

@@ -125,4 +125,26 @@ class HeuristicEventMatchingEngineTest {
assertThat(engine.matches(smEvent, triggerPoint)).isFalse();
}
@Test
void shouldMatchWildcardIfTypeMatches() {
Event smEvent = Event.of("PAY", "com.example.OrderEvents.PAY");
TriggerPoint triggerPoint = TriggerPoint.builder()
.event("event")
.eventTypeFqn("com.example.OrderEvents")
.build();
assertThat(engine.matches(smEvent, triggerPoint)).isTrue();
}
@Test
void shouldNotMatchWildcardIfTypeMismatches() {
Event smEvent = Event.of("PAY", "com.example.InvoiceEvents.PAY");
TriggerPoint triggerPoint = TriggerPoint.builder()
.event("event")
.eventTypeFqn("com.example.OrderEvents")
.build();
assertThat(engine.matches(smEvent, triggerPoint)).isFalse();
}
}