dex++ 0.3.1
C++ and C API reference
Loading...
Searching...
No Matches
dex::ClassHierarchy Class Reference

Whole-program inheritance and interface-implementation graph. More...

#include <analysis/class_hierarchy.hpp>

Public Member Functions

 ClassHierarchy ()=default
 
 ClassHierarchy (const ClassHierarchy &)=delete
 
ClassHierarchy & operator= (const ClassHierarchy &)=delete
 
 ClassHierarchy (ClassHierarchy &&)=default
 
ClassHierarchy & operator= (ClassHierarchy &&)=default
 
std::vector< std::string_view > supertypes (std::string_view descriptor) const
 Direct supertypes: at most one superclass plus any directly implemented interfaces, in that order.
 
std::optional< std::string_view > superclass_of (std::string_view descriptor) const
 The direct superclass descriptor, or nullopt when none is recorded — for Object, for descriptors not in the graph, and for unloaded placeholder nodes (the chain is unknown past a framework boundary; the three cases are not distinguished).
 
std::vector< std::string_view > direct_interfaces (std::string_view descriptor) const
 Directly implemented (or, for an interface, directly extended) interface descriptors, in declaration order.
 
std::vector< std::string_view > subclasses (std::string_view descriptor) const
 Direct subclasses: classes whose extends clause names descriptor.
 
std::vector< std::string_view > implementers (std::string_view descriptor) const
 Direct implementers: classes whose implements clause names descriptor.
 
std::vector< std::string_view > all_supertypes (std::string_view descriptor) const
 Transitive supertypes (BFS).
 
std::vector< std::string_view > all_descendants (std::string_view descriptor) const
 Transitive descendants: every class that extends descriptor (directly or transitively) plus every class that implements descriptor (if it's an interface), recursively.
 
bool is_subtype_of (std::string_view sub, std::string_view super) const
 True iff super == sub (reflexive) or super appears in all_supertypes(@p sub).
 
bool is_loaded (std::string_view descriptor) const
 True iff a class with this descriptor is defined in some loaded DEX.
 
bool is_interface (std::string_view descriptor) const
 True iff the descriptor is loaded AND has the Interface access flag.
 
bool empty () const
 

Detailed Description

Whole-program inheritance and interface-implementation graph.

Built lazily on first AnalysisContext::class_hierarchy() access and cached on the underlying impl. Every class descriptor referenced as a superclass or interface is represented, even if the class is not defined in any loaded DEX file (e.g. Ljava/lang/Object;) — those nodes have is_loaded() == false and no direct supertypes recorded, but participate in subtype queries initiated from loaded descendants.

A class defined in more than one loaded DEX file takes its superclass, interfaces and interface flag from its first definition only: the one AnalysisContext::find_class() returns, and the one Android loads.

All query results return std::string_view views into the hierarchy's internal storage; valid for the lifetime of the AnalysisContext.

Move-only: copying would deep-copy the entire descriptor index.

Constructor & Destructor Documentation

◆ ClassHierarchy() [1/3]

dex::ClassHierarchy::ClassHierarchy ( )
default

◆ ClassHierarchy() [2/3]

dex::ClassHierarchy::ClassHierarchy ( const ClassHierarchy &  )
delete

◆ ClassHierarchy() [3/3]

dex::ClassHierarchy::ClassHierarchy ( ClassHierarchy &&  )
default

Member Function Documentation

◆ operator=() [1/2]

ClassHierarchy & dex::ClassHierarchy::operator= ( const ClassHierarchy &  )
delete

◆ operator=() [2/2]

ClassHierarchy & dex::ClassHierarchy::operator= ( ClassHierarchy &&  )
default

◆ supertypes()

std::vector< std::string_view > dex::ClassHierarchy::supertypes ( std::string_view  descriptor) const

Direct supertypes: at most one superclass plus any directly implemented interfaces, in that order.

Empty if descriptor is not in the graph.

◆ superclass_of()

std::optional< std::string_view > dex::ClassHierarchy::superclass_of ( std::string_view  descriptor) const

The direct superclass descriptor, or nullopt when none is recorded — for Object, for descriptors not in the graph, and for unloaded placeholder nodes (the chain is unknown past a framework boundary; the three cases are not distinguished).

The view points into the hierarchy's storage, valid for the AnalysisContext's lifetime.

◆ direct_interfaces()

std::vector< std::string_view > dex::ClassHierarchy::direct_interfaces ( std::string_view  descriptor) const

Directly implemented (or, for an interface, directly extended) interface descriptors, in declaration order.

Empty for unknown or unloaded descriptors.

◆ subclasses()

std::vector< std::string_view > dex::ClassHierarchy::subclasses ( std::string_view  descriptor) const

Direct subclasses: classes whose extends clause names descriptor.

◆ implementers()

std::vector< std::string_view > dex::ClassHierarchy::implementers ( std::string_view  descriptor) const

Direct implementers: classes whose implements clause names descriptor.

Only meaningful when descriptor is an interface.

◆ all_supertypes()

std::vector< std::string_view > dex::ClassHierarchy::all_supertypes ( std::string_view  descriptor) const

Transitive supertypes (BFS).

Includes both class ancestors and all ancestor interfaces. Does NOT include descriptor itself.

◆ all_descendants()

std::vector< std::string_view > dex::ClassHierarchy::all_descendants ( std::string_view  descriptor) const

Transitive descendants: every class that extends descriptor (directly or transitively) plus every class that implements descriptor (if it's an interface), recursively.

Does NOT include descriptor itself.

◆ is_subtype_of()

bool dex::ClassHierarchy::is_subtype_of ( std::string_view  sub,
std::string_view  super 
) const

True iff super == sub (reflexive) or super appears in all_supertypes(@p sub).

Returns false if sub is not in the graph.

◆ is_loaded()

bool dex::ClassHierarchy::is_loaded ( std::string_view  descriptor) const

True iff a class with this descriptor is defined in some loaded DEX.

Descriptor-only nodes (referenced but not loaded) return false.

◆ is_interface()

bool dex::ClassHierarchy::is_interface ( std::string_view  descriptor) const

True iff the descriptor is loaded AND has the Interface access flag.

Returns false for unloaded descriptors (we cannot know without bytecode).

◆ empty()

bool dex::ClassHierarchy::empty ( ) const
inline

The documentation for this class was generated from the following file: