3
This commit is contained in:
@@ -413,6 +413,33 @@ public class VariableTracer {
|
||||
public Map<String, String> buildParameterValuesMap(String caller, String target, Map<String, List<CallEdge>> callGraph, List<String> path, int pathIndex) {
|
||||
Map<String, String> paramValues = new HashMap<>();
|
||||
List<CallEdge> edges = callGraph.get(caller);
|
||||
|
||||
boolean hasEdge = false;
|
||||
if (edges != null) {
|
||||
for (CallEdge edge : edges) {
|
||||
if (edge.getTargetMethod().equals(target) || isHeuristicMatch(edge.getTargetMethod(), target)) {
|
||||
hasEdge = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Bridge polymorphic interfaces to implementations without graph edges
|
||||
if (!hasEdge) {
|
||||
String callerSimple = caller.contains(".") ? caller.substring(caller.lastIndexOf('.') + 1) : caller;
|
||||
String targetSimple = target.contains(".") ? target.substring(target.lastIndexOf('.') + 1) : target;
|
||||
if (callerSimple.equals(targetSimple)) {
|
||||
List<String> callerParams = getParameterNames(caller);
|
||||
List<String> targetParams = getParameterNames(target);
|
||||
if (callerParams != null && targetParams != null && callerParams.size() == targetParams.size()) {
|
||||
for (int i = 0; i < callerParams.size(); i++) {
|
||||
paramValues.put(targetParams.get(i), callerParams.get(i));
|
||||
}
|
||||
return paramValues;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (edges == null) {
|
||||
return paramValues;
|
||||
}
|
||||
@@ -453,6 +480,26 @@ public class VariableTracer {
|
||||
return paramValues;
|
||||
}
|
||||
|
||||
private List<String> getParameterNames(String methodFqn) {
|
||||
int lastDot = methodFqn.lastIndexOf('.');
|
||||
if (lastDot < 0) return null;
|
||||
String className = methodFqn.substring(0, lastDot);
|
||||
String methodName = methodFqn.substring(lastDot + 1);
|
||||
|
||||
TypeDeclaration td = context.getTypeDeclaration(className);
|
||||
if (td == null) return null;
|
||||
|
||||
MethodDeclaration md = context.findMethodDeclaration(td, methodName, true);
|
||||
if (md == null) return null;
|
||||
|
||||
List<String> paramNames = new ArrayList<>();
|
||||
for (Object paramObj : md.parameters()) {
|
||||
SingleVariableDeclaration param = (SingleVariableDeclaration) paramObj;
|
||||
paramNames.add(param.getName().getIdentifier());
|
||||
}
|
||||
return paramNames;
|
||||
}
|
||||
|
||||
public String resolveArgumentValue(String argValue, String callerMethod, List<String> path, int pathIndex, Map<String, List<CallEdge>> callGraph) {
|
||||
if (argValue == null) return null;
|
||||
if (argValue.contains(".") || argValue.startsWith("new ") || argValue.matches(".*[0-9].*")) {
|
||||
|
||||
Reference in New Issue
Block a user