001: /* Soot - a J*va Optimization Framework
002: * Copyright (C) 2004 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: import org.eclipse.core.resources.*;
025: import org.eclipse.core.runtime.CoreException;
026: import org.eclipse.ui.texteditor.MarkerUtilities;
027:
028: public class SootAttrJavaIconGenerator implements Runnable {
029:
030: private IFile rec;
031: private SootAttributesHandler handler;
032:
033: public void run() {
034: removeOldMarkers();
035: addSootAttributeMarkers();
036: }
037:
038: private boolean typesContainsOneOf(ArrayList list) {
039: boolean result = false;
040: Iterator it = list.iterator();
041: while (it.hasNext()) {
042: if (getHandler().getTypesToShow().contains(it.next())) {
043: result = true;
044: break;
045: }
046: }
047: return result;
048: }
049:
050: public void addSootAttributeMarkers() {//SootAttributesHandler handler, IFile rec) {
051:
052: if (getHandler().getAttrList() == null)
053: return;
054: Iterator it = getHandler().getAttrList().iterator();
055: HashMap markerAttr = new HashMap();
056:
057: while (it.hasNext()) {
058: SootAttribute sa = (SootAttribute) it.next();
059: if (getHandler().isShowAllTypes()
060: || typesContainsOneOf(sa.getAnalysisTypes())) {
061: if (((sa.getAllTextAttrs("<br>") == null) || (sa
062: .getAllTextAttrs("<br>").length() == 0))
063: && ((sa.getAllLinkAttrs() == null) || (sa
064: .getAllLinkAttrs().size() == 0)))
065: continue;
066: markerAttr.put(IMarker.LINE_NUMBER, new Integer(sa
067: .getJavaStartLn()));
068: try {
069: MarkerUtilities.createMarker(getRec(), markerAttr,
070: "ca.mcgill.sable.soot.sootattributemarker");
071: } catch (CoreException e) {
072: System.out.println(e.getMessage());
073: }
074: }
075: }
076: }
077:
078: public void removeOldMarkers() {//IFile file){
079: try {
080: getRec().deleteMarkers(
081: "ca.mcgill.sable.soot.sootattributemarker", true,
082: IResource.DEPTH_INFINITE);
083: } catch (CoreException e) {
084: }
085: }
086:
087: /**
088: * @return
089: */
090: public SootAttributesHandler getHandler() {
091: return handler;
092: }
093:
094: /**
095: * @return
096: */
097: public IFile getRec() {
098: return rec;
099: }
100:
101: /**
102: * @param handler
103: */
104: public void setHandler(SootAttributesHandler handler) {
105: this .handler = handler;
106: }
107:
108: /**
109: * @param file
110: */
111: public void setRec(IFile file) {
112: rec = file;
113: }
114:
115: }
|