1 11 package org.eclipse.jdt.internal.ui.search; 12 13 import org.eclipse.core.resources.IMarker; 14 import org.eclipse.core.runtime.CoreException; 15 import org.eclipse.jdt.core.IJavaElement; 16 import org.eclipse.jdt.internal.ui.util.ExceptionHandler; 17 import org.eclipse.search.ui.IGroupByKeyComputer; 18 19 public class GroupByKeyComputer implements IGroupByKeyComputer { 20 21 IJavaElement fLastJavaElement= null; 22 String fLastHandle= null; 23 24 public Object computeGroupByKey(IMarker marker) { 25 if (marker == null) 26 return null; 27 28 IJavaElement jElement= getJavaElement(marker); 29 if (jElement != null && jElement.exists()) { 30 return fLastHandle; 33 } 34 return null; 35 } 36 37 private String getJavaElementHandleId(IMarker marker) { 38 try { 39 return (String )marker.getAttribute(IJavaSearchUIConstants.ATT_JE_HANDLE_ID); 40 } catch (CoreException ex) { 41 ExceptionHandler.handle(ex, SearchMessages.getString("Search.Error.markerAttributeAccess.title"), SearchMessages.getString("Search.Error.markerAttributeAccess.message")); return null; 43 } 44 } 45 46 private IJavaElement getJavaElement(IMarker marker) { 47 String handle= getJavaElementHandleId(marker); 48 if (handle == null) { 49 fLastHandle= null; 50 fLastJavaElement= null; 51 return null; 52 } 53 54 if (!handle.equals(fLastHandle)) { 55 fLastJavaElement= SearchUtil.getJavaElement(marker); 56 if (fLastJavaElement != null) 57 fLastHandle= fLastJavaElement.getHandleIdentifier(); 58 else 59 fLastHandle= null; 60 } 61 return fLastJavaElement; 62 } 63 } 64 | Popular Tags |