Search in sources :

Example 1 with TypeOccurrenceCollector

use of org.eclipse.jdt.internal.corext.refactoring.rename.TypeOccurrenceCollector 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)

Aggregations

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