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