1 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 JAVA_FILE_EXT = Messages.getString("SootResourceManager.java"); public static final String JIMPLE_FILE_EXT = Messages.getString("SootResourceManager.jimple"); 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 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 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 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 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 196 public HashMap getFilesWithAttributes() { 197 return filesWithAttributes; 198 } 199 200 203 public void setFilesWithAttributes(HashMap map) { 204 filesWithAttributes = map; 205 } 206 207 210 public HashMap getColorList() { 211 return colorList; 212 } 213 214 217 public void setColorList(HashMap map) { 218 colorList = map; 219 } 220 221 } 222 | Popular Tags |