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.ArrayList;
023: import java.util.HashMap;
024: import java.util.Iterator;
025: import org.eclipse.ui.*;
026: import org.eclipse.ui.texteditor.AbstractTextEditor;
027: import org.eclipse.ui.texteditor.MarkerUtilities;
028:
029: import org.eclipse.core.resources.*;
030: import org.eclipse.core.runtime.CoreException;
031: import org.eclipse.core.runtime.IAdaptable;
032: import org.eclipse.core.runtime.IPath;
033: import org.eclipse.jdt.ui.text.java.hover.*;
034: import org.eclipse.jdt.core.*;
035: import ca.mcgill.sable.soot.*;
036:
037: public class SootAttributesJavaHover extends
038: AbstractSootAttributesHover implements IJavaEditorTextHover {
039:
040: private ArrayList fileNames;
041:
042: public IJavaElement getJavaElement(AbstractTextEditor textEditor) {
043: IEditorInput input = textEditor.getEditorInput();
044: return (IJavaElement) ((IAdaptable) input)
045: .getAdapter(IJavaElement.class);
046:
047: }
048:
049: protected void computeAttributes() {
050: setAttrsHandler(new SootAttributesHandler());
051: createAttrFileNames();
052: SootAttributeFilesReader safr = new SootAttributeFilesReader();
053: Iterator it = fileNames.iterator();
054: while (it.hasNext()) {
055: String fileName = ((IPath) it.next()).toOSString();
056: AttributeDomProcessor adp = safr.readFile(fileName);
057: if (adp != null) {
058:
059: getAttrsHandler().setAttrList(adp.getAttributes());
060: }
061: }
062:
063: SootPlugin.getDefault().getManager().addToFileWithAttributes(
064: (IFile) getRec(), getAttrsHandler());
065:
066: }
067:
068: private String createAttrFileNames() {
069: fileNames = new ArrayList();
070: StringBuffer sb = new StringBuffer();
071: sb.append(SootPlugin.getWorkspace().getRoot().getProject(
072: getSelectedProj()).getLocation().toOSString());
073: sb.append(sep);
074: sb.append("sootOutput");
075: sb.append(sep);
076: sb.append("attributes");
077: sb.append(sep);
078: String dir = sb.toString();
079: IContainer c = (IContainer) SootPlugin.getWorkspace().getRoot()
080: .getProject(getSelectedProj()).getFolder(
081: "sootOutput" + sep + "attributes" + sep);
082: try {
083:
084: IResource[] files = c.members();
085: for (int i = 0; i < files.length; i++) {
086: Iterator it = getPackFileNames().iterator();
087: while (it.hasNext()) {
088:
089: String fileNameToMatch = (String) it.next();
090: if (files[i].getName().matches(
091: fileNameToMatch + "[$].*")
092: || files[i].getName().matches(
093: fileNameToMatch + "\\." + "xml")) {
094: fileNames.add(files[i].getLocation());
095: }
096: }
097: }
098: } catch (CoreException e) {
099: }
100: sb.append(getPackFileName());
101: sb.append(".xml");
102:
103: return sb.toString();
104: }
105:
106: protected void addSootAttributeMarkers() {
107:
108: if (getAttrsHandler() == null)
109: return;
110: if (getAttrsHandler().getAttrList() == null)
111: return;
112: Iterator it = getAttrsHandler().getAttrList().iterator();
113: HashMap markerAttr = new HashMap();
114:
115: while (it.hasNext()) {
116: SootAttribute sa = (SootAttribute) it.next();
117: if (((sa.getAllTextAttrs("<br>") == null) || (sa
118: .getAllTextAttrs("<br>").length() == 0))
119: && ((sa.getAllLinkAttrs() == null) || (sa
120: .getAllLinkAttrs().size() == 0)))
121: continue;
122:
123: markerAttr.put(IMarker.LINE_NUMBER, new Integer(sa
124: .getJavaStartLn()));
125:
126: try {
127: MarkerUtilities.createMarker(getRec(), markerAttr,
128: "ca.mcgill.sable.soot.sootattributemarker");
129: } catch (CoreException e) {
130: System.out.println(e.getMessage());
131: }
132:
133: }
134:
135: }
136:
137: protected String getAttributes(AbstractTextEditor editor) {
138: JavaAttributesComputer jac = new JavaAttributesComputer();
139: SootAttributesHandler handler = jac
140: .getAttributesHandler(editor);
141:
142: if (handler != null) {
143:
144: return handler.getJavaAttribute(getLineNum());
145: } else {
146: return null;
147: }
148: }
149:
150: }
|