01: /*
02: * JavaVariable.java
03: *
04: * Copyright (C) 2002 Peter Graves
05: * $Id: JavaVariable.java,v 1.1.1.1 2002/09/24 16:08:09 piso Exp $
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License
09: * as published by the Free Software Foundation; either version 2
10: * of the License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public License
18: * along with this program; if not, write to the Free Software
19: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20: */
21:
22: package org.armedbear.j;
23:
24: import java.util.StringTokenizer;
25:
26: public final class JavaVariable {
27: // what
28: public static final int FIELD = 1;
29: public static final int PARAMETER = 2;
30: public static final int LOCAL = 3;
31:
32: private final String type;
33: private final String name;
34: private final int what;
35:
36: public JavaVariable(String s, int what) {
37: StringTokenizer st = new StringTokenizer(s);
38: FastStringBuffer sb = new FastStringBuffer();
39: while (st.hasMoreTokens()) {
40: sb.append(st.nextToken());
41: sb.append(' ');
42: }
43: s = sb.toString();
44: int length = s.length();
45: for (int i = length - 1; i >= 0; i--) {
46: if (" \t=;,".indexOf(s.charAt(i)) >= 0)
47: --length;
48: else
49: break;
50: }
51: s = s.substring(0, length);
52: int index = s.lastIndexOf(' ');
53: if (index < 0)
54: index = s.lastIndexOf('\t');
55: if (index >= 0) {
56: type = s.substring(0, index);
57: name = s.substring(index + 1).trim();
58: } else {
59: type = "";
60: name = s;
61: }
62: this .what = what;
63: }
64:
65: public final String getName() {
66: return name;
67: }
68:
69: public String toString() {
70: FastStringBuffer sb = new FastStringBuffer(type);
71: sb.append(' ');
72: sb.append(name);
73: sb.append(" (");
74: switch (what) {
75: case FIELD:
76: sb.append("field");
77: break;
78: case PARAMETER:
79: sb.append("parameter");
80: break;
81: case LOCAL:
82: sb.append("local variable");
83: break;
84: }
85: sb.append(")");
86: return sb.toString();
87: }
88: }
|