com.ibm.wala.ipa.cha
Class ClassHierarchy

java.lang.Object
  extended by com.ibm.wala.ipa.cha.ClassHierarchy
All Implemented Interfaces:
java.lang.Iterable<IClass>

public class ClassHierarchy
extends java.lang.Object
implements java.lang.Iterable<IClass>

Simple implementation of a class hierarchy


Constructor Summary
protected ClassHierarchy(AnalysisScope scope, ClassLoaderFactory factory, WarningSet warnings, org.eclipse.core.runtime.IProgressMonitor monitor)
           
 
Method Summary
 boolean addClass(IClass klass)
           
 java.util.Collection<IClass> computeSubClasses(TypeReference type)
          Return set of all subclasses of type in the Class Hierarchy TODO: Tune this implementation.
 ClassLoaderFactory getFactory()
          Returns the factory.
 java.util.Collection<IClass> getImmediateSubclasses(IClass klass)
           
 java.util.Set<IClass> getImplementors(TypeReference type)
          TODO: tune this if necessary
 java.util.Collection<TypeReference> getJavaLangErrorTypes()
          Solely for optimization; return a Collection representing the subclassesOfError kind of ugly.
 IClass getLeastCommonSuperclass(IClass A, IClass B)
          Method getLeastCommonSuperclass.
 TypeReference getLeastCommonSuperclass(TypeReference A, TypeReference B)
           
 IClassLoader getLoader(ClassLoaderReference loaderRef)
           
 IClassLoader[] getLoaders()
           
 int getNumber(IClass c)
           
 int getNumberOfClasses()
           
 int getNumberOfImmediateSubclasses(IClass klass)
           
 java.util.Collection<IMethod> getPossibleTargets(MethodReference ref)
          Find the possible receivers of a call to a method reference
 IClass getRootClass()
           
 AnalysisScope getScope()
           
 boolean implementsInterface(IClass c, TypeReference T)
          Does c implement T?
 boolean isAssignableFrom(IClass c1, IClass c2)
          Does an expression c1 x := c2 y typecheck? i.e.
static boolean isInnerClass(IClass klass)
          Does it look like an inner class? [TODO: is this definitive?]
 boolean isInterface(TypeReference type)
           
 boolean isSubclassOf(IClass c, IClass T)
          Is c a subclass of T?
 boolean isSyntheticClass(IClass c)
           
 java.util.Iterator<IClass> iterator()
           
 IClass lookupClass(TypeReference A)
          Load a class using one of the loaders specified for this class hierarchy
static ClassHierarchy make(AnalysisScope scope, ClassLoaderFactory factory, WarningSet warnings)
           
static ClassHierarchy make(AnalysisScope scope, ClassLoaderFactory factory, WarningSet warnings, org.eclipse.core.runtime.IProgressMonitor monitor)
          temporarily marking this internal to avoid infinite sleep with randomly chosen IProgressMonitor.
static ClassHierarchy make(AnalysisScope scope, ClassLoaderFactory factory, WarningSet warnings, TypeReference rootDescriptor)
           
static ClassHierarchy make(AnalysisScope scope, ClassLoaderFactory factory, WarningSet warnings, TypeReference rootDescriptor, org.eclipse.core.runtime.IProgressMonitor monitor)
          temporarily marking this internal to avoid infinite sleep with randomly chosen IProgressMonitor.
static ClassHierarchy make(AnalysisScope scope, WarningSet warnings)
           
static ClassHierarchy make(AnalysisScope scope, WarningSet warnings, org.eclipse.core.runtime.IProgressMonitor monitor)
          temporarily marking this internal to avoid infinite sleep with randomly chosen IProgressMonitor.
 IField resolveField(FieldReference f)
           
 IField resolveField(IClass klass, FieldReference f)
           
 IMethod resolveMethod(IClass receiverClass, Selector selector)
          Return the unique receiver of an invocation of method on an object of type declaringClass
 IMethod resolveMethod(MethodReference m)
          Return the unique receiver of an invocation of method on an object of type m.getDeclaredClass
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ClassHierarchy

protected ClassHierarchy(AnalysisScope scope,
                         ClassLoaderFactory factory,
                         WarningSet warnings,
                         org.eclipse.core.runtime.IProgressMonitor monitor)
                  throws ClassHierarchyException
Throws:
ClassHierarchyException
Method Detail

addClass

public boolean addClass(IClass klass)
Parameters:
klass -
Returns:
true if the add succeeded; false if it failed for some reason
Throws:
java.lang.IllegalArgumentException - if klass is null

getPossibleTargets

public java.util.Collection<IMethod> getPossibleTargets(MethodReference ref)
Find the possible receivers of a call to a method reference

Parameters:
ref - method reference
Returns:
the set of IMethods that this call can resolve to.
Throws:
java.lang.IllegalArgumentException - if ref is null

resolveMethod

public IMethod resolveMethod(MethodReference m)
Return the unique receiver of an invocation of method on an object of type m.getDeclaredClass

Parameters:
m -
Returns:
IMethod, or null if no appropriate receiver is found.
Throws:
java.lang.IllegalArgumentException - if m is null

resolveField

public IField resolveField(FieldReference f)
Returns:
the canonical FieldReference that represents a given field , or null if none found
Throws:
java.lang.IllegalArgumentException - if f is null

resolveField

public IField resolveField(IClass klass,
                           FieldReference f)
