com.ashridgetech.jamda.code
Class ClassWriter

java.lang.Object
  |
  +--com.ashridgetech.jamda.code.CodeWriter
        |
        +--com.ashridgetech.jamda.code.JavaWriter
              |
              +--com.ashridgetech.jamda.code.ClassWriter

public class ClassWriter
extends JavaWriter

A JavaWriter extended with methods for writing class structural elements. These include the class declaration and headers, field variables and methods.

Version:
1.0
Author:
Paul Boocock
See Also:
JavaWriter

Nested Class Summary
static class ClassWriter.MethodDetails
          Collects the details of a method in the code.
 
Field Summary
 
Fields inherited from class com.ashridgetech.jamda.code.CodeWriter
underlyingWriter
 
Constructor Summary
ClassWriter(java.io.Writer writer)
          Construct a ClassWriter attached to a Writer.
 
Method Summary
 ClassWriter beginDoc()
          Start a Javadoc comment.
 ClassWriter beginMethod(ClassWriter.MethodDetails details)
          Start a method in the code.
 ClassWriter classDecl(java.lang.String className, int modifiers, java.lang.String extendsName, java.util.Collection implementsNames)
          Write a class declaration.
 ClassWriter classDoc(java.lang.String classDoc)
          Write the class Javadoc, if any is supplied XXX - needs to split up multi-line comments, or long lines
 ClassWriter docLine(java.lang.String line)
          Write a Javadoc comment line.
 ClassWriter docOneLine(java.lang.String line)
          Write a Javadoc comment on a single line.
 ClassWriter endDoc()
          End a Javadoc comment.
 ClassWriter field(java.lang.String typeName, java.lang.String name, int modifiers)
          Declare a field variable in the code, without a comment or initial value.
 ClassWriter field(java.lang.String typeName, java.lang.String name, int modifiers, java.lang.String initValue, java.lang.String comment)
          Declare a field variable in the code.
 ClassWriter fileHeader(java.lang.String fileName, java.lang.String generator)
          Write a file header comment.
 ClassWriter imports(java.util.Collection importNames)
          Write the import declarations.
 ClassWriter interfaceDecl(java.lang.String name, int modifiers, java.util.Collection extendsNames)
          Write an interface declaration.
 ClassWriter packageDecl(java.lang.String packageName)
          Write a package declaration, if there is one.
 
Methods inherited from class com.ashridgetech.jamda.code.JavaWriter
beginComment, commentLine, endComment, endStmt, stmt, writeModifiers
 
Methods inherited from class com.ashridgetech.jamda.code.CodeWriter
begin, commaDoubleList, commaList, copyNoIndent, copyWithIndent, end, end, endLine, flush, getWriter, in, line, newline, newline, out, quote, space, spaceWrite, spaceWrite, spaceWrite, startLine, startLine, write, write, write, writeSpace, writeSpace, writeSpace, writeSpaced, writeSpaced, writeSpaced
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassWriter

public ClassWriter(java.io.Writer writer)
Construct a ClassWriter attached to a Writer.

Parameters:
writer - the Writer to which the code is written.
Method Detail

beginDoc

public ClassWriter beginDoc()
Start a Javadoc comment.

Returns:
this instance

endDoc

public ClassWriter endDoc()
End a Javadoc comment.

Returns:
this instance

docLine

public ClassWriter docLine(java.lang.String line)
Write a Javadoc comment line. This implementation calls JavaWriter.commentLine(java.lang.String).

Parameters:
line - the text of the comment line
Returns:
this instance

docOneLine

public ClassWriter docOneLine(java.lang.String line)
Write a Javadoc comment on a single line.

Returns:
this instance

field

public ClassWriter field(java.lang.String typeName,
                         java.lang.String name,
                         int modifiers)
Declare a field variable in the code, without a comment or initial value.

Parameters:
typeName - the name of the type of the field
name - the name of the field
modifiers - as in JavaWriter.writeModifiers(int).

field

public ClassWriter field(java.lang.String typeName,
                         java.lang.String name,
                         int modifiers,
                         java.lang.String initValue,
                         java.lang.String comment)
Declare a field variable in the code.

Parameters:
typeName - the name of the type of the field
name - the name of the field
modifiers - the OR'ed values of the Java reflection modifier constants, as in Modifier.
initValue - the initial value expression, or null if there is no initialiser
comment - the Javadoc comment, or null if there is no comment
Returns:
this instance

beginMethod

public ClassWriter beginMethod(ClassWriter.MethodDetails details)
Start a method in the code. If the method is abstract. end the declaration, otherwise begin a block for the method code.

Parameters:
details - the details of the method
Returns:
this instance

fileHeader

public ClassWriter fileHeader(java.lang.String fileName,
                              java.lang.String generator)
Write a file header comment.

Parameters:
fileName - the name of the file being written to
generator - the name of the generator using this ClassWriter
Returns:
this instance

packageDecl

public ClassWriter packageDecl(java.lang.String packageName)
Write a package declaration, if there is one.

Parameters:
packageName - the name of the package - if null, nothing is written
Returns:
this instance

classDecl

public ClassWriter classDecl(java.lang.String className,
                             int modifiers,
                             java.lang.String extendsName,
                             java.util.Collection implementsNames)
Write a class declaration.

Parameters:
className - the name of the class
modifiers - the OR'ed values of the Java reflection modifier constants, as in Modifier.
extendsName - the names of the class extended. May be null if no class is extended.
implementsNames - a collection of Strings with the names of interfaces implemented. May be null or empty if no classes are extended.
Returns:
this instance

interfaceDecl

public ClassWriter interfaceDecl(java.lang.String name,
                                 int modifiers,
                                 java.util.Collection extendsNames)
Write an interface declaration.

Parameters:
name - the name of the interface
modifiers - the OR'ed values of the Java reflection modifier constants, as in Modifier.
extendsNames - a collection of Strings with the names of classes extended. May be null or empty if no classes are extended.
Returns:
this instance

classDoc

public ClassWriter classDoc(java.lang.String classDoc)
Write the class Javadoc, if any is supplied XXX - needs to split up multi-line comments, or long lines

Parameters:
classDoc - the documentation to write - may be null
Returns:
this instance

imports

public ClassWriter imports(java.util.Collection importNames)
Write the import declarations.

Parameters:
importNames - a collection of Strings with the names of imports. May be null or empty if no imports.


Copyright © 2003 Ashridge Technologies Ltd. All Rights Reserved.