fr.umlv.tatoo.cc.common.generator
Class Type

java.lang.Object
  extended by fr.umlv.tatoo.cc.common.generator.Type
All Implemented Interfaces:
Comparable<Type>

public class Type
extends Object
implements Comparable<Type>

Represents a Java Type.

Author:
Remi Forax

Field Summary
static Type BOOLEAN
          The boolean Type.
static Type BYTE
          The byte Type.
static Type CHARACTER
          The char Type.
static Type DOUBLE
          The double Type.
static Type FLOAT
          The float Type.
static Type INT
          The int Type.
static Type LONG
          The long Type.
static Type SHORT
          The short Type.
static Type VOID
          The void Type.
 
Method Summary
 void addImportsTo(Set<Type> imports)
          Add all types used by the current type to the import set.
 Type boxIfPrimitive()
          Returns the current type or its wrapper type if the the current type is a primitive.
 int compareTo(Type type)
           This implementation compares to type using their names.
static Type createArrayType(Type type)
          Creates an array type from a type.
static Type createParametrizedType(Type type, List<Type> typeArguments)
          Creates a parameterized type.
static Type createParametrizedType(Type type, Type... typeArguments)
          Creates a parameterized type.
static Type createQualifiedType(String qualifiedName)
          Creates a Type from a qualified string.
static Type createType(String typeName, Map<String,? extends Type> imports)
          Creates a type from a name with optional type arguments and a map of imports.
 boolean equals(Object o)
           
 Type getComponentType()
          Returns the component type of the current type if the current type is an array.
 String getDefaultValue()
          Returns the default value of the current type.
 String getName()
          Returns the fully qualified name of the current type.
 String getPackageName()
          Return the qualified part of the current type.
 String getRawName()
          Returns the qualified name of the current type without its type arguments.
 Type getRawType()
          Returns a qualified type corresponding to the current type without its type arguments.
 String getSimpleName()
          Returns the unqualified name of the current type.
 String getSimpleRawName()
          Returns the unqualified name of the current type without its type arguments.
 List<Type> getTypeArguments()
          Returns a read/write list of type arguments of the current type or an empty list if the current type is not a parameterized type.
 String getVMTypeName()
          Return the name used by the VM in case of erasure.
 Type getWrapperType()
          Returns the wrapper type of the current type if the current type is a primitive type.
 int hashCode()
           
 boolean hasTypeArguments()
          Returns true if the current type is a parameterized type with type arguments.
 boolean isArray()
          Returns true if the current type is an array.
 boolean isObjectType()
          Returns true if the current type is an object type.
 boolean isPrimitive()
          Returns true is the current type is a primitive type.
 boolean isQualifiedType()
          Returns true if the current type is qualified.
 boolean isVoid()
          Returns true if the current type is VOID.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

BOOLEAN

public static final Type BOOLEAN
The boolean Type.


BYTE

public static final Type BYTE
The byte Type.


SHORT

public static final Type SHORT
The short Type.


CHARACTER

public static final Type CHARACTER
The char Type.


INT

public static final Type INT
The int Type.


LONG

public static final Type LONG
The long Type.


FLOAT

public static final Type FLOAT
The float Type.


DOUBLE

public static final Type DOUBLE
The double Type.


VOID

public static final Type VOID
The void Type.

Method Detail

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object o)
Overrides:
equals in class Object

compareTo

public int compareTo(Type type)
This implementation compares to type using their names.

Specified by:
compareTo in interface Comparable<Type>
See Also:
getName()

toString

public String toString()
Overrides:
toString in class Object

isPrimitive

public boolean isPrimitive()
Returns true is the current type is a primitive type. VOID is not a primitive type.

Returns:
true is the current type is a primitive type.
See Also:
isObjectType(), isVoid()

isObjectType

public boolean isObjectType()
Returns true if the current type is an object type. VOID is an object type.

Returns:
true if the current type is an object type.
See Also:
isPrimitive(), isVoid()

isQualifiedType

public boolean isQualifiedType()
Returns true if the current type is qualified.

Returns:
true if the current type is qualified.

isArray

public boolean isArray()
Returns true if the current type is an array.

Returns:
true if the current type is an array.
See Also:
getComponentType()

isVoid

public boolean isVoid()
Returns true if the current type is VOID.

Returns:
true if the current type is VOID.
See Also:
isPrimitive(), isObjectType()

getName

public String getName()
Returns the fully qualified name of the current type. by example, java.util.List&lt;E&gt;.

