com.sun.tools.javac.code
Class Type

java.lang.Object
  extended by com.sun.tools.javac.code.Type
All Implemented Interfaces:
PrimitiveType, TypeMirror
Direct Known Subclasses:
Type.ArrayType, Type.BottomType, Type.ClassType, Type.DelegatedType, Type.JCNoType, Type.MethodType, Type.PackageType, Type.TypeVar, Type.WildcardType

public class Type
extends java.lang.Object
implements PrimitiveType

This class represents Java types. The class itself defines the behavior of the following types:

  base types (tags: BYTE, CHAR, SHORT, INT, LONG, FLOAT, DOUBLE, BOOLEAN),
  type `void' (tag: VOID),
  the bottom type (tag: BOT),
  the missing type (tag: NONE).
  

The behavior of the following types is defined in subclasses, which are all static inner classes of this class:

  class types (tag: CLASS, class: ClassType),
  array types (tag: ARRAY, class: ArrayType),
  method types (tag: METHOD, class: MethodType),
  package types (tag: PACKAGE, class: PackageType),
  type variables (tag: TYPEVAR, class: TypeVar),
  type arguments (tag: WILDCARD, class: WildcardType),
  polymorphic types (tag: FORALL, class: ForAll),
  the error type (tag: ERROR, class: ErrorType).
  

This is NOT part of any API supported by Sun Microsystems. If you write code that depends on this, you do so at your own risk. This code and its internal interfaces are subject to change or deletion without notice.

See Also:
TypeTags

Nested Class Summary
static class Type.ArrayType
           
(package private) static class Type.BottomType
           
static class Type.CapturedType
          A captured type variable comes from wildcards which can have both upper and lower bound.
static class Type.ClassType
           
static class Type.DelegatedType
           
static class Type.ErasedClassType
           
static class Type.ErrorType
           
static class Type.ForAll
           
(package private) static class Type.JCNoType
          Represents VOID or NONE.
static class Type.Mapping
          An abstract class for mappings from types to types
static class Type.MethodType
           
static class Type.PackageType
           
static class Type.TypeVar
           
static class Type.UndetVar
          A class for instantiatable variables, for use during type inference.
static interface Type.Visitor<R,S>
          A visitor for types.
static class Type.WildcardType
           
 
Field Summary
static boolean moreInfo
          If this switch is turned on, the names of type variables and anonymous classes are printed with hashcodes appended.
static Type.JCNoType noType
          Constant type: no type at all.
 int tag
          The tag of this type.
 Symbol.TypeSymbol tsym
          The defining class / interface / package / type variable
 
Constructor Summary
Type(int tag, Symbol.TypeSymbol tsym)
          Define a type given its tag and type symbol
 
Method Summary
<R,S> R
accept(Type.Visitor<R,S> v, S s)
           
<R,P> R
accept(TypeVisitor<R,P> v, P p)
          Applies a visitor to this type.
 List<Type> allparams()
          Return all parameters of this type and all its outer types in order outer (first) to inner (last).
 java.lang.String argtypes(boolean varargs)
           
 Symbol.TypeSymbol asElement()
           
 Type.MethodType asMethodType()
          The underlying method type of this type.
 Type baseType()
          If this is a constant type, return its underlying type.
static List<Type> baseTypes(List<Type> ts)
          Return the base types of a list of types.
 java.lang.Object clone()
           
 void complete()
          Complete loading all classes in this type.
 Type constType(java.lang.Object constValue)
          Define a constant type, of the same kind as this type and with given constant value
 java.lang.Object constValue()
          The constant value of this type, null if this type does not have a constant value attribute.
static boolean contains(List<Type> ts, Type t)
           
 boolean contains(Type t)
          Does this type contain occurrences of type t?
 boolean containsSome(List<Type> ts)
          Does this type contain an occurrence of some type in `elems'?
 boolean equals(java.lang.Object t)
          This method is analogous to isSameType, but weaker, since we never complete classes.
 Type getEnclosingType()
           
 TypeKind getKind()
          Returns the kind of this type.
 Type getLowerBound()
           
 List<Type> getParameterTypes()
           
 Type getReturnType()
           
 List<Type> getThrownTypes()
           
 List<Type> getTypeArguments()
          Access methods.
 Type getUpperBound()
           
 int hashCode()
          Obeys the general contract of Object.hashCode.
 boolean isCompound()
           
 boolean isErroneous()
          Does this type contain "error" elements?
static boolean isErroneous(List<Type> ts)
           
 boolean isExtendsBound()
           
 boolean isFalse()
          Is this a constant type whose value is false?
 boolean isInterface()
           
 boolean isParameterized()
          Is this type parameterized? A class type is parameterized if it has some parameters.
 boolean isPrimitive()
           
 boolean isRaw()
          Is this type a raw type? A class type is a raw type if it misses some of its parameters.
 boolean isSuperBound()
           
 boolean isTrue()
          Is this a constant type whose value is true?
 boolean isUnbound()
           
static List<Type> map(List<Type> ts, Type.Mapping f)
          map a type function over a list of types
 Type map(Type.Mapping f)
          map a type function over all immediate descendants of this type
 void setThrown(List<Type> ts)
           
 java.lang.String stringValue()
          The constant value of this type, converted to String
 java.lang.String toString()
          The Java source which this type represents.
