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:
JDefinedClass,JNullType,JTypeVar
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 protected static JTypeVar[]EMPTY_ARRAYSometimes useful reusable empty array.
-
Constructor Summary
Constructors Modifier Constructor Description protectedJClass(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 Iterator<JClass>_implements()Iterates all super interfaces directly implemented by this class/interface.abstract JPackage_package()Gets the package to which this class belongs.JClassarray()Create an array type of this type.JClassboxify()Deprecated.calling this method fromJClasswould be meaningless, since it's always guaranteed to returnthis.JExpressiondotclass()JClasserasure()Returns the erasure of this type.voidgenerate(JFormatter f)JClassgetBaseClass(JClass baseType)Gets the parameterization of the given base type.JClassgetBaseClass(Class<?> baseType)JPrimitiveTypegetPrimitiveType()If this class represents one of the wrapper classes defined in the java.lang package, return the corresponding primitive type.List<JClass>getTypeParameters()If this class is parameterized, return the type parameter of the given index.abstract booleanisAbstract()Checks if this class is an abstract class.booleanisAssignableFrom(JClass derived)Checks the relationship between two classes.abstract booleanisInterface()Checks if this object represents an interface.booleanisParameterized()Returns true if this class is a parameterized class.abstract Stringname()Gets the name of this class.JClassnarrow(JClass clazz)"Narrows" a generic class to a concrete class by specifying a type argument.JClassnarrow(JClass... clazz)JClassnarrow(JType type)JClassnarrow(Class<?> clazz)"Narrows" a generic class to a concrete class by specifying a type argument.JClassnarrow(Class<?>... clazz)JClassnarrow(List<? extends JClass> clazz)JClassouter()Returns the class in which this class is nested, ornullif this is a top-level class.JCodeModelowner()Gets the JCodeModel object to which this object belongs.JInvocationstaticInvoke(JMethod method)Generates a static method invocation.JInvocationstaticInvoke(String method)Generates a static method invocation.JFieldRefstaticRef(JVar field)Static field reference.JFieldRefstaticRef(String field)Static field reference.protected abstract JClasssubstituteParams(JTypeVar[] variables, List<JClass> bindings)Substitutes the type variables with their actual arguments.StringtoString()JTypeVar[]typeParams()Iterates all the type parameters of this class/interface.JTypeunboxify()If this class is a wrapper type for a primitive, return the primitive type.JClasswildcard()Create "? extends T" from T.-
Methods inherited from class com.sun.codemodel.JType
binaryName, compareTo, elementType, fullName, isArray, isPrimitive, isReference, parse
-
-
-
-
Field Detail
-
EMPTY_ARRAY
protected static final JTypeVar[] EMPTY_ARRAY
Sometimes useful reusable empty array.
-
-
Constructor Detail
-
JClass
protected JClass(JCodeModel _owner)
-
-
Method Detail
-
name
public abstract 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, ornullif 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 Iterator<JClass> _implements()
Iterates all super interfaces directly implemented by this class/interface.- Returns:
- A non-null valid iterator that iterates all
JClassobjects 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
@Deprecated public JClass boxify()
Deprecated.calling this method fromJClasswould be meaningless, since it's always guaranteed to returnthis.Description copied from class:JTypeIf this class is a primitive type, return the boxed class. Otherwise returnthis.For example, for "int", this method returns "java.lang.Integer".
-
unboxify
public JType unboxify()
Description copied from class:JTypeIf 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
public JClass erasure()
Description copied from class:JTypeReturns 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<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
baseTypeinthistype. or null if the type is not assignable to the base type.
-
array
public JClass 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
public JClass narrow(Class<?> clazz)
"Narrows" a generic class to a concrete class by specifying a type argument..narrow(X)buildsSet<X>fromSet.
-
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 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, 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 aJClassforMap<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(String method)
Generates a static method invocation.
-
generate
public void generate(JFormatter f)
-
-