Public Member Functions | Static Protected Member Functions

org.exolab.javasource.JCompUnit Class Reference

List of all members.

Public Member Functions

 JCompUnit (String packageName, String fileName)
 JCompUnit (JClass jClass)
 JCompUnit (JInterface jInterface)
void addStructure (JStructure jStructure) throws IllegalArgumentException
void addClass (JClass jClass)
void addInterface (JInterface jInterface)
SortedSet getImports ()
String getFilename (String destDir)
String getPackageName ()
void print ()
void print (String destDir)
void print (String destDir, String lineSeparator)
void print (JSourceWriter jsw)
final void printStructures (JSourceWriter jsw, boolean printPublic)
void setHeader (JComment comment)

Static Protected Member Functions

static String getPackageFromClassName (String className)

Detailed Description

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.

Author:
Gary Shea
Version:
Revision:
1.2
Date:
2004/10/01 13:25:38

Constructor & Destructor Documentation

org.exolab.javasource.JCompUnit.JCompUnit ( String  packageName,
String  fileName 
)

Creates a new JCompUnit

Parameters:
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 stored
org.exolab.javasource.JCompUnit.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. Package and file name are taken from jClass.

Parameters:
jClass the public class for this JCompUnit.

References org.exolab.javasource.JType.getLocalName(), and org.exolab.javasource.JStructure.getPackageName().

org.exolab.javasource.JCompUnit.JCompUnit ( JInterface  jInterface  ) 

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.

References org.exolab.javasource.JType.getLocalName(), and org.exolab.javasource.JStructure.getPackageName().


Member Function Documentation

void org.exolab.javasource.JCompUnit.addClass ( JClass  jClass  ) 

Adds a JClass which should be printed in this file.

Referenced by org.exolab.javasource.JCompUnit.addStructure().

void org.exolab.javasource.JCompUnit.addInterface ( JInterface  jInterface  ) 

Adds a JInterface which should be printed in this file.

Referenced by org.exolab.javasource.JCompUnit.addStructure().

void org.exolab.javasource.JCompUnit.addStructure ( JStructure  jStructure  )  throws IllegalArgumentException

Adds the given JStructure (either a JInterface or a JClass) to this JCompUnit.

Parameters:
jStructure the JStructure to add
Exceptions:
IllegalArgumentException when the given JStructure has the same name of an existing JStructure or if the class of jStructure is unknown.

References org.exolab.javasource.JCompUnit.addClass(), org.exolab.javasource.JCompUnit.addInterface(), and org.exolab.javasource.JStructure.getName().

String org.exolab.javasource.JCompUnit.getFilename ( String  destDir  ) 

Returns the name of the file that this JCompUnit would be printed as, given a call to print.

Parameters:
destDir the destination directory. This may be null.
Returns:
the name of the file that this JCompUnit would be printed as, given a call to print.

Referenced by org.exolab.javasource.JCompUnit.print().

SortedSet org.exolab.javasource.JCompUnit.getImports (  ) 

returns a array of String containing all import classes/packages, also imports within the same package of this object.

Returns:
a array of String containing all import classes/packages, also imports within the same package of this object.

References org.exolab.javasource.JStructure.getImports().

Referenced by org.exolab.javasource.JCompUnit.print().

static String org.exolab.javasource.JCompUnit.getPackageFromClassName ( String  className  )  [static, protected]
String org.exolab.javasource.JCompUnit.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

Referenced by org.exolab.javasource.JCompUnit.print().

void org.exolab.javasource.JCompUnit.print ( JSourceWriter  jsw  ) 
void org.exolab.javasource.JCompUnit.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(String, String)

Referenced by org.exolab.javasource.JCompUnit.print().

void org.exolab.javasource.JCompUnit.print ( String  destDir,
String  lineSeparator 
)

Prints the source code for this JCompUnit.

Parameters:
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.

References org.exolab.javasource.JSourceWriter.close(), org.exolab.javasource.JSourceWriter.flush(), org.exolab.javasource.JCompUnit.getFilename(), org.exolab.javasource.JCompUnit.print(), and org.exolab.javasource.JSourceWriter.setLineSeparator().

void org.exolab.javasource.JCompUnit.print ( String  destDir  ) 

Prints the source code for this JClass with the default line seperator of the the runtime platform.

Parameters:
destDir the destination directory to generate the file.
See also:
print(String, String)

References org.exolab.javasource.JCompUnit.print().

final void org.exolab.javasource.JCompUnit.printStructures ( JSourceWriter  jsw,
boolean  printPublic 
)

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.

References org.exolab.javasource.JStructure.getModifiers(), org.exolab.javasource.JModifiers.isPublic(), org.exolab.javasource.JClass.print(), org.exolab.javasource.JInterface.print(), and org.exolab.javasource.JSourceWriter.writeln().

Referenced by org.exolab.javasource.JCompUnit.print().

void org.exolab.javasource.JCompUnit.setHeader ( JComment  comment  ) 

Sets the header comment for this JCompUnit

Parameters:
comment the comment to display at the top of the source file when printed

The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Enumerations Properties