static java.lang.String toString(List<Type> ts)
          The Java source which this type list represents.
 Type withTypeVar(Type t)
           
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

noType

public static final Type.JCNoType noType
Constant type: no type at all.


moreInfo

public static boolean moreInfo
If this switch is turned on, the names of type variables and anonymous classes are printed with hashcodes appended.


tag

public int tag
The tag of this type.

See Also:
TypeTags

tsym

public Symbol.TypeSymbol tsym
The defining class / interface / package / type variable

Constructor Detail

Type

public Type(int tag,
            Symbol.TypeSymbol tsym)
Define a type given its tag and type symbol

Method Detail

constValue

public java.lang.Object constValue()
The constant value of this type, null if this type does not have a constant value attribute. Only primitive types and strings (ClassType) can have a constant value attribute.

Returns:
the constant value attribute of this type

accept

public <R,S> R accept(Type.Visitor<R,S> v,
                      S s)

map

public Type map(Type.Mapping f)
map a type function over all immediate descendants of this type


map

public static List<Type> map(List<Type> ts,
                             Type.Mapping f)
map a type function over a list of types


constType

public Type constType(java.lang.Object constValue)
Define a constant type, of the same kind as this type and with given constant value


baseType

public Type baseType()
If this is a constant type, return its underlying type. Otherwise, return the type itself.


baseTypes

public static List<Type> baseTypes(List<Type> ts)
Return the base types of a list of types.


toString

public java.lang.String toString()
The Java source which this type represents.

Specified by:
toString in interface TypeMirror
Overrides:
toString in class java.lang.Object
Returns:
a string representation of this type

toString

public static java.lang.String toString(List<Type> ts)
The Java source which this type list represents. A List is represented as a comma-spearated listing of the elements in that list.


stringValue

public java.lang.String stringValue()
The constant value of this type, converted to String


equals

public boolean equals(java.lang.Object t)
This method is analogous to isSameType, but weaker, since we never complete classes. Where isSameType would complete a class, equals assumes that the two types are different.

Specified by:
equals in interface TypeMirror
Overrides:
equals in class java.lang.Object
Parameters:
t - the object to be compared with this type
Returns:
true if the specified object is equal to this one

hashCode

public int hashCode()
Description copied from interface: TypeMirror
Obeys the general contract of Object.hashCode.

Specified by:
hashCode in interface TypeMirror
Overrides:
hashCode in class java.lang.Object
See Also:
TypeMirror.equals(java.lang.Object)

isFalse

public boolean isFalse()
Is this a constant type whose value is false?


isTrue

public boolean isTrue()
Is this a constant type whose value is true?


argtypes

public java.lang.String argtypes(boolean varargs)

getTypeArguments

public List<Type> getTypeArguments()
Access methods.


getEnclosingType

public Type getEnclosingType()

getParameterTypes

public List<Type> getParameterTypes()

getReturnType

public Type getReturnType()

getThrownTypes

public List<Type> getThrownTypes()

getUpperBound

public Type getUpperBound()

getLowerBound

public Type getLowerBound()

setThrown

public void setThrown(List<Type> ts)

allparams

public List<Type> allparams()
Return all parameters of this type and all its outer types in order outer (first) to inner (last).


isErroneous

public boolean isErroneous()
Does this type contain "error" elements?


isErroneous

public static boolean isErroneous(List<Type> ts)

isParameterized

public boolean isParameterized()
Is this type parameterized? A class type is parameterized if it has some parameters. An array type is parameterized if its element type is parameterized. All other types are not parameterized.


isRaw

public boolean isRaw()
Is this type a raw type? A class type is a raw type if it misses some of its parameters. An array type is a raw type if its element type is raw. All other types are not raw. Type validation will ensure that the only raw types in a program are types that miss all their type variables.


isCompound

public boolean isCompound()

isInterface

public boolean isInterface()

isPrimitive

public boolean isPrimitive()

contains

public boolean contains(Type t)
Does this type contain occurrences of type t?


contains

public static boolean contains(List<Type> ts,
                               Type t)

containsSome

public boolean containsSome(List<Type> ts)
Does this type contain an occurrence of some type in `elems'?


isSuperBound

public boolean isSuperBound()

isExtendsBound

public boolean isExtendsBound()

isUnbound

public boolean isUnbound()

withTypeVar

public Type withTypeVar(Type t)

asMethodType

public Type.MethodType asMethodType()
The underlying method type of this type.


complete

public void complete()
Complete loading all classes in this type.


clone

public java.lang.Object clone()
Overrides:
clone in class java.lang.Object

asElement

public Symbol.TypeSymbol asElement()

getKind

public TypeKind getKind()
Description copied from interface: TypeMirror
Returns the kind of this type.

Specified by:
getKind in interface TypeMirror
Returns:
the kind of this type

accept

public <R,P> R accept(TypeVisitor<R,P> v,
                      P p)
Description copied from interface: TypeMirror
Applies a visitor to this type.

Specified by:
accept in interface TypeMirror
Type Parameters:
R - the return type of the visitor's methods
P - the type of the additional parameter to the visitor's methods
Parameters:
v - the visitor operating on this type
p - additional parameter to the visitor
Returns:
a visitor-specified result