package rmi.rmiSynth.lex;
public class LexMethod extends LexStructure {
private StringVector throwsEx; private LexParam[] params; private LexBody body;
public LexMethod() {
params = new LexParam[0];
body = new LexBody();
throwsEx = new StringVector();
}
public LexParam[] getParams() {
return params;
}
public void setParams(LexParam[] _params) {
params = _params;
}
public LexParam getParam(int i) {
return params[i];
}
public LexBody getBody() {
return body;
}
public void setBody(LexBody _body) {
body = _body;
}
public void addThrow(String exName) {
throwsEx.add(exName);
}
public boolean ifThrows() {
return throwsEx.size() > 0 ? true : false;
}
public String toString(boolean forClass, boolean forMain) {
String s = "";
boolean withType = true;
boolean withoutType = false;
s = s + "\t" + getHeader();
s = s + "(";
s = s + paramsToString(withType);
s = s + ")";
s = s + (ifThrows() ? " throws " + throwsEx.toCSV() : "");
if (forClass) { s = s + "{\n";
s = s + "\t\t";
if (forMain) {
s = s + getBody().codeToString();
} else {
s = s + getBody().toString();
s = s + "(";
s = s + paramsToString(withoutType);
s = s + ");";
}
s = s + "\n";
s = s + "\t}\n";
} else { s = s + ";";
}
s = s + "\n";
return s;
}
public String paramsToString(boolean withType) {
String s = "";
for (int i = 0; i < params.length; i++) {
s = s + " " + params[i].toString(withType) + ",";
}
s = s.substring(0, Math.max(s.length() - 1, 0));
return s;
}
}