KickJava   Java API By Example, From Geeks To Geeks.

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


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.*;
23
24 import org.eclipse.core.resources.*;
25 import org.eclipse.jdt.core.*;
26 import org.eclipse.jface.viewers.*;
27 import ca.mcgill.sable.soot.*;
28 public class SootSelection {
29
30     private IStructuredSelection structured;
31     private IResource resource;
32     private IProject project;
33     private IJavaProject javaProject;
34     private IFolder folder;
35     private IFile file;
36     private ArrayList fileList;
37     private IClassFile classFile;
38     private ArrayList classFileList;
39     private ICompilationUnit javaFile;
40     private ArrayList javaFileList;
41     private IPackageFragmentRoot packageFragmentRoot;
42     private int type;
43     
44     public static final int FILE_SELECTED_TYPE = 0;
45     public static final int FOLDER_SELECTED_TYPE = 2;
46     public static final int PACKAGEROOT_SELECTED_TYPE = 3;
47     public static final int CLASSFILE_SELECTED_TYPE = 1;
48     public static final int CU_SELECTED_TYPE = 4;
49     
50     public SootSelection(IStructuredSelection struct) {
51         setStructured(struct);
52     }
53     
54     public void initialize() {
55         Iterator it = getStructured().iterator();
56         Object JavaDoc temp = it.next();
57         if (temp instanceof IResource) {
58             setResource((IResource)temp);
59             setProject(getResource().getProject());
60             SootPlugin.getDefault().setCurrentProject(getProject());
61             setJavaProject(JavaCore.create(getProject()));
62         }
63         else if (temp instanceof IJavaElement) {
64             IJavaElement jElem = (IJavaElement)temp;
65             setJavaProject(jElem.getJavaProject());
66             setProject(javaProject.getProject());
67             SootPlugin.getDefault().setCurrentProject(getProject());
68             
69         }
70         
71         if (temp instanceof IFolder) {
72             setFolder((IFolder)temp);
73             setType(FOLDER_SELECTED_TYPE);
74         }
75         else if (temp instanceof IFile) {
76             setFile((IFile)temp);
77             setType(FILE_SELECTED_TYPE);
78         }
79         else if (temp instanceof IClassFile) {
80             setClassFile((IClassFile)temp);
81             setType(CLASSFILE_SELECTED_TYPE);
82         }
83         else if (temp instanceof IPackageFragmentRoot) {
84             setPackageFragmentRoot((IPackageFragmentRoot)temp);
85             setType(PACKAGEROOT_SELECTED_TYPE);
86         }
87         else if (temp instanceof ICompilationUnit){
88             setJavaFile((ICompilationUnit)temp);
89             setType(CU_SELECTED_TYPE);
90         }
91         
92         Iterator allFilesIt = getStructured().iterator();
93         while (allFilesIt.hasNext()){
94             if (getFileList() == null) {
95                 setFileList(new ArrayList());
96             }
97             getFileList().add(allFilesIt.next());
98         }
99         
100     }
101     
102     /**
103      * Returns the folder.
104      * @return IFolder
105      */

106     public IFolder getFolder() {
107         return folder;
108     }
109
110     /**
111      * Returns the javaProject.
112      * @return IJavaProject
113      */

114     public IJavaProject getJavaProject() {
115         return javaProject;
116     }
117
118     /**
119      * Returns the project.
120      * @return IProject
121      */

122     public IProject getProject() {
123         return project;
124     }
125
126     /**
127      * Returns the resource.
128      * @return IResource
129      */

130     public IResource getResource() {
131         return resource;
132     }
133
134     /**
135      * Returns the structured.
136      * @return IStructuredSelection
137      */

138     public IStructuredSelection getStructured() {
139         return structured;
140     }
141
142     /**
143      * Sets the folder.
144      * @param folder The folder to set
145      */

146     public void setFolder(IFolder folder) {
147         this.folder = folder;
148     }
149
150     /**
151      * Sets the javaProject.
152      * @param javaProject The javaProject to set
153      */

154     public void setJavaProject(IJavaProject javaProject) {
155         this.javaProject = javaProject;
156     }
157
158     /**
159      * Sets the project.
160      * @param project The project to set
161      */

162     public void setProject(IProject project) {
163         this.project = project;
164     }
165
166     /**
167      * Sets the resource.
168      * @param resource The resource to set
169      */

170     public void setResource(IResource resource) {
171         this.resource = resource;
172     }
173
174     /**
175      * Sets the structured.
176      * @param structured The structured to set
177      */

178     public void setStructured(IStructuredSelection structured) {
179         this.structured = structured;
180     }
181
182     /**
183      * Returns the file.
184      * @return IFile
185      */

186     public IFile getFile() {
187         return file;
188     }
189
190     /**
191      * Sets the file.
192      * @param file The file to set
193      */

194     public void setFile(IFile file) {
195         this.file = file;
196     }
197
198     /**
199      * Returns the type.
200      * @return int
201      */

202     public int getType() {
203         return type;
204     }
205
206     /**
207      * Sets the type.
208      * @param type The type to set
209      */

210     public void setType(int type) {
211         this.type = type;
212     }
213
214     /**
215      * Returns the classfile.
216      * @return IClassFile
217      */

218     public IClassFile getClassFile() {
219         return classFile;
220     }
221
222     /**
223      * Sets the classfile.
224      * @param classfile The classfile to set
225      */

226     public void setClassFile(IClassFile classFile) {
227         this.classFile = classFile;
228     }
229
230     /**
231      * Returns the packageFragmentRoot.
232      * @return IPackageFragmentRoot
233      */

234     public IPackageFragmentRoot getPackageFragmentRoot() {
235         return packageFragmentRoot;
236     }
237
238     /**
239      * Sets the packageFragmentRoot.
240      * @param packageFragmentRoot The packageFragmentRoot to set
241      */

242     public void setPackageFragmentRoot(IPackageFragmentRoot packageFragmentRoot) {
243         this.packageFragmentRoot = packageFragmentRoot;
244     }
245
246     /**
247      * @return
248      */

249     public ICompilationUnit getJavaFile() {
250         return javaFile;
251     }
252
253     /**
254      * @param unit
255      */

256     public void setJavaFile(ICompilationUnit unit) {
257         javaFile = unit;
258     }
259
260     /**
261      * @return
262      */

263     public ArrayList getClassFileList() {
264         return classFileList;
265     }
266
267     /**
268      * @return
269      */

270     public ArrayList getFileList() {
271         return fileList;
272     }
273
274     /**
275      * @return
276      */

277     public ArrayList getJavaFileList() {
278         return javaFileList;
279     }
280
281     /**
282      * @param list
283      */

284     public void setClassFileList(ArrayList list) {
285         classFileList = list;
286     }
287
288     /**
289      * @param list
290      */

291     public void setFileList(ArrayList list) {
292         fileList = list;
293     }
294
295     /**
296      * @param list
297      */

298     public void setJavaFileList(ArrayList list) {
299         javaFileList = list;
300     }
301
302 }
303
Popular Tags