Class ClassHierarchy
java.lang.Object
com.ibm.wala.ipa.cha.ClassHierarchy
- All Implemented Interfaces:
IClassHierarchy, Iterable<IClass>
Simple implementation of a class hierarchy.
Note that this class hierarchy implementation is mutable. You can add classes via addClass(). You can add a class even if c.getClassLoader() does not appear in getLoaders().
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionbooleanvoidClear internal caches that may be invalidated by addition of new classes, e.g., a cache of the results ofIClassHierarchy.getPossibleTargets(MethodReference).Return set of all subclasses of type in the Class Hierarchy TODO: Tune this implementation.getImmediateSubclasses(IClass klass) getImplementors(TypeReference type) TODO: tune this if necessarySolely for optimization; return a Collection<TypeReference> representing the subclasses of ErrorSolely for optimization; return a Collection<TypeReference> representing the subclasses of RuntimeExceptiongetLoader(ClassLoaderReference loaderRef) intintintgetPossibleTargets(IClass declaredClass, MethodReference ref) Find the possible receivers of a call to a method referenceFind the possible targets of a call to a method reference.getScope()final Set<TypeReference> booleanimplementsInterface(IClass c, IClass i) Does c implement i?booleanisAssignableFrom(IClass c1, IClass c2) Does an expression c1 x := c2 y typecheck?booleanisInterface(TypeReference type) booleanbooleanisSubclassOf(IClass c, IClass t) Is c a subclass of T?iterator()Find a class in this class hierarchy.resolveField(IClass klass, FieldReference f) resolveMethod(IClass receiverClass, Selector selector) Return the unique target of an invocation of method on an object of type receiverClassReturn the unique receiver of an invocation of method on an object of typem.getDeclaredClass().toString()Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Iterable
forEach, spliterator
-
Method Details
-
clearCaches
public void clearCaches()Description copied from interface:IClassHierarchyClear internal caches that may be invalidated by addition of new classes, e.g., a cache of the results ofIClassHierarchy.getPossibleTargets(MethodReference).- Specified by:
clearCachesin interfaceIClassHierarchy
-
addClass
- Specified by:
addClassin interfaceIClassHierarchy- Returns:
- true if the add succeeded; false if it failed for some reason
- Throws:
IllegalArgumentException- if klass is null
-
getPossibleTargets
Find the possible targets of a call to a method reference. Note that if the reference is to an instance initialization method, we assume the method was called with invokespecial rather than invokevirtual.- Specified by:
getPossibleTargetsin interfaceIClassHierarchy- Parameters:
ref- method reference- Returns:
- the set of IMethods that this call can resolve to.
- Throws:
IllegalArgumentException- if ref is null
-
getPossibleTargets
Find the possible receivers of a call to a method reference- Specified by:
getPossibleTargetsin interfaceIClassHierarchy- Parameters:
declaredClass- the class of the receiverref- method reference- Returns:
- the set of IMethods that this call can resolve to.
-
resolveMethod
Description copied from interface:IClassHierarchyReturn the unique receiver of an invocation of method on an object of typem.getDeclaredClass(). Note that for Java,m.getDeclaredClass()must represent a class, not an interface. This method does not work for finding inherited methods in interfaces.- Specified by:
resolveMethodin interfaceIClassHierarchy- Returns:
- IMethod, or null if no appropriate receiver is found.
-
resolveField
- Specified by:
resolveFieldin interfaceIClassHierarchy- Returns:
- the canonical IField that represents a given field , or null if none found
- Throws:
IllegalArgumentException- if f is null
-
resolveField
- Specified by:
resolveFieldin interfaceIClassHierarchy- Returns:
- the canonical IField that represents a given field , or null if none found
- Throws:
IllegalArgumentException- if f is nullIllegalArgumentException- if klass is null
-
resolveMethod
Description copied from interface:IClassHierarchyReturn the unique target of an invocation of method on an object of type receiverClass- Specified by:
resolveMethodin interfaceIClassHierarchy- Parameters:
receiverClass- type of receiver. Note that for Java,receiverClassmust represent a class, not an interface. This method does not work for finding inherited methods in interfaces.selector- method signature- Returns:
- Method resolved method abstraction
-
toString
-
getFactory
- Specified by:
getFactoryin interfaceIClassHierarchy
-
getLeastCommonSuperclass
- Specified by:
getLeastCommonSuperclassin interfaceIClassHierarchy- Throws:
IllegalArgumentException- if A is null
-
getLeastCommonSuperclass
- Specified by:
getLeastCommonSuperclassin interfaceIClassHierarchy
-
lookupClass
Find a class in this class hierarchy.- Specified by:
lookupClassin interfaceIClassHierarchy- Returns:
- the
IClassfor a if found; null if can't find the class. - Throws:
IllegalArgumentException- if A is null
-
isSubclassOf
Is c a subclass of T?- Specified by:
isSubclassOfin interfaceIClassHierarchy- Throws:
IllegalArgumentException- if c is null
-
implementsInterface
Does c implement i?- Specified by:
implementsInterfacein interfaceIClassHierarchy- Returns:
- true iff i is an interface and c is a class that implements i, or c is an interface that extends i.
-
computeSubClasses
Return set of all subclasses of type in the Class Hierarchy TODO: Tune this implementation. Consider caching if necessary.- Specified by:
computeSubClassesin interfaceIClassHierarchy
-
getJavaLangErrorTypes
Solely for optimization; return a Collection<TypeReference> representing the subclasses of Errorkind of ugly. a better scheme?
- Specified by:
getJavaLangErrorTypesin interfaceIClassHierarchy
-
getJavaLangRuntimeExceptionTypes
Solely for optimization; return a Collection<TypeReference> representing the subclasses of RuntimeExceptionkind of ugly. a better scheme?
- Specified by:
getJavaLangRuntimeExceptionTypesin interfaceIClassHierarchy
-
isInterface
- Specified by:
isInterfacein interfaceIClassHierarchy
-
getImplementors
TODO: tune this if necessary- Specified by:
getImplementorsin interfaceIClassHierarchy- Parameters:
type- an interface- Returns:
- Set of IClass that represent implementors of the interface
-
iterator
-
getNumberOfClasses
public int getNumberOfClasses()- Specified by:
getNumberOfClassesin interfaceIClassHierarchy- Returns:
- The number of classes present in the class hierarchy.
-
getLoaders
- Specified by:
getLoadersin interfaceIClassHierarchy
-
getLoader
- Specified by:
getLoaderin interfaceIClassHierarchy
-
getScope
- Specified by:
getScopein interfaceIClassHierarchy
-
getNumberOfImmediateSubclasses
- Specified by:
getNumberOfImmediateSubclassesin interfaceIClassHierarchy- Returns:
- the number of classes that immediately extend klass. if klass is an array class A[][]...[], we return number of immediate subclasses of A. If A is primitive, we return 0.
-
getImmediateSubclasses
- Specified by:
getImmediateSubclassesin interfaceIClassHierarchy- Returns:
- the classes that immediately extend klass. if klass is an array class A[][]...[], we return array classes B[][]...[] (same dimensionality) where B is an immediate subclass of A. If A is primitive, we return the empty set.
-
getRootClass
- Specified by:
getRootClassin interfaceIClassHierarchy
-
isRootClass
- Specified by:
isRootClassin interfaceIClassHierarchy- Throws:
IllegalArgumentException
-
getNumber
- Specified by:
getNumberin interfaceIClassHierarchy
-
isAssignableFrom
Does an expression c1 x := c2 y typecheck?i.e. is c2 a subtype of c1?
- Specified by:
isAssignableFromin interfaceIClassHierarchy- Throws:
IllegalArgumentException- if c1 is nullIllegalArgumentException- if c2 is null
-
getUnresolvedClasses
- Specified by:
getUnresolvedClassesin interfaceIClassHierarchy
-
getSuperClassHandling
-