Class JClass
- All Implemented Interfaces:
JGenerable
,Comparable<JType>
- Direct Known Subclasses:
JDefinedClass
,JNullType
,JTypeVar
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 TypeFieldDescriptionprotected static final JTypeVar[]
Sometimes useful reusable empty array. -
Constructor Summary
-
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, ornull
if this is a top-level class.final JCodeModel
owner()
Gets the JCodeModel object to which this object belongs.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
-
EMPTY_ARRAY
Sometimes useful reusable empty array.
-
-
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, ornull
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 objects that represents those interfaces implemented by this object.
-
typeParams
Iterates all the type parameters of this class/interface.For example, if this represents
Set<T>
, this method returns an array that contains singleJTypeVar
for 'T'. -
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.Description copied from class:JType
If this class is a primitive type, return the boxed class. Otherwise returnthis
.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 returnthis
.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<T> extends List<List<T>> {} interface Bar extends Foo<String> {}
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
- 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 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
-