edu.ksu.cis.projects.bogor.type
Class TypeFactory

java.lang.Object
  extended by edu.ksu.cis.projects.bogor.type.TypeFactory
All Implemented Interfaces:
Disposable, Serializable

public final class TypeFactory
extends Object
implements Disposable, Serializable

Provides a factory for types. The types are cached so, there is only one instance for each unique type.

Version:
CVS $Revision: 1.9 $ $Date: 2005/05/26 18:23:14 $
Author:
Robby
See Also:
Serialized Form

Field Summary
static int UNUSABLE_TYPE_ID
          Holds the unusable type id.
 
Constructor Summary
TypeFactory()
          Default constructor.
 
Method Summary
 void disallowNew()
          Treat any request for an uncached type from this point forward as a programming error (generate an exception).
 void dispose()
          Removes references to booleanType, intType, lockType, voidType, nullType, unknownType, and clears cache.
 ArrayType getArrayType(Type baseType, int rank)
          Gets an array type.
 BooleanType getBooleanType()
          Gets a boolean type.
 DoubleType getDoubleType()
          Gets an double type.
 EnumType getEnumType(String id)
          Gets an enum type.
 NonPrimitiveExtType getExtType(String id, Type[] argTypes)
          Gets an ext type.
 FloatType getFloatType()
          Gets a float type.
 FunType getFunType(Type[] paramTypes, Type returnType)
          Gets a fun type.
 IntRangeType getIntRangeType(int lowLimit, int highLimit, boolean wrap)
          Gets an int range type.
 IntType getIntType()
          Gets an int type.
 LockType getLockType()
          Gets a lock type.
 LongRangeType getLongRangeType(long lowLimit, long highLimit, boolean wrap)
          Gets a long range type.
 LongType getLongType()
          Gets a long type.
 NullType getNullType()
          Gets a null type.
 PrimitiveExtType getPrimitiveExtType(String id, Type[] argTypes)
          Gets a primitive ext type.
 PrimitiveTypeExtensionType getPrimitiveTypeExtensionType(String id, String[] typeVarIds)
          Gets a primtive type extension type.
 RecordType getRecordType(String id)
          Gets a record type.
 StringType getStringType()
          Gets a string type.
 ThreadIdType getThreadIdType()
          Gets a thread id type.
 TypeExtensionType getTypeExtensionType(String id, String[] typeVarIds)
          Gets a type extension type.
 Set<Type> getTypeSet()
          Gets a set of types created/returned from this factory.
 UnknownType getUnknownType()
          Gets an unknown type.
 VoidType getVoidType()
          Gets a void type.
 TypeVar geTypeVar(String id)
          Gets a type var.
 Type instantiate(Type type, Map<String,Type> typeVarTypeTable)
          Instantiate a type.
 void remove(Type type)
          Removes a type from the cache.
 String toString()
          Returns the string representation of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

UNUSABLE_TYPE_ID

public static final int UNUSABLE_TYPE_ID
Holds the unusable type id.

See Also:
Constant Field Values
Constructor Detail

TypeFactory

public TypeFactory()
Default constructor.

Method Detail

disallowNew

public void disallowNew()
Treat any request for an uncached type from this point forward as a programming error (generate an exception).


getArrayType

public ArrayType getArrayType(Type baseType,
                              int rank)
Gets an array type.

Parameters:
baseType - The base type of this array. Must be non-null. Must be not instance of ASTArrayType, VoidType, or UnknownType.
rank - The rank of the array. Must be greater than zero.
Returns:
The array type. Non-null.

getBooleanType

public BooleanType getBooleanType()
Gets a boolean type.

Returns:
The boolean type. Non-null.

getDoubleType

public DoubleType getDoubleType()
Gets an double type.

Returns:
The double type. Non-null.

getEnumType

public EnumType getEnumType(String id)
Gets an enum type.

Parameters:
id - The id of the enum type. Must be non-null.
Returns:
The enum type. Non-null.

getExtType

public NonPrimitiveExtType getExtType(String id,
                                      Type[] argTypes)
Gets an ext type.

Parameters:
id - The id of the ext type. Must be non-null.
argTypes - The arguments for type variables. Must be non-null. Each element must be non-null.
Returns:
The ext type. Non-null. Its type id is equal to UNUSABLE_TYPE_ID if one of its argument type's type id is UNUSABLE_TYPE_ID.

getFloatType

public FloatType getFloatType()
Gets a float type.

