Show JavaMethod.java syntax highlighted
package ca.ucalgary.cpsc.ebe.fitClipse.FixtureGenerater;
import java.util.LinkedList;
public class JavaMethod extends JavaClassChild{
private LinkedList parameters;
private LinkedList throwableExceptions = null;
private String returnType = "void";
private LinkedList content;
public void addParameter(String name, String type){
if(this.parameters == null)
this.parameters = new LinkedList();
this.parameters.add(new JavaMethodParameter(name, type));
}
public void addContentNode(JavaMethodContent node){
if(this.content == null)
this.content = new LinkedList();
this.content.add(node);
}
public void addParameter(JavaMethodParameter param){
if(this.parameters == null)
this.parameters = new LinkedList();
this.parameters.add(param);
}
public JavaMethod(String name){
this.name = name;
}
public JavaMethod(String name, String access){
this.name = name;
this.access = access;
}
public String getIdentifier() {
StringBuffer id = new StringBuffer();
if(this.parameters != null)
id.append(this.name).append("-").append(this.parameters.size());
else
id.append(this.name).append("-").append("0");
return id.toString();
}
private String renderParameters(){
StringBuffer params = new StringBuffer();
if(this.parameters == null)
return "";
for(int i = 0; i < parameters.size(); i++){
if(i != 0)
params.append(", ");
params.append(((JavaMethodParameter)parameters.get(i)).render());
}
return params.toString();
}
private String renderContent(){
StringBuffer content = new StringBuffer();
if (this.content == null)
return "";
content.append("\t\t");
for(int i = 0; i < this.content.size(); i++){
if(i != 0)
content.append(" ");
content.append(((JavaMethodContent)this.content.get(i)).render());
}
String result = content.toString().replace("\n", "\n\t\t");
return result;
}
public String render() {
StringBuffer methodSource = new StringBuffer();
methodSource.append(this.access).append(renderStaticAbstractIndicators());
methodSource.append(" ").append(this.returnType).append(" ").append(this.name).append("(");
methodSource.append(renderParameters());
methodSource.append(")" + renderThrowableExceptions() + "{\n");
methodSource.append(this.renderContent());
methodSource.append("\n\t}\n");
return methodSource.toString();
}
public void addThrowableException(String exception){
if(this.throwableExceptions == null)
this.throwableExceptions = new LinkedList();
this.throwableExceptions.add(exception);
}
private String renderThrowableExceptions(){
StringBuffer exceptions = new StringBuffer();
if(throwableExceptions == null)
return "";
exceptions.append(" throws");
for(int i = 0; i < this.throwableExceptions.size(); i++){
exceptions.append(" " + this.throwableExceptions.get(i).toString());
}
return exceptions.toString();
}
public String getReturnType() {
return returnType;
}
public void setReturnType(String returnType) {
this.returnType = returnType;
}
}
See more files for this project here