Compare commits
1 Commits
still_miss
...
2e83af0f33
| Author | SHA1 | Date | |
|---|---|---|---|
| 2e83af0f33 |
@@ -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();
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user