Top Description Fields Constructors Methods
com.sun.codemodel

public abstract Class JClass

extends JType
Class Inheritance
Known Direct Subclasses
com.sun.codemodel.JCodeModel.JReferencedClass, com.sun.codemodel.JDefinedClass, com.sun.codemodel.JDirectClass, com.sun.codemodel.JNarrowedClass, com.sun.codemodel.JNullType, com.sun.codemodel.JTypeVar, com.sun.codemodel.JTypeWildcard, com.sun.codemodel.fmt.JStaticJavaFile.JStaticClass, com.sun.codemodel.JArrayClass
Imports
java.util.ArrayList, .Arrays, .Collections, .Iterator, .List

Represents a Java reference type, such as a class, an interface, an enum, an array type, a parameterized type.

To be exact, this object represents an "use" of a reference type, not necessarily a declaration of it, which is modeled as JDefinedClass.

Field Summary

Modifier and TypeField and Description
private final JCodeModel
private JClass
protected static final JTypeVar[]
EMPTY_ARRAY

Sometimes useful reusable empty array.

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public abstract JClass

Returns:

Returns the JClass representing the superclass of the entity (class or interface) represented by this . Even if no super class is given explicitly or this is not a class, this method still returns for Object. If this JClass represents Object, return null.
_extends
()

Gets the super class of this class.

public abstract Iterator<JClass>

Returns:

A non-null valid iterator that iterates all objects that represents those interfaces implemented by this object.
_implements
()

Iterates all super interfaces directly implemented by this class/interface.

public abstract JPackage
_package()

Gets the package to which this class belongs.

public JClass
array()

Implements abstract com.sun.codemodel.JType.array.

Create an array type of this type.

public JClass
boxify()

Implements abstract com.sun.codemodel.JType.boxify.

Deprecated

If this class is a primitive type, return the boxed class.

public final JExpression
public JClass
erasure()

Overrides com.sun.codemodel.JType.erasure.

Returns the erasure of this type.

public void
public final JClass

Returns:

The use of baseType in this type. or null if the type is not assignable to the base type.
getBaseClass
(JClass
The class whose parameterization we are interested in.
baseType
)

Gets the parameterization of the given base type.

public final JClass
getBaseClass(Class<?> baseType)

public JPrimitiveType
getPrimitiveType()

If this class represents one of the wrapper classes defined in the java.lang package, return the corresponding primitive type.

public List<JClass>
getTypeParameters()

If this class is parameterized, return the type parameter of the given index.

public abstract boolean
isAbstract()

Checks if this class is an abstract class.

public final boolean
isAssignableFrom(JClass derived)

Checks the relationship between two classes.

public abstract boolean
isInterface()

Checks if this object represents an interface.

public final boolean
isParameterized()

Returns true if this class is a parameterized class.

public abstract String

Returns:

name of this class, without any qualification. For example, this method returns "String" for java.lang.String.
name
()

Implements abstract com.sun.codemodel.JType.name.

Gets the name of this class.

public JClass
narrow(Class<?> clazz)

"Narrows" a generic class to a concrete class by specifying a type argument.

public JClass
narrow(Class<?>... clazz)

public JClass
narrow(JClass clazz)

"Narrows" a generic class to a concrete class by specifying a type argument.

public JClass
narrow(JType type)

public JClass
narrow(JClass... clazz)

public JClass
narrow(List<? extends JClass> clazz)

public JClass
outer()

Returns the class in which this class is nested, or null if this is a top-level class.

public final JCodeModel
owner()

Implements abstract com.sun.codemodel.JType.owner.

Gets the JCodeModel object to which this object belongs.

public final JInvocation
staticInvoke(JMethod method)

Generates a static method invocation.

public final JInvocation
staticInvoke(String method)

Generates a static method invocation.

public final JFieldRef
staticRef(String field)

Static field reference.

public final JFieldRef
staticRef(JVar field)

Static field reference.

protected abstract JClass
substituteParams(JTypeVar[] variables, List<JClass> bindings)

Substitutes the type variables with their actual arguments.

public String
toString()

Overrides com.sun.codemodel.JType.toString.

Returns a string representation of the object.

public JTypeVar[]
typeParams()

Iterates all the type parameters of this class/interface.

public JType
unboxify()

Implements abstract com.sun.codemodel.JType.unboxify.

If this class is a wrapper type for a primitive, return the primitive type.

public final JClass

Returns:

never null
wildcard
()

Create "?

Inherited from com.sun.codemodel.JType:
binaryNamecompareToelementTypefullNameisArrayisPrimitiveisReferenceparse

Field Detail

_ownerback to summary
private final JCodeModel _owner
arrayClassback to summary
private JClass arrayClass
EMPTY_ARRAYback to summary
protected static final JTypeVar[] EMPTY_ARRAY

Sometimes useful reusable empty array.

Constructor Detail

JClassback to summary
protected JClass(JCodeModel _owner)

Method Detail

_extendsback to summary
public abstract JClass _extends()

Gets the super class of this class.

Returns:JClass

Returns the JClass representing the superclass of the entity (class or interface) represented by this . Even if no super class is given explicitly or this is not a class, this method still returns for Object. If this JClass represents Object, return null.

_implementsback to summary
public abstract Iterator<JClass> _implements()

