polyglot.ext.jl.types
Class Type_c

java.lang.Object
  extended by polyglot.ext.jl.types.TypeObject_c
      extended by polyglot.ext.jl.types.Type_c
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Qualifier, Type, TypeObject, Copy
Direct Known Subclasses:
NullType_c, PrimitiveType_c, ReferenceType_c, UnknownType_c

public abstract class Type_c
extends TypeObject_c
implements Type

Abstract implementation of a Type. This implements most of the "isa" and "cast" methods of the type and methods which just dispatch to the type system.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class polyglot.ext.jl.types.TypeObject_c
position, ts
 
Constructor Summary
protected Type_c()
          Used for deserializing types.
  Type_c(TypeSystem ts)
          Creates a new type in the given a TypeSystem.
  Type_c(TypeSystem ts, Position pos)
          Creates a new type in the given a TypeSystem at a given position.
 
Method Summary
 ArrayType arrayOf()
          Return an array of this type.
 ArrayType arrayOf(int dims)
          Return a dims-array of this type.
 boolean descendsFrom(Type t)
          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 isCanonical()
          Return true if the type object contains no unknown/ambiguous types.
 boolean isCastValid(Type toType)
          Return true if this type can be cast to toType.
 boolean isCastValidImpl(Type toType)
          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 toType)
          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 isPackage()
          Return true if the qualifier is a package.
 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 t)
          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 isType()
          Return true if the qualifier is a type.
 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()
          Returns a non-null iff isArray() returns true.
 ClassType toClass()
          Returns a non-null iff isClass() returns true.
 NullType toNull()
          Returns a non-null iff isNull() returns true.
 Package toPackage()
          Cast the qualifier to a package, or return null.
 PrimitiveType toPrimitive()
          Returns a non-null iff isPrimitive() returns true.
 ReferenceType toReference()
          Returns a non-null iff isReference() returns true.
abstract  java.lang.String toString()
          Yields a string representing this type.
 Type toType()
          Cast the qualifier to a type, or return null.
abstract  java.lang.String translate(Resolver c)
          Return a string into which to translate the type.
 
Methods inherited from class polyglot.ext.jl.types.TypeObject_c
copy, equals, equalsImpl, hashCode, position, typeSystem
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface polyglot.types.TypeObject
equalsImpl, position, typeSystem
 
Methods inherited from interface polyglot.util.Copy
copy
 

Constructor Detail

Type_c

protected Type_c()
Used for deserializing types.


Type_c

public Type_c(TypeSystem ts)
Creates a new type in the given a TypeSystem.


Type_c

public Type_c(TypeSystem ts,
              Position pos)
Creates a new type in the given a TypeSystem at a given position.

Method Detail

translate

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

Specified by:
translate in interface Type
Parameters:
c - A resolver in which to lookup this type to determine if the type is unique in the given resolver.

isType

public boolean isType()
Description copied from interface: Qualifier
Return true if the qualifier is a type.

Specified by:
isType in interface Qualifier

isPackage

public boolean isPackage()
Description copied from interface: Qualifier
Return true if the qualifier is a package.

Specified by:
isPackage in interface Qualifier

toType

public Type toType()
Description copied from interface: Qualifier
Cast the qualifier to a type, or return null. This method will probably be deprecated.

Specified by:
toType in interface Qualifier

toPackage

public Package toPackage()
Description copied from interface: Qualifier
Cast the qualifier to a package, or return null. This method will probably be deprecated.

Specified by:
toPackage in interface Qualifier

isCanonical

public boolean isCanonical()
Description copied from interface: TypeObject
Return true if the type object contains no unknown/ambiguous types.

Specified by:
isCanonical in interface TypeObject

isPrimitive

public boolean isPrimitive()
Description copied from interface: Type
Return true if a primitive type.

Specified by:
isPrimitive in interface Type

isNumeric

public boolean isNumeric()
Description copied from interface: Type
Return true if double, float, long, int, short, byte, or char.