Returns:
the fully qualified name of the current type.
See Also:
getSimpleName(), getSimpleRawName(), getPackageName()

getComponentType

public Type getComponentType()
Returns the component type of the current type if the current type is an array.

Returns:
the component type of the current type if the current type is an array or null otherwise.
See Also:
isArray()

getWrapperType

public Type getWrapperType()
Returns the wrapper type of the current type if the current type is a primitive type.

Returns:
the wrapper type of the current type if the current type is a primitive type or null otherwise.
See Also:
boxIfPrimitive()

boxIfPrimitive

public Type boxIfPrimitive()
Returns the current type or its wrapper type if the the current type is a primitive.

Returns:
the current type or its wrapper type if the the current type is a primitive.
See Also:
getWrapperType()

getDefaultValue

public String getDefaultValue()
Returns the default value of the current type. By example, 0 for int or '\0' for char, etc.

Returns:
the default value of the current type.

getRawName

public String getRawName()
Returns the qualified name of the current type without its type arguments. This name is the name used for imports.

Returns:
the qualified name of the current type without its type arguments if it is not an array.
Throws:
IllegalStateException - if the current type is an array.
See Also:
getRawType(), getName(), getSimpleRawName()

getRawType

public Type getRawType()
Returns a qualified type corresponding to the current type without its type arguments. This type is for imports.

Returns:
the qualified name of the current type without its type arguments if it is not an array.
Throws:
IllegalStateException - if the current type is an array.
See Also:
addImportsTo(Set), getRawName()

getSimpleRawName

public String getSimpleRawName()
Returns the unqualified name of the current type without its type arguments.

Returns:
the unqualified name of the current type without its type arguments if it is not an array.
Throws:
IllegalStateException - if the current type is an array.
See Also:
getRawType(), getName(), getRawName()

getSimpleName

public String getSimpleName()
Returns the unqualified name of the current type. by example, List&lt;E&gt;.

Returns:
the unqualified name of the current type.
See Also:
getName(), getSimpleRawName(), getPackageName()

getPackageName

public String getPackageName()
Return the qualified part of the current type.

Returns:
the qualified part of the current type.
Throws:
IllegalStateException - if the current type is an array or an unqualified type.
See Also:
getName(), getSimpleName()

getVMTypeName

public String getVMTypeName()
Return the name used by the VM in case of erasure. Primitive type return their name and others return "Object".

Returns:
its name if its a primitive type or "Object" otherwise.
See Also:
getRawName(), isPrimitive()

hasTypeArguments

public boolean hasTypeArguments()
Returns true if the current type is a parameterized type with type arguments.

Returns:
if the current type has type arguments.
See Also:
getTypeArguments()

getTypeArguments

public List<Type> getTypeArguments()
Returns a read/write list of type arguments of the current type or an empty list if the current type is not a parameterized type.

Returns:
a list of type arguments.

addImportsTo

public void addImportsTo(Set<Type> imports)
Add all types used by the current type to the import set.

See Also:
getRawType()

createQualifiedType

public static Type createQualifiedType(String qualifiedName)
Creates a Type from a qualified string.

Parameters:
qualifiedName - the qualified name of the type
Returns:
the corresponding type.
Throws:
IllegalArgumentException - if the name taken as argument is not qualified.
See Also:
createType(String, Map)

createParametrizedType

public static Type createParametrizedType(Type type,
                                          Type... typeArguments)
Creates a parameterized type.

Parameters:
type - the generic type.
typeArguments - the type arguments.
Returns:
a parameterized type.
See Also:
createType(String, Map), createParametrizedType(Type, List)

createParametrizedType

public static Type createParametrizedType(Type type,
                                          List<Type> typeArguments)
Creates a parameterized type.

Parameters:
type - the generic type.
typeArguments - the type arguments.
Returns:
a parameterized type.
See Also:
createType(String, Map), createParametrizedType(Type, Type...)

createArrayType

public static Type createArrayType(Type type)
Creates an array type from a type.

Parameters:
type - the component type.
Returns:
an array type.
See Also:
getComponentType()

createType

public static Type createType(String typeName,
                              Map<String,? extends Type> imports)
Creates a type from a name with optional type arguments and a map of imports.

Parameters:
typeName - a name with optional type arguments
imports - a map of imports (unqualified name to qualified name)
Returns:
a new type.
See Also:
createParametrizedType(Type, Type...), createQualifiedType(String)