Iterates all super interfaces directly implemented by this class/interface.

Returns:Iterator<JClass>

A non-null valid iterator that iterates all objects that represents those interfaces implemented by this object.

_packageback to summary
public abstract JPackage _package()

Gets the package to which this class belongs.

Todo

shall we move move this down?

arrayback to summary
public JClass array()

Implements abstract com.sun.codemodel.JType.array.

Doc from com.sun.codemodel.JType.array.

Create an array type of this type. This method is undefined for primitive void type, which doesn't have any corresponding array representation.

Annotations
@Override
boxifyback to summary
public JClass boxify()

Implements abstract com.sun.codemodel.JType.boxify.

Doc from com.sun.codemodel.JType.boxify.

Deprecated

If this class is a primitive type, return the boxed class. Otherwise return this.

For example, for "int", this method returns "java.lang.Integer".

Annotations
@Deprecated
@Override
dotclassback to summary
public final JExpression dotclass()
erasureback to summary
public JClass erasure()

Overrides com.sun.codemodel.JType.erasure.

Doc from com.sun.codemodel.JType.erasure.

Returns the erasure of this type.

Annotations
@Override
generateback to summary
public void generate(JFormatter f)

Implements com.sun.codemodel.JGenerable.generate.

Annotations
@Override
getBaseClassback to summary
public final JClass getBaseClass(JClass baseType)

Gets the parameterization of the given base type.

For example, given the following

interface Foo<T> extends List<List<T>> {}
interface Bar extends Foo<String> {}
This method works like this:
getBaseClass( Bar, List ) = List<List<String>
getBaseClass( Bar, Foo  ) = Foo<String>
getBaseClass( Foo<? extends Number>, Collection ) = Collection<List<? extends Number>>
getBaseClass( ArrayList<? extends BigInteger>, List ) = List<? extends BigInteger>
Parameters
baseType:JClass

The class whose parameterization we are interested in.

Returns:JClass

The use of baseType in this type. or null if the type is not assignable to the base type.

getBaseClassback to summary
public final JClass getBaseClass(Class<?> baseType)
getPrimitiveTypeback to summary
public JPrimitiveType getPrimitiveType()

If this class represents one of the wrapper classes defined in the java.lang package, return the corresponding primitive type. Otherwise null.

getTypeParametersback to summary
public List<JClass> getTypeParameters()

If this class is parameterized, return the type parameter of the given index.

isAbstractback to summary
public abstract boolean isAbstract()

Checks if this class is an abstract class.

isAssignableFromback to summary
public final boolean isAssignableFrom(JClass derived)

Checks the relationship between two classes.

This method works in the same way as Class#isAssignableFrom(Class) works. For example, baseClass.isAssignableFrom(derivedClass)==true.

isInterfaceback to summary
public abstract boolean isInterface()

Checks if this object represents an interface.

isParameterizedback to summary
public final boolean isParameterized()

Returns true if this class is a parameterized class.

nameback to summary
public abstract String name()

Implements abstract com.sun.codemodel.JType.name.

Gets the name of this class.

Returns:String

name of this class, without any qualification. For example, this method returns "String" for java.lang.String.

Annotations
@Override
narrowback to summary
public JClass narrow(Class<?> clazz)

"Narrows" a generic class to a concrete class by specifying a type argument.

.narrow(X) builds Set<X> from Set.

narrowback to summary
public JClass narrow(Class<?>... clazz)
narrowback to summary
public JClass narrow(JClass clazz)

"Narrows" a generic class to a concrete class by specifying a type argument.

.narrow(X) builds Set<X> from Set.

narrowback to summary
public JClass narrow(JType type)
narrowback to summary
public JClass narrow(JClass... clazz)
narrowback to summary
public JClass narrow(List<? extends JClass> clazz)
outerback to summary
public JClass outer()

Returns the class in which this class is nested, or null if this is a top-level class.

ownerback to summary
public final JCodeModel owner()

Implements abstract com.sun.codemodel.JType.owner.

Gets the JCodeModel object to which this object belongs.

Annotations
@Override
staticInvokeback to summary
public final JInvocation staticInvoke(JMethod method)

Generates a static method invocation.

staticInvokeback to summary
public final JInvocation staticInvoke(String method)

Generates a static method invocation.

staticRefback to summary
public final JFieldRef staticRef(String field)

Static field reference.

staticRefback to summary
public final JFieldRef staticRef(JVar field)

Static field reference.

substituteParamsback to summary
protected abstract JClass substituteParams(JTypeVar[] variables, List<JClass> bindings)

Substitutes the type variables with their actual arguments.

For example, when this class is Map<String,Map<V>>, (where V then doing substituteParams( V, Integer ) returns a for Map<String,Map<Integer>>.

This method needs to work recursively.

toStringback to summary
public String toString()

Overrides com.sun.codemodel.JType.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override
typeParamsback to summary
public JTypeVar[] typeParams()

Iterates all the type parameters of this class/interface.

For example, if this represents Set<T>, this method returns an array that contains single JTypeVar for 'T'.

unboxifyback to summary
public JType unboxify()

Implements abstract com.sun.codemodel.JType.unboxify.

Doc from com.sun.codemodel.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".

Annotations
@Override
wildcardback to summary
public final JClass wildcard()

Create "? extends T" from T.

Returns:JClass

never null