All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class harpoon.ClassFile.HClass

java.lang.Object
   |
   +----harpoon.ClassFile.HClass

public abstract class HClass
extends Object
Instances of the class HClass represent classes and interfaces of a java program. Every array also belongs to a class that is reflected as a HClass object that is shared by all arrays with the same element type and number of dimensions. Finally, the primitive Java types (boolean, byte, char, short, int, long, float, and double) and the keyword void are also represented as HClass objects.

There is no public constructor for the class HClass. HClass objects are created with the forName, forDescriptor and forClass methods of this class.

Version:
$Id: HClass.java,v 1.41 1998/11/18 20:48:49 cananian Exp $
Author:
C. Scott Ananian <cananian@alumni.princeton.edu>
See Also:
ClassFile

Variable Index

 o Boolean
The HClass object representing the primitive type boolean.
 o Byte
The HClass object representing the primitive type byte.
 o Char
The HClass object representing the primitive type char.
 o Double
The HClass object representing the primitive type double.
 o Float
The HClass object representing the primitive type float.
 o Int
The HClass object representing the primitive type int.
 o Long
The HClass object representing the primitive type long.
 o Short
The HClass object representing the primitive type short.
 o Void
The HClass object representing the primitive type void.

Constructor Index

 o HClass()

Method Index

 o forClass(Class)
Returns the HClass object associated with the given java Class object.
 o forDescriptor(String)
Returns the HClass object associated with the ComponentType descriptor given.
 o forName(String)
Returns the HClass object associated with the class with the given string name.
 o getClassInitializer()
Returns the class initializer method, if there is one; otherwise null.
 o getComponentType()
If this class represents an array type, returns the HClass object representing the component type of the array; otherwise returns null.
 o getConstructor(HClass[])
Returns an HConstructor object that reflects the specified declared constructor of the class or interface represented by this HClass object.
 o getConstructors()
Returns an array of HConstructor objects reflecting all the constructors declared by the class represented by the HClass object.
 o getDeclaredField(String)
Returns a HField object that reflects the specified declared field of the class or interface represented by this HClass object.
 o getDeclaredFields()
Returns an array of HField objects reflecting all the fields declared by the class or interface represented by this HClass object.
 o getDeclaredMethod(String, HClass[])
Returns a HMethod object that reflects the specified declared method of the class or interface represented by this HClass object.
 o getDeclaredMethod(String, String)
Returns a HMethod object that reflects the specified declared method of the class or interface represented by this HClass object.
 o getDeclaredMethods()
Returns an array of HMethod objects reflecting all the methods declared by the class or interface represented by this HClass object.
 o getDescriptor()
Returns a ComponentType descriptor for the type represented by this HClass object.
 o getField(String)
Returns a HField object that reflects the specified accessible member field of the class or interface represented by this HClass object.
 o getFields()
Returns an array containing HField objects reflecting all the accessible fields of the class or interface represented by this HClass object.
 o getInterfaces()
Determines the interfaces implemented by the class or interface represented by this object.
 o getMethod(String, HClass[])
Returns an HMethod object that reflects the specified accessible method of the class or interface represented by this HClass object.
 o getMethod(String, String)
Returns an HMethod object that reflects the specified accessible method of the class or interface represented by this HClass object.
 o getMethods()
Returns an array containing HMethod object reflecting all accessible member methods of the class or interface represented by this HClass object, including those declared by the class or interface and those inherited from superclasses and superinterfaces.
 o getModifiers()
Returns the Java language modifiers for this class or interface, encoded in an integer.
 o getName()
Returns the fully-qualified name of the type (class, interface, array, or primitive) represented by this HClass object, as a String.
 o getPackage()
Returns the package name of this HClass.
 o getSourceFile()
Return the name of the source file for this class, or a zero-length string if the information is not available.
 o getSuperclass()
If this object represents any class other than the class Object, then the object that represents the superclass of that class is returned.
 o getWrapper()
If this HClass is a primitive type, return the wrapper class for values of this type.
 o hashCode()
Returns a hashcode value for this HClass.
 o isArray()
If this HClass object represents an array type, returns true, otherwise returns false.
 o isAssignableFrom(HClass)
