KickJava   Java API By Example, From Geeks To Geeks.

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


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