KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ca > mcgill > sable > soot > editors > parser > JimpleField


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

19
20
21 package ca.mcgill.sable.soot.editors.parser;
22
23 import java.util.*;
24
25 import ca.mcgill.sable.soot.editors.JimpleOutlineObject;
26
27 public class JimpleField {
28
29     private String JavaDoc val;
30     private String JavaDoc label;
31     private String JavaDoc type;
32     private ArrayList modifiers;
33     private int imageType;
34     
35     public JimpleField(String JavaDoc val){
36         setVal(val);
37     }
38     
39     public void parseField(){
40         StringTokenizer st = new StringTokenizer(getVal());
41         int numTokens = st.countTokens();
42         int counter = 1;
43         String JavaDoc tempType = "";
44         while (st.hasMoreTokens()){
45             String JavaDoc next = st.nextToken();
46             if (JimpleModifier.isModifier(next)) {
47                 if (getModifiers() == null){
48                     setModifiers(new ArrayList());
49                 }
50                 getModifiers().add(next);
51             }
52             if (!JimpleModifier.isModifier(next) && (counter != numTokens)){
53                 tempType = tempType + next;
54             }
55             if (counter == numTokens){
56                 setType(tempType);
57                 setLabel(next.substring(0, next.indexOf(";"))+" : "+getType());
58             }
59             counter++;
60         }
61     }
62     
63     public void findImageType(){
64         if (getModifiers() == null){
65             setImageType(JimpleOutlineObject.NONE_FIELD);
66             return;
67         }
68         if (getModifiers().contains("public")) {
69             setImageType(JimpleOutlineObject.PUBLIC_FIELD);
70         }
71         else if (getModifiers().contains("protected")) {
72             setImageType(JimpleOutlineObject.PROTECTED_FIELD);
73         }
74         else if (getModifiers().contains("private")) {
75             setImageType(JimpleOutlineObject.PRIVATE_FIELD);
76         }
77         else {
78             setImageType(JimpleOutlineObject.NONE_FIELD);
79         }
80     }
81     
82     public BitSet findDecorators() {
83         BitSet bits = new BitSet();
84         if (getModifiers() == null) return bits;
85         if (getModifiers().contains("abstract")){
86             bits.set(JimpleOutlineObject.ABSTRACT_DEC);
87         }
88         if (getModifiers().contains("final")){
89             bits.set(JimpleOutlineObject.FINAL_DEC);
90         }
91         if (getModifiers().contains("static")){
92             bits.set(JimpleOutlineObject.STATIC_DEC);
93         }
94         if (getModifiers().contains("synchronized")){
95             bits.set(JimpleOutlineObject.SYNCHRONIZED_DEC);
96         }
97         return bits;
98     }
99     
100     public static boolean isField(String JavaDoc val){
101         
102         if ((val.indexOf("(") != -1) || (val.indexOf(")") != -1)) return false;
103         if (val.indexOf(";") == -1) return false;
104         return true;
105     }
106     /**
107      * @return
108      */

109     public String JavaDoc getLabel() {
110         return label;
111     }
112
113     /**
114      * @return
115      */

116     public ArrayList getModifiers() {
117         return modifiers;
118     }
119
120     /**
121      * @return
122      */

123     public String JavaDoc getVal() {
124         return val;
125     }
126
127     /**
128      * @param string
129      */

130     public void setLabel(String JavaDoc string) {
131         label = string;
132     }
133
134     /**
135      * @param list
136      */

137     public void setModifiers(ArrayList list) {
138         modifiers = list;
139     }
140
141     /**
142      * @param string
143      */

144     public void setVal(String JavaDoc string) {
145         val = string;
146     }
147
148     /**
149      * @return
150      */

151     public String JavaDoc getType() {
152         return type;
153     }
154
155     /**
156      * @param string
157      */

158     public void setType(String JavaDoc string) {
159         type = string;
160     }
161
162     /**
163      * @return
164      */

165     public int getImageType() {
166         return imageType;
167     }
168
169     /**
170      * @param i
171      */

172     public void setImageType(int i) {
173         imageType = i;
174     }
175
176 }
177
Popular Tags