com.sun.codemodel
Class JDefinedClass

java.lang.Object
  extended by com.sun.codemodel.JType
      extended by com.sun.codemodel.JClass
          extended by com.sun.codemodel.JDefinedClass
All Implemented Interfaces:
JClassContainer, JDeclaration

public abstract class JDefinedClass
extends JClass
implements JDeclaration, JClassContainer

A generated Java class.


Field Summary
 java.lang.Object metadata
          Client-app spcific metadata associated with this user-created class.
 
Method Summary
 JDefinedClass _class(int mods, java.lang.String name)
          Add a new nested class to this class.
 JDefinedClass _class(int mods, java.lang.String name, boolean isInterface)
          Create a new class or a new interface.
 JDefinedClass _class(java.lang.String name)
          Add a new public nested class to this class.
 JClass _extends()
          Returns the class extended by this class, or null if this class does not explicitly extend a class.
 JDefinedClass _extends(java.lang.Class superClass)
           
 JDefinedClass _extends(JClass superClass)
          This class extends the specifed class.
 java.util.Iterator _implements()
          Returns an iterator that walks the nested classes defined in this class.
 JDefinedClass _implements(java.lang.Class iface)
           
 JDefinedClass _implements(JClass iface)
          This class implements the specifed interface.
 JDefinedClass _interface(int mods, java.lang.String name)
          Add an interface to this package.
 JDefinedClass _interface(java.lang.String name)
          Adds a public interface to this package.
 java.util.Iterator classes()
          Returns an iterator that walks the nested classes defined in this class.
 JMethod constructor(int mods)
          Adds a constructor to this class.
 java.util.Iterator 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(java.lang.String string)
          Places the given string directly inside the generated class.
 JFieldVar field(int mods, java.lang.Class type, java.lang.String name)
           
 JFieldVar field(int mods, java.lang.Class type, java.lang.String name, JExpression init)
           
 JFieldVar field(int mods, JType type, java.lang.String name)
          Adds a field to the list of field members of this JDefinedClass.
 JFieldVar field(int mods, JType type, java.lang.String name, JExpression init)
          Adds a field to the list of field members of this JDefinedClass.
 java.util.Iterator fields()
          Returns an iterator that walks the fields defined in this class.
 void generate(JFormatter f)
           
 JMethod getConstructor(JType[] argTypes)
          Looks for a method that has the specified method signature and return it.
 JMethod getMethod(java.lang.String name, JType[] argTypes)
          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.
 boolean isHidden()
           
 boolean isInterface()
          Checks if this object represents an interface.
 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, java.lang.Class type, java.lang.String name)
           
 JMethod method(int mods, JType type, java.lang.String name)
          Add a method to the list of method members of this JDefinedClass instance.
 java.util.Iterator methods()
          Returns an iterator that walks the methods defined in this class.
 java.lang.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.
 
Methods inherited from class com.sun.codemodel.JClass
_package, array, dotclass, fullName, getPrimitiveType, isAssignableFrom, owner, staticInvoke, staticInvoke, staticRef, staticRef, toString
 
Methods inherited from class com.sun.codemodel.JType
binaryName, 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, parentContainer
 

Field Detail

metadata

public java.lang.Object metadata
Client-app spcific metadata associated with this user-created class.

Method Detail

_extends

public JDefinedClass _extends(JClass superClass)
This class extends the specifed class.

Parameters:
superClass - Superclass for this class
Returns:
This class

_extends

public JDefinedClass _extends(java.lang.Class superClass)

_extends

public JClass _extends()
Returns the class extended by this class, or null if this class does not explicitly extend a class.

Specified by:
_extends in class JClass
Returns:
Returns the JClass representing the superclass of the entity (class or interface) represented by this JClass. If this JClass represents either the Object class, or an interface, then null is returned.

_implements

public JDefinedClass _implements(JClass iface)
This class implements the specifed interface.

Parameters:
iface - Interface that this class implements
Returns:
This class

_implements

public JDefinedClass _implements(java.lang.Class iface)

_implements

public java.util.Iterator _implements()
Returns an iterator that walks the nested classes defined in this class.

Specified by:
_implements in class JClass
Returns:
A non-null valid iterator that iterates all JClass objects that represents those interfaces implemented by this object.

