1 11 package org.eclipse.jdt.internal.ui.refactoring.nls.search; 12 13 import org.eclipse.core.runtime.CoreException; 14 15 import org.eclipse.core.resources.IMarker; 16 import org.eclipse.core.resources.IResource; 17 18 import org.eclipse.jdt.core.IJavaElement; 19 import org.eclipse.jdt.core.JavaModelException; 20 21 import org.eclipse.search.ui.IGroupByKeyComputer; 22 23 import org.eclipse.jdt.internal.ui.search.IJavaSearchUIConstants; 24 import org.eclipse.jdt.internal.ui.search.SearchMessages; 25 import org.eclipse.jdt.internal.ui.search.SearchUtil; 26 import org.eclipse.jdt.internal.ui.util.ExceptionHandler; 27 28 29 class NLSGroupByKeyComputer implements IGroupByKeyComputer { 30 31 IJavaElement fLastJavaElement= null; 32 String fLastHandle= null; 33 34 public Object computeGroupByKey(IMarker marker) { 35 if (marker == null || marker.getResource() == null) 36 return null; 37 38 if (!marker.getResource().getName().endsWith(".java")) return marker.getResource(); 40 41 IJavaElement jElement= getJavaElement(marker); 42 if (jElement != null && jElement.exists()) { 43 return fLastHandle; 46 } 47 return null; 48 } 49 50 private String getJavaElementHandleId(IMarker marker) { 51 try { 52 return (String )marker.getAttribute(IJavaSearchUIConstants.ATT_JE_HANDLE_ID); 53 } catch (CoreException ex) { 54 ExceptionHandler.handle(ex, SearchMessages.getString("Search.Error.markerAttributeAccess.title"), SearchMessages.getString("Search.Error.markerAttributeAccess.message")); return null; 56 } 57 } 58 59 private IJavaElement getJavaElement(IMarker marker) { 60 String handle= getJavaElementHandleId(marker); 61 if (handle == null) { 62 fLastHandle= null; 63 fLastJavaElement= null; 64 return null; 65 } 66 67 if (!handle.equals(fLastHandle)) { 68 fLastHandle= handle; 69 fLastJavaElement= SearchUtil.getJavaElement(marker); 70 IResource handleResource= null; 71 try { 72 if (fLastJavaElement != null) 73 handleResource= fLastJavaElement.getCorrespondingResource(); 74 } catch (JavaModelException ex) { 75 ExceptionHandler.handle(ex, SearchMessages.getString("Search.Error.javaElementAccess.title"), SearchMessages.getString("Search.Error.javaElementAccess.message")); } 78 if (fLastJavaElement != null && marker.getResource().equals(handleResource)) { 79 } 81 } 82 return fLastJavaElement; 83 } 84 } 85 | Popular Tags |