001: /* Soot - a J*va Optimization Framework
002: * Copyright (C) 2003 Jennifer Lhotak
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the
016: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
017: * Boston, MA 02111-1307, USA.
018: */
019:
020: package ca.mcgill.sable.soot.attributes;
021:
022: import java.util.*;
023:
024: public class SootAttributesHandler {
025:
026: private ArrayList attrList;
027: private String fileName;
028: private HashMap projList;
029: private long valuesSetTime;
030: private boolean update = true;
031: private ArrayList keyList;
032: private ArrayList typesToShow;
033: private boolean showAllTypes = true;
034:
035: private static final String NEWLINE = "\n\r";
036:
037: public SootAttributesHandler() {
038:
039: }
040:
041: public void setAttrList(ArrayList attrList) {
042: this .attrList = new ArrayList();
043: this .attrList.addAll(attrList);
044: }
045:
046: public String getJimpleAttributes(int lnNum) {
047: StringBuffer sb = new StringBuffer();
048: if (getAttrList() == null)
049: return sb.toString();
050: Iterator it = getAttrList().iterator();
051:
052: while (it.hasNext()) {
053: SootAttribute sa = (SootAttribute) it.next();
054: if (sa.attrForJimpleLn(lnNum)) {
055: if (showAllTypes) {
056: sb.append(sa.getAllTextAttrs("\n"));
057: } else {
058: Iterator typesIt = typesToShow.iterator();
059: while (typesIt.hasNext()) {
060: sb.append(sa.getTextAttrsForType("\n",
061: (String) typesIt.next()));
062: }
063:
064: }
065:
066: }
067: }
068: String result = sb.toString();
069: result = result.trim();
070: if (result.length() == 0)
071: return null;
072: return result;
073: }
074:
075: public ArrayList getJimpleLinks(int lnNum) {
076: Iterator it = getAttrList().iterator();
077: ArrayList list = new ArrayList();
078: while (it.hasNext()) {
079: SootAttribute sa = (SootAttribute) it.next();
080: if (sa.attrForJimpleLn(lnNum)) {
081: list = sa.getAllLinkAttrs();
082: }
083: }
084: return list;
085: }
086:
087: public String getJavaAttribute(int lnNum) {
088: StringBuffer sb = new StringBuffer();
089: if (getAttrList() == null)
090: return sb.toString();
091: Iterator it = getAttrList().iterator();
092: while (it.hasNext()) {
093: SootAttribute sa = (SootAttribute) it.next();
094: if (sa.attrForJavaLn(lnNum)) {
095: if (showAllTypes) {
096: sb.append(sa.getAllTextAttrs("<br>"));
097: } else {
098: Iterator typesIt = typesToShow.iterator();
099: while (typesIt.hasNext()) {
100: sb.append(sa.getTextAttrsForType("<br>",
101: (String) typesIt.next()));
102: }
103: }
104: }
105: }
106: return sb.toString();
107: }
108:
109: public ArrayList getJavaLinks(int lnNum) {
110: ArrayList list = new ArrayList();
111: if (getAttrList() == null)
112: return list;
113: Iterator it = getAttrList().iterator();
114: while (it.hasNext()) {
115: SootAttribute sa = (SootAttribute) it.next();
116: if (sa.attrForJavaLn(lnNum)) {
117: if (sa.getAllLinkAttrs() != null) {
118:
119: list.addAll(sa.getAllLinkAttrs());
120: }
121: }
122: }
123: return list;
124: }
125:
126: /**
127: * Returns the projList.
128: * @return HashMap
129: */
130: public HashMap getProjList() {
131: return projList;
132: }
133:
134: /**
135: * Sets the projList.
136: * @param projList The projList to set
137: */
138: public void setProjList(HashMap projList) {
139: this .projList = projList;
140: }
141:
142: /**
143: * Returns the attrList.
144: * @return Vector
145: */
146: public ArrayList getAttrList() {
147: return attrList;
148: }
149:
150: /**
151: * Returns the fileName.
152: * @return String
153: */
154: public String getFileName() {
155: return fileName;
156: }
157:
158: /**
159: * Sets the fileName.
160: * @param fileName The fileName to set
161: */
162: public void setFileName(String fileName) {
163: this .fileName = fileName;
164: }
165:
166: /**
167: * @return
168: */
169: public long getValuesSetTime() {
170: return valuesSetTime;
171: }
172:
173: /**
174: * @param l
175: */
176: public void setValuesSetTime(long l) {
177: valuesSetTime = l;
178: }
179:
180: /**
181: * @return
182: */
183: public boolean isUpdate() {
184: return update;
185: }
186:
187: /**
188: * @param b
189: */
190: public void setUpdate(boolean b) {
191: update = b;
192: }
193:
194: /**
195: * @return
196: */
197: public ArrayList getKeyList() {
198: if (keyList == null)
199: return keyList;
200: if (isShowAllTypes()) {
201: return keyList;
202: } else {
203: ArrayList typeList = new ArrayList();
204: Iterator kIt = keyList.iterator();
205: while (kIt.hasNext()) {
206: AnalysisKey key = (AnalysisKey) kIt.next();
207: if (getTypesToShow().contains(key.getType())) {
208: typeList.add(key);
209: }
210: }
211: return typeList;
212: }
213: }
214:
215: /**
216: * @param list
217: */
218: public void setKeyList(ArrayList list) {
219: keyList = list;
220: }
221:
222: /**
223: * @return
224: */
225: public ArrayList getTypesToShow() {
226: return typesToShow;
227: }
228:
229: /**
230: * @param list
231: */
232: public void setTypesToShow(ArrayList list) {
233: typesToShow = list;
234: }
235:
236: /**
237: * @return
238: */
239: public boolean isShowAllTypes() {
240: return showAllTypes;
241: }
242:
243: /**
244: * @param b
245: */
246: public void setShowAllTypes(boolean b) {
247: showAllTypes = b;
248: }
249:
250: }
|