public class JCompUnit
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private java.util.List<JClass> |
classes
The set of top-level classes that live in this compilation unit.
|
private static java.lang.String |
DEFAULT_HEADER
The Id for Source control systems
I needed to separate this line to prevent CVS from
expanding it here! ;-)
|
private java.lang.String |
fileName
The file to which this JCompUnit will be saved
|
private JComment |
header |
private java.util.List<JInterface> |
interfaces
The set of top-level interfaces that live in this compilation unit.
|
private java.lang.String |
packageName
The package for this JCompUnit
|
Constructor and Description |
---|
JCompUnit(JClass jClass)
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
Package and file name are taken from jInterface.
|
JCompUnit(java.lang.String packageName,
java.lang.String fileName)
Creates a new JCompUnit
|
Modifier and Type | Method and Description |
---|---|
void |
addClass(JClass jClass)
Adds a JClass which should be printed in this file.
|
void |
addInterface(JInterface jInterface)
Adds a JInterface which should be printed in this file.
|
void |
addStructure(JStructure jStructure)
Adds the given JStructure (either a JInterface or
a JClass) to this JCompUnit.
|
java.lang.String |
getFilename(java.lang.String destDir)
Returns the name of the file that this JCompUnit would be
printed as, given a call to #print.
|
java.util.SortedSet<java.lang.String> |
getImports()
returns a array of String containing all import classes/packages,
also imports within the same package of this object.
|
protected static java.lang.String |
getPackageFromClassName(java.lang.String className) |
java.lang.String |
getPackageName()
Returns the name of the package that this JCompUnit is a member of
|
private void |
init() |
void |
print()
Prints the source code for this JClass in the current directory
with the default line seperator of the the runtime platform.
|
void |
print(JSourceWriter jsw)
Prints the source code for this JClass.
|
void |
print(java.lang.String destDir)
Prints the source code for this JClass
with the default line seperator of the the runtime platform.
|
void |
print(java.lang.String destDir,
java.lang.String lineSeparator)
Prints the source code for this JCompUnit.
|
void |
printStructures(JSourceWriter jsw,
boolean printPublic)
Print the source code for the contained JClass objects.
|
private void |
resolveNames()
Update the names of nested classes and interfaces.
|
void |
setHeader(JComment comment)
Sets the header comment for this JCompUnit
|
private static final java.lang.String DEFAULT_HEADER
private JComment header
private java.lang.String packageName
private java.lang.String fileName
private java.util.List<JClass> classes
private java.util.List<JInterface> interfaces
public JCompUnit(java.lang.String packageName, java.lang.String fileName)
packageName
- the name of the package for this JCompUnit.
If packageName is null or empty, no 'package' line will be generated.fileName
- the name of the file in which this JCompUnit
will be storedpublic JCompUnit(JClass jClass)
jClass
- the public class for this JCompUnit.public JCompUnit(JInterface jInterface)
jInterface
- the public interface for this JCompUnit.private void init()
public void addStructure(JStructure jStructure) throws java.lang.IllegalArgumentException
jStructure
- the JStructure to addjava.lang.IllegalArgumentException
- when the given
JStructure has the same name of an existing JStructure
or if the class of jStructure is unknown.public void addClass(JClass jClass)
jClass
- the JClass to addpublic void addInterface(JInterface jInterface)
jInterface
- the JInterface to addpublic java.util.SortedSet<java.lang.String> getImports()
public java.lang.String getFilename(java.lang.String destDir)
destDir
- the destination directory. This may be null.public java.lang.String getPackageName()
protected static java.lang.String getPackageFromClassName(java.lang.String className)
public void print()
public void print(java.lang.String destDir)
destDir
- the destination directory to generate the file.print(java.lang.String, java.lang.String)
public void print(java.lang.String destDir, java.lang.String lineSeparator)
destDir
- the destination directory to generate the file.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.public void print(JSourceWriter jsw)
jsw
- the JSourceWriter to print to.public final void printStructures(JSourceWriter jsw, boolean printPublic)
jsw
- the JSourceWriter to print to.printPublic
- if true, print only public classes; if
false, print only non-public classes.public void setHeader(JComment comment)
comment
- the comment to display at the top of the source file
when printedprivate void resolveNames()