more bugs

This commit is contained in:
2026-06-27 15:24:07 +02:00
parent 60c666f7a1
commit 7008f162b5
3 changed files with 113 additions and 1 deletions

View File

@@ -737,6 +737,23 @@ public abstract class AbstractCallGraphEngine implements CallGraphEngine {
if (receiver instanceof SimpleName sn) {
receiverName = sn.getIdentifier();
receiverType = variableTracer.getVariableDeclaredType(entryMethod, receiverName);
} else if (receiver instanceof MethodInvocation receiverMi) {
String propName = getterName.startsWith("get") ? getterName.substring(3) : getterName;
Expression currentMi = receiverMi;
while (currentMi instanceof MethodInvocation chainMi) {
String mName = chainMi.getName().getIdentifier();
if (mName.equalsIgnoreCase("set" + propName) || mName.equalsIgnoreCase(propName)) {
if (!chainMi.arguments().isEmpty()) {
Expression arg = (Expression) chainMi.arguments().get(0);
List<String> builderConstants = new ArrayList<>();
constantExtractor.extractConstantsFromExpression(arg, builderConstants);
if (!builderConstants.isEmpty()) {
return builderConstants;
}
}
}
currentMi = chainMi.getExpression();
}
}
if (receiverType == null && path.size() > 1) {

View File

@@ -367,7 +367,23 @@ public class HeuristicCallGraphEngine extends AbstractCallGraphEngine {
cic = findReturnedCIC(receiverType, factoryMi.getName().getIdentifier(), context);
}
}
if (cic == null) return null;
if (cic == null) {
// Support builder pattern: e.g. EventWrapper.builder().event(TransitionEnum.STATE_X).build()
if (initExpr[0] instanceof MethodInvocation initMi) {
String propName = getterName.startsWith("get") ? getterName.substring(3) : getterName;
Expression currentMi = initMi;
while (currentMi instanceof MethodInvocation chainMi) {
String mName = chainMi.getName().getIdentifier();
if (mName.equalsIgnoreCase("set" + propName) || mName.equalsIgnoreCase(propName)) {
if (!chainMi.arguments().isEmpty()) {
return chainMi.arguments().get(0).toString();
}
}
currentMi = chainMi.getExpression();
}
}
return null;
}
// Resolve the variable's declared type to a TypeDeclaration
CompilationUnit cu = (CompilationUnit) getterCall.getRoot();