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 JCodeModelprivate JClassprotected 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 JExpressiondotclass()erasure()Returns the erasure of this type.voidfinal JClassgetBaseClass(JClass baseType) Gets the parameterization of the given base type.final JClassgetBaseClass(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 booleanChecks if this class is an abstract class.final booleanisAssignableFrom(JClass derived) Checks the relationship between two classes.abstract booleanChecks if this object represents an interface.final booleanReturns true if this class is a parameterized class.abstract Stringname()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 JCodeModelowner()Gets the JCodeModel object to which this object belongs.(package private) voidPrints the class name in javadoc @link format.final JInvocationstaticInvoke(JMethod method) Generates a static method invocation.final JInvocationstaticInvoke(String method) Generates a static method invocation.final JFieldRefStatic field reference.final JFieldRefStatic field reference.protected abstract JClasssubstituteParams(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 JClasswildcard()Create "? extends T" from T.Methods inherited from class 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
-
_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
-
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
-
unboxify
-
erasure
-
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
baseTypeinthistype. or null if the type is not assignable to the base type.
-
getBaseClass
-
array
Description copied from class:JTypeCreate an array type of this type. This method is undefined for primitive void type, which doesn't have any corresponding array representation. -
narrow
-
narrow
-
narrow
-
narrow
-
narrow
-
narrow
-
getTypeParameters
-
isParameterized
public final boolean isParameterized()Returns true if this class is a parameterized class. -
wildcard
-
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
JClassforMap<String,Map<Integer>>.This method needs to work recursively.
-
toString
-
dotclass
-
staticInvoke
Generates a static method invocation. -
staticInvoke
Generates a static method invocation. -
staticRef
-
staticRef
-
generate
-
printLink
Prints the class name in javadoc @link format.
-
JClasswould be meaningless, since it's always guaranteed to return this.