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 org.eclipse.jface.action.IAction;
023: import org.eclipse.jface.viewers.*;
024: import org.eclipse.ui.*;
025: import ca.mcgill.sable.soot.*;
026: import ca.mcgill.sable.soot.ui.*;
027: import java.util.*;
028: import org.eclipse.core.resources.*;
029: import org.eclipse.jdt.core.*;
030: import org.eclipse.core.runtime.*;
031: import org.eclipse.jface.dialogs.*;
032:
033: public class VisManLauncher implements IWorkbenchWindowActionDelegate {
034:
035: private IProject proj;
036: private IResource rec;
037:
038: public VisManLauncher() {
039: super ();
040: }
041:
042: /* (non-Javadoc)
043: * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
044: */
045: public void dispose() {
046: }
047:
048: /* (non-Javadoc)
049: * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
050: */
051: public void init(IWorkbenchWindow window) {
052: }
053:
054: /* (non-Javadoc)
055: * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
056: */
057: public void run(IAction action) {
058: IWorkbenchWindow window = SootPlugin.getDefault()
059: .getWorkbench().getActiveWorkbenchWindow();
060: AnalysisVisManipDialog dialog = new AnalysisVisManipDialog(
061: window.getShell());
062: dialog.setFileList(getFilesFromCon(getProj()));
063: dialog.setProj(getProj());
064: dialog.open();
065: if (dialog.getReturnCode() == Dialog.OK) {
066: if (dialog.getAllSelected() != null) {
067: Iterator selIt = dialog.getAllSelected().iterator();
068: while (selIt.hasNext()) {
069: Object next = selIt.next();
070: SootAttributesHandler handler = SootPlugin
071: .getDefault().getManager()
072: .getAttributesHandlerForFile((IFile) next);
073: Object[] elems;
074: if ((dialog.getCurrentSettingsMap() != null)
075: && (dialog.getCurrentSettingsMap()
076: .containsKey(next))) {
077: elems = (Object[]) dialog
078: .getCurrentSettingsMap().get(next);
079: } else {
080: elems = dialog.getCheckTypes()
081: .getCheckedElements();
082: }
083: ArrayList toShow = new ArrayList();
084: for (int i = 0; i < elems.length; i++) {
085: toShow.add(elems[i]);
086: }
087: handler.setTypesToShow(toShow);
088: handler.setShowAllTypes(false);
089: // also update currently shown editor and legend
090: handler.setUpdate(true);
091: final IEditorPart activeEdPart = SootPlugin
092: .getDefault().getWorkbench()
093: .getActiveWorkbenchWindow().getActivePage()
094: .getActiveEditor();
095:
096: SootPlugin.getDefault().getPartManager()
097: .updatePart(activeEdPart);
098:
099: }
100: }
101: }
102:
103: }
104:
105: public HashMap configureDataMap() {
106: HashMap map = new HashMap();
107: // get all .java and .jimple files in the project
108: // for each determine if attr xml exist and if yes which
109: // kinds of attrs there are
110: ArrayList files = getFilesFromCon(getProj());
111: Iterator it = files.iterator();
112: while (it.hasNext()) {
113: IFile next = (IFile) it.next();
114: SootAttributesHandler handler;
115: if (next.getFileExtension().equals("java")) {
116: JavaAttributesComputer jac = new JavaAttributesComputer();
117: jac.setProj(getProj());
118: jac.setRec(getRec());
119: handler = jac.getAttributesHandler(next);
120: } else {
121: JimpleAttributesComputer jac = new JimpleAttributesComputer();
122: jac.setProj(getProj());
123: jac.setRec(getRec());
124: handler = jac.getAttributesHandler(next);
125: }
126: if ((handler != null) && (handler.getAttrList() != null)) {
127: Iterator attrsIt = handler.getAttrList().iterator();
128: ArrayList types = new ArrayList();
129: while (attrsIt.hasNext()) {
130: SootAttribute sa = (SootAttribute) attrsIt.next();
131: Iterator typesIt = sa.getAnalysisTypes().iterator();
132: while (typesIt.hasNext()) {
133: String val = (String) typesIt.next();
134: if (!types.contains(val)) {
135: types.add(val);
136: }
137: }
138: }
139: map.put(next, types);
140: } else {
141: map.put(next, null);
142: }
143:
144: }
145: return map;
146: }
147:
148: public ArrayList getFilesFromCon(IContainer con) {
149: ArrayList files = new ArrayList();
150: try {
151: IResource[] recs = con.members();
152: for (int i = 0; i < recs.length; i++) {
153: if (recs[i] instanceof IFile) {
154: IFile file = (IFile) recs[i];
155: if (file.getFileExtension() == null)
156: continue;
157: if (file.getFileExtension().equals("jimple")
158: || file.getFileExtension().equals("java")) {
159: files.add(recs[i]);
160: }
161: } else if (recs[i] instanceof IContainer) {
162: files.addAll(getFilesFromCon((IContainer) recs[i]));
163: } else {
164: throw new RuntimeException("unknown member type");
165: }
166: }
167: } catch (CoreException e) {
168: }
169: return files;
170: }
171:
172: /* (non-Javadoc)
173: * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
174: */
175: public void selectionChanged(IAction action, ISelection selection) {
176: if (selection instanceof IStructuredSelection) {
177: IStructuredSelection struct = (IStructuredSelection) selection;
178: Iterator it = struct.iterator();
179: while (it.hasNext()) {
180: Object next = it.next();
181: if (next instanceof IResource) {
182: setProj(((IResource) next).getProject());
183: setRec((IResource) next);
184: } else if (next instanceof IJavaElement) {
185: IJavaElement jElem = (IJavaElement) next;
186: setProj(jElem.getJavaProject().getProject());
187: setRec(jElem.getResource());
188: }
189: }
190: }
191: }
192:
193: /**
194: * @return
195: */
196: public IProject getProj() {
197: return proj;
198: }
199:
200: /**
201: * @param project
202: */
203: public void setProj(IProject project) {
204: proj = project;
205: }
206:
207: /**
208: * @return
209: */
210: public IResource getRec() {
211: return rec;
212: }
213:
214: /**
215: * @param resource
216: */
217: public void setRec(IResource resource) {
218: rec = resource;
219: }
220:
221: }
|