1 19 20 package ca.mcgill.sable.soot.attributes; 21 22 import org.eclipse.jface.action.IAction; 23 import org.eclipse.jface.viewers.*; 24 import org.eclipse.ui.*; 25 import ca.mcgill.sable.soot.*; 26 import ca.mcgill.sable.soot.ui.*; 27 import java.util.*; 28 import org.eclipse.core.resources.*; 29 import org.eclipse.jdt.core.*; 30 import org.eclipse.core.runtime.*; 31 import org.eclipse.jface.dialogs.*; 32 33 34 public class VisManLauncher implements IWorkbenchWindowActionDelegate { 35 36 private IProject proj; 37 private IResource rec; 38 39 40 public VisManLauncher() { 41 super(); 42 } 43 44 47 public void dispose() { 48 } 49 50 53 public void init(IWorkbenchWindow window) { 54 } 55 56 59 public void run(IAction action) { 60 IWorkbenchWindow window = SootPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow(); 61 AnalysisVisManipDialog dialog = new AnalysisVisManipDialog(window.getShell()); 62 dialog.setFileList(getFilesFromCon(getProj())); 63 dialog.setProj(getProj()); 64 dialog.open(); 65 if (dialog.getReturnCode() == Dialog.OK){ 66 if (dialog.getAllSelected() != null){ 67 Iterator selIt = dialog.getAllSelected().iterator(); 68 while (selIt.hasNext()){ 69 Object next = selIt.next(); 70 SootAttributesHandler handler = SootPlugin.getDefault().getManager().getAttributesHandlerForFile((IFile)next); 71 Object [] elems; 72 if ((dialog.getCurrentSettingsMap() != null) && (dialog.getCurrentSettingsMap().containsKey(next))){ 73 elems = (Object [])dialog.getCurrentSettingsMap().get(next); 74 } 75 else { 76 elems = dialog.getCheckTypes().getCheckedElements(); 77 } 78 ArrayList toShow = new ArrayList(); 79 for (int i = 0; i < elems.length; i++){ 80 toShow.add(elems[i]); 81 } 82 handler.setTypesToShow(toShow); 83 handler.setShowAllTypes(false); 84 handler.setUpdate(true); 86 final IEditorPart activeEdPart = SootPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); 87 88 SootPlugin.getDefault().getPartManager().updatePart(activeEdPart); 89 90 } 91 } 92 } 93 94 } 95 96 public HashMap configureDataMap(){ 97 HashMap map = new HashMap(); 98 ArrayList files = getFilesFromCon(getProj()); 102 Iterator it = files.iterator(); 103 while (it.hasNext()){ 104 IFile next = (IFile)it.next(); 105 SootAttributesHandler handler; 106 if (next.getFileExtension().equals("java")){ 107 JavaAttributesComputer jac = new JavaAttributesComputer(); 108 jac.setProj(getProj()); 109 jac.setRec(getRec()); 110 handler = jac.getAttributesHandler(next); 111 } 112 else { 113 JimpleAttributesComputer jac = new JimpleAttributesComputer(); 114 jac.setProj(getProj()); 115 jac.setRec(getRec()); 116 handler = jac.getAttributesHandler(next); 117 } 118 if ((handler != null) && (handler.getAttrList() != null)){ 119 Iterator attrsIt = handler.getAttrList().iterator(); 120 ArrayList types = new ArrayList(); 121 while (attrsIt.hasNext()){ 122 SootAttribute sa = (SootAttribute)attrsIt.next(); 123 Iterator typesIt = sa.getAnalysisTypes().iterator(); 124 while (typesIt.hasNext()){ 125 String val = (String )typesIt.next(); 126 if (!types.contains(val)){ 127 types.add(val); 128 } 129 } 130 } 131 map.put(next, types); 132 } 133 else { 134 map.put(next, null); 135 } 136 137 } 138 return map; 139 } 140 141 142 143 public ArrayList getFilesFromCon(IContainer con){ 144 ArrayList files = new ArrayList(); 145 try { 146 IResource [] recs = con.members(); 147 for (int i = 0; i < recs.length; i++){ 148 if (recs[i] instanceof IFile){ 149 IFile file = (IFile)recs[i]; 150 if (file.getFileExtension() == null) continue; 151 if (file.getFileExtension().equals("jimple") || file.getFileExtension().equals("java")){ 152 files.add(recs[i]); 153 } 154 } 155 else if (recs[i] instanceof IContainer){ 156 files.addAll(getFilesFromCon((IContainer)recs[i])); 157 } 158 else { 159 throw new RuntimeException ("unknown member type"); 160 } 161 } 162 } 163 catch(CoreException e){ 164 } 165 return files; 166 } 167 170 public void selectionChanged(IAction action, ISelection selection) { 171 if (selection instanceof IStructuredSelection){ 172 IStructuredSelection struct = (IStructuredSelection)selection; 173 Iterator it = struct.iterator(); 174 while (it.hasNext()){ 175 Object next = it.next(); 176 if (next instanceof IResource) { 177 setProj(((IResource)next).getProject()); 178 setRec((IResource)next); 179 } 180 else if (next instanceof IJavaElement) { 181 IJavaElement jElem = (IJavaElement)next; 182 setProj(jElem.getJavaProject().getProject()); 183 setRec(jElem.getResource()); 184 } 185 } 186 } 187 } 188 189 192 public IProject getProj() { 193 return proj; 194 } 195 196 199 public void setProj(IProject project) { 200 proj = project; 201 } 202 203 206 public IResource getRec() { 207 return rec; 208 } 209 210 213 public void setRec(IResource resource) { 214 rec = resource; 215 } 216 217 } 218 | Popular Tags |