Determines if the class or interface represented by this HClass object is either the same as, or is a superclass or superinterface of, the class or interface represented by the specified HClass parameter.
 o isInstance(Object)
This method is the dynamic equivalent of the Java language instanceof operator.
 o isInterface()
Determines if the specified HClass object represents an interface type.
 o isPrimitive()
Determines if the specified HClass object represents a primitive Java type.
 o isSuperclassOf(HClass)
Determines if this HClass is a superclass of a given HClass hc.
 o print(PrintWriter)
Prints a formatted representation of this class.
 o toString()
Converts the object to a string.

Variables

 o Boolean
 public static final HClass Boolean
The HClass object representing the primitive type boolean.

 o Byte
 public static final HClass Byte
The HClass object representing the primitive type byte.

 o Short
 public static final HClass Short
The HClass object representing the primitive type short.

 o Int
 public static final HClass Int
The HClass object representing the primitive type int.

 o Long
 public static final HClass Long
The HClass object representing the primitive type long.

 o Float
 public static final HClass Float
The HClass object representing the primitive type float.

 o Double
 public static final HClass Double
The HClass object representing the primitive type double.

 o Char
 public static final HClass Char
The HClass object representing the primitive type char.

 o Void
 public static final HClass Void
The HClass object representing the primitive type void.

Constructors

 o HClass
 public HClass()

Methods

 o forName
 public static HClass forName(String className)
Returns the HClass object associated with the class with the given string name. Given the fully-qualified name for a class or interface, this method attempts to locate and load the class. If it succeeds, returns the HClass object representing the class. If it fails, the method throws a NoClassDefFoundError.

Parameters:
className - the fully qualified name of the desired class.
Returns:
the HClass descriptor for the class with the specified name.
Throws: NoClassDefFoundError
if the class could not be found.
 o forDescriptor
 public static HClass forDescriptor(String descriptor)
Returns the HClass object associated with the ComponentType descriptor given. Throws NoClassDefFoundError if the descriptor references a class that cannot be found. Throws Error if an invalid descriptor is given.

 o forClass
 public static HClass forClass(Class cls)
Returns the HClass object associated with the given java Class object. If (for some reason) the class file cannot be found, the method throws a NoClassDefFoundError.

Returns:
the HClass descriptor for this Class.
Throws: NoClassDefFoundError
if the classfile could not be found.
 o getComponentType
 public HClass getComponentType()
If this class represents an array type, returns the HClass object representing the component type of the array; otherwise returns null.

See Also:
Array
 o getName
 public abstract String getName()
Returns the fully-qualified name of the type (class, interface, array, or primitive) represented by this HClass object, as a String.

Returns:
the fully qualified name of the class or interface represented by this object.
 o getPackage
 public String getPackage()
Returns the package name of this HClass. If this HClass represents a primitive or array type, then returns null. Returns "" (a zero-length string) if this class is not in a package.

 o getDescriptor
 public abstract String getDescriptor()
Returns a ComponentType descriptor for the type represented by this HClass object.

 o getDeclaredField
 public HField getDeclaredField(String name) throws NoSuchFieldError
Returns a HField object that reflects the specified declared field of the class or interface represented by this HClass object. The name parameter is a String that specifies the simple name of the desired field.

Throws: NoSuchFieldError
if a field with the specified name is not found.
See Also:
HField
 o getDeclaredFields
 public abstract HField[] getDeclaredFields()
Returns an array of HField objects reflecting all the fields declared by the class or interface represented by this HClass object. This includes public, protected, default (package) access, and private fields, but excludes inherited fields. Returns an array of length 0 if the class or interface declares no fields, or if this HClass object represents a primitive type.

See Also:
HField
 o getField
 public HField getField(String name) throws NoSuchFieldError
Returns a HField object that reflects the specified accessible member field of the class or interface represented by this HClass object. The name parameter is a String specifying the simple name of the desired field.

The field to be reflected is located by searching all member fields of the class or interface represented by this HClass object (and its superclasses and interfaces) for an accessible field with the specified name.

Throws: NoSuchFieldError
if a field with the specified name is not found.
See Also:
HField
 o getFields
 public HField[] getFields()
