com.ibm.wala.ipa.cha
Class ClassHierarchy

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

public class ClassHierarchy
extends java.lang.Object
implements IClassHierarchy

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()
           
 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)
           
 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 isRootClass(IClass c)
           
 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, Language language)
           
static ClassHierarchy make(AnalysisScope scope, ClassLoaderFactory factory, WarningSet warnings, Language language, 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)
Specified by:
addClass in interface IClassHierarchy
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

Specified by:
getPossibleTargets in interface IClassHierarchy
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

Specified by:
resolveMethod in interface IClassHierarchy
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)
Specified by:
resolveField in interface IClassHierarchy
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)
Specified by:
resolveField in interface IClassHierarchy
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

Specified by:
resolveMethod in interface IClassHierarchy
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()
Specified by:
getFactory in interface IClassHierarchy

getLeastCommonSuperclass

public IClass getLeastCommonSuperclass(IClass A,
                                       IClass B)
Specified by:
getLeastCommonSuperclass in interface IClassHierarchy
Throws:
java.lang.IllegalArgumentException - if A is null

getLeastCommonSuperclass

public TypeReference getLeastCommonSuperclass(TypeReference A,
                                              TypeReference B)
Specified by:
getLeastCommonSuperclass in interface IClassHierarchy

lookupClass

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

Specified by:
lookupClass in interface IClassHierarchy
Returns:
null if can't find the class.
Throws:
java.lang.IllegalArgumentException - if A is null

isSyntheticClass

public boolean isSyntheticClass(IClass c)
Specified by:
isSyntheticClass in interface IClassHierarchy

isSubclassOf

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

Specified by:
isSubclassOf in interface IClassHierarchy
Throws:
java.lang.IllegalArgumentException - if c is null

implementsInterface

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

Specified by:
implementsInterface in interface IClassHierarchy
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.

Specified by:
computeSubClasses in interface IClassHierarchy
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?

Specified by:
getJavaLangErrorTypes in interface IClassHierarchy

isInterface

public boolean isInterface(TypeReference type)
Specified by:
isInterface in interface IClassHierarchy

getImplementors

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

Specified by:
getImplementors in interface IClassHierarchy
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()
Specified by:
getNumberOfClasses in interface IClassHierarchy
Returns:
The number of classes present in the class hierarchy.

getLoaders

public IClassLoader[] getLoaders()
Specified by:
getLoaders in interface IClassHierarchy

getLoader

public IClassLoader getLoader(ClassLoaderReference loaderRef)
Specified by:
getLoader in interface IClassHierarchy

getScope

public AnalysisScope getScope()
Specified by:
getScope in interface IClassHierarchy

getNumberOfImmediateSubclasses

public int getNumberOfImmediateSubclasses(IClass klass)
Specified by:
getNumberOfImmediateSubclasses in interface IClassHierarchy
Parameters:
klass -
Returns:
the number of classes that immediately extend klass.

getImmediateSubclasses

public java.util.Collection<IClass> getImmediateSubclasses(IClass klass)
Specified by:
getImmediateSubclasses in interface IClassHierarchy
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,
                                  Language language)
                           throws ClassHierarchyException
Throws:
ClassHierarchyException

make

public static ClassHierarchy make(AnalysisScope scope,
                                  ClassLoaderFactory factory,
                                  WarningSet warnings,
                                  Language language,
                                  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()
Specified by:
getRootClass in interface IClassHierarchy

isRootClass

public boolean isRootClass(IClass c)
Specified by:
isRootClass in interface IClassHierarchy

getNumber

public int getNumber(IClass c)
Specified by:
getNumber in interface IClassHierarchy

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:
isAssignableFrom in interface IClassHierarchy
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