Specified by:
isNumeric in interface Type

isIntOrLess

public boolean isIntOrLess()
Description copied from interface: Type
Return true if int, short, byte, or char.

Specified by:
isIntOrLess in interface Type

isLongOrLess

public boolean isLongOrLess()
Description copied from interface: Type
Return true if long, int, short, byte, or char.

Specified by:
isLongOrLess in interface Type

isVoid

public boolean isVoid()
Description copied from interface: Type
Return true if void.

Specified by:
isVoid in interface Type

isBoolean

public boolean isBoolean()
Description copied from interface: Type
Return true if boolean.

Specified by:
isBoolean in interface Type

isChar

public boolean isChar()
Description copied from interface: Type
Return true if char.

Specified by:
isChar in interface Type

isByte

public boolean isByte()
Description copied from interface: Type
Return true if byte.

Specified by:
isByte in interface Type

isShort

public boolean isShort()
Description copied from interface: Type
Return true if short.

Specified by:
isShort in interface Type

isInt

public boolean isInt()
Description copied from interface: Type
Return true if int.

Specified by:
isInt in interface Type

isLong

public boolean isLong()
Description copied from interface: Type
Return true if long.

Specified by:
isLong in interface Type

isFloat

public boolean isFloat()
Description copied from interface: Type
Return true if float.

Specified by:
isFloat in interface Type

isDouble

public boolean isDouble()
Description copied from interface: Type
Return true if double.

Specified by:
isDouble in interface Type

isReference

public boolean isReference()
Description copied from interface: Type
Return true if a reference type.

Specified by:
isReference in interface Type

isNull

public boolean isNull()
Description copied from interface: Type
Return true if a null type.

Specified by:
isNull in interface Type

isClass

public boolean isClass()
Description copied from interface: Type
Return true if a class type.

Specified by:
isClass in interface Type

isArray

public boolean isArray()
Description copied from interface: Type
Return true if an array type.

Specified by:
isArray in interface Type

isThrowable

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

Specified by:
isThrowable in interface Type

isUncheckedException

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

Specified by:
isUncheckedException in interface Type

toClass

public ClassType toClass()
Returns a non-null iff isClass() returns true.

Specified by:
toClass in interface Type

toNull

public NullType toNull()
Returns a non-null iff isNull() returns true.

Specified by:
toNull in interface Type

toReference

public ReferenceType toReference()
Returns a non-null iff isReference() returns true.

Specified by:
toReference in interface Type

toPrimitive

public PrimitiveType toPrimitive()
Returns a non-null iff isPrimitive() returns true.

Specified by:
toPrimitive in interface Type

toArray

public ArrayType toArray()
Returns a non-null iff isArray() returns true.

Specified by:
toArray in interface Type

arrayOf

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

Specified by:
arrayOf in interface Type

arrayOf

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

Specified by:
arrayOf in interface Type

isSubtype

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

Specified by:
isSubtype in interface Type

isSubtypeImpl

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

Specified by:
isSubtypeImpl in interface Type

descendsFrom

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

Specified by:
descendsFrom in interface Type

descendsFromImpl

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

Specified by:
descendsFromImpl in interface Type

isCastValid

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

Specified by:
isCastValid in interface Type

isCastValidImpl

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

Specified by:
isCastValidImpl in interface Type

isImplicitCastValid

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

Specified by:
isImplicitCastValid in interface Type

isImplicitCastValidImpl

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

Specified by:
isImplicitCastValidImpl in interface Type

numericConversionValid

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

Specified by:
numericConversionValid in interface 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.

Specified by:
numericConversionValidImpl in interface Type

numericConversionValid

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

Specified by:
numericConversionValid in interface Type

numericConversionValidImpl

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

Specified by:
numericConversionValidImpl in interface Type

isComparable

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

Specified by:
isComparable in interface Type

toString

public abstract 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.

Specified by:
toString in interface Type
Overrides:
toString in class java.lang.Object