KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ca > mcgill > sable > soot > attributes > VisManLauncher


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2004 Jennifer Lhotak
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */

19
20 package ca.mcgill.sable.soot.attributes;
21
22 import org.eclipse.jface.action.IAction;
23 import org.eclipse.jface.viewers.*;
24 import org.eclipse.ui.*;
25 import ca.mcgill.sable.soot.*;
26 import ca.mcgill.sable.soot.ui.*;
27 import java.util.*;
28 import org.eclipse.core.resources.*;
29 import org.eclipse.jdt.core.*;
30 import org.eclipse.core.runtime.*;
31 import org.eclipse.jface.dialogs.*;
32
33
34 public class VisManLauncher implements IWorkbenchWindowActionDelegate {
35
36     private IProject proj;
37     private IResource rec;
38     
39     
40     public VisManLauncher() {
41         super();
42     }
43
44     /* (non-Javadoc)
45      * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
46      */

47     public void dispose() {
48     }
49
50     /* (non-Javadoc)
51      * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
52      */

53     public void init(IWorkbenchWindow window) {
54     }
55
56     /* (non-Javadoc)
57      * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
58      */

59     public void run(IAction action) {
60         IWorkbenchWindow window = SootPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow();
61         AnalysisVisManipDialog dialog = new AnalysisVisManipDialog(window.getShell());
62         dialog.setFileList(getFilesFromCon(getProj()));
63         dialog.setProj(getProj());
64         dialog.open();
65         if (dialog.getReturnCode() == Dialog.OK){
66             if (dialog.getAllSelected() != null){
67                 Iterator selIt = dialog.getAllSelected().iterator();
68                 while (selIt.hasNext()){
69                     Object JavaDoc next = selIt.next();
70                     SootAttributesHandler handler = SootPlugin.getDefault().getManager().getAttributesHandlerForFile((IFile)next);
71                     Object JavaDoc [] elems;
72                     if ((dialog.getCurrentSettingsMap() != null) && (dialog.getCurrentSettingsMap().containsKey(next))){
73                         elems = (Object JavaDoc [])dialog.getCurrentSettingsMap().get(next);
74                     }
75                     else {
76                         elems = dialog.getCheckTypes().getCheckedElements();
77                     }
78                     ArrayList toShow = new ArrayList();
79                     for (int i = 0; i < elems.length; i++){
80                         toShow.add(elems[i]);
81                     }
82                     handler.setTypesToShow(toShow);
83                     handler.setShowAllTypes(false);
84                     // also update currently shown editor and legend
85
handler.setUpdate(true);
86                     final IEditorPart activeEdPart = SootPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
87         
88                     SootPlugin.getDefault().getPartManager().updatePart(activeEdPart);
89     
90                 }
91             }
92         }
93         
94     }
95
96     public HashMap configureDataMap(){
97         HashMap map = new HashMap();
98         // get all .java and .jimple files in the project
99
// for each determine if attr xml exist and if yes which
100
// kinds of attrs there are
101
ArrayList files = getFilesFromCon(getProj());
102         Iterator it = files.iterator();
103         while (it.hasNext()){
104             IFile next = (IFile)it.next();
105             SootAttributesHandler handler;
106             if (next.getFileExtension().equals("java")){
107                 JavaAttributesComputer jac = new JavaAttributesComputer();
108                 jac.setProj(getProj());
109                 jac.setRec(getRec());
110                 handler = jac.getAttributesHandler(next);
111             }
112             else {
113                 JimpleAttributesComputer jac = new JimpleAttributesComputer();
114                 jac.setProj(getProj());
115                 jac.setRec(getRec());
116                 handler = jac.getAttributesHandler(next);
117             }
118             if ((handler != null) && (handler.getAttrList() != null)){
119                 Iterator attrsIt = handler.getAttrList().iterator();
120                 ArrayList types = new ArrayList();
121                 while (attrsIt.hasNext()){
122                     SootAttribute sa = (SootAttribute)attrsIt.next();
123                     Iterator typesIt = sa.getAnalysisTypes().iterator();
124                     while (typesIt.hasNext()){
125                         String JavaDoc val = (String JavaDoc)typesIt.next();
126                         if (!types.contains(val)){
127                             types.add(val);
128                         }
129                     }
130                 }
131                 map.put(next, types);
132             }
133             else {
134                 map.put(next, null);
135             }
136             
137         }
138         return map;
139     }
140     
141     
142     
143     public ArrayList getFilesFromCon(IContainer con){
144         ArrayList files = new ArrayList();
145         try {
146             IResource [] recs = con.members();
147             for (int i = 0; i < recs.length; i++){
148                 if (recs[i] instanceof IFile){
149                     IFile file = (IFile)recs[i];
150                     if (file.getFileExtension() == null) continue;
151                     if (file.getFileExtension().equals("jimple") || file.getFileExtension().equals("java")){
152                         files.add(recs[i]);
153                     }
154                 }
155                 else if (recs[i] instanceof IContainer){
156                     files.addAll(getFilesFromCon((IContainer)recs[i]));
157                 }
158                 else {
159                     throw new RuntimeException JavaDoc("unknown member type");
160                 }
161             }
162         }
163         catch(CoreException e){
164         }
165         return files;
166     }
167     /* (non-Javadoc)
168      * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
169      */

170     public void selectionChanged(IAction action, ISelection selection) {
171         if (selection instanceof IStructuredSelection){
172             IStructuredSelection struct = (IStructuredSelection)selection;
173             Iterator it = struct.iterator();
174             while (it.hasNext()){
175                 Object JavaDoc next = it.next();
176                 if (next instanceof IResource) {
177                     setProj(((IResource)next).getProject());
178                     setRec((IResource)next);
179                 }
180                 else if (next instanceof IJavaElement) {
181                     IJavaElement jElem = (IJavaElement)next;
182                     setProj(jElem.getJavaProject().getProject());
183                     setRec(jElem.getResource());
184                 }
185             }
186         }
187     }
188
189     /**
190      * @return
191      */

192     public IProject getProj() {
193         return proj;
194     }
195
196     /**
197      * @param project
198      */

199     public void setProj(IProject project) {
200         proj = project;
201     }
202
203     /**
204      * @return
205      */

206     public IResource getRec() {
207         return rec;
208     }
209
210     /**
211      * @param resource
212      */

213     public void setRec(IResource resource) {
214         rec = resource;
215     }
216
217 }
218
Popular Tags