1 19 20 package ca.mcgill.sable.soot.attributes; 21 22 23 import java.util.ArrayList ; 24 import java.util.HashMap ; 25 import java.util.Iterator ; 26 import org.eclipse.ui.*; 27 import org.eclipse.ui.texteditor.AbstractTextEditor; 28 import org.eclipse.ui.texteditor.MarkerUtilities; 29 30 31 32 import org.eclipse.core.resources.*; 33 import org.eclipse.core.runtime.CoreException; 34 import org.eclipse.core.runtime.IAdaptable; 35 import org.eclipse.core.runtime.IPath; 36 import org.eclipse.jdt.ui.text.java.hover.*; 37 import org.eclipse.jdt.core.*; 38 import ca.mcgill.sable.soot.*; 39 40 public class SootAttributesJavaHover extends AbstractSootAttributesHover implements IJavaEditorTextHover { 41 42 private ArrayList fileNames; 43 44 public IJavaElement getJavaElement(AbstractTextEditor textEditor) { 45 IEditorInput input= textEditor.getEditorInput(); 46 return (IJavaElement) ((IAdaptable) input).getAdapter(IJavaElement.class); 47 48 } 49 50 51 protected void computeAttributes() { 52 setAttrsHandler(new SootAttributesHandler()); 53 createAttrFileNames(); 54 SootAttributeFilesReader safr = new SootAttributeFilesReader(); 55 Iterator it = fileNames.iterator(); 56 while (it.hasNext()){ 57 String fileName = ((IPath)it.next()).toOSString(); 58 AttributeDomProcessor adp = safr.readFile(fileName); 59 if (adp != null) { 60 61 getAttrsHandler().setAttrList(adp.getAttributes()); 62 } 63 } 64 65 SootPlugin.getDefault().getManager().addToFileWithAttributes((IFile)getRec(), getAttrsHandler()); 66 67 68 } 69 private String createAttrFileNames() { 70 fileNames = new ArrayList (); 71 StringBuffer sb = new StringBuffer (); 72 sb.append(SootPlugin.getWorkspace().getRoot().getProject(getSelectedProj()).getLocation().toOSString()); 73 sb.append(sep); 74 sb.append("sootOutput"); 75 sb.append(sep); 76 sb.append("attributes"); 77 sb.append(sep); 78 String dir = sb.toString(); 79 IContainer c = (IContainer)SootPlugin.getWorkspace().getRoot().getProject(getSelectedProj()).getFolder("sootOutput"+sep+"attributes"+sep); 80 try { 81 82 IResource [] files = c.members(); 83 for (int i = 0; i < files.length; i++){ 84 Iterator it = getPackFileNames().iterator(); 85 while (it.hasNext()){ 86 87 String fileNameToMatch = (String )it.next(); 88 if (files[i].getName().matches(fileNameToMatch+"[$].*") || files[i].getName().matches(fileNameToMatch+"\\."+"xml")){ 89 fileNames.add(files[i].getLocation()); 90 } 91 } 92 } 93 } 94 catch(CoreException e){ 95 } 96 sb.append(getPackFileName()); 97 sb.append(".xml"); 98 99 return sb.toString(); 100 } 101 102 protected void addSootAttributeMarkers() { 103 104 if (getAttrsHandler() == null)return; 105 if (getAttrsHandler().getAttrList() == null) return; 106 Iterator it = getAttrsHandler().getAttrList().iterator(); 107 HashMap markerAttr = new HashMap (); 108 109 while (it.hasNext()) { 110 SootAttribute sa = (SootAttribute)it.next(); 111 if (((sa.getAllTextAttrs("<br>") == null) || (sa.getAllTextAttrs("<br>").length() == 0)) && 112 ((sa.getAllLinkAttrs() == null) || (sa.getAllLinkAttrs().size() ==0))) continue; 113 114 markerAttr.put(IMarker.LINE_NUMBER, new Integer (sa.getJavaStartLn())); 115 116 try { 117 MarkerUtilities.createMarker(getRec(), markerAttr, "ca.mcgill.sable.soot.sootattributemarker"); 118 } 119 catch(CoreException e) { 120 System.out.println(e.getMessage()); 121 } 122 123 } 124 125 } 126 127 128 protected String getAttributes(AbstractTextEditor editor) { 129 JavaAttributesComputer jac = new JavaAttributesComputer(); 130 SootAttributesHandler handler = jac.getAttributesHandler(editor); 131 132 if (handler != null){ 133 134 return handler.getJavaAttribute(getLineNum()); 135 } 136 else { 137 return null; 138 } 139 } 140 141 142 } 143 | Popular Tags |