edu.umd.cs.findbugs.ba
Class Hierarchy

java.lang.Object
  extended by edu.umd.cs.findbugs.ba.Hierarchy

public class Hierarchy
extends java.lang.Object

Facade for class hierarchy queries. These typically access the class hierarchy using the Repository class. Callers should generally expect to handle ClassNotFoundException for when referenced classes can't be found.

Author:
David Hovemeyer

Field Summary
static org.apache.bcel.generic.ObjectType ERROR_TYPE
          Type of java.lang.Error.
static org.apache.bcel.generic.ObjectType EXCEPTION_TYPE
          Type of java.lang.Exception.
static org.apache.bcel.generic.ObjectType RUNTIME_EXCEPTION_TYPE
          Type of java.lang.RuntimeException.
 
Constructor Summary
Hierarchy()
           
 
Method Summary
static org.apache.bcel.generic.ObjectType[] findDeclaredExceptions(org.apache.bcel.generic.InvokeInstruction inv, org.apache.bcel.generic.ConstantPoolGen cpg)
          Find the declared exceptions for the method called by given instruction.
static org.apache.bcel.classfile.Method findExactMethod(org.apache.bcel.generic.InvokeInstruction inv, org.apache.bcel.generic.ConstantPoolGen cpg)
          Look up the method referenced by given InvokeInstruction.
static org.apache.bcel.classfile.Field findField(java.lang.String className, java.lang.String fieldName)
          Find a field with given name defined in given class.
static org.apache.bcel.classfile.Method findMethod(org.apache.bcel.classfile.JavaClass[] classList, java.lang.String methodName, java.lang.String methodSig)
          Find a method in given list of classes, searching the classes in order.
static org.apache.bcel.classfile.Method findMethod(org.apache.bcel.classfile.JavaClass javaClass, java.lang.String methodName, java.lang.String methodSig)
          Find a method in given class.
static org.apache.bcel.classfile.Method findPrototypeMethod(org.apache.bcel.generic.InvokeInstruction inv, org.apache.bcel.generic.ConstantPoolGen cpg)
          Get the method which serves as a "prototype" for the given InvokeInstruction.
static XField findXField(org.apache.bcel.generic.FieldInstruction fins, org.apache.bcel.generic.ConstantPoolGen cpg)
          Look up the field referenced by given FieldInstruction, returning it as an XField object.
static XField findXField(java.lang.String className, java.lang.String fieldName, java.lang.String fieldSig)
          Look up a field with given name and signature in given class, returning it as an XField object.
static InnerClassAccess getInnerClassAccess(org.apache.bcel.generic.INVOKESTATIC inv, org.apache.bcel.generic.ConstantPoolGen cpg)
          Get the InnerClassAccess for access method called by given INVOKESTATIC.
static boolean isInnerClassAccess(org.apache.bcel.generic.INVOKESTATIC inv, org.apache.bcel.generic.ConstantPoolGen cpg)
          Determine whether the given INVOKESTATIC instruction is an inner-class field accessor method.
static boolean isMonitorNotify(java.lang.String methodName, java.lang.String methodSig)
          Determine if method whose name and signature is specified is a monitor notify operation.
static boolean isMonitorWait(java.lang.String methodName, java.lang.String methodSig)
          Determine if method whose name and signature is specified is a monitor wait operation.
static boolean isSubtype(org.apache.bcel.generic.ReferenceType t, org.apache.bcel.generic.ReferenceType possibleSupertype)
          Determine if one reference type is a subtype of another.
static boolean isSubtype(java.lang.String clsName, java.lang.String possibleSupertypeClassName)
          Determine whether one class (or reference type) is a subtype of another.
static boolean isUncheckedException(org.apache.bcel.generic.ObjectType type)
          Determine if the given ObjectType refers to an unchecked exception (RuntimeException or Error).
static boolean isUniversalExceptionHandler(org.apache.bcel.generic.ObjectType catchType)
          Determine if the given ObjectType reference represents a universal exception handler.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EXCEPTION_TYPE

