|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.sun.codemodel.JType
com.sun.codemodel.JClass
com.sun.codemodel.JDefinedClass
public class JDefinedClass
A generated Java class/interface/enum/....
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).
| Field Summary | |
|---|---|
Object |
metadata
Client-app spcific metadata associated with this user-created class. |
| Fields inherited from class com.sun.codemodel.JClass |
|---|
EMPTY_ARRAY |
| Method Summary | ||
|---|---|---|
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 |
|
|
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()
JAnnotatable.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. |
|
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. |
|
| Methods inherited from class com.sun.codemodel.JClass |
|---|
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 |
| Methods inherited from class com.sun.codemodel.JType |
|---|
compareTo, elementType, isArray, isPrimitive, isReference, parse |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface com.sun.codemodel.JClassContainer |
|---|
owner |
| Field Detail |
|---|
public Object metadata
| Method Detail |
|---|
public final boolean isAnonymous()
public JDefinedClass _extends(JClass superClass)
superClass - Superclass for this class
public JDefinedClass _extends(Class<?> superClass)
public JClass _extends()
_extends in class JClassJClass.
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 implements
public JDefinedClass _implements(Class<?> iface)
public Iterator<JClass> _implements()
_implements in class JClassJClass objects that represents those interfaces
implemented by this object.public String name()
For example, for java.util.List, this method
returns "List""
name in class JClasspublic JEnumConstant enumConstant(String name)
name - The name of the constant.
public String fullName()
fullName in class JTypepublic String binaryName()
JType
binaryName in class JTypepublic boolean isInterface()
JClass
isInterface in class JClasspublic 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 field
public JFieldVar field(int mods,
Class<?> type,
String name)
public 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 JClassContainername - Name of the annotation Type declaration to be added to this package
JClassAlreadyExistsException - When the specified class/interface was already created.
public JDefinedClass _enum(String name)
throws JClassAlreadyExistsException
_enum in interface JClassContainername - Name of the enum to be added to this package
JClassAlreadyExistsException - 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 declaration
JClassAlreadyExistsException - 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 method
public JMethod method(int mods,
Class<?> type,
String name)
public Collection<JMethod> methods()
public JMethod getMethod(String name,
JType[] argTypes)
public boolean isClass()
JClassContainer
isClass in interface JClassContainerpublic boolean isPackage()
JClassContainer
isPackage in interface JClassContainerpublic JPackage getPackage()
JClassContainerIf this.isPackage(), then return this.
getPackage in interface JClassContainer
public JDefinedClass _class(int mods,
String name)
throws JClassAlreadyExistsException
_class in interface JClassContainermods - Modifiers for this class declarationname - Name of class to be added to this package
JClassAlreadyExistsException - When the specified class/interface was already created.
public JDefinedClass _class(int mods,
String name,
boolean isInterface)
throws JClassAlreadyExistsException
_class in interface JClassContainerJClassAlreadyExistsException
public JDefinedClass _class(int mods,
String name,
ClassType classTypeVal)
throws JClassAlreadyExistsException
JClassContainer
_class in interface JClassContainerJClassAlreadyExistsException
public JDefinedClass _class(String name)
throws JClassAlreadyExistsException
_class in interface JClassContainerJClassAlreadyExistsException - When the specified class/interface was already created.
public JDefinedClass _interface(int mods,
String name)
throws JClassAlreadyExistsException
_interface in interface JClassContainermods - Modifiers for this interface declarationname - Name of interface to be added to this package
JClassAlreadyExistsException - When the specified class/interface was already created.
public JDefinedClass _interface(String name)
throws JClassAlreadyExistsException
_interface in interface JClassContainerJClassAlreadyExistsException - When the specified class/interface was already created.public JDocComment javadoc()
javadoc in interface JDocCommentablepublic 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 JClassContainerpublic final JClass[] listClasses()
public JClass outer()
JClass
outer in class JClasspublic void declare(JFormatter f)
declare in interface JDeclarationprotected void declareBody(JFormatter f)
public void direct(String string)
public final JPackage _package()
JClass
_package in class JClasspublic final JClassContainer parentContainer()
JClassContainer
parentContainer in interface JClassContainerpublic 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 JGenerifiablepublic 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 JGenerifiabletypeParams 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 JClasspublic JAnnotationUse annotate(Class<? extends Annotation> clazz)
annotate in interface JAnnotatableclazz - The annotation class to annotate the class withpublic JAnnotationUse annotate(JClass clazz)
annotate in interface JAnnotatableclazz - The annotation class to annotate the class withpublic <W extends JAnnotationWriter> W annotate2(Class<W> clazz)
JAnnotatable
annotate2 in interface JAnnotatablepublic Collection<JAnnotationUse> annotations()
JAnnotatable.annotations()
annotations in interface JAnnotatablepublic JMods mods()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||