Search in sources :

Example 6 with SearchEngine

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();
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) JavaModelException(org.eclipse.jdt.core.JavaModelException) SearchEngine(org.eclipse.jdt.core.search.SearchEngine) CoreException(org.eclipse.core.runtime.CoreException) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 7 with SearchEngine

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();
}
Also used : SearchEngine(org.eclipse.jdt.core.search.SearchEngine) CollectingSearchRequestor(org.eclipse.jdt.internal.corext.refactoring.CollectingSearchRequestor)

Example 8 with SearchEngine

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();
    }
}
Also used : SearchRequestor(org.eclipse.jdt.core.search.SearchRequestor) UnhandledException(org.autorefactor.util.UnhandledException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IJavaElement(org.eclipse.jdt.core.IJavaElement) SearchMatch(org.eclipse.jdt.core.search.SearchMatch) SearchEngine(org.eclipse.jdt.core.search.SearchEngine) CoreException(org.eclipse.core.runtime.CoreException) SubMonitor(org.eclipse.core.runtime.SubMonitor) IPackageBinding(org.eclipse.jdt.core.dom.IPackageBinding) OnEclipseVersionUpgrade(org.autorefactor.util.OnEclipseVersionUpgrade)

Example 9 with SearchEngine

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);
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) SearchMatch(org.eclipse.jdt.core.search.SearchMatch) JavaModelException(org.eclipse.jdt.core.JavaModelException) MethodReferenceMatch(org.eclipse.jdt.core.search.MethodReferenceMatch) SearchEngine(org.eclipse.jdt.core.search.SearchEngine) RefactoringSearchEngine(org.eclipse.jdt.internal.corext.refactoring.RefactoringSearchEngine) CuCollectingSearchRequestor(org.eclipse.jdt.internal.corext.refactoring.CuCollectingSearchRequestor) CoreException(org.eclipse.core.runtime.CoreException) SearchPattern(org.eclipse.jdt.core.search.SearchPattern)

Example 10 with SearchEngine

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();
}
Also used : SearchEngine(org.eclipse.jdt.core.search.SearchEngine) CollectingSearchRequestor(org.eclipse.jdt.internal.corext.refactoring.CollectingSearchRequestor)

Aggregations

SearchEngine (org.eclipse.jdt.core.search.SearchEngine)21 CoreException (org.eclipse.core.runtime.CoreException)11 SearchMatch (org.eclipse.jdt.core.search.SearchMatch)10 SearchPattern (org.eclipse.jdt.core.search.SearchPattern)9 SearchRequestor (org.eclipse.jdt.core.search.SearchRequestor)8 ArrayList (java.util.ArrayList)7 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)7 JavaModelException (org.eclipse.jdt.core.JavaModelException)7 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)6 IJavaSearchScope (org.eclipse.jdt.core.search.IJavaSearchScope)5 IJavaElement (org.eclipse.jdt.core.IJavaElement)4 RefactoringSearchEngine (org.eclipse.jdt.internal.corext.refactoring.RefactoringSearchEngine)4 HashSet (java.util.HashSet)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)3 IType (org.eclipse.jdt.core.IType)3 TypeNameMatch (org.eclipse.jdt.core.search.TypeNameMatch)3 CollectingSearchRequestor (org.eclipse.jdt.internal.corext.refactoring.CollectingSearchRequestor)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 IMethod (org.eclipse.jdt.core.IMethod)2