use of org.eclipse.jdt.core.search.SearchEngine in project che by eclipse.
the class RefactoringSearchEngine2 method searchReferencedMethods.
/**
* Performs the search of referenced methods.
*
* @param element the java element whose referenced methods have to be found
* @param monitor the progress monitor, or <code>null</code>
* @throws JavaModelException if an error occurs during search
*/
public final void searchReferencedMethods(final IJavaElement element, IProgressMonitor monitor) throws JavaModelException {
Assert.isNotNull(element);
if (monitor == null)
monitor = new NullProgressMonitor();
try {
//$NON-NLS-1$
monitor.beginTask("", 1);
monitor.setTaskName(RefactoringCoreMessages.RefactoringSearchEngine_searching_referenced_methods);
try {
SearchEngine engine = null;
if (fOwner != null)
engine = new SearchEngine(fOwner);
else
engine = new SearchEngine(fWorkingCopies);
engine.searchDeclarationsOfSentMessages(element, getCollector(), new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
} catch (CoreException exception) {
throw new JavaModelException(exception);
}
} finally {
monitor.done();
}
}
use of org.eclipse.jdt.core.search.SearchEngine in project che by eclipse.
the class ReferenceFinderUtil method getTypeReferencesIn.
private static List<SearchMatch> getTypeReferencesIn(IJavaElement element, WorkingCopyOwner owner, IProgressMonitor pm) throws JavaModelException {
CollectingSearchRequestor requestor = new CollectingSearchRequestor();
SearchEngine engine = owner != null ? new SearchEngine(owner) : new SearchEngine();
engine.searchDeclarationsOfReferencedTypes(element, requestor, pm);
return requestor.getResults();
}
use of org.eclipse.jdt.core.search.SearchEngine in project AutoRefactor by JnRouvignac.
the class SuperCallRatherThanUselessOverridingRefactoring method isMethodUsedInItsPackage.
/** This method is extremely expensive. */
@OnEclipseVersionUpgrade("Replace monitor.newChild(1) by monitor.split(1)")
private boolean isMethodUsedInItsPackage(IMethodBinding methodBinding, MethodDeclaration node) {
final IPackageBinding methodPackage = methodBinding.getDeclaringClass().getPackage();
final AtomicBoolean methodIsUsedInPackage = new AtomicBoolean(false);
final SearchRequestor requestor = new SearchRequestor() {
@Override
public void acceptSearchMatch(SearchMatch match) {
methodIsUsedInPackage.set(true);
}
};
final SubMonitor subMonitor = SubMonitor.convert(ctx.getProgressMonitor(), 1);
final SubMonitor childMonitor = subMonitor.newChild(1);
try {
final SearchEngine searchEngine = new SearchEngine();
searchEngine.search(createPattern(methodBinding.getJavaElement(), REFERENCES, R_EXACT_MATCH), new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, SearchEngine.createJavaSearchScope(new IJavaElement[] { methodPackage.getJavaElement() }), requestor, childMonitor);
return methodIsUsedInPackage.get();
} catch (CoreException e) {
throw new UnhandledException(node, e);
} finally {
childMonitor.done();
}
}
use of org.eclipse.jdt.core.search.SearchEngine in project che by eclipse.
the class ChangeSignatureProcessor method findOccurrences.
private SearchResultGroup[] findOccurrences(IProgressMonitor pm, ReferencesInBinaryContext binaryRefs, RefactoringStatus status) throws JavaModelException {
final boolean isConstructor = fMethod.isConstructor();
CuCollectingSearchRequestor requestor = new CuCollectingSearchRequestor(binaryRefs) {
@Override
protected void acceptSearchMatch(ICompilationUnit unit, SearchMatch match) throws CoreException {
// workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=27236 :
if (isConstructor && match instanceof MethodReferenceMatch) {
MethodReferenceMatch mrm = (MethodReferenceMatch) match;
if (mrm.isSynthetic()) {
return;
}
}
collectMatch(match);
}
};
SearchPattern pattern;
if (isConstructor) {
// // workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=226151 : don't find binary refs for constructors for now
// return ConstructorReferenceFinder.getConstructorOccurrences(fMethod, pm, status);
// SearchPattern occPattern= SearchPattern.createPattern(fMethod, IJavaSearchConstants.ALL_OCCURRENCES, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
SearchPattern declPattern = SearchPattern.createPattern(fMethod, IJavaSearchConstants.DECLARATIONS, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
SearchPattern refPattern = SearchPattern.createPattern(fMethod, IJavaSearchConstants.REFERENCES, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
// workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=226151 : do two searches
try {
SearchEngine engine = new SearchEngine();
engine.search(declPattern, SearchUtils.getDefaultSearchParticipants(), createRefactoringScope(), requestor, new NullProgressMonitor());
engine.search(refPattern, SearchUtils.getDefaultSearchParticipants(), createRefactoringScope(), requestor, pm);
} catch (CoreException e) {
throw new JavaModelException(e);
}
return RefactoringSearchEngine.groupByCu(requestor.getResults(), status);
} else {
pattern = RefactoringSearchEngine.createOrPattern(fRippleMethods, IJavaSearchConstants.ALL_OCCURRENCES);
}
return RefactoringSearchEngine.search(pattern, createRefactoringScope(), requestor, pm, status);
}
use of org.eclipse.jdt.core.search.SearchEngine in project che by eclipse.
the class ReferenceFinderUtil method getMethodReferencesIn.
private static List<SearchMatch> getMethodReferencesIn(IJavaElement element, WorkingCopyOwner owner, IProgressMonitor pm) throws JavaModelException {
CollectingSearchRequestor requestor = new CollectingSearchRequestor();
SearchEngine engine = owner != null ? new SearchEngine(owner) : new SearchEngine();
engine.searchDeclarationsOfSentMessages(element, requestor, pm);
return requestor.getResults();
}
Aggregations