KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > filter > SignatureUtil


1 /*
2  * FindBugs - Find Bugs in Java programs
3  * Copyright (C) 2006, University of Maryland
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19
20 package edu.umd.cs.findbugs.filter;
21
22 import java.util.StringTokenizer JavaDoc;
23
24 /**
25  * @author rak
26  */

27 public class SignatureUtil {
28
29     public static String JavaDoc createMethodSignature(String JavaDoc params, String JavaDoc returns) {
30         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
31     
32         buf.append('(');
33         StringTokenizer JavaDoc tok = new StringTokenizer JavaDoc(params, " \t\n\r\f,");
34         while (tok.hasMoreTokens()) {
35             String JavaDoc param = typeToSignature(tok.nextToken());
36             buf.append(param);
37         }
38         buf.append(')');
39         buf.append(typeToSignature(returns));
40     
41         return buf.toString();
42     }
43     
44     public static String JavaDoc createFieldSignature(String JavaDoc type) {
45         return typeToSignature(type);
46     }
47
48     private static String JavaDoc typeToSignature(String JavaDoc type) {
49         if(type.endsWith("[]")) {
50             return "[" + typeToSignature(type.substring(0, type.length() - 2));
51         } else {
52             return scalarTypeToSiganture(type);
53         }
54     }
55
56     private static String JavaDoc scalarTypeToSiganture(String JavaDoc type) {
57         if (type.equals("boolean"))
58             return "Z";
59         else if (type.equals("byte"))
60             return "B";
61         else if (type.equals("char"))
62             return "C";
63         else if (type.equals("short"))
64             return "S";
65         else if (type.equals("int"))
66             return "I";
67         else if (type.equals("long"))
68             return "J";
69         else if (type.equals("float"))
70             return "F";
71         else if (type.equals("double"))
72             return "D";
73         else if (type.equals("void"))
74             return "V";
75         else
76             return "L" + type.replace('.', '/') + ";";
77     }
78 }
79
Popular Tags