edu.rit.classfile
Class TypeReference

java.lang.Object
  extended by edu.rit.classfile.TypeReference
Direct Known Subclasses:
ArrayOrClassReference, PrimitiveReference

public abstract class TypeReference
extends Object

Class TypeReference encapsulates the information needed to refer to a type. This includes the type's name. In the documentation below, the term "referenced type" means "the type referred to by this type reference object."

Class TypeReference and its subclasses are not serializable and cannot be written to an object output stream using writeObject(), or read from an object input stream using readObject(). However, instances of certain subclasses of class TypeReference can be written to a data output stream using the write() method below, and instances of these subclasses can be read from a data input stream using the static read() method below. The subclasses that can be written and read in this way are ArrayReference, NamedClassReference, and PrimitiveReference.


Method Summary
 boolean equals(Object obj)
          Determine if this type reference is equal to the given object.
 String getTypeDescriptor()
          Returns the referenced type's type descriptor.
 int getWordCount()
          Returns the number of virtual machine words needed to hold an object of the referenced type.
 int hashCode()
          Returns a hash code for this type reference.
static TypeReference read(DataInput theDataInput)
          Read a type reference from the given data input stream.
 String toString()
          Returns a string version of this type reference.
 void write(DataOutput theDataOutput)
          Write this type reference to the given data output stream.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

getTypeDescriptor

public String getTypeDescriptor()
Returns the referenced type's type descriptor.


getWordCount

public int getWordCount()
Returns the number of virtual machine words needed to hold an object of the referenced type. For type long and type double, the word count is 2. For all other types, the word count is 1.


write

public void write(DataOutput theDataOutput)
           throws IOException
Write this type reference to the given data output stream. Unless the write() method is overridden in the type reference's subclass, a type reference cannot be written, and the write() method will throw a NotSerializableException.

Parameters:
theDataOutput - Data output stream to write.
Throws:
IOException - Thrown if an I/O error occurred. In particular, a NotSerializableException is thrown if this type reference is not an instance of one of the subclasses that can be written.

read

public static TypeReference read(DataInput theDataInput)
                          throws IOException
Read a type reference from the given data input stream. It is assumed that the type reference was written using the write() method. The returned type reference is an instance of one of the subclasses that can be written.

Parameters:
theDataInput - Data input stream to read.
Returns:
Type reference.
Throws:
IOException - Thrown if an I/O error occurred.

equals

public boolean equals(Object obj)
Determine if this type reference is equal to the given object. To be equal, the given object must be a non-null instance of class TypeReference with the same type descriptor as this type reference.

Overrides:
equals in class Object
Parameters:
obj - Object to test.
Returns:
True if this type reference is equal to the given object, false otherwise.

hashCode

public int hashCode()
Returns a hash code for this type reference.

Overrides:
hashCode in class Object

toString

public String toString()
Returns a string version of this type reference. This is the described type's name, plus "[]" for each dimension if the described type is an array.

Overrides:
toString in class Object


Copyright © 2001-2006 by Alan Kaminsky. All rights reserved. Send comments to ark­@­cs.rit.edu.