org.mule.devkit.model.code
Class GeneratedClass

java.lang.Object
  extended by org.mule.devkit.model.code.Type
      extended by org.mule.devkit.model.code.TypeReference
          extended by org.mule.devkit.model.code.GeneratedClass
All Implemented Interfaces:
Comparable<Type>, Annotable, ClassContainer, Declaration, Documentable, Generable, Generifiable

public class GeneratedClass
extends TypeReference
implements Declaration, ClassContainer, Generifiable, Annotable, Documentable

A generated Java class/interface/enum/....

This class models a declaration, and since a declaration can be always used as a reference, it inherits TypeReference.

Where to go from here?

You'd want to generate fields and methods on a class. See method(int, Type, String) and field(int, Type, String).


Field Summary
static String FLOW_CONSTRUCT_FIELD_NAME
           
static String FLOW_CONSTRUCT_JAVADOC
           
 Object metadata
          Client-app spcific metadata associated with this user-created class.
static String MULE_CONTEXT_FIELD_NAME
           
static String MULE_CONTEXT_JAVADOC
           
 
Fields inherited from class org.mule.devkit.model.code.TypeReference
EMPTY_ARRAY
 
Method Summary
 GeneratedClass _annotationTypeDeclaration(String name)
          Add an annotationType Declaration to this package
 GeneratedClass _class(int mods, String name)
          Add a new nested class to this class.
 GeneratedClass _class(int mods, String name, boolean isInterface)
          Deprecated.  
 GeneratedClass _class(int mods, String name, GeneratedClassType classTypeVal)
          Creates a new class/enum/interface/annotation.
 GeneratedClass _class(String name)
          Add a new public nested class to this class.
 GeneratedClass _enum(int mods, String name)
          Add a public enum to this package
 GeneratedClass _enum(String name)
          Add a public enum to this package
 TypeReference _extends()
          Returns the class extended by this class.
 GeneratedClass _extends(Class<?> superClass)
           
 GeneratedClass _extends(TypeReference superClass)
          This class extends the specifed class.
 Iterator<TypeReference> _implements()
          Returns an iterator that walks the nested classes defined in this class.
 GeneratedClass _implements(Class<?> iface)
           
 GeneratedClass _implements(TypeReference iface)
          This class implements the specifed interface.
 GeneratedClass _interface(int mods, String name)
          Add an interface to this package.
 GeneratedClass _interface(String name)
          Adds a public interface to this package.
 GeneratedPackage _package()
          Gets the package to which this class belongs.
 GeneratedAnnotationUse annotate(Class<? extends Annotation> clazz)
          Adding ability to annotate a class
 GeneratedAnnotationUse annotate(TypeReference clazz)
          Adding ability to annotate a class
<W extends AnnotationWriter>
W
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<GeneratedAnnotationUse> annotations()
          Annotable.annotations()
 String binaryName()
          Gets the binary name of the type.
 Iterator<GeneratedClass> classes()
          Returns an iterator that walks the nested classes defined in this class.
 GeneratedMethod constructor(int mods)
          Adds a constructor to this class.
 Iterator<GeneratedMethod> constructors()
          Returns an iterator that walks the constructors defined in this class.
 void declare(Formatter f)
           
