1 11 package org.eclipse.jdt.internal.ui.search; 12 13 import org.eclipse.core.resources.IFile; 14 import org.eclipse.core.resources.IMarker; 15 import org.eclipse.core.resources.IResource; 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.jdt.core.ICompilationUnit; 18 import org.eclipse.jdt.core.IJavaElement; 19 import org.eclipse.jdt.core.JavaCore; 20 import org.eclipse.jdt.internal.ui.util.ExceptionHandler; 21 import org.eclipse.jface.text.IDocument; 22 import org.eclipse.jface.text.Position; 23 import org.eclipse.search.ui.NewSearchUI; 24 import org.eclipse.ui.texteditor.IMarkerUpdater; 25 import org.eclipse.ui.texteditor.MarkerUtilities; 26 27 public class JavaSearchMarkerUpdater implements IMarkerUpdater { 28 29 30 public JavaSearchMarkerUpdater() { 31 super(); 32 } 33 34 37 public boolean updateMarker(IMarker marker, IDocument document, Position position) { 38 39 try { 40 String id= (String ) marker.getAttribute(IJavaSearchUIConstants.ATT_JE_HANDLE_ID); 41 if (id != null) { 42 IJavaElement j= JavaCore.create(id); 43 if (j == null || !j.exists() || !j.isStructureKnown()) { 44 IResource resource= marker.getResource(); 45 if (MarkerUtilities.getCharStart(marker) != -1 && MarkerUtilities.getCharEnd(marker) != -1 && resource instanceof IFile) { 46 Object o= JavaCore.create(resource); 47 if (o instanceof ICompilationUnit) { 48 IJavaElement element= ((ICompilationUnit) o).getElementAt(position.getOffset()); 49 if (element != null) { 50 marker.setAttribute(IJavaSearchUIConstants.ATT_JE_HANDLE_ID, element.getHandleIdentifier()); 51 marker.setAttribute(IJavaSearchUIConstants.ATT_JE_HANDLE_ID_CHANGED, new Boolean (true)); 52 return true; 53 } 54 else 55 return false; 56 } 57 } 58 } else { 59 return true; 60 } 61 } 62 else 63 return true; 65 } catch (CoreException ex) { 66 ExceptionHandler.handle(ex, SearchMessages.getString("Search.Error.markerAttributeAccess.title"), SearchMessages.getString("Search.Error.markerAttributeAccess.message")); } 68 return false; 69 } 70 71 74 public String [] getAttribute() { 75 return new String [] { IJavaSearchUIConstants.ATT_JE_HANDLE_ID }; 76 } 77 78 81 public String getMarkerType() { 82 return NewSearchUI.SEARCH_MARKER; 83 } 84 } 85 | Popular Tags |