KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > incava > java > FunctionUtil


1 package org.incava.java;
2
3 import java.util.*;
4 import net.sourceforge.pmd.ast.*;
5 import org.incava.lang.StringExt;
6
7
8 /**
9  * Miscellaneous routines for functions (ctors and methods).
10  */

11 public class FunctionUtil extends SimpleNodeUtil
12 {
13     /**
14      * Returns the throws token, or null if none.
15      */

16     public static Token getThrows(SimpleNode function)
17     {
18         Token tk = function.getFirstToken();
19         while (true) {
20             if (tk.kind == JavaParserConstants.THROWS) {
21                 return tk;
22             }
23             else if (tk == function.getLastToken()) {
24                 break;
25             }
26             else {
27                 tk = tk.next;
28             }
29         }
30         return null;
31     }
32
33     /**
34      * Returns the throws list, or null if none.
35      */

36     public static ASTNameList getThrowsList(SimpleNode function)
37     {
38         List children = getChildren(function);
39         Iterator it = children.iterator();
40         while (it.hasNext()) {
41             Object JavaDoc obj = it.next();
42             if (obj instanceof Token && ((Token)obj).kind == JavaParserConstants.THROWS && it.hasNext()) {
43                 ASTNameList throwsList = (ASTNameList)it.next();
44                 return throwsList;
45             }
46         }
47         return null;
48     }
49
50     protected static String JavaDoc toFullName(Token tk, ASTFormalParameters params)
51     {
52         List types = ParameterUtil.getParameterTypes(params);
53         String JavaDoc args = StringExt.join(types, ", ");
54         return tk.image + "(" + args + ")";
55     }
56     
57 }
58
Popular Tags