1 12 package org.eclipse.jdt.internal.corext.callhierarchy; 13 14 import java.util.ArrayList ; 15 import java.util.Collection ; 16 import java.util.HashMap ; 17 import java.util.Iterator ; 18 import java.util.Map ; 19 20 import org.eclipse.core.runtime.CoreException; 21 import org.eclipse.core.runtime.IProgressMonitor; 22 import org.eclipse.core.runtime.SubProgressMonitor; 23 24 import org.eclipse.jdt.core.IJavaElement; 25 import org.eclipse.jdt.core.IMember; 26 import org.eclipse.jdt.core.JavaModelException; 27 import org.eclipse.jdt.core.search.IJavaSearchConstants; 28 import org.eclipse.jdt.core.search.IJavaSearchScope; 29 import org.eclipse.jdt.core.search.SearchEngine; 30 import org.eclipse.jdt.core.search.SearchParticipant; 31 import org.eclipse.jdt.core.search.SearchPattern; 32 33 import org.eclipse.jdt.internal.corext.util.JdtFlags; 34 import org.eclipse.jdt.internal.corext.util.SearchUtils; 35 36 import org.eclipse.jdt.internal.ui.JavaPlugin; 37 38 class CallerMethodWrapper extends MethodWrapper { 39 public CallerMethodWrapper(MethodWrapper parent, MethodCall methodCall) { 40 super(parent, methodCall); 41 } 42 43 protected IJavaSearchScope getSearchScope() { 44 return CallHierarchy.getDefault().getSearchScope(); 45 } 46 47 protected String getTaskName() { 48 return CallHierarchyMessages.CallerMethodWrapper_taskname; 49 } 50 51 54 protected MethodWrapper createMethodWrapper(MethodCall methodCall) { 55 return new CallerMethodWrapper(this, methodCall); 56 } 57 58 62 protected Map findChildren(IProgressMonitor progressMonitor) { 63 try { 64 MethodReferencesSearchRequestor searchRequestor= new MethodReferencesSearchRequestor(); 65 SearchEngine searchEngine= new SearchEngine(); 66 67 IProgressMonitor monitor= new SubProgressMonitor(progressMonitor, 95, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL); 68 IJavaSearchScope defaultSearchScope= getSearchScope(); 69 boolean isWorkspaceScope= SearchEngine.createWorkspaceScope().equals(defaultSearchScope); 70 71 for (Iterator iter= getMembers().iterator(); iter.hasNext();) { 72 checkCanceled(progressMonitor); 73 74 IMember member= (IMember) iter.next(); 75 SearchPattern pattern= SearchPattern.createPattern(member, IJavaSearchConstants.REFERENCES, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE); 76 IJavaSearchScope searchScope= isWorkspaceScope ? getAccurateSearchScope(defaultSearchScope, member) : defaultSearchScope; 77 searchEngine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, searchScope, searchRequestor, 78 monitor); 79 } 80 return searchRequestor.getCallers(); 81 82 } catch (CoreException e) { 83 JavaPlugin.log(e); 84 return new HashMap (0); 85 } 86 } 87 88 private IJavaSearchScope getAccurateSearchScope(IJavaSearchScope defaultSearchScope, IMember member) throws JavaModelException { 89 if (! JdtFlags.isPrivate(member)) 90 return defaultSearchScope; 91 92 if (member.getCompilationUnit() != null) { 93 return SearchEngine.createJavaSearchScope(new IJavaElement[] { member.getCompilationUnit() }); 94 } else if (member.getClassFile() != null) { 95 return SearchEngine.createJavaSearchScope(new IJavaElement[] { member.getAncestor(IJavaElement.PACKAGE_FRAGMENT) }); 98 } else { 99 return defaultSearchScope; 100 } 101 } 102 103 106 private Collection getMembers() { 107 Collection result = new ArrayList (); 108 109 result.add(getMember()); 110 111 return result; 112 } 113 } 114 | Popular Tags |