| 1 19 20 package ca.mcgill.sable.soot.attributes; 21 22 import java.io.File ; 23 import java.util.*; 24 25 import org.eclipse.core.resources.*; 26 import org.eclipse.core.runtime.*; 27 import org.eclipse.ui.texteditor.*; 28 29 import ca.mcgill.sable.soot.SootPlugin; 30 31 32 public abstract class AbstractAttributesComputer { 33 34 private IResource rec; 35 private IProject proj; 36 37 40 protected ArrayList computeFiles(ArrayList names){ 41 ArrayList fileList = new ArrayList(); 42 String sep = System.getProperty("file.separator"); 43 IContainer con = (IContainer)getProj().getFolder("sootOutput"+sep+"attributes"+sep); 44 try { 45 IResource [] files = con.members(); 46 for (int i = 0; i < files.length; i++){ 47 Iterator it = names.iterator(); 48 while (it.hasNext()){ 49 String fileNameToMatch = (String )it.next(); 50 if (files[i].getName().matches(fileNameToMatch+"[$].*") || files[i].getName().equals(fileNameToMatch+".xml")){ 51 fileList.add(files[i]); 52 } 53 } 54 } 55 } 56 catch(CoreException e){ 57 } 58 return fileList; 59 } 60 63 protected abstract ArrayList computeNames(AbstractTextEditor editor); 64 65 protected abstract ArrayList computeNames(IFile file); 66 67 70 protected abstract void init(AbstractTextEditor editor); 71 72 75 protected SootAttributesHandler computeAttributes(ArrayList files, SootAttributesHandler sah) { 76 SootAttributeFilesReader safr = new SootAttributeFilesReader(); 77 Iterator it = files.iterator(); 78 while (it.hasNext()){ 79 String fileName = ((IPath)((IFile)it.next()).getLocation()).toOSString(); 80 AttributeDomProcessor adp = safr.readFile(fileName); 81 if (adp != null) { 82 sah.setAttrList(adp.getAttributes()); 83 sah.setKeyList(adp.getKeys()); 84 } 85 } 86 sah.setValuesSetTime(System.currentTimeMillis()); 87 SootPlugin.getDefault().getManager().addToFileWithAttributes((IFile)getRec(), sah); 88 return sah; 89 } 90 91 public SootAttributesHandler getAttributesHandler(IFile file){ 92 ArrayList files = computeFiles(computeNames(file)); 93 return getHandler(files); 94 } 95 96 public SootAttributesHandler getAttributesHandler(AbstractTextEditor editor){ 97 init(editor); 99 ArrayList files = computeFiles(computeNames(editor)); 101 return getHandler(files); 102 } 103 104 private SootAttributesHandler getHandler(ArrayList files){ 105 if (!(getRec() instanceof IFile)) return null; 107 108 SootAttributesHandler handler = SootPlugin.getDefault().getManager().getAttributesHandlerForFile((IFile)getRec()); 109 if (handler != null){ 110 111 long valuesSetTime = handler.getValuesSetTime(); 112 boolean update = handler.isUpdate(); 113 114 Iterator it = files.iterator(); 115 while (it.hasNext()){ 116 IFile next = (IFile)it.next(); 117 File realFile = new File (next.getLocation().toOSString()); 118 119 if (realFile.lastModified() > valuesSetTime){ 120 update = true; 121 } 122 } 123 handler.setUpdate(update); 124 if (!update){ 126 return handler; 127 } 128 else { 129 return computeAttributes(files, handler); 130 } 131 } 132 else { 133 return computeAttributes(files, new SootAttributesHandler()); 134 } 135 } 136 139 public IProject getProj() { 140 return proj; 141 } 142 143 146 public IResource getRec() { 147 return rec; 148 } 149 150 153 public void setProj(IProject project) { 154 proj = project; 155 } 156 157 160 public void setRec(IResource resource) { 161 rec = resource; 162 } 163 164 } 165 | Popular Tags |