Package com.sun.codemodel
Class JType
- java.lang.Object
-
- com.sun.codemodel.JType
-
- All Implemented Interfaces:
JGenerable
,java.lang.Comparable<JType>
- Direct Known Subclasses:
JClass
,JPrimitiveType
public abstract class JType extends java.lang.Object implements JGenerable, java.lang.Comparable<JType>
A representation of a type in codeModel. A type is always either primitive (JPrimitiveType
) or a reference type (JClass
).
-
-
Constructor Summary
Constructors Constructor Description JType()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract JClass
array()
Create an array type of this type.java.lang.String
binaryName()
Gets the binary name of the type.abstract JClass
boxify()
If this class is a primitive type, return the boxed class.int
compareTo(JType o)
Compare two JTypes by FQCN, giving sorting precedence to types that belong to packages java and javax over all others.JType
elementType()
If this is an array, returns the component type of the array.JType
erasure()
Returns the erasure of this type.abstract java.lang.String
fullName()
Gets the full name of the type.boolean
isArray()
Tell whether or not this is an array type.boolean
isPrimitive()
Tell whether or not this is a built-in primitive type, such as int or void.boolean
isReference()
Returns true if this is a referenced type.abstract java.lang.String
name()
Gets the name of this type.abstract JCodeModel
owner()
Gets the owner code model object.static JPrimitiveType
parse(JCodeModel codeModel, java.lang.String typeName)
Obtains a reference to the primitive type object from a type name.java.lang.String
toString()
abstract JType
unboxify()
If this class is a wrapper type for a primitive, return the primitive type.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.sun.codemodel.JGenerable
generate
-
-
-
-
Method Detail
-
parse
public static JPrimitiveType parse(JCodeModel codeModel, java.lang.String typeName)
Obtains a reference to the primitive type object from a type name.
-
owner
public abstract JCodeModel owner()
Gets the owner code model object.
-
fullName
public abstract java.lang.String fullName()
Gets the full name of the type. See http://java.sun.com/docs/books/jls/second_edition/html/names.doc.html#25430 for the details.- Returns:
- Strings like "int", "java.lang.String", "java.io.File[]". Never null.
-
binaryName
public java.lang.String binaryName()
Gets the binary name of the type. See http://java.sun.com/docs/books/jls/third_edition/html/binaryComp.html#44909- Returns:
- Name like "Foo$Bar", "int", "java.lang.String", "java.io.File[]". Never null.
-
name
public abstract java.lang.String name()
Gets the name of this type.- Returns:
- Names like "int", "void", "BigInteger".
-
array
public abstract JClass array()
Create an array type of this type. This method is undefined for primitive void type, which doesn't have any corresponding array representation.- Returns:
- A
JClass
representing the array type whose element type is this type
-
isArray
public boolean isArray()
Tell whether or not this is an array type.
-
isPrimitive
public boolean isPrimitive()
Tell whether or not this is a built-in primitive type, such as int or void.
-
boxify
public abstract JClass boxify()
If this class is a primitive type, return the boxed class. Otherwise return this.For example, for "int", this method returns "java.lang.Integer".
-
unboxify
public abstract JType unboxify()
If this class is a wrapper type for a primitive, return the primitive type. Otherwise return this.For example, for "java.lang.Integer", this method returns "int".
-
erasure
public JType erasure()
Returns the erasure of this type.
-
isReference
public final boolean isReference()
Returns true if this is a referenced type.
-
elementType
public JType elementType()
If this is an array, returns the component type of the array. (T of T[])
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
compareTo
public int compareTo(JType o)
Compare two JTypes by FQCN, giving sorting precedence to types that belong to packages java and javax over all others. This method is used to sort generated import statments in a conventional way for readability.- Specified by:
compareTo
in interfacejava.lang.Comparable<JType>
-
-