Package edu.umd.cs.findbugs.ba.ch
Class Subtypes2
java.lang.Object
edu.umd.cs.findbugs.ba.ch.Subtypes2
Class for performing class hierarchy queries. Does not require
JavaClass objects to be in memory. Instead, uses XClass objects.
- Author:
- David Hovemeyer
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final boolean
static final boolean
static final boolean
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addApplicationClass
(XClass appXClass) Add an application class, and its transitive supertypes, to the inheritance graph.void
Add a class or interface, and its transitive supertypes, to the inheritance graph.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.getGraph()
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.getTransitiveCommonSubtypes
(ClassDescriptor classDescriptor1, ClassDescriptor classDescriptor2) Get the set of common subtypes of the two given classes.Get Collection of all XClass objects (resolved classes) seen so far.boolean
hasKnownSubclasses
(ClassDescriptor classDescriptor) boolean
hasSubtypes
(ClassDescriptor classDescriptor) Determine whether or not the given class has any known subtypes.static boolean
instanceOf
(ClassDescriptor subDescriptor, Class<?> c) static boolean
instanceOf
(ClassDescriptor subDescriptor, String dottedSupertype) static boolean
instanceOf
(String dottedSubtype, String dottedSupertype) static boolean
instanceOf
(org.apache.bcel.classfile.JavaClass subtype, String dottedSupertype) boolean
isApplicationClass
(ClassDescriptor descriptor) static boolean
isCollection
(org.apache.bcel.generic.ReferenceType target) static boolean
isContainer
(org.apache.bcel.generic.ReferenceType target) A collection, a map, or some other containerstatic boolean
isJSP
(org.apache.bcel.classfile.JavaClass javaClass) boolean
isSubtype
(ClassDescriptor subDesc, ClassDescriptor superDesc) 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.boolean
isSubtype0
(ClassDescriptor subDesc, ClassDescriptor superDesc) 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.void
traverseSupertypesDepthFirst
(ClassDescriptor start, SupertypeTraversalVisitor visitor) Starting at the class or interface named by the given ClassDescriptor, traverse the inheritance graph depth first, visiting each class only once.
-
Field Details
-
ENABLE_SUBTYPES2_FOR_COMMON_SUPERCLASS_QUERIES
public static final boolean ENABLE_SUBTYPES2_FOR_COMMON_SUPERCLASS_QUERIES- See Also:
-
DEBUG
public static final boolean DEBUG -
DEBUG_QUERIES
public static final boolean DEBUG_QUERIES
-
-
Constructor Details
-
Subtypes2
public Subtypes2()Constructor.
-
-
Method Details
-
getGraph
- Returns:
- Returns the graph.
-
isCollection
public static boolean isCollection(org.apache.bcel.generic.ReferenceType target) throws ClassNotFoundException - Throws:
ClassNotFoundException
-
isContainer
public static boolean isContainer(org.apache.bcel.generic.ReferenceType target) throws ClassNotFoundException A collection, a map, or some other container- Throws:
ClassNotFoundException
-
isJSP
public static boolean isJSP(org.apache.bcel.classfile.JavaClass javaClass) -
instanceOf
public static boolean instanceOf(@DottedClassName String dottedSubtype, @DottedClassName String dottedSupertype) -
instanceOf
-
instanceOf
public static boolean instanceOf(ClassDescriptor subDescriptor, @DottedClassName String dottedSupertype) -
instanceOf
public static boolean instanceOf(org.apache.bcel.classfile.JavaClass subtype, @DottedClassName String dottedSupertype) -
addApplicationClass
Add an application class, and its transitive supertypes, to the inheritance graph.- Parameters:
appXClass
- application XClass to add to the inheritance graph
-
isApplicationClass
-
addClass
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 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 ReferenceTypepossibleSupertype
- another Reference type- Returns:
- true if
type
is a subtype ofpossibleSupertype
, false if not - Throws:
ClassNotFoundException
- if a missing class prevents a definitive answer
-
isSubtype
public boolean isSubtype(ClassDescriptor subDesc, ClassDescriptor superDesc) throws ClassNotFoundException - Throws:
ClassNotFoundException
-
isSubtype
public boolean isSubtype(ClassDescriptor subDesc, ClassDescriptor... superDesc) throws ClassNotFoundException - Throws:
ClassNotFoundException
-
isSubtype0
public boolean isSubtype0(ClassDescriptor subDesc, ClassDescriptor superDesc) throws ClassNotFoundException - Throws:
ClassNotFoundException
-
isSubtype
public boolean isSubtype(org.apache.bcel.generic.ObjectType type, org.apache.bcel.generic.ObjectType possibleSupertype) throws 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 ReferenceTypepossibleSupertype
- another Reference type- Returns:
- true if
type
is a subtype ofpossibleSupertype
, false if not - Throws:
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 ClassNotFoundException Get the first common superclass of the given reference types. Note that an interface type is never returned unlessa
andb
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 ReferenceTypeb
- another ReferenceType- Returns:
- the first common superclass of
a
andb
- Throws:
ClassNotFoundException
-
getFirstCommonSuperclass
public org.apache.bcel.generic.ObjectType getFirstCommonSuperclass(org.apache.bcel.generic.ObjectType a, org.apache.bcel.generic.ObjectType b) throws ClassNotFoundException Get the first common superclass of the given object types. Note that an interface type is never returned unlessa
andb
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 ObjectTypeb
- another ObjectType- Returns:
- the first common superclass of
a
andb
- Throws:
ClassNotFoundException
-
getSubtypes
public Set<ClassDescriptor> getSubtypes(ClassDescriptor classDescriptor) throws 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:
ClassNotFoundException
-
hasSubtypes
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:
ClassNotFoundException
-
getDirectSubtypes
public Set<ClassDescriptor> getDirectSubtypes(ClassDescriptor classDescriptor) throws 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:
ClassNotFoundException
-
getTransitiveCommonSubtypes
public Set<ClassDescriptor> getTransitiveCommonSubtypes(ClassDescriptor classDescriptor1, ClassDescriptor classDescriptor2) throws ClassNotFoundException Get the set of common subtypes of the two given classes.- Parameters:
classDescriptor1
- a ClassDescriptor naming a classclassDescriptor2
- a ClassDescriptor naming another class- Returns:
- Set containing all common transitive subtypes of the two classes
- Throws:
ClassNotFoundException
-
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 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 startvisitor
- an InheritanceGraphVisitor- Throws:
ClassNotFoundException
- if the start vertex cannot be resolved
-
traverseSupertypesDepthFirst
public void traverseSupertypesDepthFirst(ClassDescriptor start, SupertypeTraversalVisitor visitor) throws ClassNotFoundException Starting at the class or interface named by the given ClassDescriptor, traverse the inheritance graph depth first, visiting each class only once. This is much faster than traversing all paths in certain circumstances.- Parameters:
start
- ClassDescriptor naming the class where the traversal should startvisitor
- an InheritanceGraphVisitor- Throws:
ClassNotFoundException
- if the start vertex cannot be resolved
-
hasKnownSubclasses
- Throws:
ClassNotFoundException
-
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
-