Class hierarchy and cross-references¶
Inheritance queries and the index of who uses what. See the hierarchy and cross-references guide.
ClassHierarchy
¶
Inheritance over the whole program.
Get it from AnalysisContext.class_hierarchy. It is built on the first read and
kept. Every query takes and returns class descriptors.
A class outside the loaded files is in the hierarchy when a loaded class names it
as its superclass or as an interface. Its own ancestors are not known. A query
about a descriptor the hierarchy has never seen gives an empty list or False.
supertypes
¶
The direct superclass, then the directly implemented interfaces.
implementers
¶
The classes that directly implement this interface.
all_supertypes
¶
Every ancestor: superclasses and interfaces, at any distance. The class itself is not included.
all_descendants
¶
Every class below this one, at any distance, through both extends and
implements. The class itself is not included.
is_subtype_of
¶
True when sub is super itself or has super among its ancestors.
is_interface
¶
True when the class is defined in a loaded file and is an interface. False for a class outside the loaded files, because its kind is not known.
Xrefs
¶
The cross-reference index of the whole program: who uses a method, a field, a string or a type.
Get it from AnalysisContext.xrefs. It is built on the first read and kept.
Every query returns a list of sites. A site has a code_offset and a referrer:
the number of the method whose code contains the instruction. Only instructions
are indexed.
referrers
property
¶
referrers: ReferrerView
The identity of every method that contains at least one indexed instruction.
referrers[site.referrer] is the method a site is in.
referrer_id
¶
referrer_id(referrer: int) -> MethodId
The identity of one referrer. Same as referrers[referrer].
Raises:
| Type | Description |
|---|---|
IndexError
|
The number is out of range. |
method_refs
¶
method_refs(id: MethodId) -> list[MethodXref]
The call sites whose target, as the bytecode names it, is exactly this method.
Virtual dispatch is not applied: a call to Animal.sound is not listed under
Dog.sound. Use the call graph for that.
method_refs_by_name
¶
method_refs_by_name(
name: str,
) -> list[tuple[MethodId, list[MethodXref]]]
The call sites whose target has this method name, in any class and with any prototype.
Each item of the result pairs one called method with its call sites. It is
the quick way to find every call to a name such as exec or loadUrl.
string_refs
¶
string_refs(value: str) -> list[StringXref]
The const-string instructions that load exactly this string. To search by
substring or pattern, filter referenced_strings() first.
referenced_strings
¶
Every distinct string that some const-string instruction loads.
Each call makes a new list of all of them, so keep the result when you need it more than once.
MethodXref
¶
FieldXref
¶
StringXref
¶
TypeXref
¶
TypeUseKind
¶
Bases: Enum
What an instruction does with the type it names.
CONST_CLASS
class-attribute
instance-attribute
¶
const-class: loads the class object, as Foo.class does.
INSTANCE_OF
class-attribute
instance-attribute
¶
instance-of: an instanceof test against the type.
NEW_INSTANCE
class-attribute
instance-attribute
¶
new-instance: creates an object of the type.
NEW_ARRAY
class-attribute
instance-attribute
¶
new-array: creates an array. The descriptor is the array type, such as [I.
FILLED_NEW_ARRAY
class-attribute
instance-attribute
¶
filled-new-array: creates an array and fills it from registers. The descriptor
is the array type.