Returns an array containing HField objects reflecting all the accessible fields of the class or interface represented by this HClass object. Returns an array of length 0 if the class or interface has no accessible fields, or if it represents an array type or a primitive type.

Specifically, if this HClass object represents a class, returns the accessible fields of this class and of all its superclasses. If this HClass object represents an interface, returns the accessible fields of this interface and of all its superinterfaces. If this HClass object represents an array type or a primitive type, returns an array of length 0.

The implicit length field for array types is not reflected by this method.

See Also:
HField
 o getDeclaredMethod
 public HMethod getDeclaredMethod(String name,
                                  HClass parameterTypes[]) throws NoSuchMethodError
Returns a HMethod object that reflects the specified declared method of the class or interface represented by this HClass object. The name parameter is a String that specifies the simple name of the desired method, and the parameterTypes parameter is an array of HClass objects that identify the method's formal parameter types, in declared order.

Throws: NoSuchMethodError
if a matching method is not found.
See Also:
HMethod
 o getDeclaredMethod
 public HMethod getDeclaredMethod(String name,
                                  String descriptor) throws NoSuchMethodError
Returns a HMethod object that reflects the specified declared method of the class or interface represented by this HClass object. The name parameter is a String that specifies the simple name of the desired method, and descriptor is a string describing the parameter types and return value of the method.

Throws: NoSuchMethodError
if a matching method is not found.
See Also:
getDescriptor
 o getDeclaredMethods
 public abstract HMethod[] getDeclaredMethods()
Returns an array of HMethod objects reflecting all the methods declared by the class or interface represented by this HClass object. This includes public, protected, default (package) access, and private methods, but excludes inherited methods. Returns an array of length 0 if the class or interface declares no methods, or if this HClass object represents a primitive type.

Constructors are included.

See Also:
HMethod
 o getMethod
 public HMethod getMethod(String name,
                          HClass parameterTypes[]) throws NoSuchMethodError
Returns an HMethod object that reflects the specified accessible method of the class or interface represented by this HClass object. The name parameter is a string specifying the simple name of the desired method, and the parameterTypes parameter is an array of HClass objects that identify the method's formal parameter types, in declared order.

The method to reflect is located by searching all the member methods of the class or interface represented by this HClass object for an accessible method with the specified name and exactly the same formal parameter types.

Throws: NoSuchMethodError
if a matching method is not found.
See Also:
"The
 o getMethod
 public HMethod getMethod(String name,
                          String descriptor) throws NoSuchMethodError
Returns an HMethod object that reflects the specified accessible method of the class or interface represented by this HClass object. The name parameter is a string specifying the simple name of the desired method, and the descriptor is a string describing the parameter types and return value of the method.

The method is located by searching all the member methods of the class or interface represented by this HClass object for an accessible method with the specified name and exactly the same descriptor.

Throws: NoSuchMethodError
if a matching method is not found.
See Also:
getDescriptor
 o getMethods
 public HMethod[] getMethods()
Returns an array containing HMethod object reflecting all accessible member methods of the class or interface represented by this HClass object, including those declared by the class or interface and those inherited from superclasses and superinterfaces. Returns an array of length 0 if the class or interface has no public member methods, or if the HClass corresponds to a primitive type or array type.

Constructors are included.

See Also:
"The
 o getConstructor
 public HConstructor getConstructor(HClass parameterTypes[]) throws NoSuchMethodError
Returns an HConstructor object that reflects the specified declared constructor of the class or interface represented by this HClass object. The parameterTypes parameter is an array of HClass objects that identify the constructor's formal parameter types, in declared order.

Throws: NoSuchMethodError
if a matching method is not found.
 o getConstructors
 public HConstructor[] getConstructors()
Returns an array of HConstructor objects reflecting all the constructors declared by the class represented by the HClass object. These are public, protected, default (package) access, and private constructors. Returns an array of length 0 if this HClass object represents an interface or a primitive type.

See Also:
"The
 o getClassInitializer
 public HMethod getClassInitializer()
Returns the class initializer method, if there is one; otherwise null.

See Also:
"The
 o getModifiers
 public abstract int getModifiers()
