org.brains2b.typewriter
Class MethodTemplate

java.lang.Object
  extended byorg.brains2b.typewriter.ContentTemplate
      extended byorg.brains2b.typewriter.MethodTemplate
All Implemented Interfaces:
java.lang.Comparable, Template

public class MethodTemplate
extends ContentTemplate
implements java.lang.Comparable

Template for creating a Method in a class

Version:
0.10 [05-09-2002]
Author:
dennis@brains2b.nl
See Also:
ClassTemplate.createMethod(int, String, String, String[]), ClassTemplate.createMethod(int, String, String, String[][]), ClassTemplate.createMethod(String, String, String[]), ClassTemplate.createMethod(String, String[]), ClassTemplate.createConstructor(String[]), ClassTemplate.createConstructor(String[][])

Field Summary
 
Fields inherited from class org.brains2b.typewriter.ContentTemplate
m_content
 
Constructor Summary
MethodTemplate(ClassTemplate parent, int modifiers, java.lang.String name, java.lang.String returnType, java.lang.String[] params)
          Constructor
MethodTemplate(ClassTemplate parent, int modifiers, java.lang.String name, java.lang.String returnType, java.lang.String[][] params)
          Constructor
 
Method Summary
 void addException(java.lang.String exName)
          add a throws clause to the method
 int compareTo(java.lang.Object o)
          compare this object to another MethodTemplate Compares on the following properties Modifiers, public goes for protected goes for private Name of the method Number of arguments to this method, smaller number before larger
 java.lang.String getName()
          get the name of this method
 void invokeMethod(java.lang.String instance, java.lang.String methodName, java.lang.Object value)
          invoke a method from another instance of an object TODO This method needs to change
 void invokeMethod(java.lang.String instance, java.lang.String methodName, java.lang.Object[] args)
          invoke a method from another instance of an object TODO implementation needs to change to only use Strings if explicitly defined as Literal
 boolean isConstructor()
          check if this method is a constrcutor instead of a method
 void setConstructor(boolean b)
          set this Methodtemplate to be a constructor instead of a normal method
 void write(java.io.PrintWriter pw, int indent)
          overwrite this to implement a content types specific needs and call super.write(PrintWriter,int) to write out the content for this method.
 
Methods inherited from class org.brains2b.typewriter.ContentTemplate
addImport, addText, createFor, createIf, createTry, createWhile, getContent, getObjectName, getParent, makeInstance, makeInstance, makeInstance, makeInstance, makeInstance, setContent, setParent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MethodTemplate

public MethodTemplate(ClassTemplate parent,
                      int modifiers,
                      java.lang.String name,
                      java.lang.String returnType,
                      java.lang.String[] params)
Constructor

This constructor will use number "arg" arguments as parameter names, i.e. arg0, arg1

Parameters:
parent - ClassTemplate, the parent which contains this element
modifiers - int, sum of Modifier constants which define the access to this method
name - String, name of the method
returnType - String, representation of the return type of this method i.e. "int", "String"

If null and this method is not defined as setConstructor(boolean) void will be used

params - String[], String representation of parameter types for this method ie. {"int","String"}
See Also:
setConstructor(boolean)

MethodTemplate

public MethodTemplate(ClassTemplate parent,
                      int modifiers,
                      java.lang.String name,
                      java.lang.String returnType,
                      java.lang.String[][] params)
Constructor

Parameters:
parent - ClassTemplate, the parent which contains this element
modifiers - int, sum of Modifier constants which define the access to this method
name - String, name of the method
returnType - String, representation of the return type of this method i.e. "int", "String"

If null and this method is not defined as setConstructor(boolean) void will be used

params - String[][], String representation of parameter types and parameter names for this method ie. {{"int","String"},{"id","name"}}
See Also:
setConstructor(boolean)
Method Detail

addException

public void addException(java.lang.String exName)
add a throws clause to the method

Call this for every Exception this method can throw

Parameters:
exName - String, qualified name of the Exception

invokeMethod

public void invokeMethod(java.lang.String instance,
                         java.lang.String methodName,
                         java.lang.Object value)
invoke a method from another instance of an object TODO This method needs to change

Parameters:
instance - String, instance of an object
methodName - String, the method to be called from the instance
value - Object, a String or a Literal object

invokeMethod

public void invokeMethod(java.lang.String instance,
                         java.lang.String methodName,
                         java.lang.Object[] args)
invoke a method from another instance of an object TODO implementation needs to change to only use Strings if explicitly defined as Literal

Parameters:
instance - String, instance of an object
methodName - String, the method to be called from the instance
args - Object[], list of arguments to pass to the the method

write

public void write(java.io.PrintWriter pw,
                  int indent)
Description copied from class: ContentTemplate
overwrite this to implement a content types specific needs and call super.write(PrintWriter,int) to write out the content for this method.

Specified by:
write in interface Template
Overrides:
write in class ContentTemplate
See Also:
Template.write(java.io.PrintWriter, int)

isConstructor

public boolean isConstructor()
check if this method is a constrcutor instead of a method

Returns:
boolean, true if this MethodTemplate contains a constructor, false otherwise

setConstructor

public void setConstructor(boolean b)
set this Methodtemplate to be a constructor instead of a normal method

Parameters:
b - boolean, true if this is a constructor, false otherwise

getName

public java.lang.String getName()
get the name of this method

Returns:
String

compareTo

public int compareTo(java.lang.Object o)
compare this object to another MethodTemplate