Class CallGraph


  • public class CallGraph
    extends java.lang.Object
    Collection of all Calls in a program, optimized for retrieval of incoming and outgoing edges for any method in constant time.
    • Constructor Detail

      • CallGraph

        public CallGraph()
        Create an empty call graph.
    • Method Detail

      • concurrentCallGraph

        public static CallGraph concurrentCallGraph()
        Provides concurrency ready CallGraph, backed by ConcurrentHashMaps and by synchronizedSets. Not needed without multithreading.
      • addCall

        public void addCall​(Call call)
        Add a Call to this call graph.
        Parameters:
        call - The call to be added.
      • clear

        public void clear()
        Clear the call graph references.
      • reconstructCallGraph

        public Node reconstructCallGraph​(ClassPool programClassPool,
                                         MethodSignature start,
                                         int maxDepth,
                                         int maxWidth,
                                         java.util.Set<MethodSignature> stopMethods)
        Calculate the incoming call graph for a method of interest, showing how it can be reached from a given Set of stop methods, which typically are Android lifecycle methods such as an Activity's onCreate() method:

        We have an inverted tree structure like the following example:

        
         onCreate() <-- predecessor -- proxy() <-- predecessor -- root()
                                    onResume() <-- predecessor ----|  |
                                unusedMethod() <-- predecessor -------|
        
         
        Here, root() is the method whose call graph is to be calculated, and the graph now shows that it can be reached from onCreate() via proxy(), and also directly from onResume() or unusedMethod().
        Parameters:
        programClassPool - The current ClassPool of the program that can be used for mapping. class names to the actual Clazz.
        start - The MethodSignature of the method whose incoming call graph should be calculated.
        maxDepth - maximal depth of reconstructed CallGraph similar to CallGraphWalker.MAX_DEPTH_DEFAULT.
        maxWidth - maximal width of reconstructed CallGraph similar to CallGraphWalker.MAX_WIDTH_DEFAULT.
        stopMethods - Set of method signatures to stop exploration, for example for entry points
        Returns:
        A Node that represents the single call graph root, i.e. the start method.