KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ca > mcgill > sable > soot > resources > SootResourceManager


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
21 package ca.mcgill.sable.soot.resources;
22
23 import java.util.*;
24
25 import org.eclipse.core.resources.*;
26 import org.eclipse.core.runtime.CoreException;
27 import org.eclipse.jface.text.ITextListener;
28 import org.eclipse.jface.text.TextEvent;
29 import org.eclipse.jface.text.TextPresentation;
30
31 import ca.mcgill.sable.soot.attributes.SootAttributesHandler;
32
33 public class SootResourceManager implements IResourceChangeListener, ITextListener {
34
35     private static final String JavaDoc JAVA_FILE_EXT = Messages.getString("SootResourceManager.java"); //$NON-NLS-1$
36
public static final String JavaDoc JIMPLE_FILE_EXT = Messages.getString("SootResourceManager.jimple"); //$NON-NLS-1$
37
private static final int SOOT_RAN_BIT = 1;
38     private static final int CHANGED_BIT = 0;
39     
40     
41     private HashMap filesWithAttributes;
42     private HashMap changedResources;
43     private HashMap colorList;
44         
45     public SootResourceManager() {
46         ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE);
47
48         
49     }
50     
51     public void textChanged(TextEvent e){
52     }
53
54     
55     public void updateSootRanFlag(){
56         if (getChangedResources() == null) return;
57             
58         Iterator it = getChangedResources().keySet().iterator();
59         while (it.hasNext()){
60             BitSet bits = (BitSet)getChangedResources().get(it.next());
61             bits.set(SOOT_RAN_BIT);
62             bits.clear(CHANGED_BIT);
63         }
64         setColorList(null);
65     }
66     
67     
68     
69     public void updateFileChangedFlag(IFile file){
70         if (file.getFileExtension() == null) return;
71         if ((file.getFileExtension().equals(JAVA_FILE_EXT)) ||
72             (file.getFileExtension().equals(JIMPLE_FILE_EXT))){
73             if (getChangedResources() == null){
74                 addToLists(file);
75             }
76             else if (getChangedResources().get(file) == null){
77                 addToLists(file);
78             }
79             ((BitSet)getChangedResources().get(file)).set(CHANGED_BIT);
80             }
81
82         
83     }
84     
85     public void clearColors(){
86         // clear colors
87
if (getColorList() != null){
88             Iterator it = getColorList().keySet().iterator();
89             while (it.hasNext()){
90                 ((TextPresentation)getColorList().get(it.next())).clear();
91                  
92             }
93         }
94     }
95     public boolean isFileMarkersUpdate(IFile file){
96         if (getChangedResources() == null) return false;
97         if (getChangedResources().get(file) == null) return false;
98         return ((BitSet)getChangedResources().get(file)).get(SOOT_RAN_BIT);
99     }
100
101     public void setToFalseUpdate(IFile file){
102         if (getChangedResources() == null) return;
103         if (getChangedResources().get(file) == null) return;
104         ((BitSet)getChangedResources().get(file)).clear(SOOT_RAN_BIT);
105             
106     }
107
108     public void setToFalseRemove(IFile file){
109         if (getChangedResources() == null) return;
110         if (getChangedResources().get(file) == null) return;
111         ((BitSet)getChangedResources().get(file)).clear(CHANGED_BIT);
112             
113     }
114
115     public boolean isFileMarkersRemove(IFile file){
116         if (getChangedResources() == null) return false;
117         if (getChangedResources().get(file) == null) return false;
118         return ((BitSet)getChangedResources().get(file)).get(CHANGED_BIT);
119     }
120
121     
122     public void addToLists(IResource res){
123         if (res instanceof IFile){
124             IFile file = (IFile)res;
125             if ((file.getFileExtension().equals(JAVA_FILE_EXT)) ||
126                 (file.getFileExtension().equals(JIMPLE_FILE_EXT))){
127                         
128                 if (getChangedResources() == null){
129                     setChangedResources(new HashMap());
130                 }
131                 getChangedResources().put(file, new BitSet(2));
132              }
133         }
134         
135     }
136     
137     /* (non-Javadoc)
138      * @see org.eclipse.core.resources.IResourceChangeListener#resourceChanged(org.eclipse.core.resources.IResourceChangeEvent)
139      */

140     public void resourceChanged(IResourceChangeEvent event) {
141         switch(event.getType()){
142             case IResourceChangeEvent.POST_CHANGE:{
143                 try {
144                     event.getDelta().accept(new SootDeltaVisitor());
145                 }
146                     catch (CoreException e){
147                 }
148                 break;
149             }
150         }
151
152     }
153     
154
155     public HashMap getChangedResources() {
156         return changedResources;
157     }
158
159     /**
160      * @param map
161      */

162     public void setChangedResources(HashMap map) {
163         changedResources = map;
164     }
165     
166     public void addToFileWithAttributes(IFile file, SootAttributesHandler handler){
167         if (getFilesWithAttributes() == null){
168             setFilesWithAttributes(new HashMap());
169         }
170         getFilesWithAttributes().put(file, handler);
171     }
172     
173     public SootAttributesHandler getAttributesHandlerForFile(IFile file){
174         if (getFilesWithAttributes() == null) {
175             return null;
176         }
177         else return (SootAttributesHandler)getFilesWithAttributes().get(file);
178     }
179     
180     // colors
181
public void addToColorList(IFile file, TextPresentation tp){
182         if (getColorList() == null){
183             setColorList(new HashMap());
184         }
185         getColorList().put(file, tp);
186     }
187     
188     public boolean alreadyOnColorList(IFile file){
189         if (getColorList() == null) return false;
190         else return getColorList().containsKey(file);
191     }
192     
193     /**
194      * @return
195      */

196     public HashMap getFilesWithAttributes() {
197         return filesWithAttributes;
198     }
199
200     /**
201      * @param map
202      */

203     public void setFilesWithAttributes(HashMap map) {
204         filesWithAttributes = map;
205     }
206
207     /**
208      * @return
209      */

210     public HashMap getColorList() {
211         return colorList;
212     }
213
214     /**
215      * @param map
216      */

217     public void setColorList(HashMap map) {
218         colorList = map;
219     }
220
221 }
222
Popular Tags