Interface | Description |
---|---|
Annotable |
Annotatable program elements.
|
AnnotationWriter<A extends Annotation> |
Base interface for typed annotation writer.
|
AssignmentTarget |
Marker interface for code components that can be placed to
the left of '=' in an assignment.
|
ClassContainer |
The common aspect of a package and a class.
|
Declaration |
Common interface for code components that can generate declarations
of themselves.
|
Documentable |
Program elements that can have Javadoc
|
Generable |
Common interface for code components that can generate
uses of themselves.
|
GeneratedExpression |
A Java expression.
|
Generifiable |
Declarations that can have type variables.
|
Statement |
Common interface for code components that can generate
uses of themselves as statements.
|
Class | Description |
---|---|
AbstractExpression |
Provides default implementations for
GeneratedExpression . |
AnnotationArrayMember |
Represents an arrays as annotation members
This class implements
Annotable to allow
new annotations to be added as a member of the array. |
AnnotationValue |
Things that can be values of an annotation element.
|
Assignment |
Assignment statements, which are also expressions.
|
CodeModel |
Root of the code DOM.
|
CodeWriter |
Receives generated code and writes to the appropriate storage.
|
CommentPart |
A part is a part of a javadoc comment, and it is a list of values.
|
EnumConstant |
Enum Constant.
|
ExpressionFactory |
Factory methods that generate various
GeneratedExpression s. |
Formatter |
This is a utility class for managing indentation and other basic
formatting for PrintWriter.
|
GeneratedAnnotationUse |
Represents an annotation on a program element.
|
GeneratedArray |
array creation and initialization.
|
GeneratedBlock |
A block of Java code, which may contain statements and local declarations.
|
GeneratedCast |
A cast operation.
|
GeneratedCatchBlock |
Catch block for a try/catch/finally statement
|
GeneratedClass |
A generated Java class/interface/enum/....
|
GeneratedConditional |
If statement, with optional else clause
|
GeneratedDoLoop |
Do loops
|
GeneratedField |
A field that can have a
GeneratedJavaDocComment associated with it |
GeneratedFieldReference |
Field Reference
|
GeneratedForEach |
ForEach Statement
This will generate the code for statement based on the new
j2se 1.5 j.l.s.
|
GeneratedForLoop |
For statement
|
GeneratedInvocation |
Method invocation
|
GeneratedJavaDocComment |
JavaDoc comment.
|
GeneratedLabel |
Label that can be used for continue and break.
|
GeneratedMethod |
Java method.
|
GeneratedPackage |
A Java package.
|
GeneratedSwitch |
Switch statement
|
GeneratedSwitchCase |
Case statement
|
GeneratedTry |
Try statement with Catch and/or Finally clause
|
GeneratedVariable |
Variables and fields.
|
GeneratedWhileLoop |
While statement
|
JavaName |
Utility methods that convert arbitrary strings into Java identifiers.
|
Modifier |
Modifier constants.
|
Modifiers |
Modifier groups.
|
NullType |
Special class object that represents the type of "null".
|
Op |
TypeReference for generating expressions containing operators
|
PrimitiveType |
Java built-in primitive types.
|
ResourceFile |
Represents a resource file in the application-specific file format.
|
StringLiteral |
String literal.
|
Type |
A representation of a type in codeModel.
|
TypeReference |
Represents a Java reference type, such as a class, an interface,
an enum, an array type, a parameterized type.
|
TypeVariable |
Type variable used to declare generics.
|
Enum | Description |
---|---|
GeneratedClassType |
This helps enable whether the DefinedClass is a Class or Interface or
AnnotationTypeDeclaration or Enum
|
Exception | Description |
---|---|
ClassAlreadyExistsException |
Indicates that the class is already created.
|
CodeModel is a library that allows you to generate Java source code in a type-safe fashion.
With CodeModel, you build the java source code by first building AST, then writing it out as text files that is Java source files. The AST looks like this:
You bulid this tree mostly from top-down. So, you first create
a new GeneratedClass
from CodeModel
, then you
create a GeneratedMethod
from GeneratedClass
, and so on.
This design brings the following beneefits:
CodeModel
is the entry point to
the library. See its javadoc for more details about how to use
CodeModel.
Generally speaking, CodeModel is expected to be used in an environment where the resource constraint is not severe. Therefore, we haven't spent much effort in trying to make this library lean and mean.
That said, we did some benchmark and performance analysis. In case anyone is interested in making this library better performance wise, here's the findings.
List
s Map
s, and other collections take up
a lot of space. Allocating those things lazily is generally
a good idea.
Compared to template-based code generator, the writing operation is slow, as it needs to traverse each AST node. Consider pre-encoding tokens (like 'public') to the target encoding, and consider exploting the subtree equivalence.
Copyright © 2010–2015 MuleSoft, Inc.. All rights reserved.