KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jode > type > MethodType


1 /* MethodType Copyright (C) 1998-2002 Jochen Hoenicke.
2  *
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2, or (at your option)
6  * any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; see the file COPYING. If not, write to
15  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
16  *
17  * $Id: MethodType.java,v 4.9.4.1 2002/05/28 17:34:22 hoenicke Exp $
18  */

19
20 package jode.type;
21
22 /**
23  * This type represents an method type.
24  *
25  * @author Jochen Hoenicke
26  */

27 public class MethodType extends Type {
28     final String JavaDoc signature;
29     final Type[] parameterTypes;
30     final Type returnType;
31
32     public MethodType(String JavaDoc signature) {
33     super(TC_METHOD);
34         this.signature = signature;
35         int index = 1, types = 0;
36         while (signature.charAt(index) != ')') {
37             types++;
38             while (signature.charAt(index) == '[')
39                 index++;
40             if (signature.charAt(index) == 'L')
41                 index = signature.indexOf(';', index);
42             index++;
43         }
44         parameterTypes = new Type[types];
45
46         index = 1;
47         types = 0;
48         while (signature.charAt(index) != ')') {
49             int lastindex = index;
50             while (signature.charAt(index) == '[')
51                 index++;
52             if (signature.charAt(index) == 'L')
53                 index = signature.indexOf(';', index);
54             index++;
55             parameterTypes[types++]
56                 = Type.tType(signature.substring(lastindex,index));
57         }
58         returnType = Type.tType(signature.substring(index+1));
59     }
60
61     public final int stackSize() {
62     int size = returnType.stackSize();
63     for (int i=0; i<parameterTypes.length; i++)
64         size -= parameterTypes[i].stackSize();
65     return size;
66     }
67
68     public Type[] getParameterTypes() {
69         return parameterTypes;
70     }
71
72     public Class JavaDoc[] getParameterClasses() throws ClassNotFoundException JavaDoc {
73     Class JavaDoc[] paramClasses = new Class JavaDoc[parameterTypes.length];
74     for (int i = paramClasses.length; --i >= 0; )
75         paramClasses[i] = parameterTypes[i].getTypeClass();
76         return paramClasses;
77     }
78
79     public Type getReturnType() {
80         return returnType;
81     }
82
83     public Class JavaDoc getReturnClass() throws ClassNotFoundException JavaDoc {
84     return returnType.getTypeClass();
85     }
86
87     public String JavaDoc getTypeSignature() {
88         return signature;
89     }
90
91     public String JavaDoc toString() {
92         return signature;
93     }
94
95     public boolean equals(Object JavaDoc o) {
96         MethodType mt;
97         return (o instanceof MethodType
98                 && signature.equals((mt = (MethodType)o).signature));
99     }
100 }
101
Popular Tags