protected  void declareBody(Formatter f)
          prints the body of a class.
 void direct(String string)
          Places the given string directly inside the generated class.
 EnumConstant enumConstant(String name)
          If the named enum already exists, the reference to it is returned.
 GeneratedField field(int mods, Class<?> type, String name)
           
 GeneratedField field(int mods, Class<?> type, String name, GeneratedExpression init)
           
 GeneratedField field(int mods, Type type, String name)
          Adds a field to the list of field members of this DefinedClass.
 GeneratedField field(int mods, Type type, String name, GeneratedExpression init)
          Adds a field to the list of field members of this DefinedClass.
 Map<String,GeneratedField> fields()
          Returns all the fields declred in this class.
 GeneratedField flowConstructField()
           
 String fullName()
          Gets the fully qualified name of this class.
 TypeVariable generify(String name)
          Adds a new type variable to this declaration.
 TypeVariable generify(String name, Class<?> bound)
          Adds a new type variable to this declaration with a bound.
 TypeVariable generify(String name, TypeReference bound)
          Adds a new type variable to this declaration with a bound.
 GeneratedClassType getClassType()
           
 GeneratedMethod getConstructor(Type[] argTypes)
          Looks for a method that has the specified method signature and return it.
 GeneratedMethod getMethod(String name, Type[] argTypes)
          Looks for a method that has the specified method signature and return it.
 GeneratedPackage getPackage()
          Gets the nearest package parent.
 GeneratedMethod getter(GeneratedField field)
          Generate a getter method for the specified field
 void hide()
          Mark this file as hidden, so that this file won't be generated.
 boolean implementsClass(Class clazz)
          Returns whether this class implements the provided interface or not
 GeneratedBlock init()
          Creates, if necessary, and returns the static 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.
 GeneratedJavaDocComment javadoc()
          Creates, if necessary, and returns the class javadoc for this DefinedClass
 TypeReference[] listClasses()
          Returns all the nested classes defined in this class.
 GeneratedMethod method(int mods, Class<?> type, Class<?> narrowedType, String name)
           
 GeneratedMethod method(int mods, Class<?> type, String name)
           
 GeneratedMethod method(int mods, Type type, String name)
          Add a method to the list of method members of this DefinedClass instance.
 Collection<GeneratedMethod> methods()
          Returns the set of methods defined in this class.
 Modifiers mods()
           
 GeneratedField muleContextField()
           
 String name()
          TypeReference name accessor.
 TypeReference outer()
          Returns the class in which this class is nested, or null if this is a top-level class.
 ClassContainer parentContainer()
          Parent ClassContainer.
 void removeField(GeneratedField field)
          Removes a GeneratedField from this class.
 GeneratedMethod setter(GeneratedField field)
          Generate a setter method for the specified field
 GeneratedMethod setterOverride(GeneratedField field)
          Generate a setter and puts an override annotation on it
protected  TypeReference substituteParams(TypeVariable[] variables, List<TypeReference> bindings)
          Substitutes the type variables with their actual arguments.
 List<GeneratedClass> superclasses()
          Find all the classes that inherit from this one.
 GeneratedClass topLevelClass()
          Find the top level class that inherits from this one.
 String toString()
           
 TypeVariable[] typeParams()
          Iterates all the type parameters of this class/interface.
 
Methods inherited from class org.mule.devkit.model.code.TypeReference
array, array, boxify, erasure, generate, getBaseClass, getBaseClass, getPrimitiveType, getTypeParameters, isAssignableFrom, isParameterized, narrow, narrow, narrow, narrow, narrow, narrow, owner, staticInvoke, staticInvoke, staticRef, staticRef, unboxify, wildcard
 
Methods inherited from class org.mule.devkit.model.code.Type
compareTo, dotclass, elementType, equals, hashCode, isArray, isPrimitive, isReference, parse
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.mule.devkit.model.code.ClassContainer
owner
 

Field Detail

MULE_CONTEXT_JAVADOC

public static final String MULE_CONTEXT_JAVADOC
See Also:
Constant Field Values

MULE_CONTEXT_FIELD_NAME

public static final String MULE_CONTEXT_FIELD_NAME
See Also:
Constant Field Values

FLOW_CONSTRUCT_JAVADOC

public static final String FLOW_CONSTRUCT_JAVADOC
See Also:
Constant Field Values

FLOW_CONSTRUCT_FIELD_NAME

public static final String FLOW_CONSTRUCT_FIELD_NAME
See Also:
Constant Field Values

metadata

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

Method Detail

isAnonymous

public final boolean isAnonymous()
Returns true if this is an anonymous class.


_extends

public GeneratedClass _extends(TypeReference superClass)
This class extends the specifed class.

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

_extends

public GeneratedClass _extends(Class<?> superClass)

_extends

public TypeReference _extends()
Returns the class extended by this class.

Specified by:
_extends in class TypeReference
Returns:
Returns the TypeReference representing the superclass of the entity (class or interface) represented by this TypeReference. Even if no super class is given explicitly or this TypeReference is not a class, this method still returns TypeReference for Object. If this TypeReference represents Object, return null.

_implements

public GeneratedClass _implements(TypeReference iface)
This class implements the specifed interface.

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

_implements

public GeneratedClass _implements(Class<?> iface)

_implements

public Iterator<TypeReference> _implements()
Returns an iterator that walks the nested classes defined in this class.

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

name

public String name()
TypeReference name accessor.

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

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

enumConstant

public EnumConstant enumConstant(String name)
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

public String fullName()
Gets the fully qualified name of this class.

Specified by:
fullName in class Type
Returns:
Strings like "int", "java.lang.String", "java.io.File[]". Never null.

binaryName

public String binaryName()
Description copied from class: Type
Gets the binary name of the type.

See http://java.sun.com/docs/books/jls/third_edition/html/binaryComp.html#44909

