|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.mule.devkit.model.code.CodeModel
public final class CodeModel
Root of the code DOM.
Here's your typical CodeModel application.
CodeModel cm = new CodeModel();
// generate source code by populating the 'cm' tree.
cm._class(...);
...
// write them out
cm.build(new File("."));
Every CodeModel node is always owned by one CodeModel object
at any given time (which can be often accesesd by the owner() method.)
As such, when you generate Java code, most of the operation works
in a top-down fashion. For example, you create a class from CodeModel,
which gives you a GeneratedClass. Then you invoke a method on it
to generate a new method, which gives you GeneratedMethod, and so on.
There are a few exceptions to this, most notably building GeneratedExpressions,
but generally you work with CodeModel in a top-down fashion.
Because of this design, most of the CodeModel classes aren't directly instanciable.
CodeModel.
See _class(String, GeneratedClassType).
| Field Summary | |
|---|---|
PrimitiveType |
BOOLEAN
|
static Map<Class<?>,Class<?>> |
boxToPrimitive
The reverse look up for primitiveToBox |
PrimitiveType |
BYTE
|
PrimitiveType |
CHAR
|
PrimitiveType |
DOUBLE
|
PrimitiveType |
FLOAT
|
PrimitiveType |
INT
|
protected static boolean |
isCaseSensitiveFileSystem
If the flag is true, we will consider two classes "Foo" and "foo" as a collision. |
PrimitiveType |
LONG
|
NullType |
NULL
Obtains a reference to the special "null" type. |
static Map<Class<?>,Class<?>> |
primitiveToBox
Conversion from primitive type Class (such as Integer.TYPE
to its boxed type (such as Integer.class) |
PrimitiveType |
SHORT
|
PrimitiveType |
VOID
|
| Constructor Summary | |
|---|---|
CodeModel(CodeWriter codeWriter)
|
|
| Method Summary | |
|---|---|
GeneratedClass |
_class(int mods,
String fullyqualifiedName,
GeneratedClassType t)
Creates a new generated class. |
GeneratedClass |
_class(String fullyqualifiedName)
Creates a new generated class. |
GeneratedClass |
_class(String fullyqualifiedName,
GeneratedClassType t)
Creates a new generated class. |
GeneratedClass |
_getClass(String fullyQualifiedName)
Gets a reference to the already created generated class. |
GeneratedPackage |
_package(String name)
Add a package to the list of packages to be generated |
Type |
_ref(Class<?> c)
|
GeneratedClass |
anonymousClass(Class<?> baseType)
|
GeneratedClass |
anonymousClass(TypeReference baseType)
Creates a new anonymous class. |
void |
build()
|
int |
countArtifacts()
Returns the number of files to be generated if build(java.io.File, java.io.PrintStream) is invoked now. |
TypeReference |
directClass(String name)
Creates a dummy, unknown TypeReference that represents a given name. |
CodeWriter |
getCodeWriter()
Get code writer |
OutputStream |
getRegistryBootstrapStream()
|
GeneratedClass |
newAnonymousClass(TypeReference baseType)
Deprecated. The naming convention doesn't match the rest of the CodeModel. Use anonymousClass(TypeReference) instead. |
Iterator<GeneratedPackage> |
packages()
Returns an iterator that walks the packages defined using this code writer. |
Type |
parseType(String name)
Obtains a type object from a type name. |
TypeReference |
ref(Class<?> clazz)
Obtains a reference to an existing class from its Class object. |
Type |
ref(String fullyQualifiedClassName)
Obtains a reference to an existing class from its fully-qualified class name. |
Type |
ref(TypeMirror typeMirror)
|
GeneratedPackage |
rootPackage()
|
TypeReference |
wildcard()
Gets a TypeReference representation for "?",
which is equivalent to "? extends Object". |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public final NullType NULL
public final PrimitiveType VOID
public final PrimitiveType BOOLEAN
public final PrimitiveType BYTE
public final PrimitiveType SHORT
public final PrimitiveType CHAR
public final PrimitiveType INT
public final PrimitiveType FLOAT
public final PrimitiveType LONG
public final PrimitiveType DOUBLE
protected static final boolean isCaseSensitiveFileSystem
public static final Map<Class<?>,Class<?>> primitiveToBox
Class (such as Integer.TYPE
to its boxed type (such as Integer.class)
public static final Map<Class<?>,Class<?>> boxToPrimitive
primitiveToBox
| Constructor Detail |
|---|
public CodeModel(CodeWriter codeWriter)
| Method Detail |
|---|
public GeneratedPackage _package(String name)
name - Name of the package. Use "" to indicate the root package.
public final GeneratedPackage rootPackage()
public Iterator<GeneratedPackage> packages()
public GeneratedClass _class(String fullyqualifiedName)
throws ClassAlreadyExistsException
ClassAlreadyExistsException - When the specified class/interface was already created.public TypeReference directClass(String name)
TypeReference that represents a given name.
This method is useful when the code generation needs to include the user-specified
class that may or may not exist, and only thing known about it is a class name.
public GeneratedClass _class(int mods,
String fullyqualifiedName,
GeneratedClassType t)
throws ClassAlreadyExistsException
ClassAlreadyExistsException - When the specified class/interface was already created.
public GeneratedClass _class(String fullyqualifiedName,
GeneratedClassType t)
throws ClassAlreadyExistsException
ClassAlreadyExistsException - When the specified class/interface was already created.public GeneratedClass _getClass(String fullyQualifiedName)
GeneratedPackage._getClass(String)public GeneratedClass newAnonymousClass(TypeReference baseType)
anonymousClass(TypeReference) instead.
public GeneratedClass anonymousClass(TypeReference baseType)
public GeneratedClass anonymousClass(Class<?> baseType)
public void build()
throws IOException
IOExceptionpublic int countArtifacts()
build(java.io.File, java.io.PrintStream) is invoked now.
public Type ref(TypeMirror typeMirror)
public TypeReference ref(Class<?> clazz)
for the version that handles more cases.public Type _ref(Class<?> c)
public Type ref(String fullyQualifiedClassName)
Object, and return a TypeReference.
public TypeReference wildcard()
TypeReference representation for "?",
which is equivalent to "? extends Object".
public Type parseType(String name)
throws ClassNotFoundException
Classes.
ClassNotFoundException - If the specified type is not found.
public OutputStream getRegistryBootstrapStream()
throws IOException
IOExceptionpublic CodeWriter getCodeWriter()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||