public class JDefinedClass extends AbstractJClassContainer<JDefinedClass> implements IJDeclaration, IJGenerifiable, IJAnnotatable, IJDocCommentable
This class models a declaration, and since a declaration can be always used
as a reference, it inherits AbstractJClass
.
You'd want to generate fields and methods on a class. See
method(int, AbstractJType, String)
and
field(int, AbstractJType, String)
.
Modifier and Type | Field and Description |
---|---|
Object |
metadata
Client-app specific metadata associated with this user-created class.
|
m_aClasses
EMPTY_ARRAY
Modifier | Constructor and Description |
---|---|
protected |
JDefinedClass(IJClassContainer<?> aParent,
int nMods,
String sName,
EClassType eClassType) |
protected |
JDefinedClass(JCodeModel aOwner,
int nMods,
String sName)
Constructor for creating anonymous inner class.
|
Modifier and Type | Method and Description |
---|---|
AbstractJClass |
_extends()
Returns the class extended by this class.
|
JDefinedClass |
_extends(AbstractJClass aSuperClass)
This class extends the specified class.
|
JDefinedClass |
_extends(Class<?> superClass) |
Iterator<AbstractJClass> |
_implements()
Returns an iterator that walks the nested classes defined in this class.
|
JDefinedClass |
_implements(AbstractJClass iface)
This class implements the specifed interface.
|
JDefinedClass |
_implements(Class<?> iface) |
JPackage |
_package()
Gets the package to which this class belongs.
|
JAnnotationUse |
annotate(AbstractJClass clazz)
Adds an annotation to this program element.
|
JAnnotationUse |
annotate(Class<? extends Annotation> clazz)
Adds an annotation to this program element.
|
<W extends IJAnnotationWriter<?>> |
annotate2(Class<W> clazz)
Adds an annotation to this program element and returns a type-safe writer
to fill in the values of such annotations.
|
Collection<JAnnotationUse> |
annotations()
Read-only live view of all annotations on this
IJAnnotatable |
String |
binaryName()
Gets the binary name of the type.
|
JMethod |
constructor(int mods)
Adds a constructor to this class.
|
Iterator<JMethod> |
constructors() |
boolean |
containsField(String sName) |
protected JDefinedClass |
createInnerClass(int nMods,
EClassType eClassType,
String sName) |
void |
declare(JFormatter f) |
protected void |
declareBody(JFormatter f)
prints the body of a class.
|
void |
direct(String string)
Places the given string directly inside the generated class.
|
JEnumConstant |
enumConstant(String name)
If the named enum already exists, the reference to it is returned.
|
JFieldVar |
field(int mods,
AbstractJType type,
String name)
Adds a field to the list of field members of this JDefinedClass.
|
JFieldVar |
field(int mods,
AbstractJType type,
String name,
IJExpression init)
Adds a field to the list of field members of this JDefinedClass.
|
JFieldVar |
field(int mods,
Class<?> type,
String name) |
JFieldVar |
field(int mods,
Class<?> type,
String name,
IJExpression init) |
Map<String,JFieldVar> |
fields()
Returns all the fields declared in this class.
|
JTypeVar |
generify(String name)
Adds a new type variable to this declaration.
|
JTypeVar |
generify(String name,
AbstractJClass bound)
Adds a new type variable to this declaration with a bound.
|
JTypeVar |
generify(String name,
Class<?> bound)
Adds a new type variable to this declaration with a bound.
|
JMethod |
getConstructor(AbstractJType[] aArgTypes)
Looks for a method that has the specified method signature and return it.
|
JMethod |
getMethod(String sName,
AbstractJType[] aArgTypes)
Looks for a method that has the specified method signature and return it.
|
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.
|
JBlock |
instanceInit()
Creates, if necessary, and returns the instance initializer for this class.
|
boolean |
isAbstract() |
boolean |
isHidden() |
JDocComment |
javadoc()
Creates, if necessary, and returns the class javadoc for this JDefinedClass
|
JMethod |
method(int mods,
AbstractJType type,
String name)
Add a method to the list of method members of this JDefinedClass instance.
|
JMethod |
method(int mods,
Class<?> type,
String name) |
Collection<JMethod> |
methods() |
JMods |
mods() |
void |
removeField(JFieldVar aField)
Removes a
JFieldVar from this class. |
protected AbstractJClass |
substituteParams(JTypeVar[] variables,
List<? extends AbstractJClass> bindings)
Substitutes the type variables with their actual arguments.
|
List<JTypeVar> |
typeParamList()
Get a list of all type parameters of this declaration.
|
JTypeVar[] |
typeParams()
Iterates all the type parameters of this class/interface.
|
_annotationTypeDeclaration, _annotationTypeDeclaration, _class, _class, _class, _enum, _enum, _interface, _interface, classes, fullName, getClassType, getOuter, getPackage, isAnnotationTypeDeclaration, isAnonymous, isClass, isInterface, isPackage, name, outer, parentContainer, thisAsT
array, boxify, dotclass, erasure, generate, getBaseClass, getBaseClass, getPrimitiveType, getTypeParameters, isParameterized, narrow, narrow, narrow, narrow, narrow, narrow, owner, staticInvoke, staticInvoke, staticRef, staticRef, toString, unboxify, wildcard, wildcard, wildcardSuper
elementType, isArray, isAssignableFrom, isAssignableFrom, isError, isPrimitive, isReference, parse
public Object metadata
protected JDefinedClass(@Nonnull IJClassContainer<?> aParent, int nMods, @Nullable String sName, @Nonnull EClassType eClassType)
protected JDefinedClass(@Nonnull JCodeModel aOwner, int nMods, @Nullable String sName)
aOwner
- Owning code modelnMods
- Java modifiersName
- Name of this class@Nonnull public JDefinedClass _extends(@Nonnull AbstractJClass aSuperClass)
aSuperClass
- Superclass for this class@Nonnull public JDefinedClass _extends(@Nonnull Class<?> superClass)
@Nonnull public AbstractJClass _extends()
_extends
in class AbstractJClass
AbstractJClass
representing the superclass of
the entity (class or interface) represented by this
AbstractJClass
. Even if no super class is given explicitly
or this AbstractJClass
is not a class, this method still
returns AbstractJClass
for Object
. If this
AbstractJClass
represents Object
, return null.@Nonnull public JDefinedClass _implements(@Nonnull AbstractJClass iface)
iface
- Interface that this class implements@Nonnull public JDefinedClass _implements(@Nonnull Class<?> iface)
@Nonnull public Iterator<AbstractJClass> _implements()
_implements
in class AbstractJClass
AbstractJClass
objects that represents those interfaces implemented by this
object.@Nonnull public JEnumConstant enumConstant(@Nonnull String name)
name
- The name of the constant.public String binaryName()
AbstractJType
binaryName
in class AbstractJType
public boolean isAbstract()
isAbstract
in class AbstractJClass
true
if this class is an abstract class.public JFieldVar field(int mods, AbstractJType type, String name)
mods
- Modifiers for this fieldtype
- JType of this fieldname
- Name of this field@Nonnull public JFieldVar field(int mods, AbstractJType type, String name, IJExpression init)
mods
- Modifiers for this field.type
- JType of this field.name
- Name of this field.init
- Initial value of this field.@Nonnull public JFieldVar field(int mods, Class<?> type, String name, IJExpression init)
@Nonnull public Map<String,JFieldVar> fields()
Map
is
a read-only live view.public void removeField(@Nonnull JFieldVar aField)
JFieldVar
from this class.aField
- Field to be removedIllegalArgumentException
- if the given field is not a field on this class.public boolean containsField(@Nullable String sName)
sName
- Field name to check. May be null
.true
if such a field is contained, false
otherwise.@Nonnull public JBlock init()
@Nonnull public JBlock instanceInit()
@Nonnull public JMethod constructor(int mods)
mods
- Modifiers for this constructorJMethod
@Nonnull public Iterator<JMethod> constructors()
@Nullable public JMethod getConstructor(@Nonnull AbstractJType[] aArgTypes)
aArgTypes
- Signature to searchnull
if not found.@Nonnull public JMethod method(int mods, AbstractJType type, String name)
mods
- Modifiers for this methodtype
- Return type for this methodname
- Name of the methodJMethod
@Nonnull public Collection<JMethod> methods()
@Nullable public JMethod getMethod(String sName, AbstractJType[] aArgTypes)
sName
- Method name to searchaArgTypes
- Signature to searchnull
if not found.@Nonnull public JDocComment javadoc()
javadoc
in interface IJDocCommentable
JDocComment
containing javadocs for this classpublic void hide()
public boolean isHidden()
public void declare(@Nonnull JFormatter f)
declare
in interface IJDeclaration
protected void declareBody(@Nonnull JFormatter f)
f
- Formatter to usepublic void direct(@Nullable String string)
string
- Direct code block@Nonnull public final JPackage _package()
AbstractJClass
_package
in class AbstractJClass
JPackage
this class belongs to. Is usually not
null
except for the JTypeVar
and the
JTypeWildcard
implementation.@Nonnull public JTypeVar generify(@Nonnull String name)
IJGenerifiable
generify
in interface IJGenerifiable
name
- type variable nameJTypeVar
@Nonnull public JTypeVar generify(@Nonnull String name, @Nonnull Class<?> bound)
IJGenerifiable
generify
in interface IJGenerifiable
name
- type variable namebound
- Bound classJTypeVar
@Nonnull public JTypeVar generify(@Nonnull String name, @Nonnull AbstractJClass bound)
IJGenerifiable
generify
in interface IJGenerifiable
name
- type variable namebound
- Bound classJTypeVar
@Nonnull public JTypeVar[] typeParams()
AbstractJClass
AbstractJClass
represents
Set<T>
, this method returns an array that contains
single JTypeVar
for 'T'.typeParams
in interface IJGenerifiable
typeParams
in class AbstractJClass
@Nonnull public List<JTypeVar> typeParamList()
IJGenerifiable
typeParamList
in interface IJGenerifiable
protected AbstractJClass substituteParams(JTypeVar[] variables, List<? extends AbstractJClass> bindings)
AbstractJClass
AbstractJClass
for Map<String,Map<Integer>>
. substituteParams
in class AbstractJClass
variables
- Type variablesbindings
- Bindingsnull
.@Nonnull public JAnnotationUse annotate(@Nonnull Class<? extends Annotation> clazz)
IJAnnotatable
annotate
in interface IJAnnotatable
clazz
- The annotation class to annotate the program element withJAnnotationUse
@Nonnull public JAnnotationUse annotate(@Nonnull AbstractJClass clazz)
IJAnnotatable
annotate
in interface IJAnnotatable
clazz
- The annotation class to annotate the program element withJAnnotationUse
@Nonnull public <W extends IJAnnotationWriter<?>> W annotate2(@Nonnull Class<W> clazz)
IJAnnotatable
annotate2
in interface IJAnnotatable
W
- Implementation typeclazz
- Source class@Nonnull public Collection<JAnnotationUse> annotations()
IJAnnotatable
IJAnnotatable
annotations
in interface IJAnnotatable
null
.@Nonnull public JMods mods()
@Nonnull protected JDefinedClass createInnerClass(int nMods, EClassType eClassType, String sName)
createInnerClass
in class AbstractJClassContainer<JDefinedClass>
Copyright © 2013–2015 Philip Helger. All rights reserved.