public class JDefinedClass extends JClass implements JDeclaration, JClassContainer, JGenerifiable, JAnnotatable, JDocCommentable
This class models a declaration, and since a declaration can be always
used as a reference, it inherits JClass
.
You'd want to generate fields and methods on a class.
See method(int, JType, String)
and field(int, JType, String)
.
Modifier and Type | Field and Description |
---|---|
private java.util.List<JAnnotationUse> |
annotations
Annotations on this variable.
|
private java.util.Map<java.lang.String,JDefinedClass> |
classes
Nested classes as a map from name to JDefinedClass.
|
private ClassType |
classType
Default value is class or interface
or annotationTypeDeclaration
or enum
|
private java.util.List<JMethod> |
constructors
Set of constructors for this class, if any
|
private java.lang.String |
directBlock
String that will be put directly inside the generated code.
|
private java.util.Map<java.lang.String,JEnumConstant> |
enumConstantsByName
Set of enum constants that are keyed by names.
|
(package private) java.util.Map<java.lang.String,JFieldVar> |
fields
Fields keyed by their names.
|
private JGenerifiableImpl |
generifiable
Helper class to implement
JGenerifiable . |
private boolean |
hideFile
Flag that controls whether this class should be really generated or not.
|
private JBlock |
init
Static initializer, if this class has one
|
private java.util.Set<JClass> |
interfaces
List of interfaces that this class implements
|
private JDocComment |
jdoc
class javadoc
|
java.lang.Object |
metadata
Client-app spcific metadata associated with this user-created class.
|
private java.util.List<JMethod> |
methods
Set of methods that are members of this class
|
private JMods |
mods
Modifiers for the class declaration
|
private java.lang.String |
name
Name of this class.
|
private JClassContainer |
outer
If this is a package-member class, this is
JPackage . |
private JClass |
superClass
Name of the super class of this class.
|
EMPTY_ARRAY
Modifier | Constructor and Description |
---|---|
private |
JDefinedClass(int mods,
java.lang.String name,
JClassContainer parent,
JCodeModel owner) |
private |
JDefinedClass(int mods,
java.lang.String name,
JClassContainer parent,
JCodeModel owner,
ClassType classTypeVal)
JClass constructor
|
(package private) |
JDefinedClass(JClassContainer parent,
int mods,
java.lang.String name,
ClassType classTypeval) |
(package private) |
JDefinedClass(JCodeModel owner,
int mods,
java.lang.String name)
Constructor for creating anonymous inner class.
|
Modifier and Type | Method and Description |
---|---|
JDefinedClass |
_annotationTypeDeclaration(java.lang.String name)
Add an annotationType Declaration to this package
|
JDefinedClass |
_class(int mods,
java.lang.String name)
Add a new nested class to this class.
|
JDefinedClass |
_class(int mods,
java.lang.String name,
boolean isInterface)
Deprecated.
|
JDefinedClass |
_class(int mods,
java.lang.String name,
ClassType classTypeVal)
Creates a new class/enum/interface/annotation.
|
JDefinedClass |
_class(java.lang.String name)
Add a new public nested class to this class.
|
JDefinedClass |
_enum(int mods,
java.lang.String name)
Add a public enum to this package
|
JDefinedClass |
_enum(java.lang.String name)
Add a public enum to this package
|
JClass |
_extends()
Returns the class extended by this class.
|
JDefinedClass |
_extends(java.lang.Class<?> superClass) |
JDefinedClass |
_extends(JClass superClass)
This class extends the specifed class.
|
java.util.Iterator<JClass> |
_implements()
Returns an iterator that walks the nested classes defined in this
class.
|
JDefinedClass |
_implements(java.lang.Class<?> iface) |
JDefinedClass |
_implements(JClass iface)
This class implements the specifed interface.
|
JDefinedClass |
_interface(int mods,
java.lang.String name)
Add an interface to this package.
|
JDefinedClass |
_interface(java.lang.String name)
Adds a public interface to this package.
|
JPackage |
_package()
Gets the package to which this class belongs.
|
JAnnotationUse |
annotate(java.lang.Class<? extends java.lang.annotation.Annotation> clazz)
Adding ability to annotate a class
|
JAnnotationUse |
annotate(JClass clazz)
Adding ability to annotate a class
|
<W extends JAnnotationWriter> |
annotate2(java.lang.Class<W> clazz)
Adds an annotation to this program element
and returns a type-safe writer to fill in the values of such annotations.
|
java.util.Collection<JAnnotationUse> |
annotations()
|
java.lang.String |
binaryName()
Gets the binary name of the type.
|
java.util.Iterator<JDefinedClass> |
classes()
Returns an iterator that walks the nested classes defined in this
class.
|
JMethod |
constructor(int mods)
Adds a constructor to this class.
|
java.util.Iterator<JMethod> |
constructors()
Returns an iterator that walks the constructors defined in this class.
|
void |
declare(JFormatter f) |
protected void |
declareBody(JFormatter f)
prints the body of a class.
|
void |
direct(java.lang.String string)
Places the given string directly inside the generated class.
|
JEnumConstant |
enumConstant(java.lang.String name)
If the named enum already exists, the reference to it is returned.
|
JFieldVar |
field(int mods,
java.lang.Class<?> type,
java.lang.String name) |
JFieldVar |
field(int mods,
java.lang.Class<?> type,
java.lang.String name,
JExpression init) |
JFieldVar |
field(int mods,
JType type,
java.lang.String name)
Adds a field to the list of field members of this JDefinedClass.
|
JFieldVar |
field(int mods,
JType type,
java.lang.String name,
JExpression init)
Adds a field to the list of field members of this JDefinedClass.
|
java.util.Map<java.lang.String,JFieldVar> |
fields()
Returns all the fields declred in this class.
|
java.lang.String |
fullName()
Gets the fully qualified name of this class.
|
JTypeVar |
generify(java.lang.String name)
Adds a new type variable to this declaration.
|
JTypeVar |
generify(java.lang.String name,
java.lang.Class<?> bound)
Adds a new type variable to this declaration with a bound.
|
JTypeVar |
generify(java.lang.String name,
JClass bound)
Adds a new type variable to this declaration with a bound.
|
private java.util.Map<java.lang.String,JDefinedClass> |
getClasses() |
ClassType |
getClassType() |
JMethod |
getConstructor(JType[] argTypes)
Looks for a method that has the specified method signature
and return it.
|
JMethod |
getMethod(java.lang.String name,
JType[] argTypes)
Looks for a method that has the specified method signature
and return it.
|
JPackage |
getPackage()
Gets the nearest package parent.
|
void |
hide()
Mark this file as hidden, so that this file won't be
generated.
|
JBlock |
init()
Creates, if necessary, and returns the static initializer
for this class.
|
boolean |
isAbstract()
Checks if this class is an abstract class.
|
boolean |
isAnnotationTypeDeclaration()
This method indicates if the interface
is an annotationTypeDeclaration
|
boolean |
isAnonymous()
Returns true if this is an anonymous class.
|
boolean |
isClass()
Returns true if the container is a class.
|
boolean |
isHidden() |
boolean |
isInterface()
Checks if this object represents an interface.
|
boolean |
isPackage()
Returns true if the container is a package.
|
JDocComment |
javadoc()
Creates, if necessary, and returns the class javadoc for this
JDefinedClass
|
JClass[] |
listClasses()
Returns all the nested classes defined in this class.
|
JMethod |
method(int mods,
java.lang.Class<?> type,
java.lang.String name) |
JMethod |
method(int mods,
JType type,
java.lang.String name)
Add a method to the list of method members of this JDefinedClass instance.
|
java.util.Collection<JMethod> |
methods()
Returns the set of methods defined in this class.
|
JMods |
mods() |
java.lang.String |
name()
JClass name accessor.
|
JClass |
outer()
Returns the class in which this class is nested, or null if
this is a top-level class.
|
JClassContainer |
parentContainer()
Parent JClassContainer.
|
void |
removeField(JFieldVar field)
Removes a
JFieldVar from this class. |
protected JClass |
substituteParams(JTypeVar[] variables,
java.util.List<JClass> bindings)
Substitutes the type variables with their actual arguments.
|
JTypeVar[] |
typeParams()
Iterates all the type parameters of this class/interface.
|
array, boxify, dotclass, erasure, generate, getBaseClass, getBaseClass, getPrimitiveType, getTypeParameters, isAssignableFrom, isParameterized, narrow, narrow, narrow, narrow, narrow, narrow, owner, printLink, staticInvoke, staticInvoke, staticRef, staticRef, toString, unboxify, wildcard
compareTo, elementType, isArray, isPrimitive, isReference, parse
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
owner
private java.lang.String name
private JMods mods
private JClass superClass
private final java.util.Set<JClass> interfaces
final java.util.Map<java.lang.String,JFieldVar> fields
private JBlock init
private JDocComment jdoc
private final java.util.List<JMethod> constructors
private final java.util.List<JMethod> methods
private java.util.Map<java.lang.String,JDefinedClass> classes
JCodeModel.isCaseSensitiveFileSystem
) to avoid conflicts.
Lazily created to save footprint.getClasses()
private boolean hideFile
public java.lang.Object metadata
private java.lang.String directBlock
private JClassContainer outer
JPackage
.
If this is a nested class, this is JDefinedClass
.
If this is an anonymous class, this constructor shouldn't be used.private final ClassType classType
private final java.util.Map<java.lang.String,JEnumConstant> enumConstantsByName
private java.util.List<JAnnotationUse> annotations
private final JGenerifiableImpl generifiable
JGenerifiable
.JDefinedClass(JClassContainer parent, int mods, java.lang.String name, ClassType classTypeval)
JDefinedClass(JCodeModel owner, int mods, java.lang.String name)
private JDefinedClass(int mods, java.lang.String name, JClassContainer parent, JCodeModel owner)
private JDefinedClass(int mods, java.lang.String name, JClassContainer parent, JCodeModel owner, ClassType classTypeVal)
mods
- Modifiers for this class declarationname
- Name of this classpublic final boolean isAnonymous()
public JDefinedClass _extends(JClass superClass)
superClass
- Superclass for this classpublic JDefinedClass _extends(java.lang.Class<?> superClass)
public JClass _extends()
_extends
in class JClass
JClass
.
Even if no super class is given explicitly or this JClass
is not a class, this method still returns
JClass
for Object
.
If this JClass represents Object
, return null.public JDefinedClass _implements(JClass iface)
iface
- Interface that this class implementspublic JDefinedClass _implements(java.lang.Class<?> iface)
public java.util.Iterator<JClass> _implements()
_implements
in class JClass
JClass
objects that represents those interfaces
implemented by this object.public java.lang.String name()
For example, for java.util.List
, this method
returns "List"
"
public JEnumConstant enumConstant(java.lang.String name)
name
- The name of the constant.public java.lang.String fullName()
public java.lang.String binaryName()
JType
binaryName
in class JType
public boolean isInterface()
JClass
isInterface
in class JClass
public boolean isAbstract()
JClass
isAbstract
in class JClass
public JFieldVar field(int mods, JType type, java.lang.String name)
mods
- Modifiers for this fieldtype
- JType of this fieldname
- Name of this fieldpublic JFieldVar field(int mods, java.lang.Class<?> type, java.lang.String name)
public JFieldVar field(int mods, JType type, java.lang.String name, JExpression init)
mods
- Modifiers for this field.type
- JType of this field.name
- Name of this field.init
- Initial value of this field.public boolean isAnnotationTypeDeclaration()
public JDefinedClass _annotationTypeDeclaration(java.lang.String name) throws JClassAlreadyExistsException
_annotationTypeDeclaration
in interface JClassContainer
name
- Name of the annotation Type declaration to be added to this packageJClassAlreadyExistsException
- When the specified class/interface was already created.public JDefinedClass _enum(java.lang.String name) throws JClassAlreadyExistsException
_enum
in interface JClassContainer
name
- Name of the enum to be added to this packageJClassAlreadyExistsException
- When the specified class/interface was already created.public JDefinedClass _enum(int mods, java.lang.String name) throws JClassAlreadyExistsException
name
- Name of the enum to be added to this packagemods
- Modifiers for this enum declarationJClassAlreadyExistsException
- When the specified class/interface was already created.public ClassType getClassType()
public JFieldVar field(int mods, java.lang.Class<?> type, java.lang.String name, JExpression init)
public java.util.Map<java.lang.String,JFieldVar> fields()
Map
is a read-only live view.public void removeField(JFieldVar field)
JFieldVar
from this class.java.lang.IllegalArgumentException
- if the given field is not a field on this class.public JBlock init()
public JMethod constructor(int mods)
mods
- Modifiers for this constructorpublic java.util.Iterator<JMethod> constructors()
public JMethod getConstructor(JType[] argTypes)
public JMethod method(int mods, JType type, java.lang.String name)
mods
- Modifiers for this methodtype
- Return type for this methodname
- Name of the methodpublic JMethod method(int mods, java.lang.Class<?> type, java.lang.String name)
public java.util.Collection<JMethod> methods()
public JMethod getMethod(java.lang.String name, JType[] argTypes)
public boolean isClass()
JClassContainer
isClass
in interface JClassContainer
public boolean isPackage()
JClassContainer
isPackage
in interface JClassContainer
public JPackage getPackage()
JClassContainer
If this.isPackage(), then return this.
getPackage
in interface JClassContainer
public JDefinedClass _class(int mods, java.lang.String name) throws JClassAlreadyExistsException
_class
in interface JClassContainer
mods
- Modifiers for this class declarationname
- Name of class to be added to this packageJClassAlreadyExistsException
- When the specified class/interface was already created.public JDefinedClass _class(int mods, java.lang.String name, boolean isInterface) throws JClassAlreadyExistsException
_class
in interface JClassContainer
JClassAlreadyExistsException
public JDefinedClass _class(int mods, java.lang.String name, ClassType classTypeVal) throws JClassAlreadyExistsException
JClassContainer
_class
in interface JClassContainer
JClassAlreadyExistsException
public JDefinedClass _class(java.lang.String name) throws JClassAlreadyExistsException
_class
in interface JClassContainer
JClassAlreadyExistsException
- When the specified class/interface was already created.public JDefinedClass _interface(int mods, java.lang.String name) throws JClassAlreadyExistsException
_interface
in interface JClassContainer
mods
- Modifiers for this interface declarationname
- Name of interface to be added to this packageJClassAlreadyExistsException
- When the specified class/interface was already created.public JDefinedClass _interface(java.lang.String name) throws JClassAlreadyExistsException
_interface
in interface JClassContainer
JClassAlreadyExistsException
- When the specified class/interface was already created.public JDocComment javadoc()
javadoc
in interface JDocCommentable
public void hide()
This feature could be used to generate code that refers to class X, without actually generating X.java.
public boolean isHidden()
public final java.util.Iterator<JDefinedClass> classes()
classes
in interface JClassContainer
private java.util.Map<java.lang.String,JDefinedClass> getClasses()
public final JClass[] listClasses()
public JClass outer()
JClass
public void declare(JFormatter f)
declare
in interface JDeclaration
protected void declareBody(JFormatter f)
public void direct(java.lang.String string)
public final JPackage _package()
JClass
public final JClassContainer parentContainer()
JClassContainer
parentContainer
in interface JClassContainer
public JTypeVar generify(java.lang.String name)
JGenerifiable
generify
in interface JGenerifiable
public JTypeVar generify(java.lang.String name, java.lang.Class<?> bound)
JGenerifiable
generify
in interface JGenerifiable
public JTypeVar generify(java.lang.String name, JClass bound)
JGenerifiable
generify
in interface JGenerifiable
public JTypeVar[] typeParams()
JClass
For example, if this JClass
represents
Set<T>
, this method returns an array
that contains single JTypeVar
for 'T'.
typeParams
in interface JGenerifiable
typeParams
in class JClass
protected JClass substituteParams(JTypeVar[] variables, java.util.List<JClass> bindings)
JClass
For example, when this class is Map<String,Map<V>>,
(where V then doing
substituteParams( V, Integer ) returns a JClass
for Map<String,Map<Integer>>
.
This method needs to work recursively.
substituteParams
in class JClass
public JAnnotationUse annotate(java.lang.Class<? extends java.lang.annotation.Annotation> clazz)
annotate
in interface JAnnotatable
clazz
- The annotation class to annotate the class withpublic JAnnotationUse annotate(JClass clazz)
annotate
in interface JAnnotatable
clazz
- The annotation class to annotate the class withpublic <W extends JAnnotationWriter> W annotate2(java.lang.Class<W> clazz)
JAnnotatable
annotate2
in interface JAnnotatable
public java.util.Collection<JAnnotationUse> annotations()
annotations
in interface JAnnotatable
public JMods mods()