1 12 package org.eclipse.jdt.internal.corext.callhierarchy; 13 14 import java.util.Arrays ; 15 import java.util.Comparator ; 16 import java.util.HashMap ; 17 import java.util.Map ; 18 19 import org.eclipse.core.runtime.IProgressMonitor; 20 21 import org.eclipse.jdt.core.IJavaElement; 22 import org.eclipse.jdt.core.IMethod; 23 import org.eclipse.jdt.core.dom.CompilationUnit; 24 25 class CalleeMethodWrapper extends MethodWrapper { 26 private Comparator fMethodWrapperComparator = new MethodWrapperComparator(); 27 28 private static class MethodWrapperComparator implements Comparator { 29 32 public int compare(Object o1, Object o2) { 33 MethodWrapper m1 = (MethodWrapper) o1; 34 MethodWrapper m2 = (MethodWrapper) o2; 35 36 CallLocation callLocation1 = m1.getMethodCall().getFirstCallLocation(); 37 CallLocation callLocation2 = m2.getMethodCall().getFirstCallLocation(); 38 39 if ((callLocation1 != null) && (callLocation2 != null)) { 40 if (callLocation1.getStart() == callLocation2.getStart()) { 41 return callLocation1.getEnd() - callLocation2.getEnd(); 42 } 43 44 return callLocation1.getStart() - callLocation2.getStart(); 45 } 46 47 return 0; 48 } 49 } 50 51 54 public CalleeMethodWrapper(MethodWrapper parent, MethodCall methodCall) { 55 super(parent, methodCall); 56 } 57 58 61 public MethodWrapper[] getCalls(IProgressMonitor progressMonitor) { 62 MethodWrapper[] result = super.getCalls(progressMonitor); 63 Arrays.sort(result, fMethodWrapperComparator); 64 65 return result; 66 } 67 68 71 protected String getTaskName() { 72 return CallHierarchyMessages.CalleeMethodWrapper_taskname; 73 } 74 75 78 protected MethodWrapper createMethodWrapper(MethodCall methodCall) { 79 return new CalleeMethodWrapper(this, methodCall); 80 } 81 82 86 protected Map findChildren(IProgressMonitor progressMonitor) { 87 if (getMember().exists() && getMember().getElementType() == IJavaElement.METHOD) { 88 CompilationUnit cu= CallHierarchy.getCompilationUnitNode(getMember(), true); 89 if (progressMonitor != null) { 90 progressMonitor.worked(5); 91 } 92 93 if (cu != null) { 94 CalleeAnalyzerVisitor visitor = new CalleeAnalyzerVisitor((IMethod) getMember(), 95 cu, progressMonitor); 96 97 cu.accept(visitor); 98 return visitor.getCallees(); 99 } 100 } 101 return new HashMap (0); 102 } 103 } 104 | Popular Tags |