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 |
---|---|
Object |
metadata
Client-app spcific metadata associated with this user-created class.
|
EMPTY_ARRAY
Modifier and Type | Method and Description |
---|---|
JDefinedClass |
_annotationTypeDeclaration(String name)
Add an annotationType Declaration to this package
|
JDefinedClass |
_class(int mods,
String name)
Add a new nested class to this class.
|
JDefinedClass |
_class(int mods,
String name,
boolean isInterface)
Deprecated.
|
JDefinedClass |
_class(int mods,
String name,
ClassType classTypeVal)
Creates a new class/enum/interface/annotation.
|
JDefinedClass |
_class(String name)
Add a new public nested class to this class.
|
JDefinedClass |
_enum(int mods,
String name)
Add a public enum to this package
|
JDefinedClass |
_enum(String name)
Add a public enum to this package
|
JClass |
_extends()
Returns the class extended by this class.
|
JDefinedClass |
_extends(Class<?> superClass) |
JDefinedClass |
_extends(JClass superClass)
This class extends the specifed class.
|
Iterator<JClass> |
_implements()
Returns an iterator that walks the nested classes defined in this
class.
|
JDefinedClass |
_implements(Class<?> iface) |
JDefinedClass |
_implements(JClass iface)
This class implements the specifed interface.
|
JDefinedClass |
_interface(int mods,
String name)
Add an interface to this package.
|
JDefinedClass |
_interface(String name)
Adds a public interface to this package.
|
JPackage |
_package()
Gets the package to which this class belongs.
|
JAnnotationUse |
annotate(Class<? extends Annotation> clazz)
Adding ability to annotate a class
|
JAnnotationUse |
annotate(JClass clazz)
Adding ability to annotate a class
|
<W extends JAnnotationWriter> |
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()
|
String |
binaryName()
Gets the binary name of the type.
|
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.
|
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(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,
Class<?> type,
String name) |
JFieldVar |
field(int mods,
Class<?> type,
String name,
JExpression init) |
JFieldVar |
field(int mods,
JType type,
String name)
Adds a field to the list of field members of this JDefinedClass.
|
JFieldVar |
field(int mods,
JType type,
String name,
JExpression init)
Adds a field to the list of field members of this JDefinedClass.
|
Map<String,JFieldVar> |
fields()
Returns all the fields declred in this class.
|
String |
fullName()
Gets the fully qualified name of this class.
|
JTypeVar |
generify(String name)
Adds a new type variable to this declaration.
|
JTypeVar |
generify(String name,
Class<?> bound)
Adds a new type variable to this declaration with a bound.
|
JTypeVar |
generify(String name,
JClass bound)
Adds a new type variable to this declaration with a bound.
|
ClassType |
getClassType() |
JMethod |
getConstructor(JType[] argTypes)
Looks for a method that has the specified method signature
and return it.
|
JMethod |
getMethod(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.
|
JBlock |
instanceInit()
Creates, if necessary, and returns the instance 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,
Class<?> type,
String name) |
JMethod |
method(int mods,
JType type,
String name)
Add a method to the list of method members of this JDefinedClass instance.
|
Collection<JMethod> |
methods()
Returns the set of methods defined in this class.
|
JMods |
mods() |
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.
|
boolean |
removeAnnotation(JAnnotationUse annotation)
Removes annotation from this program element.
|
void |
removeField(JFieldVar field)
Removes a
JFieldVar from this class. |
protected JClass |
substituteParams(JTypeVar[] variables,
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, staticInvoke, staticInvoke, staticRef, staticRef, toString, unboxify, wildcard
compareTo, elementType, isArray, isPrimitive, isReference, parse
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
owner
public Object metadata
public final boolean isAnonymous()
public JDefinedClass _extends(JClass superClass)
superClass
- Superclass for this classpublic JDefinedClass _extends(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(Class<?> iface)
public Iterator<JClass> _implements()
_implements
in class JClass
JClass
objects that represents those interfaces
implemented by this object.public String name()
For example, for java.util.List
, this method
returns "List"
"
public JEnumConstant enumConstant(String name)
name
- The name of the constant.public String fullName()
public 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, String name)
mods
- Modifiers for this fieldtype
- JType of this fieldname
- Name of this fieldpublic JFieldVar field(int mods, JType type, 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(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(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, 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, Class<?> type, String name, JExpression init)
public Map<String,JFieldVar> fields()
Map
is a read-only live view.public void removeField(JFieldVar field)
JFieldVar
from this class.IllegalArgumentException
- if the given field is not a field on this class.public JBlock init()
public JBlock instanceInit()
public JMethod constructor(int mods)
mods
- Modifiers for this constructorpublic Iterator<JMethod> constructors()
public JMethod getConstructor(JType[] argTypes)
public JMethod method(int mods, JType type, String name)
mods
- Modifiers for this methodtype
- Return type for this methodname
- Name of the methodpublic Collection<JMethod> methods()
public JMethod getMethod(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, 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.@Deprecated public JDefinedClass _class(int mods, String name, boolean isInterface) throws JClassAlreadyExistsException
_class
in interface JClassContainer
JClassAlreadyExistsException
public JDefinedClass _class(int mods, String name, ClassType classTypeVal) throws JClassAlreadyExistsException
JClassContainer
_class
in interface JClassContainer
JClassAlreadyExistsException
public JDefinedClass _class(String name) throws JClassAlreadyExistsException
_class
in interface JClassContainer
JClassAlreadyExistsException
- When the specified class/interface was already created.public JDefinedClass _interface(int mods, 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(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 Iterator<JDefinedClass> classes()
classes
in interface JClassContainer
public final JClass[] listClasses()
public JClass outer()
JClass
null
if
this is a top-level class.public void declare(JFormatter f)
declare
in interface JDeclaration
protected void declareBody(JFormatter f)
public void direct(String string)
public final JPackage _package()
JClass
public final JClassContainer parentContainer()
JClassContainer
parentContainer
in interface JClassContainer
public JTypeVar generify(String name)
JGenerifiable
generify
in interface JGenerifiable
public JTypeVar generify(String name, Class<?> bound)
JGenerifiable
generify
in interface JGenerifiable
public JTypeVar generify(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, 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(Class<? extends 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(Class<W> clazz)
JAnnotatable
annotate2
in interface JAnnotatable
public boolean removeAnnotation(JAnnotationUse annotation)
JAnnotatable
removeAnnotation
in interface JAnnotatable
annotation
- The annotation to be removed from the program elementpublic Collection<JAnnotationUse> annotations()
annotations
in interface JAnnotatable
public JMods mods()
Copyright © 2021 JBoss by Red Hat. All rights reserved.