Package org.exolab.javasource
Class JCompUnit
java.lang.Object
org.exolab.javasource.JCompUnit
A representation of the Java Source code for a Java compilation unit. This is a useful utility
when creating in memory source code. This package was modelled after the Java Reflection API as
much as possible to reduce the learning curve.
- Version:
- $Revision$ $Date: 2005-03-05 06:42:06 -0700 (Sat, 05 Mar 2005) $
- Author:
- Gary Shea
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new JCompUnit.Creates a new JCompUnit with the given JClass (which must have been created with either a full class name or package/local name) as the public class.JCompUnit
(JInterface jInterface) Creates a new JCompUnit with the given JInterface as public interface. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a JClass to be printed in this file.void
addInterface
(JInterface jInterface) Adds a JInterface to be printed in this file.void
addStructure
(JStructure jStructure) Adds the given JStructure (either a JInterface or a JClass) to this JCompUnit.getFilename
(String destDir) Returns the name of the file that this JCompUnit would be printed to, given a call toprint(String, String)
, or if destDir is null, a call toprint()
.Returns a array of String containing all imported classes/packages, also imports within the same package of this object.Returns the name of the package that this JCompUnit is a member of.void
print()
Prints the source code for this JClass in the current directory with the default line seperator of the the runtime platform.void
Prints the source code for this JClass with the default line seperator of the the runtime platform.void
Prints the source code for this JCompUnit using the provided root directory and line separator.void
print
(JSourceWriter jsw) Prints the source code for this JClass to the provided JSourceWriter.void
printStructures
(JSourceWriter jsw, boolean printPublic) Print the source code for the contained JClass objects.void
Sets the header comment for this JCompUnit.
-
Constructor Details
-
JCompUnit
-
JCompUnit
Creates a new JCompUnit with the given JClass (which must have been created with either a full class name or package/local name) as the public class. Package and file name are taken from jClass.- Parameters:
jClass
- The public class for this JCompUnit.
-
JCompUnit
Creates a new JCompUnit with the given JInterface as public interface. Package and file name are taken from jInterface.- Parameters:
jInterface
- The public interface for this JCompUnit.
-
-
Method Details
-
setHeader
Sets the header comment for this JCompUnit.- Parameters:
comment
- The comment to display at the top of the source file when printed.
-
addStructure
Adds the given JStructure (either a JInterface or a JClass) to this JCompUnit.- Parameters:
jStructure
- The JStructure to add.
-
addClass
Adds a JClass to be printed in this file.- Parameters:
jClass
- The JClass to be printed in this file.
-
addInterface
Adds a JInterface to be printed in this file.- Parameters:
jInterface
- The JInterface to be printed in this file.
-
getImports
-
getFilename
Returns the name of the file that this JCompUnit would be printed to, given a call toprint(String, String)
, or if destDir is null, a call toprint()
.- Parameters:
destDir
- The destination directory. This may be null.- Returns:
- The name of the file that this JCompUnit would be printed to.
-
getPackageName
Returns the name of the package that this JCompUnit is a member of.- Returns:
- The name of the package that this JCompUnit is a member of, or null if there is no current package name defined.
-
print
public void print()Prints the source code for this JClass in the current directory with the default line seperator of the the runtime platform.- See Also:
-
print
Prints the source code for this JClass with the default line seperator of the the runtime platform.- Parameters:
destDir
- The destination directory to use as the root directory for source generation.- See Also:
-
print
Prints the source code for this JCompUnit using the provided root directory and line separator.- Parameters:
destDir
- The destination directory to use as the root directory for source generation.lineSeparator
- The line separator to use at the end of each line. If null, then the default line separator for the runtime platform will be used.
-
print
Prints the source code for this JClass to the provided JSourceWriter.- Parameters:
jsw
- The JSourceWriter to print to.
-
printStructures
Print the source code for the contained JClass objects.- Parameters:
jsw
- The JSourceWriter to print to.printPublic
- If true, print only public classes; if false, print only non-public classes.
-