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.11 [27-05-2005]
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 This constructor will use number "arg" arguments as parameter names, i.e. arg0, arg1
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 Call this for every Exception this method can throw
 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
 java.lang.String getReturnType()
          get the return type of this method
 void invokeMethod(java.lang.String instance, java.lang.String methodName, java.lang.Object arg)
          invoke a method from another instance of an object
 void invokeMethod(java.lang.String instance, java.lang.String methodName, java.lang.Object[] args)
          invoke a method from an instance of an object
 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 setModifiers(int modifiers)
          set the modifiers for this method
 void setName(java.lang.String name)
          get the name of this method
 void setReturnType(java.lang.String returnType)
          set the return type of this 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, getParent, 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 arg)
invoke a method from another instance of an object

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

invokeMethod

public void invokeMethod(java.lang.String instance,
                         java.lang.String methodName,
                         java.lang.Object[] args)
invoke a method from an instance of an object

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)
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

setName

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

Parameters:
name - String, the name of the method
Since:
TypeWriter 0.21

compareTo

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

setModifiers

public void setModifiers(int modifiers)
set the modifiers for this method

Parameters:
modifiers - The modifier to set.
See Also:
Modifier

getReturnType

public java.lang.String getReturnType()
get the return type of this method

Returns:
String the String representation of this return type

setReturnType

public void setReturnType(java.lang.String returnType)
set the return type of this method

Parameters:
returnType - String a representation of the return type to set.