Skip to content

Commit

Permalink
use ArrayListMultimap
Browse files Browse the repository at this point in the history
  • Loading branch information
Liyw979 committed Jan 23, 2025
1 parent b37d99c commit 23020b8
Showing 1 changed file with 21 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* #L%
*/

import com.google.common.collect.ArrayListMultimap;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand Down Expand Up @@ -49,7 +50,7 @@
public class RapidTypeAnalysisAlgorithm extends AbstractCallGraphAlgorithm {

@Nonnull protected Set<ClassType> instantiatedClasses = Collections.emptySet();
@Nonnull protected Map<ClassType, List<Call>> ignoredCalls = Collections.emptyMap();
@Nonnull protected ArrayListMultimap<ClassType, Call> ignoredCalls = ArrayListMultimap.create();

/**
* The constructor of the RTA algorithm.
Expand All @@ -72,13 +73,13 @@ public CallGraph initialize() {
public CallGraph initialize(@Nonnull List<MethodSignature> entryPoints) {
// init helper data structures
instantiatedClasses = new HashSet<>();
ignoredCalls = new HashMap<>();
ignoredCalls = ArrayListMultimap.create();

CallGraph cg = constructCompleteCallGraph(entryPoints);

// delete the data structures
instantiatedClasses = Collections.emptySet();
ignoredCalls = Collections.emptyMap();
ignoredCalls = ArrayListMultimap.create();
return cg;
}

Expand Down Expand Up @@ -198,13 +199,8 @@ private Stream<MethodSignature> resolveAllCallTargets(
private void saveIgnoredCall(
MethodSignature source, MethodSignature target, InvokableStmt invokableStmt) {
ClassType notInstantiatedClass = target.getDeclClassType();
List<Call> calls = ignoredCalls.get(notInstantiatedClass);
Call ignoredCall = new Call(source, target, invokableStmt);
if (calls == null) {
calls = new ArrayList<>();
ignoredCalls.put(notInstantiatedClass, calls);
}
calls.add(ignoredCall);
ignoredCalls.put(notInstantiatedClass, ignoredCall);
}

/**
Expand Down Expand Up @@ -247,24 +243,22 @@ protected void preProcessingMethod(
protected void includeIgnoredCallsToClass(
ClassType classType, MutableCallGraph cg, Deque<MethodSignature> workList) {
List<Call> newEdges = ignoredCalls.get(classType);
if (newEdges != null) {
newEdges.forEach(
call -> {
MethodSignature concreteTarget =
resolveConcreteDispatch(view, call.getTargetMethodSignature()).orElse(null);
if (concreteTarget == null) {
return;
}
addCallToCG(
call.getSourceMethodSignature(),
concreteTarget,
call.getInvokableStmt(),
cg,
workList);
});
// can be removed because the instantiated class will be considered in future resolves
ignoredCalls.remove(classType);
}
newEdges.forEach(
call -> {
MethodSignature concreteTarget =
resolveConcreteDispatch(view, call.getTargetMethodSignature()).orElse(null);
if (concreteTarget == null) {
return;
}
addCallToCG(
call.getSourceMethodSignature(),
concreteTarget,
call.getInvokableStmt(),
cg,
workList);
});
// can be removed because the instantiated class will be considered in future resolves
ignoredCalls.removeAll(classType);
}

/**
Expand Down

0 comments on commit 23020b8

Please sign in to comment.