Class Type

java.lang.Object
org.glassfish.rmic.tools.java.Type
All Implemented Interfaces:
Constants, RuntimeConstants
Direct Known Subclasses:
ArrayType, ClassType, MethodType

public class Type extends Object implements Constants
This class represents an Java Type.

It encapsulates an Java type signature and it provides quick access to the components of the type. Note that all types are hashed into a hashtable (typeHash), that means that each distinct type is only allocated once, saving space and making equality checks cheap.

For simple types use the constants defined in this class. (Type.tInt, Type.tShort, ...). To create complex types use the static methods Type.tArray, Type.tMethod or Type.tClass. For classes, arrays and method types a sub class of class type is created which defines the extra type components. WARNING: The contents of this source file are not part of any supported API. Code that depends on them does so at its own risk: they are subject to change or removal without notice.

See Also:
  • Field Details

    • typeHash

      private static final Hashtable<String,Type> typeHash
      This hashtable is used to cache types
    • typeCode

      private TypeCode typeCode
      The TypeCode of this type.
    • typeSig

      protected String typeSig
      The TypeSignature of this type. This type signature is equivalent to the runtime type signatures used by the interpreter.
    • noArgs

      public static final Type[] noArgs
    • tError

      public static final Type tError
    • tPackage

      public static final Type tPackage
    • tNull

      public static final Type tNull
    • tVoid

      public static final Type tVoid
    • tBoolean

      public static final Type tBoolean
    • tByte

      public static final Type tByte
    • tChar

      public static final Type tChar
    • tShort

      public static final Type tShort
    • tInt

      public static final Type tInt
    • tFloat

      public static final Type tFloat
    • tLong

      public static final Type tLong
    • tDouble

      public static final Type tDouble
    • tObject

      public static final Type tObject
    • tClassDesc

      public static final Type tClassDesc
    • tString

      public static final Type tString
    • tCloneable

      public static final Type tCloneable
    • tSerializable

      public static final Type tSerializable
  • Constructor Details

    • Type

      protected Type(TypeCode tc, String typeSig)
      Create a type given a typecode and a type signature.
  • Method Details

    • getTypeSignature

      public final String getTypeSignature()
      Return the Java type signature.
    • getTypeCode

      public final int getTypeCode()
      Return the type code.
    • getTypeMask

      public final int getTypeMask()
      Return the type mask. The bits in this mask correspond to the TM_* constants defined in Constants. Only one bit is set at a type.
      See Also:
    • isType

      public final boolean isType(int tc)
      Check for a certain type.
    • isVoidArray

      public boolean isVoidArray()
      Check to see if this is the bogus type "array of void" Although this highly degenerate "type" is not constructable from the grammar, the Parser accepts it. Rather than monkey with the Parser, we check for the bogus type at specific points and give a nice error.
    • inMask

      public final boolean inMask(int tm)
      Check for a certain set of types.
    • tArray

      public static Type tArray(Type elem)
      Create an array type.
    • getElementType

      public Type getElementType()
      Return the element type of an array type. Only works for array types.
    • getArrayDimension

      public int getArrayDimension()
      Return the array dimension. Only works for array types.
    • tClass

      public static Type tClass(Identifier className)
      Create a class type.
    • getClassName

      public Identifier getClassName()
      Return the ClassName. Only works on class types.
    • mangleInnerType

      public static Identifier mangleInnerType(Identifier className)
      Given an inner identifier, return the non-inner, mangled representation used to manage signatures. Note: It is changed to 'public' for Jcov file generation. (see Assembler.java)
    • changeClassName

      private static void changeClassName(Identifier oldName, Identifier newName)
      We have learned that a signature means something other that what we thought it meant. Live with it: Change all affected data structures to reflect the new name of the old type.

      (This is necessary because of an ambiguity between the low-level signatures of inner types and their manglings. Note that the latter are also valid class names.)

    • tMethod

      public static Type tMethod(Type ret)
      Create a method type with no arguments.
    • tMethod

      public static Type tMethod(Type returnType, Type[] argTypes)
      Create a method type with arguments.
    • getReturnType

      public Type getReturnType()
      Return the return type. Only works for method types.
    • getArgumentTypes

      public Type[] getArgumentTypes()
      Return the argument types. Only works for method types.
    • tType

      public static Type tType(String sig)
      Create a Type from an Java type signature.
      Throws:
      CompilerError - invalid type signature.
    • equalArguments

      public boolean equalArguments(Type t)
      Check if the type arguments are the same.
      Returns:
      true if both types are method types and the argument types are identical.
    • stackSize

      public int stackSize()
      Return the amount of space this type takes up on the Java operand stack. For a method this is equal to the total space taken up by the arguments.
    • getTypeCodeOffset

      public int getTypeCodeOffset()
      Return the type code offset. This offset can be added to an opcode to get the right opcode type. Most opcodes are ordered: int, long, float, double, array. For example: iload, lload fload, dload, aload. So the appropriate opcode is iadd + type.getTypeCodeOffset().
    • typeString

      public String typeString(String id, boolean abbrev, boolean ret)
      Convert a Type to a string, if abbrev is true class names are not fully qualified, if ret is true the return type is included.
    • typeString

      public String typeString(String id)
      Create a type string, given an identifier.
    • toString

      public String toString()
      Convert to a String
      Overrides:
      toString in class Object
    • toStringValue

      public String toStringValue(Object value)