heuristics updated consolidation
This commit is contained in:
@@ -26,94 +26,6 @@ import java.util.*;
|
|||||||
String resolve(Expression rhs, Map<String, String> paramValues, TypeDeclaration td);
|
String resolve(Expression rhs, Map<String, String> paramValues, TypeDeclaration td);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected 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);
|
|
||||||
if (edges == null) {
|
|
||||||
return paramValues;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (CallEdge edge : edges) {
|
|
||||||
if (edge.getTargetMethod().equals(target) || isHeuristicMatch(edge.getTargetMethod(), target)) {
|
|
||||||
List<String> args = edge.getArguments();
|
|
||||||
if (args == null || args.isEmpty()) break;
|
|
||||||
|
|
||||||
int lastDot = target.lastIndexOf('.');
|
|
||||||
if (lastDot < 0) break;
|
|
||||||
String className = target.substring(0, lastDot);
|
|
||||||
String methodName = target.substring(lastDot + 1);
|
|
||||||
|
|
||||||
TypeDeclaration td = context.getTypeDeclaration(className);
|
|
||||||
if (td == null) break;
|
|
||||||
|
|
||||||
MethodDeclaration md = context.findMethodDeclaration(td, methodName, true);
|
|
||||||
if (md == null) break;
|
|
||||||
|
|
||||||
List<String> paramNames = new ArrayList<>();
|
|
||||||
for (Object paramObj : md.parameters()) {
|
|
||||||
SingleVariableDeclaration param = (SingleVariableDeclaration) paramObj;
|
|
||||||
paramNames.add(param.getName().getIdentifier());
|
|
||||||
}
|
|
||||||
|
|
||||||
int minSize = Math.min(paramNames.size(), args.size());
|
|
||||||
for (int j = 0; j < minSize; j++) {
|
|
||||||
String argValue = args.get(j);
|
|
||||||
String resolvedArgValue = resolveArgumentValue(argValue, caller, path, pathIndex, callGraph);
|
|
||||||
paramValues.put(paramNames.get(j), resolvedArgValue);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return paramValues;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected 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].*")) {
|
|
||||||
return argValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
int callerIndex = path.indexOf(callerMethod);
|
|
||||||
if (callerIndex <= 0) return argValue;
|
|
||||||
|
|
||||||
String prevCaller = path.get(callerIndex - 1);
|
|
||||||
List<CallEdge> prevEdges = callGraph.get(prevCaller);
|
|
||||||
if (prevEdges == null) return argValue;
|
|
||||||
|
|
||||||
for (CallEdge edge : prevEdges) {
|
|
||||||
if (edge.getTargetMethod().equals(callerMethod) || isHeuristicMatch(edge.getTargetMethod(), callerMethod)) {
|
|
||||||
List<String> prevArgs = edge.getArguments();
|
|
||||||
if (prevArgs == null || prevArgs.isEmpty()) break;
|
|
||||||
|
|
||||||
int lastDot = callerMethod.lastIndexOf('.');
|
|
||||||
if (lastDot < 0) break;
|
|
||||||
String className = callerMethod.substring(0, lastDot);
|
|
||||||
String methodName = callerMethod.substring(lastDot + 1);
|
|
||||||
|
|
||||||
TypeDeclaration td = context.getTypeDeclaration(className);
|
|
||||||
if (td == null) break;
|
|
||||||
|
|
||||||
MethodDeclaration md = context.findMethodDeclaration(td, methodName, true);
|
|
||||||
if (md == null) break;
|
|
||||||
|
|
||||||
List<String> paramNames = new ArrayList<>();
|
|
||||||
for (Object paramObj : md.parameters()) {
|
|
||||||
SingleVariableDeclaration param = (SingleVariableDeclaration) paramObj;
|
|
||||||
paramNames.add(param.getName().getIdentifier());
|
|
||||||
}
|
|
||||||
|
|
||||||
int paramIdx = paramNames.indexOf(argValue);
|
|
||||||
if (paramIdx >= 0 && paramIdx < prevArgs.size()) {
|
|
||||||
String prevArg = prevArgs.get(paramIdx);
|
|
||||||
return resolveArgumentValue(prevArg, prevCaller, path, pathIndex, callGraph);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return argValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<CallChain> findChains(List<EntryPoint> entryPoints, List<TriggerPoint> triggers) {
|
public List<CallChain> findChains(List<EntryPoint> entryPoints, List<TriggerPoint> triggers) {
|
||||||
Map<String, List<CallEdge>> callGraph = buildCallGraph();
|
Map<String, List<CallEdge>> callGraph = buildCallGraph();
|
||||||
List<CallChain> chains = new ArrayList<>();
|
List<CallChain> chains = new ArrayList<>();
|
||||||
@@ -166,7 +78,8 @@ import java.util.*;
|
|||||||
int paramIndex = getParameterIndex(target, currentParamName);
|
int paramIndex = getParameterIndex(target, currentParamName);
|
||||||
if (paramIndex < 0) {
|
if (paramIndex < 0) {
|
||||||
// Not a parameter. Maybe it's a local variable initialized from a parameter or method call?
|
// Not a parameter. Maybe it's a local variable initialized from a parameter or method call?
|
||||||
String tracedVar = traceLocalVariable(target, currentParamName);
|
Map<String, String> parameterValues = buildParameterValuesMap(caller, target, callGraph, path, i);
|
||||||
|
String tracedVar = traceLocalVariable(target, currentParamName, parameterValues);
|
||||||
if (tracedVar != null && !tracedVar.equals(currentParamName)) {
|
if (tracedVar != null && !tracedVar.equals(currentParamName)) {
|
||||||
// Extract method calls like .getType() from the traced variable
|
// Extract method calls like .getType() from the traced variable
|
||||||
String[] extractedTraced = extractMethodSuffix(tracedVar, methodSuffix);
|
String[] extractedTraced = extractMethodSuffix(tracedVar, methodSuffix);
|
||||||
@@ -1655,6 +1568,93 @@ import java.util.*;
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected java.util.Map<String, String> buildParameterValuesMap(String caller, String target, Map<String, List<CallEdge>> callGraph, List<String> path, int pathIndex) {
|
||||||
|
java.util.Map<String, String> paramValues = new java.util.HashMap<>();
|
||||||
|
List<CallEdge> edges = callGraph.get(caller);
|
||||||
|
if (edges == null) {
|
||||||
|
return paramValues;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (CallEdge edge : edges) {
|
||||||
|
if (edge.getTargetMethod().equals(target) || isHeuristicMatch(edge.getTargetMethod(), target)) {
|
||||||
|
List<String> args = edge.getArguments();
|
||||||
|
if (args == null || args.isEmpty()) break;
|
||||||
|
|
||||||
|
int lastDot = target.lastIndexOf('.');
|
||||||
|
if (lastDot < 0) break;
|
||||||
|
String className = target.substring(0, lastDot);
|
||||||
|
String methodName = target.substring(lastDot + 1);
|
||||||
|
|
||||||
|
TypeDeclaration td = context.getTypeDeclaration(className);
|
||||||
|
if (td == null) break;
|
||||||
|
|
||||||
|
MethodDeclaration md = context.findMethodDeclaration(td, methodName, true);
|
||||||
|
if (md == null) break;
|
||||||
|
|
||||||
|
List<String> paramNames = new java.util.ArrayList<>();
|
||||||
|
for (Object paramObj : md.parameters()) {
|
||||||
|
org.eclipse.jdt.core.dom.SingleVariableDeclaration param = (org.eclipse.jdt.core.dom.SingleVariableDeclaration) paramObj;
|
||||||
|
paramNames.add(param.getName().getIdentifier());
|
||||||
|
}
|
||||||
|
|
||||||
|
int minSize = java.lang.Math.min(paramNames.size(), args.size());
|
||||||
|
for (int j = 0; j < minSize; j++) {
|
||||||
|
String argValue = args.get(j);
|
||||||
|
String resolvedArgValue = resolveArgumentValue(argValue, caller, path, pathIndex, callGraph);
|
||||||
|
paramValues.put(paramNames.get(j), resolvedArgValue);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return paramValues;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected 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].*")) {
|
||||||
|
return argValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
int callerIndex = path.indexOf(callerMethod);
|
||||||
|
if (callerIndex <= 0) return argValue;
|
||||||
|
|
||||||
|
String prevCaller = path.get(callerIndex - 1);
|
||||||
|
List<CallEdge> prevEdges = callGraph.get(prevCaller);
|
||||||
|
if (prevEdges == null) return argValue;
|
||||||
|
|
||||||
|
for (CallEdge edge : prevEdges) {
|
||||||
|
if (edge.getTargetMethod().equals(callerMethod) || isHeuristicMatch(edge.getTargetMethod(), callerMethod)) {
|
||||||
|
List<String> prevArgs = edge.getArguments();
|
||||||
|
if (prevArgs == null || prevArgs.isEmpty()) break;
|
||||||
|
|
||||||
|
int lastDot = callerMethod.lastIndexOf('.');
|
||||||
|
if (lastDot < 0) break;
|
||||||
|
String className = callerMethod.substring(0, lastDot);
|
||||||
|
String methodName = callerMethod.substring(lastDot + 1);
|
||||||
|
|
||||||
|
TypeDeclaration td = context.getTypeDeclaration(className);
|
||||||
|
if (td == null) break;
|
||||||
|
|
||||||
|
MethodDeclaration md = context.findMethodDeclaration(td, methodName, true);
|
||||||
|
if (md == null) break;
|
||||||
|
|
||||||
|
List<String> paramNames = new java.util.ArrayList<>();
|
||||||
|
for (Object paramObj : md.parameters()) {
|
||||||
|
org.eclipse.jdt.core.dom.SingleVariableDeclaration param = (org.eclipse.jdt.core.dom.SingleVariableDeclaration) paramObj;
|
||||||
|
paramNames.add(param.getName().getIdentifier());
|
||||||
|
}
|
||||||
|
|
||||||
|
int paramIdx = paramNames.indexOf(argValue);
|
||||||
|
if (paramIdx >= 0 && paramIdx < prevArgs.size()) {
|
||||||
|
String prevArg = prevArgs.get(paramIdx);
|
||||||
|
return resolveArgumentValue(prevArg, prevCaller, path, pathIndex, callGraph);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return argValue;
|
||||||
|
}
|
||||||
|
|
||||||
protected org.eclipse.jdt.core.dom.Expression traceLocalSetter(String methodFqn, String varName, String getterName) {
|
protected org.eclipse.jdt.core.dom.Expression traceLocalSetter(String methodFqn, String varName, String getterName) {
|
||||||
if (methodFqn == null || !methodFqn.contains(".")) return null;
|
if (methodFqn == null || !methodFqn.contains(".")) return null;
|
||||||
String className = methodFqn.substring(0, methodFqn.lastIndexOf('.'));
|
String className = methodFqn.substring(0, methodFqn.lastIndexOf('.'));
|
||||||
|
|||||||
@@ -839,90 +839,4 @@ public class HeuristicCallGraphEngine extends AbstractCallGraphEngine {
|
|||||||
return initExpr[0];
|
return initExpr[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
private java.util.Map<String, String> buildParameterValuesMap(String caller, String target, Map<String, List<CallEdge>> callGraph, List<String> path, int pathIndex) {
|
|
||||||
java.util.Map<String, String> paramValues = new java.util.HashMap<>();
|
|
||||||
List<CallEdge> edges = callGraph.get(caller);
|
|
||||||
if (edges == null) {
|
|
||||||
return paramValues;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (CallEdge edge : edges) {
|
|
||||||
if (edge.getTargetMethod().equals(target) || isHeuristicMatch(edge.getTargetMethod(), target)) {
|
|
||||||
List<String> args = edge.getArguments();
|
|
||||||
if (args == null || args.isEmpty()) break;
|
|
||||||
|
|
||||||
int lastDot = target.lastIndexOf('.');
|
|
||||||
if (lastDot < 0) break;
|
|
||||||
String className = target.substring(0, lastDot);
|
|
||||||
String methodName = target.substring(lastDot + 1);
|
|
||||||
|
|
||||||
TypeDeclaration td = context.getTypeDeclaration(className);
|
|
||||||
if (td == null) break;
|
|
||||||
|
|
||||||
MethodDeclaration md = context.findMethodDeclaration(td, methodName, true);
|
|
||||||
if (md == null) break;
|
|
||||||
|
|
||||||
List<String> paramNames = new java.util.ArrayList<>();
|
|
||||||
for (Object paramObj : md.parameters()) {
|
|
||||||
org.eclipse.jdt.core.dom.SingleVariableDeclaration param = (org.eclipse.jdt.core.dom.SingleVariableDeclaration) paramObj;
|
|
||||||
paramNames.add(param.getName().getIdentifier());
|
|
||||||
}
|
|
||||||
|
|
||||||
int minSize = java.lang.Math.min(paramNames.size(), args.size());
|
|
||||||
for (int j = 0; j < minSize; j++) {
|
|
||||||
String argValue = args.get(j);
|
|
||||||
String resolvedArgValue = resolveArgumentValue(argValue, caller, path, pathIndex, callGraph);
|
|
||||||
paramValues.put(paramNames.get(j), resolvedArgValue);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return paramValues;
|
|
||||||
}
|
|
||||||
|
|
||||||
private 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].*")) {
|
|
||||||
return argValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
int callerIndex = path.indexOf(callerMethod);
|
|
||||||
if (callerIndex <= 0) return argValue;
|
|
||||||
|
|
||||||
String prevCaller = path.get(callerIndex - 1);
|
|
||||||
List<CallEdge> prevEdges = callGraph.get(prevCaller);
|
|
||||||
if (prevEdges == null) return argValue;
|
|
||||||
|
|
||||||
for (CallEdge edge : prevEdges) {
|
|
||||||
if (edge.getTargetMethod().equals(callerMethod) || isHeuristicMatch(edge.getTargetMethod(), callerMethod)) {
|
|
||||||
List<String> prevArgs = edge.getArguments();
|
|
||||||
if (prevArgs == null || prevArgs.isEmpty()) break;
|
|
||||||
|
|
||||||
int lastDot = callerMethod.lastIndexOf('.');
|
|
||||||
if (lastDot < 0) break;
|
|
||||||
String className = callerMethod.substring(0, lastDot);
|
|
||||||
String methodName = callerMethod.substring(lastDot + 1);
|
|
||||||
|
|
||||||
TypeDeclaration td = context.getTypeDeclaration(className);
|
|
||||||
if (td == null) break;
|
|
||||||
|
|
||||||
MethodDeclaration md = context.findMethodDeclaration(td, methodName, true);
|
|
||||||
if (md == null) break;
|
|
||||||
|
|
||||||
List<String> paramNames = new java.util.ArrayList<>();
|
|
||||||
for (Object paramObj : md.parameters()) {
|
|
||||||
org.eclipse.jdt.core.dom.SingleVariableDeclaration param = (org.eclipse.jdt.core.dom.SingleVariableDeclaration) paramObj;
|
|
||||||
paramNames.add(param.getName().getIdentifier());
|
|
||||||
}
|
|
||||||
|
|
||||||
int paramIdx = paramNames.indexOf(argValue);
|
|
||||||
if (paramIdx >= 0 && paramIdx < prevArgs.size()) {
|
|
||||||
String prevArg = prevArgs.get(paramIdx);
|
|
||||||
return resolveArgumentValue(prevArg, prevCaller, path, pathIndex, callGraph);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return argValue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user