com.ashridgetech.jamda.code
Class ClassGenerator.MethodGenerator

java.lang.Object
  |
  +--com.ashridgetech.jamda.code.ClassGenerator.MethodGenerator
Enclosing class:
ClassGenerator

public class ClassGenerator.MethodGenerator
extends java.lang.Object

Generates a method in the code. May only be obtained from ClassGenerator.addMethod(java.lang.String). After setting the details, call ClassGenerator.getWriter() to get a JavaWriter to which the method body may be written.

See Also:
ClassGenerator.addMethod(java.lang.String)

Constructor Summary
protected ClassGenerator.MethodGenerator(java.lang.String name)
          Create a MethodGenerator with the given name, modifiers of PUBLIC, void return type and no parameters, which may be abstract.
 
Method Summary
 ClassGenerator.MethodGenerator addModifiers(int modifiers)
          Add modifiers to the existing modifiers.
 ClassGenerator.MethodGenerator addTag(java.lang.String tag)
          Set an extra tag for the method Javadoc.
 ClassGenerator.MethodGenerator addThrows(java.lang.String exceptionName)
          Add the name of an exception thrown by this method.
 ClassGenerator.MethodGenerator addThrows(java.lang.String exceptionName, java.lang.String exceptionComment)
          Add the name of an exception thrown by this method, with a Javadoc description.
 ClassGenerator.MethodGenerator description(java.lang.String comment)
          Set the method description.
 void generate()
          Generate this method's documentation, declaration and copy the code written to its writer() into its containing ClassGenerator's ClassWriter.
 boolean isAbstract()
          Indicate whether this method is abstract, as defined by the modifiers set by setModifiers(int).
 ClassGenerator.MethodGenerator param(java.lang.String type, java.lang.String name)
          Add a parameter with no description.
 ClassGenerator.MethodGenerator param(java.lang.String type, java.lang.String name, java.lang.String comment)
          Add a parameter.
 ClassGenerator.MethodGenerator returns(java.lang.String returnTypeName)
          Set the return type name.
 ClassGenerator.MethodGenerator returns(java.lang.String returnTypeName, java.lang.String comment)
          Set the return type name.
 ClassGenerator.MethodGenerator setModifiers(int modifiers)
          Replace the existing modifiers with modifiers.
 JavaWriter writer()
          Get the JavaWriter to which the method code can be written.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassGenerator.MethodGenerator

protected ClassGenerator.MethodGenerator(java.lang.String name)
Create a MethodGenerator with the given name, modifiers of PUBLIC, void return type and no parameters, which may be abstract.

Parameters:
name - the method name
Method Detail

returns

public ClassGenerator.MethodGenerator returns(java.lang.String returnTypeName)
Set the return type name.

Parameters:
returnTypeName - the name of the return type - may be null to indicate no return type for a constructor.
Returns:
this instance

returns

public ClassGenerator.MethodGenerator returns(java.lang.String returnTypeName,
                                              java.lang.String comment)
Set the return type name.

Parameters:
returnTypeName - the name of the return type - may be null to indicate no return type for a constructor.
comment - the description of the return type - must be null if returnTypeName is null
Returns:
this instance

addModifiers

public ClassGenerator.MethodGenerator addModifiers(int modifiers)
Add modifiers to the existing modifiers.

Parameters:
modifiers - the modifiers to OR with the existing ones.
Returns:
this instance

setModifiers

public ClassGenerator.MethodGenerator setModifiers(int modifiers)
Replace the existing modifiers with modifiers. If the constructor set this MethodGenerator to abstract, the abstract modifier will be added to those set.

Parameters:
modifiers - the new modifiers.
Returns:
this instance

description

public ClassGenerator.MethodGenerator description(java.lang.String comment)
Set the method description.

Parameters:
comment - the description of the method
Returns:
this instance

addThrows

public ClassGenerator.MethodGenerator addThrows(java.lang.String exceptionName)
Add the name of an exception thrown by this method.

Parameters:
exceptionName - the name of the exception class
Returns:
this instance

addThrows

public ClassGenerator.MethodGenerator addThrows(java.lang.String exceptionName,
                                                java.lang.String exceptionComment)
Add the name of an exception thrown by this method, with a Javadoc description.

Parameters:
exceptionName - the name of the exception class
exceptionComment - the reason why the exception is thrown
Returns:
this instance

addTag

public ClassGenerator.MethodGenerator addTag(java.lang.String tag)
Set an extra tag for the method Javadoc. This should not incluse the @param and @return tags, which are created from the comments supplied to returns(java.lang.String) and param(java.lang.String, java.lang.String, java.lang.String).

Parameters:
tag - the full text of the extra tag, such as "@see Widget#grumble"
Returns:
this instance

param

public ClassGenerator.MethodGenerator param(java.lang.String type,
                                            java.lang.String name,
                                            java.lang.String comment)
Add a parameter.

Parameters:
type - the name of the type of this parameter - must not be null
name - the name of this parameter - must not be null
comment - the description of this parameter - may be null if there is no comment
Returns:
this instance

param

public ClassGenerator.MethodGenerator param(java.lang.String type,
                                            java.lang.String name)
Add a parameter with no description.

Parameters:
type - the name of the type of this parameter - must not be null
name - the name of this parameter - must not be null
Returns:
this instance

writer

public JavaWriter writer()
Get the JavaWriter to which the method code can be written.

Returns:
the JavaWriter
Throws:
java.lang.IllegalStateException - if this MethodGenerator is abstract
See Also:
isAbstract()

isAbstract

public boolean isAbstract()
Indicate whether this method is abstract, as defined by the modifiers set by setModifiers(int).

Returns:
true if it is abstract

generate

public void generate()
Generate this method's documentation, declaration and copy the code written to its writer() into its containing ClassGenerator's ClassWriter.



Copyright © 2003 Ashridge Technologies Ltd. All Rights Reserved.