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