KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ca > mcgill > sable > soot > launching > SootOptionsFileLauncher


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2003 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.launching;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.Iterator JavaDoc;
24
25 import org.eclipse.jface.action.*;
26 import org.eclipse.jface.dialogs.*;
27 import ca.mcgill.sable.soot.*;
28 import ca.mcgill.sable.soot.ui.PhaseOptionsDialog;
29
30 /**
31  * Displays the Soot Options dialog and launches Soot with
32  * selected options on selected file.
33  */

34 public class SootOptionsFileLauncher extends SootFileLauncher {
35
36     public void run(IAction action) {
37         
38         super.run(action);
39         super.handleMultipleFiles();
40         
41         if (isDoNotContinue()) return;
42         // sometimes window needs to be reset (not sure why)
43
window = SootPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow();
44         
45         PhaseOptionsDialog dialog = new PhaseOptionsDialog(window.getShell());
46         setSdc(new SootDefaultCommands(dialog));
47         presetDialog();
48         dialog.open();
49
50         if (dialog.getReturnCode() == Dialog.CANCEL) {
51             SavedConfigManager scm = new SavedConfigManager();
52             scm.setEditMap(dialog.getEditMap());
53             scm.handleEdits();
54         }
55         else {
56             SootSavedConfiguration ssc = new SootSavedConfiguration("Temp", dialog.getConfig());
57             ssc.toSaveArray();
58             
59             
60             
61             setCmd(ssc.toRunArray());
62             String JavaDoc mainClass = dialog.getSootMainClass();
63             if ((mainClass == null) || (mainClass.length() == 0)){
64                 runSootDirectly();
65             }
66             else {
67                 runSootDirectly(mainClass);
68             }
69             runFinish();
70             
71             // save config if nessesary
72
SavedConfigManager scm = new SavedConfigManager();
73             scm.setEditMap(dialog.getEditMap());
74             scm.handleEdits();
75         }
76         
77             
78         
79         
80     }
81     
82     private void presetDialog() {
83         getSdc().setOutputDir(getOutputLocation());
84         getSdc().setSootClassPath(getClasspathAppend());
85         if (isSrcPrec()) {
86             getSdc().setSrcPrec(getSrcPrec());
87         }
88         getSdc().setKeepLineNum();
89         getSdc().setPrintTags();
90         getSdc().setSootMainClass();
91     }
92     
93     // TODO use this instead of String one
94
private void setCmd(ArrayList JavaDoc user_cmd){
95         getSootCommandList().addSingleOpt(user_cmd);
96         Iterator JavaDoc it = getToProcessList().iterator();
97         while (it.hasNext()){
98             getSootCommandList().addSingleOpt((String JavaDoc)it.next());
99         }
100     }
101     private void setCmd(String JavaDoc user_cmd) {
102         
103         
104         getSootCommandList().addSingleOpt(user_cmd);
105         ArrayList JavaDoc commands = new ArrayList JavaDoc();
106         Iterator JavaDoc it = getToProcessList().iterator();
107         while (it.hasNext()){
108             commands.add((String JavaDoc)it.next());
109         }
110         getSootCommandList().addSingleOpt(commands);
111         
112     }
113
114 }
115
Popular Tags