Overrides:
binaryName in class Type
Returns:
Name like "Foo$Bar", "int", "java.lang.String", "java.io.File[]". Never null.

isInterface

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

Specified by:
isInterface in class TypeReference

isAbstract

public boolean isAbstract()
Description copied from class: TypeReference
Checks if this class is an abstract class.

Specified by:
isAbstract in class TypeReference

field

public GeneratedField field(int mods,
                            Type type,
                            String name)
Adds a field to the list of field members of this DefinedClass.

Parameters:
mods - Modifiers for this field
type - Type of this field
name - Name of this field
Returns:
Newly generated field

field

public GeneratedField field(int mods,
                            Class<?> type,
                            String name)

field

public GeneratedField field(int mods,
                            Type type,
                            String name,
                            GeneratedExpression init)
Adds a field to the list of field members of this DefinedClass.

Parameters:
mods - Modifiers for this field.
type - Type 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

public GeneratedClass _annotationTypeDeclaration(String name)
                                          throws ClassAlreadyExistsException
Add an annotationType Declaration to this package

Specified by:
_annotationTypeDeclaration in interface ClassContainer
Parameters:
name - Name of the annotation Type declaration to be added to this package
Returns:
newly created Annotation Type Declaration
Throws:
ClassAlreadyExistsException - When the specified class/interface was already created.

_enum

public GeneratedClass _enum(String name)
                     throws ClassAlreadyExistsException
Add a public enum to this package

Specified by:
_enum in interface ClassContainer
Parameters:
name - Name of the enum to be added to this package
Returns:
newly created Enum
Throws:
ClassAlreadyExistsException - When the specified class/interface was already created.

_enum

public GeneratedClass _enum(int mods,
                            String name)
                     throws ClassAlreadyExistsException
Add a public enum to this package

Parameters:
name - Name of the enum to be added to this package
mods - Modifiers for this enum declaration
Returns:
newly created Enum
Throws:
ClassAlreadyExistsException - When the specified class/interface was already created.

getClassType

public GeneratedClassType getClassType()

field

public GeneratedField field(int mods,
                            Class<?> type,
                            String name,
                            GeneratedExpression init)

fields

public Map<String,GeneratedField> fields()
Returns all the fields declred in this class. The returned Map is a read-only live view.

Returns:
always non-null.

removeField

public void removeField(GeneratedField field)
Removes a GeneratedField from this class.

Throws:
IllegalArgumentException - if the given field is not a field on this class.

init

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

Returns:
JBlock containing initialization statements for this class

constructor

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

Parameters:
mods - Modifiers for this constructor

constructors

public Iterator<GeneratedMethod> constructors()
Returns an iterator that walks the constructors defined in this class.


getConstructor

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

Returns:
null if not found.

method

public GeneratedMethod method(int mods,
                              Type type,
                              String name)
Add a method to the list of method members of this DefinedClass instance.

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

method

public GeneratedMethod method(int mods,
                              Class<?> type,
                              String name)

method

public GeneratedMethod method(int mods,
                              Class<?> type,
                              Class<?> narrowedType,
                              String name)

methods

public Collection<GeneratedMethod> methods()
Returns the set of methods defined in this class.


getMethod

public GeneratedMethod getMethod(String name,
                                 Type[] argTypes)
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: ClassContainer
Returns true if the container is a class.

Specified by:
isClass in interface ClassContainer

isPackage

public boolean isPackage()
Description copied from interface: ClassContainer
Returns true if the container is a package.

Specified by:
isPackage in interface ClassContainer

getPackage

public GeneratedPackage getPackage()
Description copied from interface: ClassContainer
Gets the nearest package parent.

If this.isPackage(), then return this.

Specified by:
getPackage in interface ClassContainer

_class

public GeneratedClass _class(int mods,
                             String name)
                      throws ClassAlreadyExistsException
Add a new nested class to this class.

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

_class

public GeneratedClass _class(int mods,
                             String name,
                             boolean isInterface)
                      throws ClassAlreadyExistsException
Deprecated. 

Create a new class or a new interface.

Specified by:
_class in interface ClassContainer
Throws:
ClassAlreadyExistsException

_class

public GeneratedClass _class(int mods,
                             String name,
                             GeneratedClassType classTypeVal)
                      throws ClassAlreadyExistsException
Description copied from interface: ClassContainer
Creates a new class/enum/interface/annotation.

Specified by:
_class in interface ClassContainer
Throws:
ClassAlreadyExistsException

_class

public GeneratedClass _class(String name)
Add a new public nested class to this class.

Specified by:
_class in interface ClassContainer

_interface

