Class GraphBasedCallGraph

java.lang.Object
sootup.callgraph.GraphBasedCallGraph
All Implemented Interfaces:
CallGraph, MutableCallGraph

public class GraphBasedCallGraph extends Object implements MutableCallGraph
This class implements a mutable call graph as a graph.
  • Constructor Details

  • Method Details

    • addMethod

      public void addMethod(@Nonnull MethodSignature calledMethod)
      Description copied from interface: MutableCallGraph
      This method enables to add method that are nodes in the call graph.
      Specified by:
      addMethod in interface MutableCallGraph
      Parameters:
      calledMethod - the method that will be added to the call graph.
    • addMethod

      protected void addMethod(@Nonnull MethodSignature calledMethod, GraphBasedCallGraph.Vertex vertex)
    • addCall

      public void addCall(@Nonnull MethodSignature sourceMethod, @Nonnull MethodSignature targetMethod, @Nonnull InvokableStmt invokableStmt)
      Description copied from interface: MutableCallGraph
      This method enables to add calls that are edges in the call graph.
      Specified by:
      addCall in interface MutableCallGraph
      Parameters:
      sourceMethod - this parameter defines the source node of the edge in the call graph.
      targetMethod - this paramter defines the target node of the edge in the call graph.
      invokableStmt - this paramter defines the invoke statement of the edge in the call graph.
    • addCall

      public void addCall(@Nonnull CallGraph.Call call)
      Description copied from interface: MutableCallGraph
      This method enables to add calls that are edges in the call graph.
      Specified by:
      addCall in interface MutableCallGraph
      Parameters:
      call - this parameter defines the call that is transformed to the edge in the call graph.
    • getMethodSignatures

      @Nonnull public Set<MethodSignature> getMethodSignatures()
      Description copied from interface: CallGraph
      This method returns method signatures in the call graph. A method signature is a node in the call graph.
      Specified by:
      getMethodSignatures in interface CallGraph
      Returns:
      a set containing all method signatures in the call graph.
    • callTargetsFrom

      @Nonnull public Set<MethodSignature> callTargetsFrom(@Nonnull MethodSignature sourceMethod)
      Description copied from interface: CallGraph
      This method returns all method signatures that are called by a given method signature. It returns the targets of outgoing edges of the given node (method signature) in the call graph
      Specified by:
      callTargetsFrom in interface CallGraph
      Parameters:
      sourceMethod - the method signature of the requested node in the call graph
      Returns:
      a set of method signatures that are reached by a direct outgoing edge in the call graph
    • callSourcesTo

      @Nonnull public Set<MethodSignature> callSourcesTo(@Nonnull MethodSignature targetMethod)
      Description copied from interface: CallGraph
      This method returns all method signatures that call a given method signature. It returns the sources of incoming edges of the given node (method signature) in the call graph
      Specified by:
      callSourcesTo in interface CallGraph
      Parameters:
      targetMethod - the method signature of the requested node in the call graph
      Returns:
      a set of method signatures that reach the targetMethod by a direct edge in the call graph
    • callsFrom

      @Nonnull public Set<CallGraph.Call> callsFrom(@Nonnull MethodSignature sourceMethod)
      Description copied from interface: CallGraph
      This method returns all method signatures that are called by a given method signature. It returns the targets of outgoing edges of the given node (method signature) in the call graph
      Specified by:
      callsFrom in interface CallGraph
      Parameters:
      sourceMethod - the method signature of the requested node in the call graph
      Returns:
      a set of method signatures that are reached by a direct outgoing edge in the call graph
    • callsTo

      @Nonnull public Set<CallGraph.Call> callsTo(@Nonnull MethodSignature targetMethod)
      Description copied from interface: CallGraph
      This method returns all method signatures that call a given method signature. It returns the sources of incoming edges of the given node (method signature) in the call graph
      Specified by:
      callsTo in interface CallGraph
      Parameters:
      targetMethod - the method signature of the requested node in the call graph
      Returns:
      a set of method signatures that reach the targetMethod by a direct edge in the call graph
    • containsMethod

      public boolean containsMethod(@Nonnull MethodSignature method)
      Description copied from interface: CallGraph
      This method checks if a given method signature is a node in the call graph.
      Specified by:
      containsMethod in interface CallGraph
      Parameters:
      method - the method signature of the requested node
      Returns:
      it returns true if the node described by the method signature is included in the call graph, otherwise it will return false.
    • containsCall

      public boolean containsCall(@Nonnull MethodSignature sourceMethod, @Nonnull MethodSignature targetMethod, @Nonnull InvokableStmt invokableStmt)
      Description copied from interface: CallGraph
      This method checks if an edge is contained in the call graph. The edge is defined by a source and target method signature which can be nodes in the call graph
      Specified by:
      containsCall in interface CallGraph
      Parameters:
      sourceMethod - it defines the source node in the call graph
      targetMethod - it defines the target node in the call graph
      invokableStmt - it defines the invoke stmt of the call
      Returns:
      true if the edge is contained in the call graph, otherwise it will be false.
    • containsCall

      public boolean containsCall(@Nonnull CallGraph.Call call)
      Description copied from interface: CallGraph
      This method checks if an edge is contained in the call graph. The edge is defined by a source and target method signature which can be nodes in the call graph
      Specified by:
      containsCall in interface CallGraph
      Parameters:
      call - it defines the requested call in the call graph
      Returns:
      true if the edge is contained in the call graph, otherwise it will be false.
    • callCount

      public int callCount()
      Description copied from interface: CallGraph
      This method counts every edge in the call graph.
      Specified by:
      callCount in interface CallGraph
      Returns:
      it returns the number of all edges in the call graph.
    • exportAsDot

      public String exportAsDot()
      Description copied from interface: CallGraph
      This method converts the call graph object into dot format and write it to a string file.
      Specified by:
      exportAsDot in interface CallGraph
    • toDotEdge

      protected String toDotEdge(CallGraph.Call call)
      exports a call of the call graph to an edge in a dot file
      Parameters:
      call - the data of the call
      Returns:
      an edge defining the call in the dot file
    • copy

      @Nonnull public MutableCallGraph copy()
      Description copied from interface: CallGraph
      This method copies a call graph.
      Specified by:
      copy in interface CallGraph
      Returns:
      it returns a copied call graph.
    • diff

      Description copied from interface: CallGraph
      This method compares the difference between the current call graph and call graph passed into the argument.
      Specified by:
      diff in interface CallGraph
    • vertexOf

      it returns the vertex of the graph that describes the given method signature in the call graph. It will throw an exception if the vertex is not found
      Parameters:
      method - the method signature searched in the call graph
      Returns:
      the vertex of the requested method signature in optional otherwise an empty optional.
      Throws:
      IllegalArgumentException - if there is no vertex for the requested method signature
    • edgeOf

      @Nonnull protected CallGraph.Call edgeOf(@Nonnull MethodSignature source, @Nonnull MethodSignature target, @Nonnull InvokableStmt invokableStmt)
      it returns the edge of the graph that is described by the given source, target, stmt in the call graph. It will throw an exception if the source or target is not contained in the call graph or if the edge could not be found.
      Parameters:
      source - the signature of the source method
      target - the signature of the target method
      invokableStmt - the stmt causing the call
      Returns:
      the found edge in an optional or otherwise an empty optional
    • toString

      public String toString()
      This method exports the call graph in a human-readable string. The String lists all nodes in the call graph. For each node it also lists the outgoing and incoming edges. An outgoing edge is marked by a "To" and an incoming edge by a "From" The nodes, incoming edges, and outgoing edges are sorted in order by the classname, method name, parameter list
      Overrides:
      toString in class Object
      Returns:
      a string containing all nodes and edges of the call graph.
    • printCallingMethods

      protected String printCallingMethods(CallGraph.Call call)
      This returns the string that is used in the toString Method to define the methods that call a specific method
      Parameters:
      call - The data of the call
      Returns:
      The returned String will be used in the toString method to define the methods that call a specific method
    • printCalledMethods

      protected String printCalledMethods(CallGraph.Call call)
      This returns the string that is used in the toString Method to define the called methods
      Parameters:
      call - The data of the call
      Returns:
      The returned String will be used in the toString method to define the called methods
    • getEntryMethods

      @Nonnull public List<MethodSignature> getEntryMethods()
      Description copied from interface: CallGraph
      This method returns all entry methods of the call graph
      Specified by:
      getEntryMethods in interface CallGraph
      Returns:
      a list of method signatures of entry points of the call graph