KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ca > mcgill > sable > soot > attributes > SootAttribute


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 package ca.mcgill.sable.soot.attributes;
21
22 import java.util.*;
23
24
25 public class SootAttribute {
26
27     private int javaEndLn;
28     private int javaStartLn;
29     private int jimpleEndLn;
30     private int jimpleStartLn;
31     private int jimpleStartPos;
32     private int jimpleEndPos;
33     private int javaStartPos;
34     private int javaEndPos;
35
36     private ArrayList colorList;
37     private ArrayList textList;
38
39     private ArrayList linkList;
40     
41     private int jimpleLength;
42     private int javaLength;
43     
44
45     public ArrayList getAnalysisTypes(){
46         ArrayList types = new ArrayList();
47         if (getTextList() != null){
48             Iterator it = getTextList().iterator();
49             while (it.hasNext()){
50                 TextAttribute ta = (TextAttribute)it.next();
51                 if (!types.contains(ta.getType())){
52                     types.add(ta.getType());
53                 }
54             }
55         }
56         if (getLinkList() != null){
57             Iterator lit = getLinkList().iterator();
58             while (lit.hasNext()){
59                 LinkAttribute la = (LinkAttribute)lit.next();
60                 if (!types.contains(la.getType())){
61                     types.add(la.getType());
62                 }
63             }
64         }
65         
66         if (getColorList() != null){
67             Iterator cit = getColorList().iterator();
68             while (cit.hasNext()){
69                 ColorAttribute ca = (ColorAttribute)cit.next();
70                 if (!types.contains(ca.type())){
71                     types.add(ca.type());
72                 }
73             }
74         }
75         return types;
76     }
77     
78     public void addColorAttr(ColorAttribute color){
79         if (getColorList() == null){
80             setColorList(new ArrayList());
81         }
82         getColorList().add(color);
83         
84     }
85     
86     private static final String JavaDoc NEWLINE = "\n";
87     
88     public void addLinkAttr(LinkAttribute link){
89         if (getLinkList() == null){
90             setLinkList(new ArrayList());
91         }
92         getLinkList().add(link);
93         TextAttribute ta = new TextAttribute();
94         ta.setInfo(link.getLabel());
95         ta.setType(link.getType());
96         addTextAttr(ta);
97     }
98     
99     public ArrayList getAllLinkAttrs(){
100         return getLinkList();
101     }
102
103     public void addTextAttr(TextAttribute text){
104         if (getTextList() == null){
105             setTextList(new ArrayList());
106         }
107         text.setInfo(formatText(text.getInfo()));
108         getTextList().add(text);
109     }
110     
111     public String JavaDoc formatText(String JavaDoc text){
112         text = text.replaceAll("&lt;", "<");
113         text = text.replaceAll("&gt;", ">");
114         text = text.replaceAll("&amp;", "&");
115         return text;
116     }
117     
118     public StringBuffer JavaDoc getAllTextAttrs(String JavaDoc lineSep){
119         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
120         if (getTextList() != null){
121             Iterator it = getTextList().iterator();
122             while (it.hasNext()){
123                 TextAttribute ta = (TextAttribute)it.next();
124                 String JavaDoc next = ta.getInfo();
125                 if (lineSep.equals("<br>")){
126                     // implies java tooltip
127
next = convertHTMLTags(next);
128                 }
129                 sb.append(next);
130                 sb.append(lineSep);
131             }
132         }
133         return sb;
134     }
135     
136     public StringBuffer JavaDoc getTextAttrsForType(String JavaDoc lineSep, String JavaDoc type){
137         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
138         
139         if (getTextList() != null){
140             Iterator it = getTextList().iterator();
141             while (it.hasNext()){
142                 TextAttribute ta = (TextAttribute)it.next();
143                 if (ta.getType().equals(type)){
144                     String JavaDoc next = ta.getInfo();
145                     if (lineSep.equals("<br>")){
146                         // implies java tooltip
147
next = convertHTMLTags(next);
148                     }
149                     sb.append(next);
150                     sb.append(lineSep);
151                 }
152             }
153         }
154         return sb;
155     }
156     
157     public String JavaDoc convertHTMLTags(String JavaDoc next){
158         if (next == null) return null;
159         else {
160             next = next.replaceAll("<", "&lt;");
161             next = next.replaceAll(">", "&gt;");
162             return next;
163         }
164     }
165     
166
167     // these two are maybe not accurate maybe
168
// need to check if ln in question is between
169
// the start and end ln's
170
public boolean attrForJimpleLn(int jimple_ln) {
171         if (getJimpleStartLn() == jimple_ln) return true;
172         else return false;
173     }
174     
175     public boolean attrForJavaLn(int java_ln) {
176         if (getJavaStartLn() == java_ln) return true;
177         else return false;
178     }
179     
180     public SootAttribute() {
181     }
182     
183     
184
185     /**
186      * @return
187      */

188     public int getJimpleEndPos() {
189         return jimpleEndPos;
190     }
191
192     /**
193      * @return
194      */

195     public int getJimpleStartPos() {
196         return jimpleStartPos;
197     }
198
199
200     /**
201      * @param i
202      */

203     public void setJimpleEndPos(int i) {
204         jimpleEndPos = i;
205     }
206
207     /**
208      * @param i
209      */

210     public void setJimpleStartPos(int i) {
211         jimpleStartPos = i;
212     }
213
214     /**
215      * @return
216      */

217     public ArrayList getTextList() {
218         return textList;
219     }
220
221     /**
222      * @param list
223      */

224     public void setTextList(ArrayList list) {
225         textList = list;
226     }
227
228
229
230     /**
231      * @return
232      */

233     public ArrayList getLinkList() {
234         return linkList;
235     }
236
237     /**
238      * @param list
239      */

240     public void setLinkList(ArrayList list) {
241         linkList = list;
242     }
243
244     /**
245      * @return
246      */

247     public int getJavaEndPos() {
248         return javaEndPos;
249     }
250
251     /**
252      * @return
253      */

254     public int getJavaStartPos() {
255         return javaStartPos;
256     }
257
258     /**
259      * @param i
260      */

261     public void setJavaEndPos(int i) {
262         javaEndPos = i;
263     }
264
265     /**
266      * @param i
267      */

268     public void setJavaStartPos(int i) {
269         javaStartPos = i;
270     }
271
272
273
274     /**
275      * @return
276      */

277     public int getJavaEndLn() {
278         return javaEndLn;
279     }
280
281     /**
282      * @return
283      */

284     public int getJavaStartLn() {
285         return javaStartLn;
286     }
287
288     /**
289      * @return
290      */

291     public int getJimpleEndLn() {
292         return jimpleEndLn;
293     }
294
295     /**
296      * @return
297      */

298     public int getJimpleStartLn() {
299         return jimpleStartLn;
300     }
301
302     /**
303      * @param i
304      */

305     public void setJavaEndLn(int i) {
306         javaEndLn = i;
307     }
308
309     /**
310      * @param i
311      */

312     public void setJavaStartLn(int i) {
313         javaStartLn = i;
314     }
315
316     /**
317      * @param i
318      */

319     public void setJimpleEndLn(int i) {
320         jimpleEndLn = i;
321     }
322
323     /**
324      * @param i
325      */

326     public void setJimpleStartLn(int i) {
327         jimpleStartLn = i;
328     }
329
330
331     /**
332      * @return
333      */

334     public int getJavaLength() {
335         return javaLength;
336     }
337
338     /**
339      * @return
340      */

341     public int getJimpleLength() {
342         return jimpleLength;
343     }
344
345     /**
346      * @param i
347      */

348     public void setJavaLength(int i) {
349         javaLength = i;
350     }
351
352     /**
353      * @param i
354      */

355     public void setJimpleLength(int i) {
356         jimpleLength = i;
357     }
358
359     /**
360      * @return
361      */

362     public ArrayList getColorList() {
363         return colorList;
364     }
365
366     /**
367      * @param list
368      */

369     public void setColorList(ArrayList list) {
370         colorList = list;
371     }
372
373 }
374
Popular Tags