Returns the Java language modifiers for this class or interface, encoded in an integer. The modifiers consist of the Java Virtual Machine's constants for public, protected, private, final, and interface; they should be decoded using the methods of class Modifier.

See Also:
Modifier
 o getSuperclass
 public abstract HClass getSuperclass()
If this object represents any class other than the class Object, then the object that represents the superclass of that class is returned.

If this object is the one that represents the class Object or this object represents an interface, null is returned.

Returns:
the superclass of the class represented by this object.
 o getInterfaces
 public abstract HClass[] getInterfaces()
Determines the interfaces implemented by the class or interface represented by this object.

If this object represents a class, the return value is an array containing objects representing all interfaces implemented by the class. The order of the interface objects in the array corresponds to the order of the interface names in the implements clause of the declaration of the class represented by this object.

If the object represents an interface, the array contains objects representing all interfaces extended by the interface. The order of the interface objects in the array corresponds to the order of the interface names in the extends clause of the declaration of the interface represented by this object.

If the class or interface implements no interfaces, the method returns an array of length 0.

Returns:
an array of interfaces implemented by this class.
 o getSourceFile
 public String getSourceFile()
Return the name of the source file for this class, or a zero-length string if the information is not available.

See Also:
AttributeSourceFile
 o getWrapper
 public HClass getWrapper()
If this HClass is a primitive type, return the wrapper class for values of this type. For example:

HClass.forDescriptor("I").getWrapper()

will return HClass.forName("java.lang.Integer"). Calling getWrapper with a non-primitive HClass will return the value null.

 o isArray
 public boolean isArray()
If this HClass object represents an array type, returns true, otherwise returns false.

 o isInterface
 public boolean isInterface()
Determines if the specified HClass object represents an interface type.

Returns:
true is this object represents an interface; false otherwise.
 o isPrimitive
 public boolean isPrimitive()
Determines if the specified HClass object represents a primitive Java type.

There are nine predefined HClass objects to represent the eight primitive Java types and void.

 o isAssignableFrom
 public boolean isAssignableFrom(HClass cls)
Determines if the class or interface represented by this HClass object is either the same as, or is a superclass or superinterface of, the class or interface represented by the specified HClass parameter. It returns true if so, false otherwise. If this HClass object represents a primitive type, returns true if the specified HClass parameter is exactly this HClass object, false otherwise.

Specifically, this method tests whether the type represented by the specified HClass parameter can be converted to the type represented by this HClass object via an identity conversion or via a widening reference conversion.

Throws: NullPointerException
if the specified HClass parameter is null.
See Also:
"The
 o isInstance
 public boolean isInstance(Object obj)
This method is the dynamic equivalent of the Java language instanceof operator. The method returns true if the specified Object argument is non-null and can be cast to the reference type represented by this HClass object without raising a ClassCastException. It returns false otherwise.

Specifically, if this HClass object represents a declared class, return true is the specified Object argument is an instance of the represented class (or any of its subclasses); false otherwise. If this HClass object represents an array class, returns true if the specified Object argument can be converted to an object of the array type by an identity conversion or by a widening reference conversion, false otherwise. If this HClass object represents an interface, returns true if the class or any superclass of the specified Object argument implements this interface, false otherwise. If this HClass object represents a primitive type, returns false.

Parameters:
obj - The object to check.
 o isSuperclassOf
 public boolean isSuperclassOf(HClass hc)
Determines if this HClass is a superclass of a given HClass hc.

Returns:
true if this is a superclass of hc, false otherwise.
 o hashCode
 public int hashCode()
Returns a hashcode value for this HClass. The hashcode is identical to the hashcode for the class descriptor string.

Overrides:
hashCode in class Object
 o toString
 public abstract String toString()
Converts the object to a string. The string representation is the string "class" or "interface" followed by a space and then the fully qualified name of the class. If this HClass object represents a primitive type, returns the name of the primitive type.

Returns:
a string representation of this class object.
Overrides:
toString in class Object
 o print
 public void print(PrintWriter pw)
Prints a formatted representation of this class. Output is pseudo-Java source.


All Packages  Class Hierarchy  This Package  Previous  Next  Index