sofya.base
Class MethodSignature

java.lang.Object
  extended by sofya.base.MethodSignature
All Implemented Interfaces:
java.io.Serializable

public class MethodSignature
extends java.lang.Object
implements java.io.Serializable

This class represents a full method signature including class name. It is primarily intended to serve as a consistent key for method lookups in handlers. Various constructors are provided to facilitate convenient creation of instances of this class from several types of BCEL method-related objects.

The equals and hashCode methods of this class are implemented to strictly conform to all contracts. The hash code algorithm is based on the definition found in the Effective Java Programming Language Guide.

Version:
06/22/2006
Author:
Alex Kinneer
See Also:
Serialized Form

Nested Class Summary
static class MethodSignature.NameComparator
          A utility comparator which orders method signatures.
 
Constructor Summary
MethodSignature(org.apache.bcel.generic.InvokeInstruction invoke, org.apache.bcel.generic.ConstantPoolGen cpg)
          Constructs a signature object from a BCEL InvokeInstruction object.
MethodSignature(org.apache.bcel.generic.MethodGen mg)
          Constructs a signature object from a BCEL MethodGen object.
MethodSignature(org.apache.bcel.classfile.Method m, java.lang.String className)
          Constructs a signature object from a BCEL Method object.
MethodSignature(java.lang.String className, MethodSignature signature)
          Constructs a signature object which represents the same method bound to a different class.
MethodSignature(java.lang.String className, java.lang.String methodName, java.lang.String signature)
          Constructs a signature object from explicit signature constituents.
MethodSignature(java.lang.String className, java.lang.String methodName, org.apache.bcel.generic.Type returnType, org.apache.bcel.generic.Type[] argTypes)
          Constructs a signature object from explicit signature constituents.
 
Method Summary
 MethodSignature copy()
          Creates a new method signature object which is a copy of this method signature.
 boolean equals(java.lang.Object obj)
          Tests whether this method signature represents the same method as another method signature.
 java.lang.Class[] getArgumentClasses()
          Gets the method's argument types as an array of java.lang.Class objects.
 org.apache.bcel.generic.Type[] getArgumentTypes()
          Gets the method's argument types.
 java.lang.String getClassName()
          Gets the name of the class implementing the method.
 java.lang.String getMethodName()
          Gets the method's name.
 java.lang.Class getReturnClass()
          Gets the java.lang.Class for the method's return type.
 org.apache.bcel.generic.Type getReturnType()
          Gets the method's return type.
 java.lang.String getTypeSignature()
          Gets the method's JNI-style type signature.
 int hashCode()
          Returns the hash code for this method signature.
 java.lang.String toString()
          Returns the string representation of this method signature.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MethodSignature

public MethodSignature(org.apache.bcel.classfile.Method m,
                       java.lang.String className)
Constructs a signature object from a BCEL Method object.

Parameters:
m - BCEL Method representation of a method.
className - Name of the class implementing the method.

MethodSignature

public MethodSignature(org.apache.bcel.generic.MethodGen mg)
Constructs a signature object from a BCEL MethodGen object.

Parameters:
mg - BCEL MethodGen representation of a method.

MethodSignature

public MethodSignature(org.apache.bcel.generic.InvokeInstruction invoke,
                       org.apache.bcel.generic.ConstantPoolGen cpg)
Constructs a signature object from a BCEL InvokeInstruction object.

Parameters:
invoke - BCEL InvokeInstruction representing a method call.
cpg - Constant pool from the class containing the invoke instruction (BCEL representation).

MethodSignature

public MethodSignature(java.lang.String className,
                       java.lang.String methodName,
                       org.apache.bcel.generic.Type returnType,
                       org.apache.bcel.generic.Type[] argTypes)
Constructs a signature object from explicit signature constituents.

Parameters:
className - Name of the class implementing the method.
methodName - Name of the method.
returnType - Return type of the method.
argTypes - Types of the method's arguments.

MethodSignature

public MethodSignature(java.lang.String className,
                       MethodSignature signature)
Constructs a signature object which represents the same method bound to a different class.

Parameters:
className - Name of the new class which will be associated with the method signature.
signature - Existing signature to be copied to a new class binding.

MethodSignature

public MethodSignature(java.lang.String className,
                       java.lang.String methodName,
                       java.lang.String signature)
Constructs a signature object from explicit signature constituents.

Parameters:
className - Name of the class implementing the method.
methodName - Name of the method.
signature - JNI-style string providing thetype signature of the method.
Method Detail

getClassName

public java.lang.String getClassName()
Gets the name of the class implementing the method.

Returns:
The name of the class that would be used as the basis for dynamic binding of the method.

getMethodName

public java.lang.String getMethodName()
Gets the method's name.

Returns:
The name of the method represented by this signature.

getReturnType

public org.apache.bcel.generic.Type getReturnType()
Gets the method's return type.

Returns:
The return type of the method represented by this signature.

getReturnClass

public java.lang.Class getReturnClass()
                               throws java.lang.ClassNotFoundException
Gets the java.lang.Class for the method's return type.

Returns:
The class object for the return type of the method represented by this signature.
Throws:
java.lang.ClassNotFoundException

getArgumentTypes

public org.apache.bcel.generic.Type[] getArgumentTypes()
Gets the method's argument types.

Returns:
The types of the arguments to the method represented by this signature.

getArgumentClasses

public java.lang.Class[] getArgumentClasses()
                                     throws java.lang.ClassNotFoundException
Gets the method's argument types as an array of java.lang.Class objects.

Returns:
The class objects for the types of the arguments to the method represented by this signature.
Throws:
java.lang.ClassNotFoundException

getTypeSignature

public java.lang.String getTypeSignature()
Gets the method's JNI-style type signature.

Returns:
The JNI-style type signature of the method.

equals

public boolean equals(java.lang.Object obj)
Tests whether this method signature represents the same method as another method signature.

Overrides:
equals in class java.lang.Object
Parameters:
obj - Method signature against which this signature should be tested for equivalence.
Returns:
true if this signature represents the same method as the provided signature; that is, a virtual call would bind to the same method for both signatures. Returns false if the signatures do not represent the same method, or the argument is an instance of any class other than a MethodSignature (this preserves the contract of the equals method).

hashCode

public int hashCode()
Returns the hash code for this method signature.

Overrides:
hashCode in class java.lang.Object
Returns:
The hash code computed from this method signature.

copy

public MethodSignature copy()
Creates a new method signature object which is a copy of this method signature.

Returns:
A completely new method signature object equivalent to this method signature.

toString

public java.lang.String toString()
Returns the string representation of this method signature.

Overrides:
toString in class java.lang.Object
Returns:
A string representation of the signature.