com.ashridgetech.jamda.code
Class MethodCoder

java.lang.Object
  |
  +--com.ashridgetech.jamda.code.CodeWriter
        |
        +--com.ashridgetech.jamda.code.JavaWriter
              |
              +--com.ashridgetech.jamda.code.MethodCoder
Direct Known Subclasses:
OperationMethodCoder, TestMethodCoderFactory.Coder

public abstract class MethodCoder
extends JavaWriter

Base class for classes which write the code for Java method bodies. Each instance can only be used once. Extends JavaWriter to provide common Java statement coding functions. Also provides some useful utility functions. Uses a private buffer to which the code is written. Subclasses must implement the codeBody() method.

Version:
1.0
Author:
Paul Boocock
See Also:
MethodCoderFactory

Field Summary
 
Fields inherited from class com.ashridgetech.jamda.code.CodeWriter
underlyingWriter
 
Constructor Summary
protected MethodCoder(Operation op, UmlClassGenerator gen)
          Construct a MethodCoder attached to a StringWriter.
 
Method Summary
abstract  void codeBody()
          Must be implemented by subclasses to write the method body statements.
 void generate(java.io.Writer writer)
          Write the generated class code to the output Writer.
 UmlClassGenerator getClassGenerator()
          Get the UmlClassGenerator for which this instance is generating code.
 Operation getOperation()
          Get the Operation for which this instance is generating code.
 java.util.List getParameters()
          Get the Parameters of the Operation for which this instance is generating code.
 Type getReturnType()
          Get the return Type of the Operation for which this instance is generating code.
 
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

MethodCoder

protected MethodCoder(Operation op,
                      UmlClassGenerator gen)
Construct a MethodCoder attached to a StringWriter.

Parameters:
op - the Operation being coded
gen - the UmlClassGenerator using this coder. May be used to access methods of the generator. One need for this is to call ClassGenerator.addImport(java.lang.String) if the code uses a type which is not already used by a method or field of the class.
Method Detail

getOperation

public Operation getOperation()
Get the Operation for which this instance is generating code.

Returns:
the Operation

getParameters

public java.util.List getParameters()
Get the Parameters of the Operation for which this instance is generating code.

Returns:
a List of Parameter objects

getReturnType

public Type getReturnType()
Get the return Type of the Operation for which this instance is generating code.

Returns:
the Type

getClassGenerator

public UmlClassGenerator getClassGenerator()
Get the UmlClassGenerator for which this instance is generating code.

Returns:
the Operation

codeBody

public abstract void codeBody()
Must be implemented by subclasses to write the method body statements. The implementation can use any of the methods of JavaWriter.


generate

public void generate(java.io.Writer writer)
              throws java.io.IOException
Write the generated class code to the output Writer. Calls codeBody().

Parameters:
writer - the destination for the generated code
java.io.IOException


Copyright © 2003 Ashridge Technologies Ltd. All Rights Reserved.