public GeneratedClass _interface(int mods,
                                 String name)
                          throws ClassAlreadyExistsException
Add an interface to this package.

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

_interface

public GeneratedClass _interface(String name)
                          throws ClassAlreadyExistsException
Adds a public interface to this package.

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

javadoc

public GeneratedJavaDocComment javadoc()
Creates, if necessary, and returns the class javadoc for this DefinedClass

Specified by:
javadoc in interface Documentable
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 Iterator<GeneratedClass> classes()
Returns an iterator that walks the nested classes defined in this class.

Specified by:
classes in interface ClassContainer

listClasses

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


outer

public TypeReference outer()
Description copied from class: TypeReference
Returns the class in which this class is nested, or null if this is a top-level class.

Overrides:
outer in class TypeReference

declare

public void declare(Formatter f)
Specified by:
declare in interface Declaration

declareBody

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


direct

public void direct(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.


_package

public final GeneratedPackage _package()
Description copied from class: TypeReference
Gets the package to which this class belongs. TODO: shall we move move this down?

Specified by:
_package in class TypeReference

parentContainer

public final ClassContainer parentContainer()
Description copied from interface: ClassContainer
Parent ClassContainer.

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:
parentContainer in interface ClassContainer

generify

public TypeVariable generify(String name)
Description copied from interface: Generifiable
Adds a new type variable to this declaration.

Specified by:
generify in interface Generifiable

generify

public TypeVariable generify(String name,
                             Class<?> bound)
Description copied from interface: Generifiable
Adds a new type variable to this declaration with a bound.

Specified by:
generify in interface Generifiable

generify

public TypeVariable generify(String name,
                             TypeReference bound)
Description copied from interface: Generifiable
Adds a new type variable to this declaration with a bound.

Specified by:
generify in interface Generifiable

typeParams

public TypeVariable[] typeParams()
Description copied from class: TypeReference
Iterates all the type parameters of this class/interface.

For example, if this TypeReference represents Set<T>, this method returns an array that contains single TypeVariable for 'T'.

Specified by:
typeParams in interface Generifiable
Overrides:
typeParams in class TypeReference

substituteParams

protected TypeReference substituteParams(TypeVariable[] variables,
                                         List<TypeReference> bindings)
Description copied from class: TypeReference
Substitutes 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 a TypeReference for Map<String,Map<Integer>>.

This method needs to work recursively.

Specified by:
substituteParams in class TypeReference

annotate

public GeneratedAnnotationUse annotate(Class<? extends Annotation> clazz)
Adding ability to annotate a class

Specified by:
annotate in interface Annotable
Parameters:
clazz - The annotation class to annotate the class with

annotate

public GeneratedAnnotationUse annotate(TypeReference clazz)
Adding ability to annotate a class

Specified by:
annotate in interface Annotable
Parameters:
clazz - The annotation class to annotate the class with

annotate2

public <W extends AnnotationWriter> W annotate2(Class<W> clazz)
Description copied from interface: Annotable
Adds an annotation to this program element and returns a type-safe writer to fill in the values of such annotations.

Specified by:
annotate2 in interface Annotable

annotations

public Collection<GeneratedAnnotationUse> annotations()
Annotable.annotations()

Specified by:
annotations in interface Annotable
Returns:
Can be empty but never null.

mods

public Modifiers mods()
Returns:
the current modifiers of this class. Always return non-null valid object.

setter

public GeneratedMethod setter(GeneratedField field)
Generate a setter method for the specified field

Parameters:
field - Field for which a setter method needs to be build
Returns:
A setter method

setterOverride

public GeneratedMethod setterOverride(GeneratedField field)
Generate a setter and puts an override annotation on it


getter

public GeneratedMethod getter(GeneratedField field)
Generate a getter method for the specified field

Parameters:
field - Field for which a getter method needs to be build
Returns:
A getter method

superclasses

public List<GeneratedClass> superclasses()
Find all the classes that inherit from this one.

Returns:
A list of GeneratedClass that inherit from this one

topLevelClass

public GeneratedClass topLevelClass()
                             throws IllegalArgumentException
Find the top level class that inherits from this one.

If the class is inherited by more than one superclass this method will fail.

Returns:
Throws:
IllegalArgumentException

toString

public String toString()
Overrides:
toString in class TypeReference

implementsClass

public boolean implementsClass(Class clazz)
Returns whether this class implements the provided interface or not


muleContextField

public GeneratedField muleContextField()

flowConstructField

public GeneratedField flowConstructField()


Copyright © 2010-2013 MuleSoft, Inc.. All Rights Reserved.