name

public java.lang.String name()
JClass name accessor.

For example, for java.util.List, this method returns "List""

Specified by:
name in class JClass
Returns:
Name of this class

isInterface

public boolean isInterface()
Description copied from class: JClass
Checks if this object represents an interface.

Specified by:
isInterface in class JClass

field

public JFieldVar field(int mods,
                       JType type,
                       java.lang.String name)
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
Returns:
Newly generated field

field

public JFieldVar field(int mods,
                       java.lang.Class type,
                       java.lang.String name)

field

public JFieldVar field(int mods,
                       JType type,
                       java.lang.String name,
                       JExpression init)
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

field

public JFieldVar field(int mods,
                       java.lang.Class type,
                       java.lang.String name,
                       JExpression init)

fields

public java.util.Iterator fields()
Returns an iterator that walks the fields defined in this class.


init

public JBlock init()
Creates, if necessary, and returns the static initializer for this class.

Returns:
JBlock containing initialization statements for this class

constructor

public JMethod constructor(int mods)
Adds a constructor to this class.

Parameters:
mods - Modifiers for this constructor

constructors

public java.util.Iterator constructors()
Returns an iterator that walks the constructors defined in this class.


getConstructor

public JMethod getConstructor(JType[] argTypes)
Looks for a method that has the specified method signature and return it.

Returns:
null if not found.

method

public JMethod method(int mods,
                      JType type,
                      java.lang.String name)
Add a method to the list of method members of this JDefinedClass instance.

Parameters:
mods - Modifiers for this method
type - Return type for this method
name - Name of the method
Returns:
Newly generated JMethod

method

public JMethod method(int mods,
                      java.lang.Class type,
                      java.lang.String name)

methods

public java.util.Iterator methods()
Returns an iterator that walks the methods defined in this class.


getMethod

public JMethod getMethod(java.lang.String name,
                         JType[] argTypes)
Looks for a method that has the specified method signature and return it.

Returns:
null if not found.

_class

public JDefinedClass _class(int mods,
                            java.lang.String name)
                     throws JClassAlreadyExistsException
Add a new nested class to this class.

Specified by:
_class in interface JClassContainer
Parameters:
mods - Modifiers for this class declaration
name - Name of class to be added to this package
Returns:
Newly generated class
Throws:
JClassAlreadyExistsException - When the specified class/interface was already created.

_class

public JDefinedClass _class(int mods,
                            java.lang.String name,
                            boolean isInterface)
                     throws JClassAlreadyExistsException
Description copied from interface: JClassContainer
Create a new class or a new interface.

Specified by:
_class in interface JClassContainer
Throws:
JClassAlreadyExistsException

_class

public JDefinedClass _class(java.lang.String name)
                     throws JClassAlreadyExistsException
Add a new public nested class to this class.

Specified by:
_class in interface JClassContainer
Throws:
JClassAlreadyExistsException - When the specified class/interface was already created.

_interface

public JDefinedClass _interface(int mods,
                                java.lang.String name)
                         throws JClassAlreadyExistsException
Add an interface to this package.

Specified by:
_interface in interface JClassContainer
Parameters:
mods - Modifiers for this interface declaration
name - Name of interface to be added to this package
Returns:
Newly generated interface
Throws:
JClassAlreadyExistsException - When the specified class/interface was already created.

_interface

public JDefinedClass _interface(java.lang.String name)
                         throws JClassAlreadyExistsException
Adds a public interface to this package.

Specified by:
_interface in interface JClassContainer
Throws:
JClassAlreadyExistsException - When the specified class/interface was already created.

javadoc

public JDocComment javadoc()
Creates, if necessary, and returns the class javadoc for this JDefinedClass

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

public final java.util.Iterator classes()
Returns an iterator that walks the nested classes defined in this class.

Specified by:
classes in interface JClassContainer

listClasses

public final JClass[] listClasses()
Returns all the nested classes defined in this class.


outer

public JClass outer()
Returns the class in which this class is nested, or null if this is a top-level class.


declare

public void declare(JFormatter f)
Specified by:
declare in interface JDeclaration

declareBody

protected void declareBody(JFormatter f)
prints the body of a class.


generate

public void generate(JFormatter f)

direct

public void direct(java.lang.String string)
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.