public class

Type

extends Object
implements Constants
java.lang.Object
   ↳ sun.tools.java.Type
Known Direct Subclasses

Class Overview

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.

Summary

[Expand]
Inherited Constants
From interface sun.tools.java.Constants
From interface sun.tools.java.RuntimeConstants
Fields
public static final Type[] noArgs
public static final Type tBoolean
public static final Type tByte
public static final Type tChar
public static final Type tClassDesc
public static final Type tCloneable
public static final Type tDouble
public static final Type tError
public static final Type tFloat
public static final Type tInt
public static final Type tLong
public static final Type tNull
public static final Type tObject
public static final Type tPackage
public static final Type tSerializable
public static final Type tShort
public static final Type tString
public static final Type tVoid
protected int typeCode The TypeCode of this type.
protected String typeSig The TypeSignature of this type.
[Expand]
Inherited Fields
From interface sun.tools.java.Constants
From interface sun.tools.java.RuntimeConstants
Protected Constructors
Type(int typeCode, String typeSig)
Create a type given a typecode and a type signature.
Public Methods
boolean equalArguments(Type t)
Check if the type arguments are the same.
Type[] getArgumentTypes()
Return the argument types.
int getArrayDimension()
Return the array dimension.
Identifier getClassName()
Return the ClassName.
Type getElementType()
Return the element type of an array type.
Type getReturnType()
Return the return type.
final int getTypeCode()
Return the type code.
int getTypeCodeOffset()
Return the type code offset.
final int getTypeMask()
Return the type mask.
final String getTypeSignature()
Return the Java type signature.
final boolean inMask(int tm)
Check for a certain set of types.
final boolean isType(int tc)
Check for a certain type.
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.
static Identifier mangleInnerType(Identifier className)
Given an inner identifier, return the non-inner, mangled representation used to manage signatures.
int stackSize()
Return the amount of space this type takes up on the Java operand stack.
synchronized static Type tArray(Type elem)
Create an array type.
synchronized static Type tClass(Identifier className)
Create a class type.
synchronized static Type tMethod(Type ret)
Create a method type with no arguments.
synchronized static Type tMethod(Type returnType, Type[] argTypes)
Create a method type with arguments.
synchronized static Type tType(String sig)
Create a Type from an Java type signature.
String toString()
Convert to a String
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.
String typeString(String id)
Create a type string, given an identifier.
[Expand]
Inherited Methods
From class java.lang.Object

Fields

public static final Type[] noArgs

public static final Type tBoolean

public static final Type tByte

public static final Type tChar

public static final Type tClassDesc

public static final Type tCloneable

public static final Type tDouble

public static final Type tError

public static final Type tFloat

public static final Type tInt

public static final Type tLong

public static final Type tNull

public static final Type tObject

public static final Type tPackage

public static final Type tSerializable

public static final Type tShort

public static final Type tString

public static final Type tVoid

protected int typeCode

The TypeCode of this type. The value of this field is one of the TC_* contant values defined in Constants.

See Also

protected String typeSig

The TypeSignature of this type. This type signature is equivalent to the runtime type signatures used by the interpreter.

Protected Constructors

protected Type (int typeCode, String typeSig)

Create a type given a typecode and a type signature.

Public Methods

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.

public Type[] getArgumentTypes ()

Return the argument types. Only works for method types.

public int getArrayDimension ()

Return the array dimension. Only works for array types.

public Identifier getClassName ()

Return the ClassName. Only works on class types.

public Type getElementType ()

Return the element type of an array type. Only works for array types.

public Type getReturnType ()

Return the return type. Only works for method types.

public final int getTypeCode ()

Return the type code.

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().

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

public final String getTypeSignature ()

Return the Java type signature.

public final boolean inMask (int tm)

Check for a certain set of types.

public final boolean isType (int tc)

Check for a certain type.

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.

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)

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.

public static synchronized Type tArray (Type elem)

Create an array type.

public static synchronized Type tClass (Identifier className)

Create a class type.

public static synchronized Type tMethod (Type ret)

Create a method type with no arguments.

public static synchronized Type tMethod (Type returnType, Type[] argTypes)

Create a method type with arguments.

public static synchronized Type tType (String sig)

Create a Type from an Java type signature.

Throws
CompilerError invalid type signature.

public String toString ()

Convert to a String

Returns
  • a string representation of the object.

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.

public String typeString (String id)

Create a type string, given an identifier.