KickJava   Java API By Example, From Geeks To Geeks.

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


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 public class SootAttributesHandler {
25
26     private ArrayList attrList;
27     private String JavaDoc fileName;
28     private HashMap projList;
29     private long valuesSetTime;
30     private boolean update = true;
31     private ArrayList keyList;
32     private ArrayList typesToShow;
33     private boolean showAllTypes = true;
34
35     private static final String JavaDoc NEWLINE = "\n\r";
36     
37     public SootAttributesHandler() {
38                 
39     }
40     
41     public void setAttrList(ArrayList attrList) {
42         this.attrList = new ArrayList();
43         this.attrList.addAll(attrList);
44     }
45
46     public String JavaDoc getJimpleAttributes(int lnNum) {
47         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
48         if (getAttrList() == null) return sb.toString();
49         Iterator it = getAttrList().iterator();
50         
51         while (it.hasNext()) {
52             SootAttribute sa = (SootAttribute)it.next();
53             if (sa.attrForJimpleLn(lnNum)) {
54                 if (showAllTypes){
55                     sb.append(sa.getAllTextAttrs("\n"));
56                 }
57                 else {
58                     Iterator typesIt = typesToShow.iterator();
59                     while (typesIt.hasNext()){
60                         sb.append(sa.getTextAttrsForType("\n", (String JavaDoc)typesIt.next()));
61                     }
62                     
63                 }
64                 
65             }
66         }
67         String JavaDoc result = sb.toString();
68         result = result.trim();
69         if (result.length() == 0 ) return null;
70         return result;
71     }
72     
73     public ArrayList getJimpleLinks(int lnNum){
74         Iterator it = getAttrList().iterator();
75         ArrayList list = new ArrayList();
76         while (it.hasNext()){
77             SootAttribute sa = (SootAttribute)it.next();
78             if (sa.attrForJimpleLn(lnNum)){
79                 list = sa.getAllLinkAttrs();
80             }
81         }
82         return list;
83     }
84     
85     public String JavaDoc getJavaAttribute(int lnNum) {
86         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
87         if (getAttrList() == null) return sb.toString();
88         Iterator it = getAttrList().iterator();
89         while (it.hasNext()) {
90             SootAttribute sa = (SootAttribute)it.next();
91             if (sa.attrForJavaLn(lnNum)) {
92                 if (showAllTypes){
93                     sb.append(sa.getAllTextAttrs("<br>"));
94                 }
95                 else {
96                     Iterator typesIt = typesToShow.iterator();
97                     while (typesIt.hasNext()){
98                         sb.append(sa.getTextAttrsForType("<br>", (String JavaDoc)typesIt.next()));
99                     }
100                 }
101             }
102         }
103         return sb.toString();
104     }
105
106     public ArrayList getJavaLinks(int lnNum){
107         ArrayList list = new ArrayList();
108         if (getAttrList() == null) return list;
109         Iterator it = getAttrList().iterator();
110         while (it.hasNext()){
111             SootAttribute sa = (SootAttribute)it.next();
112             if (sa.attrForJavaLn(lnNum)){
113                 if (sa.getAllLinkAttrs() != null){
114                 
115                     list.addAll(sa.getAllLinkAttrs());
116                 }
117             }
118         }
119         return list;
120     }
121
122
123     /**
124      * Returns the projList.
125      * @return HashMap
126      */

127     public HashMap getProjList() {
128         return projList;
129     }
130
131     /**
132      * Sets the projList.
133      * @param projList The projList to set
134      */

135     public void setProjList(HashMap projList) {
136         this.projList = projList;
137     }
138
139     /**
140      * Returns the attrList.
141      * @return Vector
142      */

143     public ArrayList getAttrList() {
144         return attrList;
145     }
146
147     /**
148      * Returns the fileName.
149      * @return String
150      */

151     public String JavaDoc getFileName() {
152         return fileName;
153     }
154
155     /**
156      * Sets the fileName.
157      * @param fileName The fileName to set
158      */

159     public void setFileName(String JavaDoc fileName) {
160         this.fileName = fileName;
161     }
162
163     /**
164      * @return
165      */

166     public long getValuesSetTime() {
167         return valuesSetTime;
168     }
169
170     /**
171      * @param l
172      */

173     public void setValuesSetTime(long l) {
174         valuesSetTime = l;
175     }
176
177     /**
178      * @return
179      */

180     public boolean isUpdate() {
181         return update;
182     }
183
184     /**
185      * @param b
186      */

187     public void setUpdate(boolean b) {
188         update = b;
189     }
190
191     /**
192      * @return
193      */

194     public ArrayList getKeyList() {
195         if (keyList == null) return keyList;
196         if (isShowAllTypes()){
197             return keyList;
198         }
199         else {
200             ArrayList typeList = new ArrayList();
201             Iterator kIt = keyList.iterator();
202             while (kIt.hasNext()){
203                 AnalysisKey key = (AnalysisKey)kIt.next();
204                 if (getTypesToShow().contains(key.getType())){
205                     typeList.add(key);
206                 }
207             }
208             return typeList;
209         }
210     }
211
212     /**
213      * @param list
214      */

215     public void setKeyList(ArrayList list) {
216         keyList = list;
217     }
218
219     /**
220      * @return
221      */

222     public ArrayList getTypesToShow() {
223         return typesToShow;
224     }
225
226     /**
227      * @param list
228      */

229     public void setTypesToShow(ArrayList list) {
230         typesToShow = list;
231     }
232
233     /**
234      * @return
235      */

236     public boolean isShowAllTypes() {
237         return showAllTypes;
238     }
239
240     /**
241      * @param b
242      */

243     public void setShowAllTypes(boolean b) {
244         showAllTypes = b;
245     }
246
247 }
248
Popular Tags