Search in sources :

Example 1 with RefactoringSearchEngine2

use of org.eclipse.jdt.internal.corext.refactoring.RefactoringSearchEngine2 in project che by eclipse.

the class CreateCopyOfCompilationUnitChange method getReferences.

private static SearchResultGroup getReferences(final ICompilationUnit copy, IProgressMonitor monitor) throws JavaModelException {
    final ICompilationUnit[] copies = new ICompilationUnit[] { copy };
    IJavaSearchScope scope = SearchEngine.createJavaSearchScope(copies);
    final IType type = copy.findPrimaryType();
    if (type == null)
        return null;
    SearchPattern pattern = createSearchPattern(type);
    final RefactoringSearchEngine2 engine = new RefactoringSearchEngine2(pattern);
    engine.setScope(scope);
    engine.setWorkingCopies(copies);
    engine.setRequestor(new IRefactoringSearchRequestor() {

        TypeOccurrenceCollector fTypeOccurrenceCollector = new TypeOccurrenceCollector(type);

        public SearchMatch acceptSearchMatch(SearchMatch match) {
            try {
                return fTypeOccurrenceCollector.acceptSearchMatch2(copy, match);
            } catch (CoreException e) {
                JavaPlugin.log(e);
                return null;
            }
        }
    });
    engine.searchPattern(monitor);
    final Object[] results = engine.getResults();
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=106127)
    for (int index = 0; index < results.length; index++) {
        SearchResultGroup group = (SearchResultGroup) results[index];
        if (group.getCompilationUnit().equals(copy))
            return group;
    }
    return null;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) SearchMatch(org.eclipse.jdt.core.search.SearchMatch) SearchResultGroup(org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup) IType(org.eclipse.jdt.core.IType) IRefactoringSearchRequestor(org.eclipse.jdt.internal.corext.refactoring.IRefactoringSearchRequestor) CoreException(org.eclipse.core.runtime.CoreException) IJavaSearchScope(org.eclipse.jdt.core.search.IJavaSearchScope) SearchPattern(org.eclipse.jdt.core.search.SearchPattern) TypeOccurrenceCollector(org.eclipse.jdt.internal.corext.refactoring.rename.TypeOccurrenceCollector) RefactoringSearchEngine2(org.eclipse.jdt.internal.corext.refactoring.RefactoringSearchEngine2)

Example 2 with RefactoringSearchEngine2

use of org.eclipse.jdt.internal.corext.refactoring.RefactoringSearchEngine2 in project che by eclipse.

the class MemberVisibilityAdjustor method adjustVisibility.

/**
	 * Adjusts the visibilities of the referenced and referencing elements.
	 *
	 * @param monitor the progress monitor to use
	 * @throws JavaModelException if an error occurs during search
	 */