Returns:
the canonical FieldReference that represents a given field , or null if none found
Throws:
java.lang.IllegalArgumentException - if f is null
java.lang.IllegalArgumentException - if klass is null

resolveMethod

public IMethod resolveMethod(IClass receiverClass,
                             Selector selector)
Return the unique receiver of an invocation of method on an object of type declaringClass

Parameters:
receiverClass - type of receiver
selector - method signature
Returns:
Method resolved method abstraction
Throws:
java.lang.IllegalArgumentException - if receiverClass is null

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getFactory

public ClassLoaderFactory getFactory()
Returns the factory.

Returns:
ClassLoaderFactory

getLeastCommonSuperclass

public IClass getLeastCommonSuperclass(IClass A,
                                       IClass B)
Method getLeastCommonSuperclass.

Parameters:
A -
B -
Throws:
java.lang.IllegalArgumentException - if A is null

getLeastCommonSuperclass

public TypeReference getLeastCommonSuperclass(TypeReference A,
                                              TypeReference B)

lookupClass

public IClass lookupClass(TypeReference A)
Load a class using one of the loaders specified for this class hierarchy

Returns:
null if can't find the class.
Throws:
java.lang.IllegalArgumentException - if A is null

isSyntheticClass

public boolean isSyntheticClass(IClass c)

isSubclassOf

public boolean isSubclassOf(IClass c,
                            IClass T)
Is c a subclass of T?

Throws:
java.lang.IllegalArgumentException - if c is null

implementsInterface

public boolean implementsInterface(IClass c,
                                   TypeReference T)
Does c implement T?

Parameters:
c -
T -
Returns:
true iff T is an interface and c is a class that implements T,

computeSubClasses

public java.util.Collection<IClass> computeSubClasses(TypeReference type)
Return set of all subclasses of type in the Class Hierarchy TODO: Tune this implementation. Consider caching if necessary.

Returns:
Set of IClasses

getJavaLangErrorTypes

public java.util.Collection<TypeReference> getJavaLangErrorTypes()
Solely for optimization; return a Collection representing the subclassesOfError kind of ugly. a better scheme?


isInterface

public boolean isInterface(TypeReference type)

getImplementors

public java.util.Set<IClass> getImplementors(TypeReference type)
TODO: tune this if necessary

Parameters:
type - an interface
Returns:
Set of IClass that represent implementors of the interface

iterator

public java.util.Iterator<IClass> iterator()
Specified by:
iterator in interface java.lang.Iterable<IClass>
Returns:
Iterator of IClass

getNumberOfClasses

public int getNumberOfClasses()
Returns:
The number of classes present in the class hierarchy.

getLoaders

public IClassLoader[] getLoaders()

getLoader

public IClassLoader getLoader(ClassLoaderReference loaderRef)

getScope

public AnalysisScope getScope()

getNumberOfImmediateSubclasses

public int getNumberOfImmediateSubclasses(IClass klass)
Parameters:
klass -
Returns:
the number of classes that immediately extend klass.

getImmediateSubclasses

public java.util.Collection<IClass> getImmediateSubclasses(IClass klass)
Parameters:
klass -
Returns:
the classes that immediately extend klass.

make

public static ClassHierarchy make(AnalysisScope scope,
                                  WarningSet warnings)
                           throws java.lang.NullPointerException,
                                  ClassHierarchyException
Parameters:
scope -
warnings -
Returns:
a ClassHierarchy object representing the analysis scope
Throws:
ClassHierarchyException
java.lang.NullPointerException - if scope is null

make

public static ClassHierarchy make(AnalysisScope scope,
                                  WarningSet warnings,
                                  org.eclipse.core.runtime.IProgressMonitor monitor)
                           throws ClassHierarchyException
temporarily marking this internal to avoid infinite sleep with randomly chosen IProgressMonitor. TODO: nanny for testgen

Throws:
ClassHierarchyException

make

public static ClassHierarchy make(AnalysisScope scope,
                                  ClassLoaderFactory factory,
                                  WarningSet warnings)
                           throws ClassHierarchyException
Throws:
ClassHierarchyException

make

public static ClassHierarchy make(AnalysisScope scope,
                                  ClassLoaderFactory factory,
                                  WarningSet warnings,
                                  org.eclipse.core.runtime.IProgressMonitor monitor)
                           throws ClassHierarchyException
temporarily marking this internal to avoid infinite sleep with randomly chosen IProgressMonitor. TODO: nanny for testgen

Throws:
ClassHierarchyException

make

public static ClassHierarchy make(AnalysisScope scope,
                                  ClassLoaderFactory factory,
                                  WarningSet warnings,
                                  TypeReference rootDescriptor)
                           throws ClassHierarchyException
Throws:
ClassHierarchyException

make

public static ClassHierarchy make(AnalysisScope scope,
                                  ClassLoaderFactory factory,
                                  WarningSet warnings,
                                  TypeReference rootDescriptor,
                                  org.eclipse.core.runtime.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()

getNumber

public int getNumber(IClass c)

isAssignableFrom

public boolean isAssignableFrom(IClass c1,
                                IClass c2)
Does an expression c1 x := c2 y typecheck? i.e. is c2 a subtype of c1?

Throws:
java.lang.IllegalArgumentException - if c1 is null
java.lang.IllegalArgumentException - if c2 is null

isInnerClass

public static boolean isInnerClass(IClass klass)
                            throws java.lang.NullPointerException
Does it look like an inner class? [TODO: is this definitive?]

Throws:
java.lang.NullPointerException