Package com.tonic.analysis.cpg
Class CPGIndex
- java.lang.Object
-
- com.tonic.analysis.cpg.CPGIndex
-
public class CPGIndex extends Object
Secondary lookup structure over CPG nodes, keyed by node type, method signature, call target, instruction class, and property key/value pairs.
-
-
Constructor Summary
Constructors Constructor Description CPGIndex()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Empties every index.Set<MethodNode>getAllMethods()Set<CPGNode>getByProperty(String key, Object value)Looks up nodes carrying a property with the given key and value.Set<CPGNode>getByType(CPGNodeType type)Looks up all nodes of a given node type.Set<CallSiteNode>getCallsTo(String owner, String name)Looks up call sites targeting a method name regardless of descriptor.Set<CallSiteNode>getCallsTo(String owner, String name, String descriptor)Looks up call sites targeting an exact method signature.Set<InstructionNode>getInstructionsOfType(Class<? extends IRInstruction> type)Looks up instruction nodes wrapping a specific IR instruction class.MethodNodegetMethod(String owner, String name, String descriptor)Looks up a method node by its exact signature.intgetMethodCount()intgetNodeCount()voidindex(CPGNode node)Adds a node to every applicable index.voidreindex(CPGNode node)Removes and re-adds a node, refreshing stale index entries.voidremove(CPGNode node)Removes a node from every applicable index.
-
-
-
Method Detail
-
index
public void index(CPGNode node)
Adds a node to every applicable index.- Parameters:
node- the node to index
-
reindex
public void reindex(CPGNode node)
Removes and re-adds a node, refreshing stale index entries.- Parameters:
node- the node to reindex
-
remove
public void remove(CPGNode node)
Removes a node from every applicable index.- Parameters:
node- the node to remove
-
getByType
public Set<CPGNode> getByType(CPGNodeType type)
Looks up all nodes of a given node type.- Parameters:
type- the node type- Returns:
- the indexed nodes, or an empty set
-
getMethod
public MethodNode getMethod(String owner, String name, String descriptor)
Looks up a method node by its exact signature.- Parameters:
owner- the declaring class internal namename- the method namedescriptor- the method descriptor- Returns:
- the method node, or null if not indexed
-
getAllMethods
public Set<MethodNode> getAllMethods()
- Returns:
- a copy of all indexed method nodes
-
getCallsTo
public Set<CallSiteNode> getCallsTo(String owner, String name, String descriptor)
Looks up call sites targeting an exact method signature.- Parameters:
owner- the target class internal namename- the target method namedescriptor- the target method descriptor- Returns:
- the matching call sites, or an empty set
-
getCallsTo
public Set<CallSiteNode> getCallsTo(String owner, String name)
Looks up call sites targeting a method name regardless of descriptor.- Parameters:
owner- the target class internal namename- the target method name- Returns:
- the matching call sites across all overloads
-
getInstructionsOfType
public Set<InstructionNode> getInstructionsOfType(Class<? extends IRInstruction> type)
Looks up instruction nodes wrapping a specific IR instruction class.- Parameters:
type- the IR instruction class- Returns:
- the matching instruction nodes, or an empty set
-
getByProperty
public Set<CPGNode> getByProperty(String key, Object value)
Looks up nodes carrying a property with the given key and value.- Parameters:
key- the property keyvalue- the property value- Returns:
- the matching nodes, or an empty set
-
getNodeCount
public int getNodeCount()
- Returns:
- the total number of indexed nodes across all node types
-
getMethodCount
public int getMethodCount()
- Returns:
- the number of indexed methods
-
clear
public void clear()
Empties every index.
-
-