| java.lang.Object com.sun.codemodel.JCodeModel
JCodeModel | final public class JCodeModel (Code) | | Root of the code DOM.
Here's your typical CodeModel application.
JCodeModel cm = new JCodeModel();
// 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
JCodeModel 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
JCodeModel ,
which gives you a
JDefinedClass . Then you invoke a method on it
to generate a new method, which gives you
JMethod , and so on.
There are a few exceptions to this, most notably building
JExpression s,
but generally you work with CodeModel in a top-down fashion.
Because of this design, most of the CodeModel classes aren't directly instanciable.
Where to go from here?
Most of the time you'd want to populate new type definitions in a
JCodeModel .
See
JCodeModel._class(String,ClassType) .
|
Method Summary | |
public JDefinedClass | _class(String fullyqualifiedName) Creates a new generated class. | public JDefinedClass | _class(String fullyqualifiedName, ClassType t) Creates a new generated class. | public JDefinedClass | _getClass(String fullyQualifiedName) Gets a reference to the already created generated class. | public JPackage | _package(String name) Add a package to the list of packages to be generated
Parameters: name - Name of the package. | public JType | _ref(Class c) | public JDefinedClass | anonymousClass(JClass baseType) Creates a new anonymous class. | public JDefinedClass | anonymousClass(Class baseType) | public void | build(File destDir, PrintStream status) Generates Java source code. | public void | build(File srcDir, File resourceDir, PrintStream status) Generates Java source code. | public void | build(File destDir) A convenience method for build(destDir,System.out) . | public void | build(File srcDir, File resourceDir) A convenience method for build(srcDir,resourceDir,System.out) . | public void | build(CodeWriter out) A convenience method for build(out,out) . | public void | build(CodeWriter source, CodeWriter resource) Generates Java source code. | public int | countArtifacts() Returns the number of files to be generated if
JCodeModel.build is invoked now. | public JClass | directClass(String name) Creates a dummy, unknown
JClass that represents a given name. | public JDefinedClass | newAnonymousClass(JClass baseType) Creates a new anonymous class. | public Iterator<JPackage> | packages() Returns an iterator that walks the packages defined using this code
writer. | public JType | parseType(String name) Obtains a type object from a type name. | public JClass | ref(Class clazz) Obtains a reference to an existing class from its Class object. | public JClass | ref(String fullyQualifiedClassName) Obtains a reference to an existing class from its fully-qualified
class name. | final public JPackage | rootPackage() | public JClass | wildcard() Gets a
JClass representation for "?",
which is equivalent to "? extends Object". |
NULL | final public JNullType NULL(Code) | | Obtains a reference to the special "null" type.
|
isCaseSensitiveFileSystem | final protected static boolean isCaseSensitiveFileSystem(Code) | | If the flag is true, we will consider two classes "Foo" and "foo"
as a collision.
|
JCodeModel | public JCodeModel()(Code) | | |
_package | public JPackage _package(String name)(Code) | | Add a package to the list of packages to be generated
Parameters: name - Name of the package. Use "" to indicate the root package. Newly generated package |
build | public void build(File destDir, PrintStream status) throws IOException(Code) | | Generates Java source code.
A convenience method for build(destDir,destDir,System.out) .
Parameters: destDir - source files are generated into this directory. Parameters: status - if non-null, progress indication will be sent to this stream. |
build | public void build(File srcDir, File resourceDir, PrintStream status) throws IOException(Code) | | Generates Java source code.
A convenience method that calls
JCodeModel.build(CodeWriter,CodeWriter) .
Parameters: srcDir - Java source files are generated into this directory. Parameters: resourceDir - Other resource files are generated into this directory. Parameters: status - if non-null, progress indication will be sent to this stream. |
build | public void build(File destDir) throws IOException(Code) | | A convenience method for build(destDir,System.out) .
|
build | public void build(File srcDir, File resourceDir) throws IOException(Code) | | A convenience method for build(srcDir,resourceDir,System.out) .
|
countArtifacts | public int countArtifacts()(Code) | | Returns the number of files to be generated if
JCodeModel.build is invoked now.
|
directClass | public JClass directClass(String name)(Code) | | Creates a dummy, unknown
JClass 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.
|
packages | public Iterator<JPackage> packages()(Code) | | Returns an iterator that walks the packages defined using this code
writer.
|
ref | public JClass ref(Class clazz)(Code) | | Obtains a reference to an existing class from its Class object.
The parameter may not be primitive.
See Also: JCodeModel._ref(Class) See Also: for the version that handles more cases. |
ref | public JClass ref(String fullyQualifiedClassName)(Code) | | Obtains a reference to an existing class from its fully-qualified
class name.
First, this method attempts to load the class of the given name.
If that fails, we assume that the class is derived straight from
Object , and return a
JClass .
|
wildcard | public JClass wildcard()(Code) | | Gets a
JClass representation for "?",
which is equivalent to "? extends Object".
|
|
|