Class JDefinedClass
- All Implemented Interfaces:
JAnnotatable,JClassContainer,JDeclaration,JDocCommentable,JGenerable,JGenerifiable,Comparable<JType>
This class models a declaration, and since a declaration can be always
used as a reference, it inherits JClass.
Where to go from here?
You'd want to generate fields and methods on a class.
See method(int, JType, String) and field(int, JType, String).
-
Field Summary
FieldsModifier and TypeFieldDescriptionClient-app spcific metadata associated with this user-created class.Fields inherited from class com.sun.codemodel.JClass
EMPTY_ARRAY -
Method Summary
Modifier and TypeMethodDescriptionAdd an annotationType Declaration to this packageAdd a new nested class to this class.Deprecated.Creates a new class/enum/interface/annotation.Add a new public nested class to this class.Add a public enum to this packageAdd a public enum to this package_extends()Returns the class extended by this class.This class extends the specifed class.Returns an iterator that walks the nested classes defined in this class._implements(JClass iface) This class implements the specifed interface._implements(Class<?> iface) _interface(int mods, String name) Add an interface to this package._interface(String name) Adds a public interface to this package.final JPackage_package()Gets the package to which this class belongs.Adding ability to annotate a classannotate(Class<? extends Annotation> clazz) Adding ability to annotate a class<W extends JAnnotationWriter<? extends Annotation>>
WAdds an annotation to this program element and returns a type-safe writer to fill in the values of such annotations.Gets the binary name of the type.final Iterator<JDefinedClass>classes()Returns an iterator that walks the nested classes defined in this class.constructor(int mods) Adds a constructor to this class.Returns an iterator that walks the constructors defined in this class.voidprotected voidprints the body of a class.voidPlaces the given string directly inside the generated class.enumConstant(String name) If the named enum already exists, the reference to it is returned.Adds a field to the list of field members of this JDefinedClass.field(int mods, JType type, String name, JExpression init) Adds a field to the list of field members of this JDefinedClass.field(int mods, Class<?> type, String name, JExpression init) fields()Returns all the fields declred in this class.fullName()Gets the fully qualified name of this class.Adds a new type variable to this declaration.Adds a new type variable to this declaration with a bound.Adds a new type variable to this declaration with a bound.getConstructor(JType[] argTypes) Looks for a method that has the specified method signature and return it.Looks for a method that has the specified method signature and return it.Gets the nearest package parent.voidhide()Mark this file as hidden, so that this file won't be generated.init()Creates, if necessary, and returns the static initializer for this class.Creates, if necessary, and returns the instance initializer for this class.booleanChecks if this class is an abstract class.booleanThis method indicates if the interface is an annotationTypeDeclarationfinal booleanReturns true if this is an anonymous class.booleanisClass()Returns true if the container is a class.booleanisHidden()booleanChecks if this object represents an interface.booleanReturns true if the container is a package.javadoc()Creates, if necessary, and returns the class javadoc for this JDefinedClassfinal JClass[]Returns all the nested classes defined in this class.Add a method to the list of method members of this JDefinedClass instance.methods()Returns the set of methods defined in this class.mods()name()JClass name accessor.outer()Returns the class in which this class is nested, ornullif this is a top-level class.final JClassContainerParent JClassContainer.booleanremoveAnnotation(JAnnotationUse annotation) Removes annotation from this program element.voidremoveField(JFieldVar field) Removes aJFieldVarfrom this class.protected JClasssubstituteParams(JTypeVar[] variables, List<JClass> bindings) Substitutes the type variables with their actual arguments.JTypeVar[]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, wildcardMethods inherited from class com.sun.codemodel.JType
compareTo, elementType, isArray, isPrimitive, isReference, parseMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.sun.codemodel.JClassContainer
owner
-
Field Details
-
metadata
Client-app spcific metadata associated with this user-created class.
-
-
Method Details
-
isAnonymous
public final boolean isAnonymous()Returns true if this is an anonymous class. -
_extends
This class extends the specifed class.- Parameters:
superClass- Superclass for this class- Returns:
- This class
-
_extends
-
_extends
Returns the class extended by this class.- Specified by:
_extendsin classJClass- Returns:
- Returns the JClass representing the superclass of the
entity (class or interface) represented by this
JClass. Even if no super class is given explicitly or thisJClassis not a class, this method still returnsJClassforObject. If this JClass representsObject, return null.
-
_implements
This class implements the specifed interface.- Parameters:
iface- Interface that this class implements- Returns:
- This class
-
_implements
-
_implements
Returns an iterator that walks the nested classes defined in this class.- Specified by:
_implementsin classJClass- Returns:
- A non-null valid iterator that iterates all
JClassobjects that represents those interfaces implemented by this object.
-
name
JClass name accessor.For example, for
java.util.List, this method returns"List"" -
enumConstant
If the named enum already exists, the reference to it is returned. Otherwise this method generates a new enum reference with the given name and returns it.- Parameters:
name- The name of the constant.- Returns:
- The generated type-safe enum constant.
-
fullName
Gets the fully qualified name of this class. -
binaryName
Description copied from class:JTypeGets the binary name of the type. See http://java.sun.com/docs/books/jls/third_edition/html/binaryComp.html#44909- Overrides:
binaryNamein classJType- Returns:
- Name like "Foo$Bar", "int", "java.lang.String", "java.io.File[]". Never null.
-
isInterface
public boolean isInterface()Description copied from class:JClassChecks if this object represents an interface.- Specified by:
isInterfacein classJClass
-
isAbstract
public boolean isAbstract()Description copied from class:JClassChecks if this class is an abstract class.- Specified by:
isAbstractin classJClass
-
field
Adds a field to the list of field members of this JDefinedClass.- Parameters:
mods- Modifiers for this fieldtype- JType of this fieldname- Name of this field- Returns:
- Newly generated field
-
field
-
field
Adds a field to the list of field members of this JDefinedClass.- Parameters:
mods- Modifiers for this field.type- JType of this field.name- Name of this field.init- Initial value of this field.- Returns:
- Newly generated field
-
isAnnotationTypeDeclaration
public boolean isAnnotationTypeDeclaration()This method indicates if the interface is an annotationTypeDeclaration -
_annotationTypeDeclaration
Add an annotationType Declaration to this package- Specified by:
_annotationTypeDeclarationin interfaceJClassContainer- Parameters:
name- Name of the annotation Type declaration to be added to this package- Returns:
- newly created Annotation Type Declaration
- Throws:
JClassAlreadyExistsException- When the specified class/interface was already created.
-
_enum
Add a public enum to this package- Specified by:
_enumin interfaceJClassContainer- Parameters:
name- Name of the enum to be added to this package- Returns:
- newly created Enum
- Throws:
JClassAlreadyExistsException- When the specified class/interface was already created.
-
_enum
Add a public enum to this package- Parameters:
name- Name of the enum to be added to this packagemods- Modifiers for this enum declaration- Returns:
- newly created Enum
- Throws:
JClassAlreadyExistsException- When the specified class/interface was already created.
-
getClassType
-
field
-
fields
Returns all the fields declred in this class. The returnedMapis a read-only live view.- Returns:
- always non-null.
-
removeField
Removes aJFieldVarfrom this class.- Throws:
IllegalArgumentException- if the given field is not a field on this class.
-
init
Creates, if necessary, and returns the static initializer for this class.- Returns:
- JBlock containing initialization statements for this class
-
instanceInit
Creates, if necessary, and returns the instance initializer for this class.- Returns:
- JBlock containing initialization statements for this class
-
constructor
Adds a constructor to this class.- Parameters:
mods- Modifiers for this constructor
-
constructors
Returns an iterator that walks the constructors defined in this class. -
getConstructor
Looks for a method that has the specified method signature and return it.- Returns:
- null if not found.
-
method
Add a method to the list of method members of this JDefinedClass instance.- Parameters:
mods- Modifiers for this methodtype- Return type for this methodname- Name of the method- Returns:
- Newly generated JMethod
-
method
-
methods
Returns the set of methods defined in this class. -
getMethod
Looks for a method that has the specified method signature and return it.- Returns:
- null if not found.
-
isClass
public boolean isClass()Description copied from interface:JClassContainerReturns true if the container is a class.- Specified by:
isClassin interfaceJClassContainer
-
isPackage
public boolean isPackage()Description copied from interface:JClassContainerReturns true if the container is a package.- Specified by:
isPackagein interfaceJClassContainer
-
getPackage
Description copied from interface:JClassContainerGets the nearest package parent.If
this.isPackage(), then returnthis.- Specified by:
getPackagein interfaceJClassContainer
-
_class
Add a new nested class to this class.- Specified by:
_classin interfaceJClassContainer- Parameters:
mods- Modifiers for this class declarationname- Name of class to be added to this package- Returns:
- Newly generated class
- Throws:
JClassAlreadyExistsException- When the specified class/interface was already created.
-
_class
@Deprecated public JDefinedClass _class(int mods, String name, boolean isInterface) throws JClassAlreadyExistsException Deprecated.Create a new class or a new interface.- Specified by:
_classin interfaceJClassContainer- Throws:
JClassAlreadyExistsException
-
_class
public JDefinedClass _class(int mods, String name, ClassType classTypeVal) throws JClassAlreadyExistsException Description copied from interface:JClassContainerCreates a new class/enum/interface/annotation.- Specified by:
_classin interfaceJClassContainer- Throws:
JClassAlreadyExistsException
-
_class
Add a new public nested class to this class.- Specified by:
_classin interfaceJClassContainer- Throws:
JClassAlreadyExistsException- When the specified class/interface was already created.
-
_interface
Add an interface to this package.- Specified by:
_interfacein interfaceJClassContainer- Parameters:
mods- Modifiers for this interface declarationname- Name of interface to be added to this package- Returns:
- Newly generated interface
- Throws:
JClassAlreadyExistsException- When the specified class/interface was already created.
-
_interface
Adds a public interface to this package.- Specified by:
_interfacein interfaceJClassContainer- Throws:
JClassAlreadyExistsException- When the specified class/interface was already created.
-
javadoc
Creates, if necessary, and returns the class javadoc for this JDefinedClass- Specified by:
javadocin interfaceJDocCommentable- Returns:
- JDocComment containing javadocs for this class
-
hide
public void hide()Mark this file as hidden, so that this file won't be generated.This feature could be used to generate code that refers to class X, without actually generating X.java.
-
isHidden
public boolean isHidden() -
classes
Returns an iterator that walks the nested classes defined in this class.- Specified by:
classesin interfaceJClassContainer
-
listClasses
Returns all the nested classes defined in this class. -
outer
Description copied from class:JClassReturns the class in which this class is nested, ornullif this is a top-level class. -
declare
- Specified by:
declarein interfaceJDeclaration
-
declareBody
prints the body of a class. -
direct
Places the given string directly inside the generated class. This method can be used to add methods/fields that are not generated by CodeModel. This method should be used only as the last resort. -
_package
Description copied from class:JClassGets the package to which this class belongs. TODO: shall we move move this down? -
parentContainer
Description copied from interface:JClassContainerParent JClassContainer. If this is a package, this method returns a parent package, or null if this package is the root package. If this is an outer-most class, this method returns a package to which it belongs. If this is an inner class, this method returns the outer class.- Specified by:
parentContainerin interfaceJClassContainer
-
generify
Description copied from interface:JGenerifiableAdds a new type variable to this declaration.- Specified by:
generifyin interfaceJGenerifiable
-
generify
Description copied from interface:JGenerifiableAdds a new type variable to this declaration with a bound.- Specified by:
generifyin interfaceJGenerifiable
-
generify
Description copied from interface:JGenerifiableAdds a new type variable to this declaration with a bound.- Specified by:
generifyin interfaceJGenerifiable
-
typeParams
Description copied from class:JClassIterates all the type parameters of this class/interface.For example, if this
JClassrepresentsSet<T>, this method returns an array that contains singleJTypeVarfor 'T'.- Specified by:
typeParamsin interfaceJGenerifiable- Overrides:
typeParamsin classJClass
-
substituteParams
Description copied from class:JClassSubstitutes the type variables with their actual arguments.For example, when this class is
Map<String,Map<V>>, (where V then doing substituteParams( V, Integer ) returns aJClassforMap<String,Map<Integer>>.This method needs to work recursively.
- Specified by:
substituteParamsin classJClass
-
annotate
Adding ability to annotate a class- Specified by:
annotatein interfaceJAnnotatable- Parameters:
clazz- The annotation class to annotate the class with
-
annotate
Adding ability to annotate a class- Specified by:
annotatein interfaceJAnnotatable- Parameters:
clazz- The annotation class to annotate the class with
-
annotate2
Description copied from interface:JAnnotatableAdds an annotation to this program element and returns a type-safe writer to fill in the values of such annotations.- Specified by:
annotate2in interfaceJAnnotatable- Returns:
-
removeAnnotation
Description copied from interface:JAnnotatableRemoves annotation from this program element.- Specified by:
removeAnnotationin interfaceJAnnotatable- Parameters:
annotation- The annotation to be removed from the program element
-
annotations
- Specified by:
annotationsin interfaceJAnnotatable- Returns:
- Can be empty but never null.
-
mods
- Returns:
- the current modifiers of this class. Always return non-null valid object.
-