01: package net.sourceforge.jaxor.parser;
02:
03: import com.thoughtworks.qdox.model.JavaClass;
04: import com.thoughtworks.qdox.model.JavaMethod;
05: import com.thoughtworks.qdox.model.JavaParameter;
06: import com.thoughtworks.qdox.model.Type;
07:
08: import java.util.ArrayList;
09: import java.util.List;
10:
11: /*
12: * User: Mike
13: * Date: Aug 12, 2003
14: * Time: 10:29:39 PM
15: */
16:
17: public class SourceClass {
18: private final JavaClass _class;
19:
20: public SourceClass(JavaClass aClass) {
21: _class = aClass;
22: }
23:
24: public List getImplMethods() {
25: List _methods = new ArrayList();
26: JavaMethod[] methods = _class.getMethods();
27: for (int i = 0; i < methods.length; i++) {
28: JavaMethod method = methods[i];
29: if (method.isPublic() && !method.isConstructor()
30: && !method.isStatic()) {
31: String value = "public ";
32: value += getType(method.getReturns()) + " ";
33: value += method.getName() + "(";
34: JavaParameter[] params = method.getParameters();
35: for (int j = 0; j < params.length; j++) {
36: JavaParameter param = params[j];
37: if (j > 0)
38: value += ",";
39: value += getType(param.getType()) + " "
40: + param.getName();
41: }
42: value += ")";
43: value += getExceptions(method.getExceptions());
44: value += ";";
45: _methods.add(value);
46: }
47: }
48: return _methods;
49: }
50:
51: private String getType(Type t) {
52: if (!t.isArray())
53: return t.getValue();
54: return t.getValue() + "[]";
55: }
56:
57: private String getExceptions(Type[] types) {
58: String exc = "";
59: if (types.length == 0)
60: return exc;
61: exc += "throws ";
62: for (int i = 0; i < types.length; i++) {
63: Type type = types[i];
64: if (i > 0)
65: exc += ", ";
66: exc += getType(type);
67: }
68: return exc;
69: }
70: }
|