FindBugs™ 1.3.9

edu.umd.cs.findbugs.ba.ch
Class Subtypes2

java.lang.Object
  extended by edu.umd.cs.findbugs.ba.ch.Subtypes2

@ParametersAreNonnullByDefault
public class Subtypes2
extends java.lang.Object

Class for performing class hierarchy queries. Does not require JavaClass objects to be in memory. Instead, uses XClass objects.

Author:
David Hovemeyer

Field Summary
static boolean DEBUG
           
static boolean DEBUG_QUERIES
           
static boolean ENABLE_SUBTYPES2
           
static boolean ENABLE_SUBTYPES2_FOR_COMMON_SUPERCLASS_QUERIES
           
 
Constructor Summary
Subtypes2()
          Constructor.
 
Method Summary
 void addApplicationClass(XClass appXClass)
          Add an application class, and its transitive supertypes, to the inheritance graph.
 void addClass(XClass xclass)
          Add a class or interface, and its transitive supertypes, to the inheritance graph.
 java.util.Set<ClassDescriptor> getDirectSubtypes(ClassDescriptor classDescriptor)
          Get known subtypes of given class.
 org.apache.bcel.generic.ObjectType getFirstCommonSuperclass(org.apache.bcel.generic.ObjectType a, org.apache.bcel.generic.ObjectType b)
          Get the first common superclass of the given object types.
 org.apache.bcel.generic.ReferenceType getFirstCommonSuperclass(org.apache.bcel.generic.ReferenceType a, org.apache.bcel.generic.ReferenceType b)
          Get the first common superclass of the given reference types.
 InheritanceGraph getGraph()
           
 java.util.Set<ClassDescriptor> getSubtypes(ClassDescriptor classDescriptor)
          Get known subtypes of given class.
 edu.umd.cs.findbugs.ba.ch.Subtypes2.SupertypeQueryResults getSupertypeQueryResults(ClassDescriptor classDescriptor)
          Look up or compute the SupertypeQueryResults for class named by given ClassDescriptor.
 java.util.Set<ClassDescriptor> getTransitiveCommonSubtypes(ClassDescriptor classDescriptor1, ClassDescriptor classDescriptor2)
          Get the set of common subtypes of the two given classes.
 java.util.Collection<XClass> getXClassCollection()
          Get Collection of all XClass objects (resolved classes) seen so far.
 boolean hasSubtypes(ClassDescriptor classDescriptor)
          Determine whether or not the given class has any known subtypes.
static boolean instanceOf(ClassDescriptor subDescriptor, java.lang.String dottedSupertype)
           
static boolean instanceOf(org.apache.bcel.classfile.JavaClass subtype, java.lang.String dottedSupertype)
           
static boolean instanceOf(java.lang.String dottedSubtype, java.lang.String dottedSupertype)
           
 boolean isApplicationClass(ClassDescriptor descriptor)
           
 boolean isSubtype(ClassDescriptor subDesc, ClassDescriptor superDesc)
           
 boolean isSubtype(org.apache.bcel.generic.ObjectType type, org.apache.bcel.generic.ObjectType possibleSupertype)
          Determine whether or not a given ObjectType is a subtype of another.
 boolean isSubtype(org.apache.bcel.generic.ReferenceType type, org.apache.bcel.generic.ReferenceType possibleSupertype)
          Determine whether or not a given ReferenceType is a subtype of another.
 void traverseSupertypes(ClassDescriptor start, InheritanceGraphVisitor visitor)
          Starting at the class or interface named by the given ClassDescriptor, traverse the inheritance graph, exploring all paths from the class or interface to java.lang.Object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ENABLE_SUBTYPES2

public static final boolean ENABLE_SUBTYPES2
See Also:
Constant Field Values

ENABLE_SUBTYPES2_FOR_COMMON_SUPERCLASS_QUERIES

public static final boolean ENABLE_SUBTYPES2_FOR_COMMON_SUPERCLASS_QUERIES
See Also:
Constant Field Values

DEBUG

public static final boolean DEBUG

DEBUG_QUERIES

public static final boolean DEBUG_QUERIES
Constructor Detail

Subtypes2

public Subtypes2()
Constructor.

Method Detail

getGraph

public InheritanceGraph getGraph()
Returns:
Returns the graph.

instanceOf

public static boolean instanceOf(@DottedClassName
                                 java.lang.String dottedSubtype,
                                 @DottedClassName
                                 java.lang.String dottedSupertype)

instanceOf

public static boolean instanceOf(ClassDescriptor subDescriptor,
                                 @DottedClassName
                                 java.lang.String dottedSupertype)

instanceOf

public static boolean instanceOf(org.apache.bcel.classfile.JavaClass subtype,
                                 @DottedClassName
                                 java.lang.String dottedSupertype)

addApplicationClass

public void addApplicationClass(XClass appXClass)
Add an application class, and its transitive supertypes, to the inheritance graph.

Parameters:
appXClass - application XClass to add to the inheritance graph

isApplicationClass

public boolean isApplicationClass(ClassDescriptor descriptor)

addClass

public void addClass(XClass xclass)
Add a class or interface, and its transitive supertypes, to the inheritance graph.

Parameters:
xclass - XClass to add to the inheritance graph

isSubtype

public boolean isSubtype(org.apache.bcel.generic.ReferenceType type,
                         org.apache.bcel.generic.ReferenceType possibleSupertype)
                  throws java.lang.ClassNotFoundException
Determine whether or not a given ReferenceType is a subtype of another. Throws ClassNotFoundException if the question cannot be answered definitively due to a missing class.

