1 Commits

Author SHA1 Message Date
2e83af0f33 fix attempt 1 2026-06-20 06:51:15 +02:00
3 changed files with 28 additions and 17 deletions

View File

@@ -44,7 +44,7 @@ public class TransitionLinkerEnricher implements AnalysisEnricher {
boolean isWildcard = triggerEvent.equals("event") || triggerEvent.equals("e") ||
triggerEvent.equals("msg") || triggerEvent.equals("message") ||
triggerEvent.equals("payload");
triggerEvent.equals("payload") || triggerEvent.matches(".*\\.getType\\(\\)");
if (isWildcard) {
String targetVar = chain.getContextMachineId();

View File

@@ -147,21 +147,12 @@ public class CallGraphBuilder {
}
List<String> polymorphicEvents = new ArrayList<>();
if (resolvedValue.matches(".*\\.[a-zA-Z0-9_]+\\(\\)")) {
int lastDot = resolvedValue.lastIndexOf('.');
int firstDot = resolvedValue.indexOf('.');
int openParen = resolvedValue.indexOf('(', lastDot);
if (resolvedValue.matches(".*\\.get[A-Z].*\\(\\)")) {
String varName = resolvedValue.substring(0, resolvedValue.indexOf('.'));
String methodName = resolvedValue.substring(resolvedValue.indexOf('.') + 1, resolvedValue.indexOf('('));
if (lastDot > 0 && openParen > lastDot) {
String varName = resolvedValue.substring(0, firstDot);
if (varName.contains("(")) {
varName = null;
}
String methodName = resolvedValue.substring(lastDot + 1, openParen);
if (varName != null) {
// Resolve in the first method in the path where the variable might be declared
for (String methodFqn : path) {
// Resolve in the first method in the path where the variable might be declared
for (String methodFqn : path) {
String declaredType = getVariableDeclaredType(methodFqn, varName);
if (declaredType != null) {
System.out.println("DEEP TRACE: " + methodFqn + " " + varName + " -> " + declaredType);
@@ -196,8 +187,6 @@ public class CallGraphBuilder {
break;
}
}
}
}
}
if (!resolvedValue.equals(event) || !polymorphicEvents.isEmpty()) {

View File

@@ -143,7 +143,29 @@ class TransitionLinkerEnricherTest {
assertThat(updatedChain.getMatchedTransitions()).hasSize(1);
}
@Test
void shouldMatchMethodCallWildcard() {
Transition t1 = new Transition();
t1.setSourceStates(List.of(State.of("NEW", "NEW")));
t1.setTargetStates(List.of(State.of("PAID", "PAID")));
t1.setEvent(Event.of("PAY", "PAY"));
CallChain chain = CallChain.builder()
.triggerPoint(TriggerPoint.builder().event("richEvent.getType()").build())
.contextMachineId("testMachine")
.build();
AnalysisResult result = AnalysisResult.builder()
.name("testMachine")
.transitions(List.of(t1))
.metadata(CodebaseMetadata.builder().callChains(List.of(chain)).build())
.build();
enricher.enrich(result, null, null);
CallChain updatedChain = result.getMetadata().getCallChains().get(0);
assertThat(updatedChain.getMatchedTransitions()).hasSize(1);
}
@Test
void shouldNotMatchArbitraryGetXMethodWildcard() {