public static final org.apache.bcel.generic.ObjectType EXCEPTION_TYPE
Type of java.lang.Exception.


ERROR_TYPE

public static final org.apache.bcel.generic.ObjectType ERROR_TYPE
Type of java.lang.Error.


RUNTIME_EXCEPTION_TYPE

public static final org.apache.bcel.generic.ObjectType RUNTIME_EXCEPTION_TYPE
Type of java.lang.RuntimeException.

Constructor Detail

Hierarchy

public Hierarchy()
Method Detail

isSubtype

public static boolean isSubtype(java.lang.String clsName,
                                java.lang.String possibleSupertypeClassName)
                         throws java.lang.ClassNotFoundException
Determine whether one class (or reference type) is a subtype of another.

Parameters:
clsName - the name of the class or reference type
possibleSupertypeClassName - the name of the possible superclass
Returns:
true if clsName is a subtype of possibleSupertypeClassName, false if not
Throws:
java.lang.ClassNotFoundException

isSubtype

public static boolean isSubtype(org.apache.bcel.generic.ReferenceType t,
                                org.apache.bcel.generic.ReferenceType possibleSupertype)
                         throws java.lang.ClassNotFoundException
Determine if one reference type is a subtype of another.

Parameters:
t - a reference type
possibleSupertype - the possible supertype
Returns:
true if t is a subtype of possibleSupertype, false if not
Throws:
java.lang.ClassNotFoundException

isUniversalExceptionHandler

public static boolean isUniversalExceptionHandler(org.apache.bcel.generic.ObjectType catchType)
Determine if the given ObjectType reference represents a universal exception handler. That is, one that will catch any kind of exception.

Parameters:
catchType - the ObjectType of the exception handler
Returns:
true if catchType is null, or if catchType is java.lang.Throwable

isUncheckedException

public static boolean isUncheckedException(org.apache.bcel.generic.ObjectType type)
                                    throws java.lang.ClassNotFoundException
Determine if the given ObjectType refers to an unchecked exception (RuntimeException or Error).

Throws:
java.lang.ClassNotFoundException

isMonitorWait

public static boolean isMonitorWait(java.lang.String methodName,
                                    java.lang.String methodSig)
Determine if method whose name and signature is specified is a monitor wait operation.

Parameters:
methodName - name of the method
methodSig - signature of the method
Returns:
true if the method is a monitor wait, false if not

isMonitorNotify

public static boolean isMonitorNotify(java.lang.String methodName,
                                      java.lang.String methodSig)
Determine if method whose name and signature is specified is a monitor notify operation.

Parameters:
methodName - name of the method
methodSig - signature of the method
Returns:
true if the method is a monitor notify, false if not

findExactMethod

public static org.apache.bcel.classfile.Method findExactMethod(org.apache.bcel.generic.InvokeInstruction inv,
                                                               org.apache.bcel.generic.ConstantPoolGen cpg)
                                                        throws java.lang.ClassNotFoundException
Look up the method referenced by given InvokeInstruction. This method does not look for implementations in super or subclasses according to the virtual dispatch rules.

Parameters:
inv - the InvokeInstruction
cpg - the ConstantPoolGen used by the class the InvokeInstruction belongs to
Returns:
the Method, or null if no such method is defined in the class
Throws:
java.lang.ClassNotFoundException

findPrototypeMethod

public static org.apache.bcel.classfile.Method findPrototypeMethod(org.apache.bcel.generic.InvokeInstruction inv,
                                                                   org.apache.bcel.generic.ConstantPoolGen cpg)
                                                            throws java.lang.ClassNotFoundException
Get the method which serves as a "prototype" for the given InvokeInstruction. The "prototype" is the method which defines the contract for the invoked method, in particular the declared list of exceptions that the method can throw.

