Package com.sun.codemodel
Class JClass
java.lang.Object
com.sun.codemodel.JType
com.sun.codemodel.JClass
- All Implemented Interfaces:
JGenerable
,Comparable<JType>
- Direct Known Subclasses:
JArrayClass
,JCodeModel.JReferencedClass
,JDefinedClass
,JDirectClass
,JNarrowedClass
,JNullType
,JStaticJavaFile.JStaticClass
,JTypeVar
,JTypeWildcard
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
FieldsModifier and TypeFieldDescriptionprivate final JCodeModel
private JClass
protected static final JTypeVar[]
Sometimes useful reusable empty array. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract JClass
_extends()
Gets the super class of this class.Iterates all super interfaces directly implemented by this class/interface.abstract JPackage
_package()
Gets the package to which this class belongs.array()
Create an array type of this type.boxify()
Deprecated.final JExpression
dotclass()
erasure()
Returns the erasure of this type.void
final JClass
getBaseClass
(JClass baseType) Gets the parameterization of the given base type.final JClass
getBaseClass
(Class<?> baseType) If this class represents one of the wrapper classes defined in the java.lang package, return the corresponding primitive type.If this class is parameterized, return the type parameter of the given index.abstract boolean
Checks if this class is an abstract class.final boolean
isAssignableFrom
(JClass derived) Checks the relationship between two classes.abstract boolean
Checks if this object represents an interface.final boolean
Returns true if this class is a parameterized class.abstract String
name()
Gets the name of this class."Narrows" a generic class to a concrete class by specifying a type argument."Narrows" a generic class to a concrete class by specifying a type argument.outer()
Returns the class in which this class is nested, or null if this is a top-level class.final JCodeModel
owner()
Gets the JCodeModel object to which this object belongs.(package private) void
Prints the class name in javadoc @link format.final JInvocation
staticInvoke
(JMethod method) Generates a static method invocation.final JInvocation
staticInvoke
(String method) Generates a static method invocation.final JFieldRef
Static field reference.final JFieldRef
Static field reference.protected abstract JClass
substituteParams
(JTypeVar[] variables, List<JClass> bindings) Substitutes the type variables with their actual arguments.toString()
JTypeVar[]
Iterates all the type parameters of this class/interface.unboxify()
If this class is a wrapper type for a primitive, return the primitive type.final JClass
wildcard()
Create "? extends T" from T.Methods inherited from class com.sun.codemodel.JType
binaryName, compareTo, elementType, fullName, isArray, isPrimitive, isReference, parse
-
Field Details
-
_owner
-
EMPTY_ARRAY
Sometimes useful reusable empty array. -
arrayClass
-
-
Constructor Details
-
JClass
-
-
Method Details
-
name
Gets the name of this class. -
_package
Gets the package to which this class belongs. TODO: shall we move move this down? -
outer
Returns the class in which this class is nested, or null if this is a top-level class. -
owner
Gets the JCodeModel object to which this object belongs. -
_extends
Gets the super class of this class. -
_implements
Iterates all super interfaces directly implemented by this class/interface.- Returns:
- A non-null valid iterator that iterates all
JClass
objects that represents those interfaces implemented by this object.
-
typeParams
-
isInterface
public abstract boolean isInterface()Checks if this object represents an interface. -
isAbstract
public abstract boolean isAbstract()Checks if this class is an abstract class. -
getPrimitiveType
If this class represents one of the wrapper classes defined in the java.lang package, return the corresponding primitive type. Otherwise null. -
boxify
Deprecated.calling this method fromJClass
would be meaningless, since it's always guaranteed to return this.Description copied from class:JType
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
Description copied from class:JType
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
Description copied from class:JType
Returns the erasure of this type. -
isAssignableFrom
Checks the relationship between two classes.This method works in the same way as
Class.isAssignableFrom(Class)
works. For example, baseClass.isAssignableFrom(derivedClass)==true. -
getBaseClass
Gets the parameterization of the given base type.For example, given the following
This method works like this:interface Foo extends Listinvalid input: '<'List > {} interface Bar extends Foo {} getBaseClass( Bar, List ) = Listinvalid input: '<'List getBaseClass( Bar, Foo ) = Foo getBaseClass( Fooinvalid input: '<'? extends Number>, Collection ) = Collectioninvalid input: '<'Listinvalid input: '<'? extends Number>> getBaseClass( ArrayListinvalid input: '<'? extends BigInteger>, List ) = Listinvalid input: '<'? extends BigInteger> - Parameters:
baseType
- The class whose parameterization we are interested in.- Returns:
- The use of
baseType
inthis
type. or null if the type is not assignable to the base type.
-
getBaseClass
-
array
Description copied from class:JType
Create an array type of this type. This method is undefined for primitive void type, which doesn't have any corresponding array representation. -
narrow
"Narrows" a generic class to a concrete class by specifying a type argument..narrow(X)
buildsSet<X>
fromSet
. -
narrow
-
narrow
"Narrows" a generic class to a concrete class by specifying a type argument..narrow(X)
buildsSet<X>
fromSet
. -
narrow
-
narrow
-
narrow
-
getTypeParameters
If this class is parameterized, return the type parameter of the given index. -
isParameterized
public final boolean isParameterized()Returns true if this class is a parameterized class. -
wildcard
Create "? extends T" from T.- Returns:
- never null
-
substituteParams
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
JClass
forMap<String,Map<Integer>>
.This method needs to work recursively.
-
toString
-
dotclass
-
staticInvoke
Generates a static method invocation. -
staticInvoke
Generates a static method invocation. -
staticRef
Static field reference. -
staticRef
Static field reference. -
generate
-
printLink
Prints the class name in javadoc @link format.
-
JClass
would be meaningless, since it's always guaranteed to return this.