polyglot.types
Interface Type

All Superinterfaces:
java.lang.Cloneable, Copy, Qualifier, java.io.Serializable, TypeObject
All Known Subinterfaces:
ArrayType, ClassType, CofferClassType, CofferParsedClassType, CofferSubstType, InstType, NullType, ParsedClassType, PrimitiveType, ReferenceType, SubstType, UnknownType
All Known Implementing Classes:
ArrayType_c, ClassType_c, CofferParsedClassType_c, CofferSubstClassType_c, NullType_c, ParsedClassType_c, PrimitiveType_c, ReferenceType_c, SubstClassType_c, Type_c, UnknownType_c

public interface Type
extends Qualifier

A Type is the base type of all classes which represent types.


Method Summary
 ArrayType arrayOf()
          Return an array of this type.
 ArrayType arrayOf(int dims)
          Return a dims-array of this type.
 boolean descendsFrom(Type ancestor)
          Return true if this type descends from ancestor.
 boolean descendsFromImpl(Type t)
          Return true if this type descends from ancestor.
 boolean isArray()
          Return true if an array type.
 boolean isBoolean()
          Return true if boolean.
 boolean isByte()
          Return true if byte.
 boolean isCastValid(Type toType)
          Return true if this type can be cast to toType.
 boolean isCastValidImpl(Type t)
          Return true if this type can be cast to toType.
 boolean isChar()
          Return true if char.
 boolean isClass()
          Return true if a class type.
 boolean isComparable(Type t)
          Return true if the types can be compared; that is, if they have the same type system.
 boolean isDouble()
          Return true if double.
 boolean isFloat()
          Return true if float.
 boolean isImplicitCastValid(Type toType)
          Return true if a value of this type can be assigned to a variable of type toType.
 boolean isImplicitCastValidImpl(Type t)
          Return true if a value of this type can be assigned to a variable of type toType.
 boolean isInt()
          Return true if int.
 boolean isIntOrLess()
          Return true if int, short, byte, or char.
 boolean isLong()
          Return true if long.
 boolean isLongOrLess()
          Return true if long, int, short, byte, or char.
 boolean isNull()
          Return true if a null type.
 boolean isNumeric()
          Return true if double, float, long, int, short, byte, or char.
 boolean isPrimitive()
          Return true if a primitive type.
 boolean isReference()
          Return true if a reference type.
 boolean isShort()
          Return true if short.
 boolean isSubtype(Type ancestor)
          Return true if this type is a subtype of ancestor.
 boolean isSubtypeImpl(Type t)
          Return true if this type is a subtype of ancestor.
 boolean isThrowable()
          Return true if a subclass of Throwable.
 boolean isUncheckedException()
          Return true if an unchecked exception.
 boolean isVoid()
          Return true if void.
 boolean numericConversionValid(long value)
          Return true a literal value can be converted to this type.
 boolean numericConversionValid(java.lang.Object value)
          Return true a literal value can be converted to this type.
 boolean numericConversionValidImpl(long value)
          Return true a literal value can be converted to this type.
 boolean numericConversionValidImpl(java.lang.Object value)
          Return true a literal value can be converted to this type.
 ArrayType toArray()
          Cast the type to an array type, or null.
 ClassType toClass()
          Cast the type to a class type, or null.
 NullType toNull()
          Cast the type to a null type, or null.
 PrimitiveType toPrimitive()
          Cast the type to a primitive type, or null.
 ReferenceType toReference()
          Cast the type to a reference type, or null.
 java.lang.String toString()
          Yields a string representing this type.
 java.lang.String translate(Resolver c)
          Return a string into which to translate the type.
 
Methods inherited from interface polyglot.types.Qualifier
isPackage, isType, toPackage, toType
 
Methods inherited from interface polyglot.types.TypeObject
equalsImpl, isCanonical, position, typeSystem
 
Methods inherited from interface polyglot.util.Copy
copy
 

Method Detail

translate

public java.lang.String translate(Resolver c)
Return a string into which to translate the type.

Parameters:
c - A resolver in which to lookup this type to determine if the type is unique in the given resolver.

arrayOf

public ArrayType arrayOf()
Return an array of this type.


arrayOf

public ArrayType arrayOf(int dims)
Return a dims-array of this type.


toClass

public ClassType toClass()
Cast the type to a class type, or null.


toNull

public NullType toNull()
Cast the type to a null type, or null.


toReference

public ReferenceType toReference()
Cast the type to a reference type, or null.


toPrimitive

public PrimitiveType toPrimitive()
Cast the type to a primitive type, or null.


toArray

public ArrayType toArray()
Cast the type to an array type, or null.


isSubtype

public boolean isSubtype(Type ancestor)
Return true if this type is a subtype of ancestor.


descendsFrom

public boolean descendsFrom(Type ancestor)
Return true if this type descends from ancestor.


isCastValid

public boolean isCastValid(Type toType)
Return true if this type can be cast to toType.


isImplicitCastValid

public boolean isImplicitCastValid(Type toType)
Return true if a value of this type can be assigned to a variable of type toType.


numericConversionValid

public boolean numericConversionValid(java.lang.Object value)
Return true a literal value can be converted to this type.


numericConversionValid

public boolean numericConversionValid(long value)
Return true a literal value can be converted to this type.


isSubtypeImpl

public boolean isSubtypeImpl(Type t)
Return true if this type is a subtype of ancestor.


descendsFromImpl

public boolean descendsFromImpl(Type t)
Return true if this type descends from ancestor.


isCastValidImpl

public boolean isCastValidImpl(Type t)
Return true if this type can be cast to toType.


isImplicitCastValidImpl

public boolean isImplicitCastValidImpl(Type t)
Return true if a value of this type can be assigned to a variable of type toType.


numericConversionValidImpl

public boolean numericConversionValidImpl(java.lang.Object value)
Return true a literal value can be converted to this type.


numericConversionValidImpl

public boolean numericConversionValidImpl(long value)
Return true a literal value can be converted to this type. This method should be removed. It is kept for backward compatibility.


isPrimitive

public boolean isPrimitive()
Return true if a primitive type.


isVoid

public boolean isVoid()
Return true if void.


isBoolean

public boolean isBoolean()
Return true if boolean.


isChar

public boolean isChar()
Return true if char.


isByte

public boolean isByte()
Return true if byte.


isShort

public boolean isShort()
Return true if short.


isInt

public boolean isInt()
Return true if int.


isLong

public boolean isLong()
Return true if long.


isFloat

public boolean isFloat()
Return true if float.


isDouble

public boolean isDouble()
Return true if double.


isIntOrLess

public boolean isIntOrLess()
Return true if int, short, byte, or char.


isLongOrLess

public boolean isLongOrLess()
Return true if long, int, short, byte, or char.


isNumeric

public boolean isNumeric()
Return true if double, float, long, int, short, byte, or char.


isReference

public boolean isReference()
Return true if a reference type.


isNull

public boolean isNull()
Return true if a null type.


isArray

public boolean isArray()
Return true if an array type.


isClass

public boolean isClass()
Return true if a class type.


isThrowable

public boolean isThrowable()
Return true if a subclass of Throwable.


isUncheckedException

public boolean isUncheckedException()
Return true if an unchecked exception.


isComparable

public boolean isComparable(Type t)
Return true if the types can be compared; that is, if they have the same type system.


toString

public java.lang.String toString()
Yields a string representing this type. The string should be consistent with equality. That is, if this.equals(anotherType), then it should be that this.toString().equals(anotherType.toString()). The string does not have to be a legal Java identifier. It is suggested, but not required, that it be an easily human readable representation, and thus useful in error messages and generated output.