01: package org.incava.java;
02:
03: import java.util.*;
04: import net.sourceforge.pmd.ast.*;
05: import org.incava.lang.StringExt;
06:
07: /**
08: * Miscellaneous routines for functions (ctors and methods).
09: */
10: public class FunctionUtil extends SimpleNodeUtil {
11: /**
12: * Returns the throws token, or null if none.
13: */
14: public static Token getThrows(SimpleNode function) {
15: Token tk = function.getFirstToken();
16: while (true) {
17: if (tk.kind == JavaParserConstants.THROWS) {
18: return tk;
19: } else if (tk == function.getLastToken()) {
20: break;
21: } else {
22: tk = tk.next;
23: }
24: }
25: return null;
26: }
27:
28: /**
29: * Returns the throws list, or null if none.
30: */
31: public static ASTNameList getThrowsList(SimpleNode function) {
32: List children = getChildren(function);
33: Iterator it = children.iterator();
34: while (it.hasNext()) {
35: Object obj = it.next();
36: if (obj instanceof Token
37: && ((Token) obj).kind == JavaParserConstants.THROWS
38: && it.hasNext()) {
39: ASTNameList throwsList = (ASTNameList) it.next();
40: return throwsList;
41: }
42: }
43: return null;
44: }
45:
46: protected static String toFullName(Token tk,
47: ASTFormalParameters params) {
48: List types = ParameterUtil.getParameterTypes(params);
49: String args = StringExt.join(types, ", ");
50: return tk.image + "(" + args + ")";
51: }
52:
53: }
|