public class MethodTemplate extends ContentTemplate implements java.lang.Comparable
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[][])m_content| Constructor and Description |
|---|
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
|
| Modifier and Type | Method and Description |
|---|---|
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
|
JavaDocTemplate |
createJavadoc()
create an empty javadoc template for this method
|
JavaDocTemplate |
generateJavadoc()
create an javadoc and generates default entries for params, exceptions and return
|
java.util.ArrayList |
getExceptions() |
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. |
addImport, addText, createFor, createIf, createTry, createTry, createWhile, getContent, getParent, makeInstance, makeInstance, makeInstance, setContent, setParentpublic MethodTemplate(ClassTemplate parent, int modifiers, java.lang.String name, java.lang.String returnType, java.lang.String[] params)
This constructor will use number "arg" arguments as parameter names, i.e. arg0, arg1
parent - ClassTemplate, the parent which contains this elementmodifiers - int, sum of Modifier constants which define the access to this methodname - String, name of the methodreturnType - 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"}setConstructor(boolean)public MethodTemplate(ClassTemplate parent, int modifiers, java.lang.String name, java.lang.String returnType, java.lang.String[][] params)
parent - ClassTemplate, the parent which contains this elementmodifiers - int, sum of Modifier constants which define the access to this methodname - String, name of the methodreturnType - 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"}}setConstructor(boolean)public void addException(java.lang.String exName)
Call this for every Exception this method can throw
exName - String, qualified name of the Exceptionpublic void invokeMethod(java.lang.String instance,
java.lang.String methodName,
java.lang.Object arg)
instance - String, instance of an objectmethodName - String, the method to be called from the instancearg - Object, a String or a Literal object to pass as parameter to
the methodpublic void invokeMethod(java.lang.String instance,
java.lang.String methodName,
java.lang.Object[] args)
instance - String, instance of an objectmethodName - String, the method to be called from the instanceargs - Object[], list of arguments to pass to the the methodpublic void write(java.io.PrintWriter pw,
int indent)
super.write(PrintWriter,int) to write out
the content for this method.write in interface Templatewrite in class ContentTemplatepw - PrintWriter, an initialized PrintWriter to write this
element of the Class toindent - int, the indention for this element.
Value is multiplied by four to give the number of spaces used for indention
Template.write(java.io.PrintWriter, int)public boolean isConstructor()
public void setConstructor(boolean b)
b - boolean, true if this is a constructor, false otherwisepublic java.lang.String getName()
public void setName(java.lang.String name)
name - String, the name of the methodpublic int compareTo(java.lang.Object o)
compareTo in interface java.lang.ComparableComparable.compareTo(Object)public void setModifiers(int modifiers)
modifiers - The modifier to set.Modifierpublic java.lang.String getReturnType()
public void setReturnType(java.lang.String returnType)
returnType - String a representation of the return type to set.public JavaDocTemplate createJavadoc()
generateJavadoc()public JavaDocTemplate generateJavadoc()
public java.util.ArrayList getExceptions()