Parameters:
type - a ReferenceType
possibleSupertype - another Reference type
Returns:
true if type is a subtype of possibleSupertype, false if not
Throws:
java.lang.ClassNotFoundException - if a missing class prevents a definitive answer

isSubtype

public boolean isSubtype(ClassDescriptor subDesc,
                         ClassDescriptor superDesc)
                  throws java.lang.ClassNotFoundException
Throws:
java.lang.ClassNotFoundException

isSubtype

public boolean isSubtype(org.apache.bcel.generic.ObjectType type,
                         org.apache.bcel.generic.ObjectType possibleSupertype)
                  throws java.lang.ClassNotFoundException
Determine whether or not a given ObjectType is a subtype of another. Throws ClassNotFoundException if the question cannot be answered definitively due to a missing class.

Parameters:
type - a ReferenceType
possibleSupertype - another Reference type
Returns:
true if type is a subtype of possibleSupertype, false if not
Throws:
java.lang.ClassNotFoundException - if a missing class prevents a definitive answer

getFirstCommonSuperclass

public org.apache.bcel.generic.ReferenceType getFirstCommonSuperclass(org.apache.bcel.generic.ReferenceType a,
                                                                      org.apache.bcel.generic.ReferenceType b)
                                                               throws java.lang.ClassNotFoundException
Get the first common superclass of the given reference types. Note that an interface type is never returned unless a and b are the same type. Otherwise, we try to return as accurate a type as possible. This method is used as the meet operator in TypeDataflowAnalysis, and is intended to follow (more or less) the JVM bytecode verifier semantics.

This method should be used in preference to the getFirstCommonSuperclass() method in ReferenceType.

Parameters:
a - a ReferenceType
b - another ReferenceType
Returns:
the first common superclass of a and b
Throws:
java.lang.ClassNotFoundException

getFirstCommonSuperclass

public org.apache.bcel.generic.ObjectType getFirstCommonSuperclass(org.apache.bcel.generic.ObjectType a,
                                                                   org.apache.bcel.generic.ObjectType b)
                                                            throws java.lang.ClassNotFoundException
Get the first common superclass of the given object types. Note that an interface type is never returned unless a and b are the same type. Otherwise, we try to return as accurate a type as possible. This method is used as the meet operator in TypeDataflowAnalysis, and is intended to follow (more or less) the JVM bytecode verifier semantics.

This method should be used in preference to the getFirstCommonSuperclass() method in ReferenceType.

Parameters:
a - an ObjectType
b - another ObjectType
Returns:
the first common superclass of a and b
Throws:
java.lang.ClassNotFoundException

getSubtypes

public java.util.Set<ClassDescriptor> getSubtypes(ClassDescriptor classDescriptor)
                                           throws java.lang.ClassNotFoundException
Get known subtypes of given class. The set returned DOES include the class itself.

Parameters:
classDescriptor - ClassDescriptor naming a class
Returns:
Set of ClassDescriptors which are the known subtypes of the class
Throws:
java.lang.ClassNotFoundException

hasSubtypes

public boolean hasSubtypes(ClassDescriptor classDescriptor)
                    throws java.lang.ClassNotFoundException
Determine whether or not the given class has any known subtypes.

Parameters:
classDescriptor - ClassDescriptor naming a class
Returns:
true if the class has subtypes, false if it has no subtypes
Throws:
java.lang.ClassNotFoundException

getDirectSubtypes

public java.util.Set<ClassDescriptor> getDirectSubtypes(ClassDescriptor classDescriptor)
                                                 throws java.lang.ClassNotFoundException
Get known subtypes of given class.

Parameters:
classDescriptor - ClassDescriptor naming a class
Returns:
Set of ClassDescriptors which are the known subtypes of the class
Throws:
java.lang.ClassNotFoundException

getTransitiveCommonSubtypes

public java.util.Set<ClassDescriptor> getTransitiveCommonSubtypes(ClassDescriptor classDescriptor1,
                                                                  ClassDescriptor classDescriptor2)
                                                           throws java.lang.ClassNotFoundException
Get the set of common subtypes of the two given classes.

Parameters:
classDescriptor1 - a ClassDescriptor naming a class
classDescriptor2 - a ClassDescriptor naming another class
Returns:
Set containing all common transitive subtypes of the two classes
Throws:
java.lang.ClassNotFoundException

getXClassCollection

public java.util.Collection<XClass> getXClassCollection()
Get Collection of all XClass objects (resolved classes) seen so far.

Returns:
Collection of all XClass objects

traverseSupertypes

public void traverseSupertypes(ClassDescriptor start,
                               InheritanceGraphVisitor visitor)
                        throws java.lang.ClassNotFoundException
Starting at the class or interface named by the given ClassDescriptor, traverse the inheritance graph, exploring all paths from the class or interface to java.lang.Object.

Parameters:
start - ClassDescriptor naming the class where the traversal should start
visitor - an InheritanceGraphVisitor
Throws:
java.lang.ClassNotFoundException - if the start vertex cannot be resolved

getSupertypeQueryResults

public edu.umd.cs.findbugs.ba.ch.Subtypes2.SupertypeQueryResults getSupertypeQueryResults(ClassDescriptor classDescriptor)
Look up or compute the SupertypeQueryResults for class named by given ClassDescriptor.

Parameters:
classDescriptor - a ClassDescriptor
Returns:
SupertypeQueryResults for the class named by the ClassDescriptor
Throws:
java.lang.ClassNotFoundException

FindBugs™ 1.3.9

FindBugs™ is licenced under the LGPL. Copyright © 2006 University of Maryland.