Package com.ibm.wala.ipa.cha
Class ClassHierarchy
- java.lang.Object
-
- com.ibm.wala.ipa.cha.ClassHierarchy
-
- All Implemented Interfaces:
IClassHierarchy,Iterable<IClass>
public class ClassHierarchy extends Object implements IClassHierarchy
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().
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaddClass(IClass klass)Collection<IClass>computeSubClasses(TypeReference type)Return set of all subclasses of type in the Class Hierarchy TODO: Tune this implementation.ClassLoaderFactorygetFactory()Collection<IClass>getImmediateSubclasses(IClass klass)Set<IClass>getImplementors(TypeReference type)TODO: tune this if necessaryCollection<TypeReference>getJavaLangErrorTypes()Solely for optimization; return a Collectionrepresenting the subclasses of Error kind of ugly. Collection<TypeReference>getJavaLangRuntimeExceptionTypes()Solely for optimization; return a Collectionrepresenting the subclasses of RuntimeException kind of ugly. IClassgetLeastCommonSuperclass(IClass a, IClass b)TypeReferencegetLeastCommonSuperclass(TypeReference a, TypeReference b)IClassLoadergetLoader(ClassLoaderReference loaderRef)IClassLoader[]getLoaders()intgetNumber(IClass c)intgetNumberOfClasses()intgetNumberOfImmediateSubclasses(IClass klass)Set<IMethod>getPossibleTargets(IClass declaredClass, MethodReference ref)Find the possible receivers of a call to a method referenceSet<IMethod>getPossibleTargets(MethodReference ref)Find the possible targets of a call to a method reference.IClassgetRootClass()AnalysisScopegetScope()Set<TypeReference>getUnresolvedClasses()BEGIN Custom change: remember unresolved classesbooleanimplementsInterface(IClass c, IClass i)Does c implement i?booleanisAssignableFrom(IClass c1, IClass c2)Does an expression c1 x := c2 y typecheck? i.e.booleanisInterface(TypeReference type)booleanisRootClass(IClass c)booleanisSubclassOf(IClass c, IClass t)Is c a subclass of T?Iterator<IClass>iterator()IClasslookupClass(TypeReference a)Find a class in this class hierarchy.static ClassHierarchymake(AnalysisScope scope)static ClassHierarchymake(AnalysisScope scope, ClassLoaderFactory factory)static ClassHierarchymake(AnalysisScope scope, ClassLoaderFactory factory, Language language)static ClassHierarchymake(AnalysisScope scope, ClassLoaderFactory factory, Language language, MonitorUtil.IProgressMonitor monitor)temporarily marking this internal to avoid infinite sleep with randomly chosen IProgressMonitor.static ClassHierarchymake(AnalysisScope scope, ClassLoaderFactory factory, MonitorUtil.IProgressMonitor monitor)temporarily marking this internal to avoid infinite sleep with randomly chosen IProgressMonitor.static ClassHierarchymake(AnalysisScope scope, ClassLoaderFactory factory, Set<Language> languages)static ClassHierarchymake(AnalysisScope scope, MonitorUtil.IProgressMonitor monitor)temporarily marking this internal to avoid infinite sleep with randomly chosen IProgressMonitor.IFieldresolveField(IClass klass, FieldReference f)IFieldresolveField(FieldReference f)IMethodresolveMethod(IClass receiverClass, Selector selector)Return the unique target of an invocation of method on an object of type declaringClassIMethodresolveMethod(MethodReference m)Return the unique receiver of an invocation of method on an object of type m.getDeclaredClassStringtoString()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Method Detail
-
addClass
public boolean addClass(IClass klass)
- Specified by:
addClassin interfaceIClassHierarchy- Returns:
- true if the add succeeded; false if it failed for some reason
- Throws:
IllegalArgumentException- if klass is null
-
getPossibleTargets
public Set<IMethod> getPossibleTargets(MethodReference ref)
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
public Set<IMethod> getPossibleTargets(IClass declaredClass, MethodReference ref)
Find the possible receivers of a call to a method reference- Specified by:
getPossibleTargetsin interfaceIClassHierarchy- Parameters:
ref- method referencedeclaredClass- the class of the receiver- Returns:
- the set of IMethods that this call can resolve to.
-
resolveMethod
public IMethod resolveMethod(MethodReference m)
Return the unique receiver of an invocation of method on an object of type m.getDeclaredClass- Specified by:
resolveMethodin interfaceIClassHierarchy- Parameters:
m-- Returns:
- IMethod, or null if no appropriate receiver is found.
- Throws:
IllegalArgumentException- if m is null
-
resolveField
public IField resolveField(FieldReference f)
- 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
public IField resolveField(IClass klass, FieldReference f)
- 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
public IMethod resolveMethod(IClass receiverClass, Selector selector)
Return the unique target of an invocation of method on an object of type declaringClass- Specified by:
resolveMethodin interfaceIClassHierarchy- Parameters:
receiverClass- type of receiverselector- method signature- Returns:
- Method resolved method abstraction
- Throws:
IllegalArgumentException- if receiverClass is null
-
getFactory
public ClassLoaderFactory getFactory()
- Specified by:
getFactoryin interfaceIClassHierarchy
-
getLeastCommonSuperclass
public IClass getLeastCommonSuperclass(IClass a, IClass b)
- Specified by:
getLeastCommonSuperclassin interfaceIClassHierarchy- Throws:
IllegalArgumentException- if A is null
-
getLeastCommonSuperclass
public TypeReference getLeastCommonSuperclass(TypeReference a, TypeReference b)
- Specified by:
getLeastCommonSuperclassin interfaceIClassHierarchy
-
lookupClass
public IClass lookupClass(TypeReference a)
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
public boolean isSubclassOf(IClass c, IClass t)
Is c a subclass of T?- Specified by:
isSubclassOfin interfaceIClassHierarchy- Throws:
IllegalArgumentException- if c is null
-
implementsInterface
public boolean implementsInterface(IClass c, IClass i)
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
public Collection<IClass> computeSubClasses(TypeReference type)
Return set of all subclasses of type in the Class Hierarchy TODO: Tune this implementation. Consider caching if necessary.- Specified by:
computeSubClassesin interfaceIClassHierarchy
-
getJavaLangErrorTypes
public Collection<TypeReference> getJavaLangErrorTypes()
Solely for optimization; return a Collectionrepresenting the subclasses of Error kind of ugly. a better scheme? - Specified by:
getJavaLangErrorTypesin interfaceIClassHierarchy
-
getJavaLangRuntimeExceptionTypes
public Collection<TypeReference> getJavaLangRuntimeExceptionTypes()
Solely for optimization; return a Collectionrepresenting the subclasses of RuntimeException kind of ugly. a better scheme? - Specified by:
getJavaLangRuntimeExceptionTypesin interfaceIClassHierarchy
-
isInterface
public boolean isInterface(TypeReference type)
- Specified by:
isInterfacein interfaceIClassHierarchy
-
getImplementors
public Set<IClass> getImplementors(TypeReference type)
TODO: tune this if necessary- Specified by:
getImplementorsin interfaceIClassHierarchy- Parameters:
type- an interface- Returns:
- Set of IClass that represent implementors of the interface
-
getNumberOfClasses
public int getNumberOfClasses()
- Specified by:
getNumberOfClassesin interfaceIClassHierarchy- Returns:
- The number of classes present in the class hierarchy.
-
getLoaders
public IClassLoader[] getLoaders()
- Specified by:
getLoadersin interfaceIClassHierarchy
-
getLoader
public IClassLoader getLoader(ClassLoaderReference loaderRef)
- Specified by:
getLoaderin interfaceIClassHierarchy
-
getScope
public AnalysisScope getScope()
- Specified by:
getScopein interfaceIClassHierarchy
-
getNumberOfImmediateSubclasses
public int getNumberOfImmediateSubclasses(IClass klass)
- 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
public Collection<IClass> getImmediateSubclasses(IClass klass)
- Specified by:
getImmediateSubclassesin interfaceIClassHierarchy- Parameters:
klass-- 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.
-
make
public static ClassHierarchy make(AnalysisScope scope) throws ClassHierarchyException
- Returns:
- a ClassHierarchy object representing the analysis scope
- Throws:
ClassHierarchyException
-
make
public static ClassHierarchy make(AnalysisScope scope, MonitorUtil.IProgressMonitor monitor) throws ClassHierarchyException
temporarily marking this internal to avoid infinite sleep with randomly chosen IProgressMonitor.- Throws:
ClassHierarchyException
-
make
public static ClassHierarchy make(AnalysisScope scope, ClassLoaderFactory factory) throws ClassHierarchyException
- Throws:
ClassHierarchyException
-
make
public static ClassHierarchy make(AnalysisScope scope, ClassLoaderFactory factory, MonitorUtil.IProgressMonitor monitor) throws ClassHierarchyException
temporarily marking this internal to avoid infinite sleep with randomly chosen IProgressMonitor.- Throws:
ClassHierarchyException
-
make
public static ClassHierarchy make(AnalysisScope scope, ClassLoaderFactory factory, Set<Language> languages) throws ClassHierarchyException
- Throws:
ClassHierarchyException
-
make
public static ClassHierarchy make(AnalysisScope scope, ClassLoaderFactory factory, Language language) throws ClassHierarchyException
- Throws:
ClassHierarchyException
-
make
public static ClassHierarchy make(AnalysisScope scope, ClassLoaderFactory factory, Language language, MonitorUtil.IProgressMonitor monitor) throws ClassHierarchyException
temporarily marking this internal to avoid infinite sleep with randomly chosen IProgressMonitor. TODO: nanny for testgen- Throws:
ClassHierarchyException
-
getRootClass
public IClass getRootClass()
- Specified by:
getRootClassin interfaceIClassHierarchy
-
isRootClass
public boolean isRootClass(IClass c) throws IllegalArgumentException
- Specified by:
isRootClassin interfaceIClassHierarchy- Throws:
IllegalArgumentException
-
getNumber
public int getNumber(IClass c)
- Specified by:
getNumberin interfaceIClassHierarchy
-
isAssignableFrom
public boolean isAssignableFrom(IClass c1, IClass c2)
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
public final Set<TypeReference> getUnresolvedClasses()
Description copied from interface:IClassHierarchyBEGIN Custom change: remember unresolved classes- Specified by:
getUnresolvedClassesin interfaceIClassHierarchy
-
-