1 11 package org.eclipse.jdt.internal.ui.packageview; 12 13 import org.eclipse.jface.viewers.IElementComparer; 14 15 import org.eclipse.jdt.core.ICompilationUnit; 16 import org.eclipse.jdt.core.IJavaElement; 17 18 class PackageExplorerElementComparer implements IElementComparer { 19 20 public boolean equals(Object o1, Object o2) { 21 if (o1 == o2) return true; 23 if (o1 == null) 24 return false; if (o1.equals(o2)) 26 return true; 27 IJavaElement j1= (o1 instanceof IJavaElement) ? (IJavaElement)o1 : null; 28 IJavaElement j2= (o2 instanceof IJavaElement) ? (IJavaElement)o2 : null; 29 if (j1 == null || j2 == null) 30 return false; 31 ICompilationUnit c1= (ICompilationUnit)j1.getAncestor(IJavaElement.COMPILATION_UNIT); 32 ICompilationUnit c2= (ICompilationUnit)j2.getAncestor(IJavaElement.COMPILATION_UNIT); 33 if (c1 == null || c2 == null) 34 return false; 35 if (c1.isWorkingCopy() && c2.isWorkingCopy() || !c1.isWorkingCopy() && !c2.isWorkingCopy()) 36 return false; 37 if (c1.isWorkingCopy()) { 39 j1= c1.getOriginal(j1); 40 } else if (c2.isWorkingCopy()) { 41 j2= c2.getOriginal(j2); 42 } 43 if (j1 == null || j2 == null) 44 return false; 45 return j1.equals(j2); 46 } 47 48 public int hashCode(Object o1) { 49 IJavaElement j1= (o1 instanceof IJavaElement) ? (IJavaElement)o1 : null; 50 if (j1 == null) 51 return o1.hashCode(); 52 ICompilationUnit c1= (ICompilationUnit)j1.getAncestor(IJavaElement.COMPILATION_UNIT); 53 if (c1 == null || !c1.isWorkingCopy()) 54 return o1.hashCode(); 55 j1= c1.getOriginal(j1); 57 if (j1 == null) 58 return o1.hashCode(); 59 return j1.hashCode(); 60 } 61 } 62 | Popular Tags |