Parameters:
inv - the InvokeInstruction
cpg - the ConstantPoolGen used by the class the InvokeInstruction belongs to
Returns:
the Method, or null if no matching method can be found
Throws:
java.lang.ClassNotFoundException

findDeclaredExceptions

public static org.apache.bcel.generic.ObjectType[] findDeclaredExceptions(org.apache.bcel.generic.InvokeInstruction inv,
                                                                          org.apache.bcel.generic.ConstantPoolGen cpg)
                                                                   throws java.lang.ClassNotFoundException
Find the declared exceptions for the method called by given instruction.

Parameters:
inv - the InvokeInstruction
cpg - the ConstantPoolGen used by the class the InvokeInstruction belongs to
Returns:
array of ObjectTypes of thrown exceptions, or null if we can't find the list of declared exceptions
Throws:
java.lang.ClassNotFoundException

findMethod

public static org.apache.bcel.classfile.Method findMethod(org.apache.bcel.classfile.JavaClass javaClass,
                                                          java.lang.String methodName,
                                                          java.lang.String methodSig)
Find a method in given class.

Parameters:
javaClass - the class
methodName - the name of the method
methodSig - the signature of the method
Returns:
the Method, or null if no such method exists in the class

findMethod

public static org.apache.bcel.classfile.Method findMethod(org.apache.bcel.classfile.JavaClass[] classList,
                                                          java.lang.String methodName,
                                                          java.lang.String methodSig)
Find a method in given list of classes, searching the classes in order.

Parameters:
classList - list of classes in which to search
methodName - the name of the method
methodSig - the signature of the method
Returns:
the Method, or null if no such method exists in the class

findField

public static org.apache.bcel.classfile.Field findField(java.lang.String className,
                                                        java.lang.String fieldName)
                                                 throws java.lang.ClassNotFoundException
Find a field with given name defined in given class.

Parameters:
className - the name of the class
fieldName - the name of the field
Returns:
the Field, or null if no such field could be found
Throws:
java.lang.ClassNotFoundException

findXField

public static XField findXField(java.lang.String className,
                                java.lang.String fieldName,
                                java.lang.String fieldSig)
                         throws java.lang.ClassNotFoundException
Look up a field with given name and signature in given class, returning it as an XField object. If a field can't be found in the immediate class, its superclass is search, and so forth.

Parameters:
className - name of the class through which the field is referenced
fieldName - name of the field
fieldSig - signature of the field
Returns:
an XField object representing the field, or null if no such field could be found
Throws:
java.lang.ClassNotFoundException

findXField

public static XField findXField(org.apache.bcel.generic.FieldInstruction fins,
                                org.apache.bcel.generic.ConstantPoolGen cpg)
                         throws java.lang.ClassNotFoundException
Look up the field referenced by given FieldInstruction, returning it as an XField object.

Parameters:
fins - the FieldInstruction
cpg - the ConstantPoolGen used by the class containing the instruction
Returns:
an XField object representing the field, or null if no such field could be found
Throws:
java.lang.ClassNotFoundException

isInnerClassAccess

public static boolean isInnerClassAccess(org.apache.bcel.generic.INVOKESTATIC inv,
                                         org.apache.bcel.generic.ConstantPoolGen cpg)
Determine whether the given INVOKESTATIC instruction is an inner-class field accessor method.

Parameters:
inv - the INVOKESTATIC instruction
cpg - the ConstantPoolGen for the method
Returns:
true if the instruction is an inner-class field accessor, false if not

getInnerClassAccess

public static InnerClassAccess getInnerClassAccess(org.apache.bcel.generic.INVOKESTATIC inv,
                                                   org.apache.bcel.generic.ConstantPoolGen cpg)
                                            throws java.lang.ClassNotFoundException
Get the InnerClassAccess for access method called by given INVOKESTATIC.

Parameters:
inv - the INVOKESTATIC instruction
cpg - the ConstantPoolGen for the method
Returns:
the InnerClassAccess, or null if the instruction is not an inner-class access
Throws:
java.lang.ClassNotFoundException