Package sootup.callgraph
Class GraphBasedCallGraph
java.lang.Object
sootup.callgraph.GraphBasedCallGraph
- All Implemented Interfaces:
CallGraph
,MutableCallGraph
This class implements a mutable call graph as a graph.
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static class
This internal class is used to describe a vertex in the graph.Nested classes/interfaces inherited from interface sootup.callgraph.CallGraph
CallGraph.Call
-
Constructor Summary
ModifierConstructorDescriptionGraphBasedCallGraph
(List<MethodSignature> entryMethods) The constructor of the graph based call graph.protected
GraphBasedCallGraph
(org.jgrapht.graph.DirectedPseudograph<GraphBasedCallGraph.Vertex, CallGraph.Call> graph, Map<MethodSignature, GraphBasedCallGraph.Vertex> signatureToVertex, List<MethodSignature> entryMethods) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addCall
(CallGraph.Call call) This method enables to add calls that are edges in the call graph.void
addCall
(MethodSignature sourceMethod, MethodSignature targetMethod, InvokableStmt invokableStmt) This method enables to add calls that are edges in the call graph.void
addMethod
(MethodSignature calledMethod) This method enables to add method that are nodes in the call graph.protected void
addMethod
(MethodSignature calledMethod, GraphBasedCallGraph.Vertex vertex) int
This method counts every edge in the call graph.callsFrom
(MethodSignature sourceMethod) This method returns all method signatures that are called by a given method signature.callSourcesTo
(MethodSignature targetMethod) This method returns all method signatures that call a given method signature.callsTo
(MethodSignature targetMethod) This method returns all method signatures that call a given method signature.callTargetsFrom
(MethodSignature sourceMethod) This method returns all method signatures that are called by a given method signature.boolean
containsCall
(CallGraph.Call call) This method checks if an edge is contained in the call graph.boolean
containsCall
(MethodSignature sourceMethod, MethodSignature targetMethod, InvokableStmt invokableStmt) This method checks if an edge is contained in the call graph.boolean
containsMethod
(MethodSignature method) This method checks if a given method signature is a node in the call graph.copy()
This method copies a call graph.This method compares the difference between the current call graph and call graph passed into the argument.protected CallGraph.Call
edgeOf
(MethodSignature source, MethodSignature target, InvokableStmt invokableStmt) it returns the edge of the graph that is described by the given source, target, stmt in the call graph.This method converts the call graph object into dot format and write it to a string file.This method returns all entry methods of the call graphThis method returns method signatures in the call graph.protected String
This returns the string that is used in the toString Method to define the called methodsprotected String
This returns the string that is used in the toString Method to define the methods that call a specific methodprotected String
toDotEdge
(CallGraph.Call call) exports a call of the call graph to an edge in a dot filetoString()
This method exports the call graph in a human-readable string.protected GraphBasedCallGraph.Vertex
vertexOf
(MethodSignature method) it returns the vertex of the graph that describes the given method signature in the call graph.
-
Constructor Details
-
GraphBasedCallGraph
The constructor of the graph based call graph. it initializes the call graph object. -
GraphBasedCallGraph
protected GraphBasedCallGraph(@Nonnull org.jgrapht.graph.DirectedPseudograph<GraphBasedCallGraph.Vertex, CallGraph.Call> graph, @Nonnull Map<MethodSignature, GraphBasedCallGraph.Vertex> signatureToVertex, @Nonnull List<MethodSignature> entryMethods)
-
-
Method Details
-
addMethod
Description copied from interface:MutableCallGraph
This method enables to add method that are nodes in the call graph.- Specified by:
addMethod
in interfaceMutableCallGraph
- Parameters:
calledMethod
- the method that will be added to the call graph.
-
addMethod
-
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 interfaceMutableCallGraph
- 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
Description copied from interface:MutableCallGraph
This method enables to add calls that are edges in the call graph.- Specified by:
addCall
in interfaceMutableCallGraph
- Parameters:
call
- this parameter defines the call that is transformed to the edge in the call graph.
-
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 interfaceCallGraph
- Returns:
- a set containing all method signatures in the call graph.
-
callTargetsFrom
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 interfaceCallGraph
- 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
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 interfaceCallGraph
- 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
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 -
callsTo
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 -
containsMethod
Description copied from interface:CallGraph
This method checks if a given method signature is a node in the call graph.- Specified by:
containsMethod
in interfaceCallGraph
- 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 interfaceCallGraph
- Parameters:
sourceMethod
- it defines the source node in the call graphtargetMethod
- it defines the target node in the call graphinvokableStmt
- 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
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 interfaceCallGraph
- 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. -
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 interfaceCallGraph
-
toDotEdge
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
Description copied from interface:CallGraph
This method copies a 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. -
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 methodtarget
- the signature of the target methodinvokableStmt
- the stmt causing the call- Returns:
- the found edge in an optional or otherwise an empty optional
-
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 -
printCallingMethods
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
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
Description copied from interface:CallGraph
This method returns all entry methods of the call graph- Specified by:
getEntryMethods
in interfaceCallGraph
- Returns:
- a list of method signatures of entry points of the call graph
-