public class JDefinedClass extends AbstractJClassContainer<JDefinedClass> implements 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).
m_aClassesEMPTY_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<?> aSuperClass) |
Iterator<AbstractJClass> |
_implements()
Returns an iterator that walks the nested classes defined in this class.
|
JDefinedClass |
_implements(AbstractJClass aInterface)
This class implements the specifed interface.
|
JDefinedClass |
_implements(Class<?> aInterface) |
JPackage |
_package()
Gets the package to which this class belongs.
|
JAnnotationUse |
annotate(AbstractJClass aClazz)
Adds an annotation to this program element.
|
JAnnotationUse |
annotate(Class<? extends Annotation> aClazz)
Adds an annotation to this program element.
|
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 nMods)
Adds a constructor to this class.
|
Iterator<JMethod> |
constructors() |
boolean |
containsErrorTypes()
Returns true if this class or it's inner classes contains references to
error-types.
|
boolean |
containsField(String sName) |
protected JDefinedClass |
createInnerClass(int nMods,
EClassType eClassType,
String sName) |
void |
declare(IJFormatter f) |
protected void |
declareBody(IJFormatter f)
prints the body of a class.
|
void |
direct(String string)
Places the given string directly inside the generated class.
|
JEnumConstant |
enumConstant(String sName)
If the named enum already exists, the reference to it is returned.
|
JFieldVar |
field(int nMods,
AbstractJType aType,
String sName)
Adds a field to the list of field members of this JDefinedClass.
|
JFieldVar |
field(int nMods,
AbstractJType aType,
String sName,
IJExpression aInit)
Adds a field to the list of field members of this JDefinedClass.
|
JFieldVar |
field(int nMods,
Class<?> aType,
String sName) |
JFieldVar |
field(int nMods,
Class<?> aType,
String sName,
IJExpression aInit) |
Map<String,JFieldVar> |
fields()
Returns all the fields declared in this class.
|
JTypeVar |
generify(String sName)
Adds a new type variable to this declaration.
|
JTypeVar |
generify(String sName,
AbstractJClass aBoundClass)
Adds a new type variable to this declaration with a bound.
|
JTypeVar |
generify(String sName,
Class<?> aBoundClass)
Adds a new type variable to this declaration with a bound.
|
JAnnotationUse |
getAnnotation(Class<?> aAnnotationClass) |
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.
|
boolean |
hasHeaderComment() |
JDocComment |
headerComment() |
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() |
JMethod |
method(int nMods,
AbstractJType aType,
String sName)
Add a method to the list of method members of this JDefinedClass instance.
|
JMethod |
method(int nMods,
Class<?> aType,
String sName) |
Collection<JMethod> |
methods() |
JMods |
mods() |
void |
removeField(JFieldVar aField)
Removes a
JFieldVar from this class. |
protected AbstractJClass |
substituteParams(JTypeVar[] aVariables,
List<? extends AbstractJClass> aBindings)
Substitutes the type variables with their actual arguments.
|
JTypeVar[] |
typeParams()
Iterates all the type parameters of this class/interface.
|
_class, classes, fullName, getClassType, getOuter, getPackage, isAnnotationTypeDeclaration, isAnonymous, isClass, isInterface, isPackage, name, outer, parentContainer, thisAsTarray, boxify, dotclass, erasure, generate, getAllInnerClasses, getBaseClass, getBaseClass, getInnerClass, getPrimitiveType, getTypeParameters, isParameterized, methodRef, narrow, narrow, narrow, narrow, narrow, narrow, narrowAny, narrowEmpty, owner, staticInvoke, staticInvoke, staticRef, staticRef, toString, unboxify, wildcard, wildcard, wildcardExtends, wildcardSuper_new, containsTypeVar, declarable, elementType, isArray, isAssignableFrom, isAssignableFrom, isError, isPrimitive, isReference, parseclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitannotate2_annotationTypeDeclaration, _annotationTypeDeclaration, _class, _class, _enum, _enum, _interface, _interfaceprotected 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 JMods mods()
@Nonnull public JDefinedClass _extends(@Nonnull AbstractJClass aSuperClass)
aSuperClass - Superclass for this class@Nonnull public JDefinedClass _extends(@Nonnull Class<?> aSuperClass)
@Nonnull public AbstractJClass _extends()
_extends in class AbstractJClassAbstractJClass 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 aInterface)
aInterface - Interface that this class implements@Nonnull public JDefinedClass _implements(@Nonnull Class<?> aInterface)
@Nonnull public Iterator<AbstractJClass> _implements()
_implements in class AbstractJClassAbstractJClass
objects that represents those interfaces implemented by this
object.@Nonnull public JEnumConstant enumConstant(@Nonnull String sName)
sName - The name of the constant.public String binaryName()
AbstractJTypebinaryName in class AbstractJTypepublic boolean isAbstract()
isAbstract in class AbstractJClasstrue if this class is an abstract class.public JFieldVar field(int nMods, AbstractJType aType, String sName)
nMods - Modifiers for this fieldaType - JType of this fieldsName - Name of this field@Nonnull public JFieldVar field(int nMods, @Nonnull AbstractJType aType, @Nonnull String sName, @Nullable IJExpression aInit)
nMods - Modifiers for this field.aType - JType of this field.sName - Name of this field.aInit - Initial value of this field.@Nonnull public JFieldVar field(int nMods, Class<?> aType, String sName, IJExpression aInit)
@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 nMods)
nMods - 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 nMods, @Nonnull AbstractJType aType, @Nonnull String sName)
nMods - Modifiers for this methodaType - Return type for this methodsName - 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.public boolean hasHeaderComment()
true if a header comment (before the package) is
present, false if not.@Nonnull public JDocComment headerComment()
null.@Nonnull public JDocComment javadoc()
javadoc in interface IJDocCommentablenull.public void hide()
public boolean isHidden()
public void declare(@Nonnull IJFormatter f)
declare in interface IJDeclarationprotected void declareBody(@Nonnull IJFormatter f)
f - Formatter to usepublic void direct(@Nullable String string)
string - Direct code block@Nonnull public final JPackage _package()
AbstractJClass_package in class AbstractJClassJPackage this class belongs to. Is usually not
null except for the JTypeVar and the
JTypeWildcard implementation.@Nonnull public JTypeVar generify(@Nonnull String sName)
IJGenerifiablegenerify in interface IJGenerifiablesName - type variable nameJTypeVar@Nonnull public JTypeVar generify(@Nonnull String sName, @Nonnull Class<?> aBoundClass)
IJGenerifiablegenerify in interface IJGenerifiablesName - type variable nameaBoundClass - Bound classJTypeVar@Nonnull public JTypeVar generify(@Nonnull String sName, @Nonnull AbstractJClass aBoundClass)
IJGenerifiablegenerify in interface IJGenerifiablesName - type variable nameaBoundClass - Bound classJTypeVar@Nonnull public JTypeVar[] typeParams()
AbstractJClassAbstractJClass represents
Set<T>, this method returns an array that contains
single JTypeVar for 'T'.typeParams in interface IJGenerifiabletypeParams in class AbstractJClassprotected AbstractJClass substituteParams(JTypeVar[] aVariables, List<? extends AbstractJClass> aBindings)
AbstractJClassAbstractJClass
for Map<String,Map<Integer>>. substituteParams in class AbstractJClassaVariables - Type variablesaBindings - Bindingsnull.@Nonnull public JAnnotationUse annotate(@Nonnull Class<? extends Annotation> aClazz)
IJAnnotatableannotate in interface IJAnnotatableaClazz - The annotation class to annotate the program element withJAnnotationUse@Nonnull public JAnnotationUse annotate(@Nonnull AbstractJClass aClazz)
IJAnnotatableannotate in interface IJAnnotatableaClazz - The annotation class to annotate the program element withJAnnotationUse@Nonnull public Collection<JAnnotationUse> annotations()
IJAnnotatableIJAnnotatableannotations in interface IJAnnotatablenull.@Nullable public JAnnotationUse getAnnotation(Class<?> aAnnotationClass)
@Nonnull protected JDefinedClass createInnerClass(int nMods, EClassType eClassType, String sName)
createInnerClass in class AbstractJClassContainer<JDefinedClass>public boolean containsErrorTypes()
true if an error type is contained, false
otherwiseJErrorClassCopyright © 2013–2018 Philip Helger. All rights reserved.