Returns:
The float type. Non-null.

getFunType

public FunType getFunType(Type[] paramTypes,
                          Type returnType)
Gets a fun type.

Parameters:
paramTypes - The parameter types. Must be non-null. Each element must be non-null.
returnType - The return type
Returns:
The fun type. Non-null. Its type id is equal to UNUSABLE_TYPE_ID if one of its param type's type id is UNUSABLE_TYPE_ID.

getIntRangeType

public IntRangeType getIntRangeType(int lowLimit,
                                    int highLimit,
                                    boolean wrap)
Gets an int range type.

Parameters:
lowLimit - The low limit.
highLimit - The high limit. Must be at least equal to the low limit.
wrap - Indicates whether to support wrap around for the int range type.
Returns:
The int range type. Non-null.

getIntType

public IntType getIntType()
Gets an int type.

Returns:
The int type. Non-null.

getLockType

public LockType getLockType()
Gets a lock type.

Returns:
The lock type. Non-null.

getLongRangeType

public LongRangeType getLongRangeType(long lowLimit,
                                      long highLimit,
                                      boolean wrap)
Gets a long range type.

Parameters:
lowLimit - The low limit.
highLimit - The high limit. Must be at least equal to the low limit.
wrap - Indicates whether to support wrap around for the long range type.
Returns:
The long range type. Non-null.

getLongType

public LongType getLongType()
Gets a long type.

Returns:
The long type. Non-null.

getNullType

public NullType getNullType()
Gets a null type.

Returns:
The null type. Non-null.

getPrimitiveExtType

public PrimitiveExtType getPrimitiveExtType(String id,
                                            Type[] argTypes)
Gets a primitive ext type.

Parameters:
id - The id of the ext type. Must be non-null.
argTypes - The arguments for type variables. Must be non-null. Each element must be non-null.
Returns:
The ext type. Non-null. Its type id is equal to UNUSABLE_TYPE_ID if one of its argument type's type id is UNUSABLE_TYPE_ID.

getPrimitiveTypeExtensionType

public PrimitiveTypeExtensionType getPrimitiveTypeExtensionType(String id,
                                                                String[] typeVarIds)
Gets a primtive type extension type.

Parameters:
id - The primitive extension type id. Must be non-null.
typeVarIds - The fixed type variable ids. Must be non-null. Each element must be non-null. Each element must be distinct.
Returns:
The primitive type extension type. Non-null.

getRecordType

public RecordType getRecordType(String id)
Gets a record type.

Parameters:
id - The id of the record type. Must be non-null.
Returns:
The record type. Non-null.

getStringType

public StringType getStringType()
Gets a string type.

Returns:
The string type. Non-null.

getThreadIdType

public ThreadIdType getThreadIdType()
Gets a thread id type.

Returns:
The thread id type. Non-null.

getTypeExtensionType

public TypeExtensionType getTypeExtensionType(String id,
                                              String[] typeVarIds)
Gets a type extension type.

Parameters:
id - The extension type id. Must be non-null.
typeVarIds - The fixed type variable ids. Must be non-null. Each element must be non-null. Each element must be distinct.
Returns:
The type extension type. Non-null.

getTypeSet

public Set<Type> getTypeSet()
Gets a set of types created/returned from this factory.

Returns:
The set of types created/returned from this factory.

getUnknownType

public UnknownType getUnknownType()
Gets an unknown type.

Returns:
The unknown type. Non-null.

getVoidType

public VoidType getVoidType()
Gets a void type.

Returns:
The void type. Non-null.

dispose

public void dispose()
Removes references to booleanType, intType, lockType, voidType, nullType, unknownType, and clears cache. Once called, avoid using this object.

Specified by:
dispose in interface Disposable

geTypeVar

public TypeVar geTypeVar(String id)
Gets a type var.

Parameters:
id - The id of the a type var. Must be non-null.
Returns:
The a type var. Non-null.

instantiate

public Type instantiate(Type type,
                        Map<String,Type> typeVarTypeTable)
Instantiate a type.

Parameters:
type - The type to be instantiated. Must be non-null.
typeVarTypeTable - The mapping from the type variables of the type to their type counterpart. Must be non-null.
Returns:
The instantiated type. Non-null.

remove

public void remove(Type type)
Removes a type from the cache.

Parameters:
type - The type to be removed.

toString

public String toString()
Returns the string representation of this object.

Overrides:
toString in class Object
Returns:
The string representation of the set returned by getTypeSet().