more bugs
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user