Class CrossLanguageClassHierarchy
java.lang.Object
com.ibm.wala.cast.ipa.cha.CrossLanguageClassHierarchy
- All Implemented Interfaces:
IClassHierarchy
,Iterable<IClass>
This class hierarchy represents a family of disjoint class hierarchies, one for each of a
selection of languages. The implementation creates a separate ClassHierarchy object for each
language, and this overall IClassHierarchy implementation delegates to the appropriate language
class hierarchy based on the language associated with the class loader of the given TypeReference
or IClass object.
Note that, because of this delegating structure and representation of multiple languages, the getRootClass API call does not make sense for this hierarchy. In general, any code that wants to use multiple language must deal with the fact that there is no longer a single root type. Each individual language is still expected to have a root type, however.
- Author:
- Julian Dolby (dolby@us.ibm.com)
-
Method Summary
Modifier and TypeMethodDescriptionboolean
void
Clear 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 HierarchygetImmediateSubclasses
(IClass klass) getImplementors
(TypeReference type) Solely for optimization; return a Collection<TypeReference> representing the subclasses of ErrorSolely for optimization; return a Collection<TypeReference> representing the subclasses ofRuntimeException
getLoader
(ClassLoaderReference loaderRef) int
int
int
getPossibleTargets
(IClass receiverClass, MethodReference ref) Find the possible targets of a call to a method reference where the receiver is of a certain typeFind the possible targets of a call to a method referencegetScope()
boolean
implementsInterface
(IClass c, IClass i) Does c implement i?boolean
isAssignableFrom
(IClass c1, IClass c2) Does an expression c1 x := c2 y typecheck?boolean
isInterface
(TypeReference type) boolean
boolean
isSubclassOf
(IClass c, IClass T) Is c a subclass of T?iterator()
Load a class using one of the loaders specified for this class hierarchystatic CrossLanguageClassHierarchy
make
(AnalysisScope scope, ClassLoaderFactory factory) resolveField
(IClass klass, FieldReference f) resolveMethod
(IClass receiver, 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()
.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Method Details
-
getFactory
- Specified by:
getFactory
in interfaceIClassHierarchy
-
getScope
- Specified by:
getScope
in interfaceIClassHierarchy
-
getLoaders
- Specified by:
getLoaders
in interfaceIClassHierarchy
-
getLoader
- Specified by:
getLoader
in interfaceIClassHierarchy
-
addClass
- Specified by:
addClass
in interfaceIClassHierarchy
- Returns:
- true if the add succeeded; false if it failed for some reason
-
getNumberOfClasses
public int getNumberOfClasses()- Specified by:
getNumberOfClasses
in interfaceIClassHierarchy
- Returns:
- The number of classes present in the class hierarchy.
-
isRootClass
- Specified by:
isRootClass
in interfaceIClassHierarchy
-
getRootClass
- Specified by:
getRootClass
in interfaceIClassHierarchy
-
getNumber
- Specified by:
getNumber
in interfaceIClassHierarchy
-
getPossibleTargets
Description copied from interface:IClassHierarchy
Find the possible targets of a call to a method reference- Specified by:
getPossibleTargets
in interfaceIClassHierarchy
- Parameters:
ref
- method reference- Returns:
- the set of IMethods that this call can resolve to.
-
getPossibleTargets
Description copied from interface:IClassHierarchy
Find the possible targets of a call to a method reference where the receiver is of a certain type- Specified by:
getPossibleTargets
in interfaceIClassHierarchy
- Parameters:
receiverClass
- the class of the receiverref
- method reference- Returns:
- the set of IMethods that this call can resolve to.
-
resolveMethod
Description copied from interface:IClassHierarchy
Return 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:
resolveMethod
in interfaceIClassHierarchy
- Returns:
- IMethod, or null if no appropriate receiver is found.
-
resolveField
- Specified by:
resolveField
in interfaceIClassHierarchy
- Returns:
- the canonical IField that represents a given field , or null if none found
-
resolveField
- Specified by:
resolveField
in interfaceIClassHierarchy
- Returns:
- the canonical IField that represents a given field , or null if none found
-
resolveMethod
Description copied from interface:IClassHierarchy
Return the unique target of an invocation of method on an object of type receiverClass- Specified by:
resolveMethod
in interfaceIClassHierarchy
- Parameters:
receiver
- type of receiver. Note that for Java,receiverClass
must 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
-
lookupClass
Description copied from interface:IClassHierarchy
Load a class using one of the loaders specified for this class hierarchy- Specified by:
lookupClass
in interfaceIClassHierarchy
- Returns:
- null if can't find the class.
-
isInterface
- Specified by:
isInterface
in interfaceIClassHierarchy
-
getLeastCommonSuperclass
- Specified by:
getLeastCommonSuperclass
in interfaceIClassHierarchy
-
getLeastCommonSuperclass
- Specified by:
getLeastCommonSuperclass
in interfaceIClassHierarchy
-
isSubclassOf
Description copied from interface:IClassHierarchy
Is c a subclass of T?- Specified by:
isSubclassOf
in interfaceIClassHierarchy
-
implementsInterface
Description copied from interface:IClassHierarchy
Does c implement i?- Specified by:
implementsInterface
in 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
Description copied from interface:IClassHierarchy
Return set of all subclasses of type in the Class Hierarchy- Specified by:
computeSubClasses
in interfaceIClassHierarchy
-
getJavaLangRuntimeExceptionTypes
Description copied from interface:IClassHierarchy
Solely for optimization; return a Collection<TypeReference> representing the subclasses ofRuntimeException
kind of ugly. a better scheme?
- Specified by:
getJavaLangRuntimeExceptionTypes
in interfaceIClassHierarchy
-
getJavaLangErrorTypes
Description copied from interface:IClassHierarchy
Solely for optimization; return a Collection<TypeReference> representing the subclasses of Errorkind of ugly. a better scheme?
- Specified by:
getJavaLangErrorTypes
in interfaceIClassHierarchy
-
getImplementors
- Specified by:
getImplementors
in interfaceIClassHierarchy
- Parameters:
type
- an interface- Returns:
- Set of IClass that represent implementors of the interface
-
getNumberOfImmediateSubclasses
- Specified by:
getNumberOfImmediateSubclasses
in interfaceIClassHierarchy
- Returns:
- the number of classes that immediately extend klass.
-
getImmediateSubclasses
- Specified by:
getImmediateSubclasses
in interfaceIClassHierarchy
- Returns:
- the classes that immediately extend klass.
-
isAssignableFrom
Description copied from interface:IClassHierarchy
Does an expression c1 x := c2 y typecheck?i.e. is c2 a subtype of c1?
- Specified by:
isAssignableFrom
in interfaceIClassHierarchy
-
iterator
-
make
public static CrossLanguageClassHierarchy make(AnalysisScope scope, ClassLoaderFactory factory) throws ClassHierarchyException - Throws:
ClassHierarchyException
-
getUnresolvedClasses
- Specified by:
getUnresolvedClasses
in interfaceIClassHierarchy
-
clearCaches
public void clearCaches()Description copied from interface:IClassHierarchy
Clear internal caches that may be invalidated by addition of new classes, e.g., a cache of the results ofIClassHierarchy.getPossibleTargets(MethodReference)
.- Specified by:
clearCaches
in interfaceIClassHierarchy
-