public final void adjustVisibility(final IProgressMonitor monitor) throws JavaModelException {
    try {
        //$NON-NLS-1$
        monitor.beginTask("", 7);
        monitor.setTaskName(RefactoringCoreMessages.MemberVisibilityAdjustor_checking);
        final RefactoringSearchEngine2 engine = new RefactoringSearchEngine2(SearchPattern.createPattern(fReferenced, IJavaSearchConstants.REFERENCES, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE));
        engine.setScope(fScope);
        engine.setStatus(fStatus);
        engine.setOwner(fOwner);
        if (fIncoming) {
            // check calls to the referenced (moved) element, adjust element
            // visibility if necessary.
            engine.searchPattern(new SubProgressMonitor(monitor, 1));
            adjustIncomingVisibility((SearchResultGroup[]) engine.getResults(), new SubProgressMonitor(monitor, 1));
            engine.clearResults();
            // of the type if they are accessed outside of the moved type
            if (fReferenced instanceof IType) {
                final IType type = (IType) fReferenced;
                adjustMemberVisibility(type, new SubProgressMonitor(monitor, 1));
            }
        }
        if (fOutgoing) {
            /*
				 * Search for the types, fields, and methods which
				 * are called/acted upon inside the referenced element (the one
				 * to be moved) and assure that they are also visible from
				 * within the referencing element (the destination type (or
				 * package if move to new type)).
				 */
            engine.searchReferencedTypes(fReferenced, new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
            engine.searchReferencedFields(fReferenced, new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
            engine.searchReferencedMethods(fReferenced, new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
            adjustOutgoingVisibility((SearchResultGroup[]) engine.getResults(), new SubProgressMonitor(monitor, 1));
        }
    } finally {
        monitor.done();
    }
}
Also used : SearchResultGroup(org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup) RefactoringSearchEngine2(org.eclipse.jdt.internal.corext.refactoring.RefactoringSearchEngine2) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IType(org.eclipse.jdt.core.IType)

Example 3 with RefactoringSearchEngine2

use of org.eclipse.jdt.internal.corext.refactoring.RefactoringSearchEngine2 in project che by eclipse.

the class IntroduceFactoryRefactoring method findNonPrimaryType.

private IType findNonPrimaryType(String fullyQualifiedName, IProgressMonitor pm, RefactoringStatus status) throws JavaModelException {
    SearchPattern p = SearchPattern.createPattern(fullyQualifiedName, IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
    final RefactoringSearchEngine2 engine = new RefactoringSearchEngine2(p);
    engine.setFiltering(true, true);
    engine.setScope(RefactoringScopeFactory.create(fCtorBinding.getJavaElement().getJavaProject()));
    engine.setStatus(status);
    engine.searchPattern(new SubProgressMonitor(pm, 1));
    SearchResultGroup[] groups = (SearchResultGroup[]) engine.getResults();
    if (groups.length != 0) {
        for (int i = 0; i < groups.length; i++) {
            SearchMatch[] matches = groups[i].getSearchResults();
            for (int j = 0; j < matches.length; j++) {
                if (matches[j].getAccuracy() == SearchMatch.A_ACCURATE)
                    return (IType) matches[j].getElement();
            }
        }
    }
    return null;
}
Also used : SearchMatch(org.eclipse.jdt.core.search.SearchMatch) SearchPattern(org.eclipse.jdt.core.search.SearchPattern) SearchResultGroup(org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup) RefactoringSearchEngine2(org.eclipse.jdt.internal.corext.refactoring.RefactoringSearchEngine2) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 4 with RefactoringSearchEngine2

use of org.eclipse.jdt.internal.corext.refactoring.RefactoringSearchEngine2 in project che by eclipse.

the class IntroduceFactoryRefactoring method searchForCallsTo.

/**
	 * Search for all calls to the given <code>IMethodBinding</code> in the project
	 * that contains the compilation unit <code>fCUHandle</code>.
	 * @param methodBinding
	 * @param pm
	 * @param status
	 * @return an array of <code>SearchResultGroup</code>'s that identify the search matches
	 * @throws JavaModelException
	 */
private SearchResultGroup[] searchForCallsTo(IMethodBinding methodBinding, IProgressMonitor pm, RefactoringStatus status) throws JavaModelException {
    IMethod method = (IMethod) methodBinding.getJavaElement();
    final RefactoringSearchEngine2 engine = new RefactoringSearchEngine2(createSearchPattern(method, methodBinding));
    engine.setFiltering(true, true);
    engine.setScope(createSearchScope(method, methodBinding));
    engine.setStatus(status);
    engine.searchPattern(new SubProgressMonitor(pm, 1));
    return (SearchResultGroup[]) engine.getResults();
}
Also used : IMethod(org.eclipse.jdt.core.IMethod) RefactoringSearchEngine2(org.eclipse.jdt.internal.corext.refactoring.RefactoringSearchEngine2) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 5 with RefactoringSearchEngine2

use of org.eclipse.jdt.internal.corext.refactoring.RefactoringSearchEngine2 in project che by eclipse.

the class InlineConstantRefactoring method findReferences.

private SearchResultGroup[] findReferences(IProgressMonitor pm, RefactoringStatus status) throws JavaModelException {
    final RefactoringSearchEngine2 engine = new RefactoringSearchEngine2(SearchPattern.createPattern(fField, IJavaSearchConstants.REFERENCES));
    engine.setFiltering(true, true);
    engine.setScope(RefactoringScopeFactory.create(fField));
    engine.setStatus(status);
    engine.setRequestor(new IRefactoringSearchRequestor() {

        public SearchMatch acceptSearchMatch(SearchMatch match) {
            return match.isInsideDocComment() ? null : match;
        }
    });
    engine.searchPattern(new SubProgressMonitor(pm, 1));
    return (SearchResultGroup[]) engine.getResults();
}
Also used : IRefactoringSearchRequestor(org.eclipse.jdt.internal.corext.refactoring.IRefactoringSearchRequestor) SearchMatch(org.eclipse.jdt.core.search.SearchMatch) RefactoringSearchEngine2(org.eclipse.jdt.internal.corext.refactoring.RefactoringSearchEngine2) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Aggregations

RefactoringSearchEngine2 (org.eclipse.jdt.internal.corext.refactoring.RefactoringSearchEngine2)6 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)5 SearchMatch (org.eclipse.jdt.core.search.SearchMatch)3 SearchResultGroup (org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup)3 IType (org.eclipse.jdt.core.IType)2 SearchPattern (org.eclipse.jdt.core.search.SearchPattern)2 IRefactoringSearchRequestor (org.eclipse.jdt.internal.corext.refactoring.IRefactoringSearchRequestor)2 CoreException (org.eclipse.core.runtime.CoreException)1 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1 IMethod (org.eclipse.jdt.core.IMethod)1 IJavaSearchScope (org.eclipse.jdt.core.search.IJavaSearchScope)1 TypeOccurrenceCollector (org.eclipse.jdt.internal.corext.refactoring.rename.TypeOccurrenceCollector)1