|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectharpoon.ClassFile.HClass
public abstract class HClass
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
Linker
.
A note on mutability: HClass
objects may be
mutable. Of course, this is unpleasant for any attempt to cache
the result of the expensive computations on such objects (e.g.,
getMethod(String,String)
). If you are VERY familiar with
Flex, you can use caching in the periods when HClass
es
are guaranteed not to be mutated. You just have to enter such a
period (we call it immutability epoch) explicitly using
HClass.enterImmutableEpoch()
and end it using HClass.exitImmutableEpoch()
. E.g.,
HClass.enterImmutableEpoch(); Big computation that does not mutate HClass'es; e.g., a computation that calls HClass.getMethod(String, String) a lot: construction of a CallGraphImpl + all possible queries on it. HClass.exitImmutableEpoch();
Knowing that HClass
es
are not mutated in a certain code sequence is actually tricky,
because most of the HCodeFactories
are lazy; a good method is to use a CachingCodeFactory
that has
already computed the code of every method of interest.
ClassFile
,
Class
Field Summary | |
---|---|
static ArrayFactory<HClass> |
arrayFactory
Array factory: returns new HClass[] . |
static HClass |
Boolean
The HClass object representing the primitive type boolean. |
static HClass |
Byte
The HClass object representing the primitive type byte. |
static HClass |
Char
The HClass object representing the primitive type char. |
static HClass |
Double
The HClass object representing the primitive type double. |
static HClass |
Float
The HClass object representing the primitive type float. |
static HClass |
Int
The HClass object representing the primitive type int. |
static HClass |
Long
The HClass object representing the primitive type long. |
static HClass |
Short
The HClass object representing the primitive type short. |
static HClass |
Void
The HClass object representing the primitive type void. |
Method Summary | |
---|---|
int |
compareTo(HClass o)
Compares two HClass es by lexicographic order of their
descriptors. |
static void |
enterImmutableEpoch()
Notifies the HClass implementation that Flex
enters an immutability epoch, i.e., a period of time when no
HClass will be mutated. |
static void |
exitImmutableEpoch()
Notifies the HClass implementation that Flex exits
an immutability epoch (i.e., in the future, Flex may mutate one
or more HClass . |
abstract HInitializer |
getClassInitializer()
Returns the class initializer method, if there is one; otherwise null . |
abstract HClass |
getComponentType()
If this class represents an array type, returns the HClass
object representing the component type of the array; otherwise returns
null. |
abstract HConstructor |
getConstructor(HClass[] parameterTypes)
Returns an HConstructor object that reflects the
specified declared constructor of the class or interface represented
by this HClass object. |
abstract HConstructor[] |
getConstructors()
Returns an array of HConstructor objects reflecting
all the constructors declared by the class represented by the
HClass object. |
abstract HField |
getDeclaredField(String name)
Returns a HField object that reflects the specified
declared field of the class or interface represented by this
HClass object. |
abstract HField[] |
getDeclaredFields()
Returns an array of HField objects reflecting all the
fields declared by the class or interface represented by this
HClass object. |
abstract HMethod |
getDeclaredMethod(String name,
HClass[] parameterTypes)
Returns a HMethod object that reflects the specified
declared method of the class or interface represented by this
HClass object. |
abstract HMethod |
getDeclaredMethod(String name,
String descriptor)
Returns a HMethod object that reflects the specified
declared method of the class or interface represented by this
HClass object. |
abstract HMethod[] |
getDeclaredMethods()
Returns an array of HMethod objects reflecting all the
methods declared by the class or interface represented by this
HClass object. |
abstract String |
getDescriptor()
Returns a ComponentType descriptor for the type represented by this HClass object. |
HField |
getField(String name)
Returns a HField object that reflects the specified
accessible member field of the class or interface represented by this
HClass object. |
HField[] |
getFields()
Returns an array containing HField objects reflecting
all the accessible fields of the class or interface represented by this
HClass object. |
HType[] |
getGenericInterfaces()
Returns the HType s representing the interfaces
implemented by the class or interface represented by this object. |
HType |
getGenericSuperclass()
Returns the HType representing the superclass of the
entity (class, interface, primitive type or void) represented by
this HClass . |
abstract HClass[] |
getInterfaces()
Determines the interfaces implemented by the class or interface represented by this object. |
Linker |
getLinker()
Returns the linker responsible for the resolution of this HClass object. |
HMethod |
getMethod(String name,
HClass[] parameterTypes)
Returns an HMethod object that reflects the specified
accessible method of the class or interface represented by this
HClass object. |
HMethod |
getMethod(String name,
String descriptor)
Returns an HMethod object that reflects the specified
accessible method of the class or interface represented by this
HClass object. |
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. |
abstract int |
getModifiers()
Returns the Java language modifiers for this class or interface, encoded in an integer. |
HClassMutator |
getMutator()
Returns a mutator for this HClass , or null
if this object is immutable. |
abstract String |
getName()
Returns the fully-qualified name of the type (class, interface, array, or primitive) represented by this HClass object,
as a String . |
abstract String |
getPackage()
Returns the package name of this HClass . |
abstract String |
getSourceFile()
Return the name of the source file for this class, or a zero-length string if the information is not available. |
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. |
HClassTypeVariable[] |
getTypeParameters()
Returns an array of HClassTypeVariable objects that
represents the type variables declared by the class or interface
represented by this HClass object, in declaration
order. |
HClass |
getWrapper(Linker l)
If this HClass is a primitive type, return the
wrapper class for values of this type. |
boolean |
hasBeenModified()
Determines whether any part of this HClass has been
modified from its originally loaded state. |
int |
hashCode()
Returns a hashcode value for this HClass. |
abstract boolean |
isArray()
If this HClass object represents an array type,
returns true , otherwise returns false . |
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. |
boolean |
isInstanceOf(HClass hc)
Determines if this HClass is an instance of the given
HClass hc . |
abstract boolean |
isInterface()
Determines if the specified HClass object represents an
interface type. |
abstract boolean |
isPrimitive()
Determines if the specified HClass object represents a
primitive Java type. |
boolean |
isSuperclassOf(HClass hc)
Determines if this HClass is a superclass of a given
HClass hc . |
boolean |
isSuperinterfaceOf(HClass hc)
Determines if this HClass is a superinterface of a given
HClass hc . |
Set<HClass> |
parents()
Return the parents of this HClass . |
void |
print(PrintWriter pw)
Prints a formatted representation of this class. |
String |
toString()
Converts the object to a string. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final HClass Boolean
HClass
object representing the primitive type boolean.
public static final HClass Byte
HClass
object representing the primitive type byte.
public static final HClass Short
HClass
object representing the primitive type short.
public static final HClass Int
HClass
object representing the primitive type int.
public static final HClass Long
HClass
object representing the primitive type long.
public static final HClass Float
HClass
object representing the primitive type float.
public static final HClass Double
HClass
object representing the primitive type double.
public static final HClass Char
HClass
object representing the primitive type char.
public static final HClass Void
HClass
object representing the primitive type void.
public static final ArrayFactory<HClass> arrayFactory
HClass[]
.
Method Detail |
---|
public final Linker getLinker()
HClass
object.
public HClassMutator getMutator()
HClass
, or null
if this object is immutable.
public boolean hasBeenModified()
HClass
has been
modified from its originally loaded state.
public abstract HClass getComponentType()
HClass
object representing the component type of the array; otherwise returns
null.
Array
public abstract String getName()
HClass
object,
as a String
.
public abstract String getPackage()
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.
public abstract String getDescriptor()
HClass
object.
public abstract HField getDeclaredField(String name) throws NoSuchFieldError
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.
NoSuchFieldError
- if a field with the specified name is not found.HField
public abstract HField[] getDeclaredFields()
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.
HField
public final HField getField(String name) throws NoSuchFieldError
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.
NoSuchFieldError
- if a field with the specified name is not found.HField
public HField[] getFields()
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.
HField
public abstract HMethod getDeclaredMethod(String name, HClass[] parameterTypes) throws NoSuchMethodError
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.
NoSuchMethodError
- if a matching method is not found.HMethod
public abstract HMethod getDeclaredMethod(String name, String descriptor) throws NoSuchMethodError
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.
NoSuchMethodError
- if a matching method is not found.HMethod.getDescriptor()
public abstract HMethod[] getDeclaredMethods()
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.
HMethod
public final HMethod getMethod(String name, HClass[] parameterTypes) throws NoSuchMethodError
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.
NoSuchMethodError
- if a matching method is not found.public final HMethod getMethod(String name, String descriptor) throws NoSuchMethodError
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.
NoSuchMethodError
- if a matching method is not found.HMethod.getDescriptor()
public static final void enterImmutableEpoch()
HClass
implementation that Flex
enters an immutability epoch, i.e., a period of time when no
HClass will be mutated. Inside an immutability epoch, expensive
HClass
computations may perform caching. These
caches are invalidated at the end of the current immutability
epoch, so there is danger of reusing caches from an old
epoch.
public static final void exitImmutableEpoch()
HClass
implementation that Flex exits
an immutability epoch (i.e., in the future, Flex may mutate one
or more HClass
.
public HMethod[] getMethods()
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.
public abstract HConstructor getConstructor(HClass[] parameterTypes) throws NoSuchMethodError
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.
NoSuchMethodError
- if a matching method is not found.public abstract HConstructor[] getConstructors()
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.
public abstract HInitializer getClassInitializer()
null
.
public abstract int getModifiers()
Modifier
public abstract HClass getSuperclass()
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.
If this object represents an array, then the HClass
representing java.lang.Object
is returned.
public abstract HClass[] getInterfaces()
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.
NOTE THAT the array returned does NOT contain interfaces
implemented by superclasses. Thus the interface list may
be incomplete. This is pretty bogus behaviour, but it's what
our prototype, java.lang.Class
, does.
public final Set<HClass> parents()
HClass
. The returned
set contains this class'es superclass and the interfaces that
this class implements. This information is not transitive: we
do not consider the superclass of the superclass, nor the
interfaces extended by the directly implemented interfaces.
public abstract String getSourceFile()
AttributeSourceFile
public final HClass getWrapper(Linker l)
HClass
is a primitive type, return the
wrapper class for values of this type. For example:
HClass.forDescriptor("I").getWrapper()
will return l.forName("java.lang.Integer")
.
Calling getWrapper
with a non-primitive HClass
will return the value null
.
public abstract boolean isArray()
HClass
object represents an array type,
returns true
, otherwise returns false
.
public abstract boolean isInterface()
HClass
object represents an
interface type.
true
is this object represents an interface;
false
otherwise.public abstract boolean isPrimitive()
HClass
object represents a
primitive Java type.
There are nine predefined HClass
objects to represent
the eight primitive Java types and void.
public final boolean isAssignableFrom(HClass cls)
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.
NullPointerException
- if the specified HClass
parameter is null.public final boolean isSuperclassOf(HClass hc)
HClass
is a superclass of a given
HClass
hc
.
[Does not look at interface information.]
true
if this
is a superclass of
hc
, false
otherwise.public final boolean isSuperinterfaceOf(HClass hc)
HClass
is a superinterface of a given
HClass
hc
.
[does not look at superclass information]
true
if this
is a superinterface of
hc
, false
otherwise.public final boolean isInstanceOf(HClass hc)
HClass
is an instance of the given
HClass
hc
.
public int hashCode()
public final String toString()
"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.
toString
in class Object
public final void print(PrintWriter pw)
public HType[] getGenericInterfaces()
HType
s representing 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. In the case of an array class, the
interfaces Cloneable
and Serializable
are
returned in that order.
If this 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 this object represents a class or interface that implements no interfaces, the method returns an array of length 0.
If this object represents a primitive type or void, the method returns an array of length 0.
In particular, if the compile-time type of any superinterface is
a parameterized type, than an object of the appropriate type
(i.e., HParameterizedType
) will be returned.
public HType getGenericSuperclass()
HType
representing the superclass of the
entity (class, interface, primitive type or void) represented by
this HClass
. If this HClass
represents
either the Object
class, an interface, a primitive
type, or void, then null is returned. If this object represents
an array class then the HClass
object representing
the Object
class is returned.
In particular, if the compile-time superclass declaration is a
parameterized type, than an object of the appropriate type (i.e.,
HParameterizedType
) will be returned.
public HClassTypeVariable[] getTypeParameters()
HClassTypeVariable
objects that
represents the type variables declared by the class or interface
represented by this HClass
object, in declaration
order. Returns an array of length 0 if the underlying class or
interface declares no type variables.
public final int compareTo(HClass o)
HClass
es by lexicographic order of their
descriptors.
compareTo
in interface Comparable<HClass>
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |