Class ClassResolver
- java.lang.Object
-
- com.tonic.analysis.execution.resolve.ClassResolver
-
public class ClassResolver extends Object
Resolver of classes, methods, and fields against a class pool and its hierarchy, with memoized lookups.
-
-
Constructor Summary
Constructors Constructor Description ClassResolver(ClassPool classPool)Creates a resolver that builds its own hierarchy from the pool.ClassResolver(ClassPool classPool, ClassHierarchy hierarchy)Creates a resolver using a prebuilt hierarchy.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ClassPoolgetClassPool()ClassHierarchygetHierarchy()List<String>getInterfaces(String className)Lists the directly implemented interfaces of a class known to the hierarchy.StringgetSuperclass(String className)Looks up the superclass of a pooled class.booleanhasField(String className, String fieldName, String descriptor)Tests whether a pooled class directly declares a matching field.voidinvalidateCache()Clears all memoized resolution results.booleanisAssignableFrom(String targetType, String sourceType)Tests reference assignability, handling Object, covariant arrays, and the class hierarchy.voidregisterClass(ClassFile classFile)Adds a class file to the pool.ClassFileresolveClass(String className)Looks up a class in the pool, caching the result.ResolvedFieldresolveField(String owner, String name, String descriptor)Resolves a field by searching the owner, then its superclasses, then inherited interfaces.ResolvedMethodresolveInterfaceMethod(String interfaceName, String name, String desc)Resolves an interface method, searching the interface then its superinterfaces.ResolvedMethodresolveMethod(String owner, String name, String descriptor)Resolves a method by searching the owner, then its superclasses, then inherited interfaces.ResolvedMethodresolveSpecialMethod(String owner, String name, String desc)Resolves a method declared directly on the named owner for invokespecial dispatch.ResolvedMethodresolveVirtualMethod(String type, String name, String desc)Resolves a concrete implementation for virtual dispatch, skipping abstract methods.booleanusesCompactStrings()Detects compact strings by probing the pooled String class for its coder field.
-
-
-
Constructor Detail
-
ClassResolver
public ClassResolver(ClassPool classPool)
Creates a resolver that builds its own hierarchy from the pool.- Parameters:
classPool- the pool to resolve against
-
ClassResolver
public ClassResolver(ClassPool classPool, ClassHierarchy hierarchy)
Creates a resolver using a prebuilt hierarchy.- Parameters:
classPool- the pool to resolve againsthierarchy- the hierarchy to consult for supertype walks
-
-
Method Detail
-
getClassPool
public ClassPool getClassPool()
- Returns:
- the class pool
-
getHierarchy
public ClassHierarchy getHierarchy()
- Returns:
- the hierarchy
-
resolveClass
public ClassFile resolveClass(String className)
Looks up a class in the pool, caching the result.- Parameters:
className- internal name of the class- Returns:
- the resolved class file
- Throws:
ResolutionException- if the class is not in the pool
-
registerClass
public void registerClass(ClassFile classFile)
Adds a class file to the pool.- Parameters:
classFile- the class to register
-
resolveMethod
public ResolvedMethod resolveMethod(String owner, String name, String descriptor)
Resolves a method by searching the owner, then its superclasses, then inherited interfaces.- Parameters:
owner- internal name of the class named in the referencename- method namedescriptor- method descriptor- Returns:
- the resolved method with its invoke kind
- Throws:
ResolutionException- if the owner or the method cannot be found
-
resolveVirtualMethod
public ResolvedMethod resolveVirtualMethod(String type, String name, String desc)
Resolves a concrete implementation for virtual dispatch, skipping abstract methods.- Parameters:
type- internal name of the receiver's runtime classname- method namedesc- method descriptor- Returns:
- the resolved concrete method
- Throws:
ResolutionException- if no concrete implementation exists
-
resolveInterfaceMethod
public ResolvedMethod resolveInterfaceMethod(String interfaceName, String name, String desc)
Resolves an interface method, searching the interface then its superinterfaces.- Parameters:
interfaceName- internal name of the interfacename- method namedesc- method descriptor- Returns:
- the resolved method with INTERFACE invoke kind
- Throws:
ResolutionException- if the interface or the method cannot be found
-
resolveSpecialMethod
public ResolvedMethod resolveSpecialMethod(String owner, String name, String desc)
Resolves a method declared directly on the named owner for invokespecial dispatch.- Parameters:
owner- internal name of the declaring classname- method namedesc- method descriptor- Returns:
- the resolved method with SPECIAL invoke kind
- Throws:
ResolutionException- if the owner or the method cannot be found
-
resolveField
public ResolvedField resolveField(String owner, String name, String descriptor)
Resolves a field by searching the owner, then its superclasses, then inherited interfaces.- Parameters:
owner- internal name of the class named in the referencename- field namedescriptor- field descriptor- Returns:
- the resolved field with its declaring class
- Throws:
ResolutionException- if the owner or the field cannot be found
-
isAssignableFrom
public boolean isAssignableFrom(String targetType, String sourceType)
Tests reference assignability, handling Object, covariant arrays, and the class hierarchy.- Parameters:
targetType- internal name or array descriptor of the assignment targetsourceType- internal name or array descriptor of the value being assigned- Returns:
- true if a value of the source type can be assigned to the target type
-
getSuperclass
public String getSuperclass(String className)
Looks up the superclass of a pooled class.- Parameters:
className- internal name of the class- Returns:
- the superclass internal name, or null if the class is not pooled
-
getInterfaces
public List<String> getInterfaces(String className)
Lists the directly implemented interfaces of a class known to the hierarchy.- Parameters:
className- internal name of the class- Returns:
- the interface names, empty if the class is unknown
-
invalidateCache
public void invalidateCache()
Clears all memoized resolution results.
-
hasField
public boolean hasField(String className, String fieldName, String descriptor)
Tests whether a pooled class directly declares a matching field.- Parameters:
className- internal name of the classfieldName- field namedescriptor- field descriptor- Returns:
- true if the class is pooled and declares the field
-
usesCompactStrings
public boolean usesCompactStrings()
Detects compact strings by probing the pooled String class for its coder field.- Returns:
- true if java/lang/String declares a byte coder field
-
-