Search in sources :

Example 26 with SearchMatch

use of org.eclipse.jdt.core.search.SearchMatch in project che by eclipse.

the class RenameFieldProcessor method addReferenceUpdates.

private void addReferenceUpdates(IProgressMonitor pm) {
    //$NON-NLS-1$
    pm.beginTask("", fReferences.length);
    String editName = RefactoringCoreMessages.RenameFieldRefactoring_Update_field_reference;
    for (int i = 0; i < fReferences.length; i++) {
        ICompilationUnit cu = fReferences[i].getCompilationUnit();
        if (cu == null)
            continue;
        SearchMatch[] results = fReferences[i].getSearchResults();
        for (int j = 0; j < results.length; j++) {
            addTextEdit(fChangeManager.get(cu), editName, createTextChange(results[j]));
        }
        pm.worked(1);
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) SearchMatch(org.eclipse.jdt.core.search.SearchMatch)

Example 27 with SearchMatch

use of org.eclipse.jdt.core.search.SearchMatch in project che by eclipse.

the class RenameFieldProcessor method addAccessorOccurrences.

private void addAccessorOccurrences(IProgressMonitor pm, IMethod accessor, String editName, String newAccessorName, RefactoringStatus status) throws CoreException {
    Assert.isTrue(accessor.exists());
    IJavaSearchScope scope = RefactoringScopeFactory.create(accessor);
    SearchPattern pattern = SearchPattern.createPattern(accessor, IJavaSearchConstants.ALL_OCCURRENCES, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
    SearchResultGroup[] groupedResults = RefactoringSearchEngine.search(pattern, scope, new MethodOccurenceCollector(accessor.getElementName()), pm, status);
    for (int i = 0; i < groupedResults.length; i++) {
        ICompilationUnit cu = groupedResults[i].getCompilationUnit();
        if (cu == null)
            continue;
        SearchMatch[] results = groupedResults[i].getSearchResults();
        for (int j = 0; j < results.length; j++) {
            SearchMatch searchResult = results[j];
            TextEdit edit = new ReplaceEdit(searchResult.getOffset(), searchResult.getLength(), newAccessorName);
            addTextEdit(fChangeManager.get(cu), editName, edit);
        }
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) SearchMatch(org.eclipse.jdt.core.search.SearchMatch) IJavaSearchScope(org.eclipse.jdt.core.search.IJavaSearchScope) TextEdit(org.eclipse.text.edits.TextEdit) SearchPattern(org.eclipse.jdt.core.search.SearchPattern) ReplaceEdit(org.eclipse.text.edits.ReplaceEdit) SearchResultGroup(org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup)

Example 28 with SearchMatch

use of org.eclipse.jdt.core.search.SearchMatch in project che by eclipse.

the class RenameMethodProcessor method searchForOuterTypesOfReferences.

private IType[] searchForOuterTypesOfReferences(IMethod[] newNameMethods, IProgressMonitor pm) throws CoreException {
    final Set<IType> outerTypesOfReferences = new HashSet<IType>();
    SearchPattern pattern = RefactoringSearchEngine.createOrPattern(newNameMethods, IJavaSearchConstants.REFERENCES);
    IJavaSearchScope scope = createRefactoringScope(getMethod());
    SearchRequestor requestor = new SearchRequestor() {

        @Override
        public void acceptSearchMatch(SearchMatch match) throws CoreException {
            Object element = match.getElement();
            if (!(element instanceof IMember))
                // e.g. an IImportDeclaration for a static method import
                return;
            IMember member = (IMember) element;
            IType declaring = member.getDeclaringType();
            if (declaring == null)
                return;
            IType outer = declaring.getDeclaringType();
            if (outer != null)
                outerTypesOfReferences.add(declaring);
        }
    };
    new SearchEngine().search(pattern, SearchUtils.getDefaultSearchParticipants(), scope, requestor, pm);
    return outerTypesOfReferences.toArray(new IType[outerTypesOfReferences.size()]);
}
Also used : SearchRequestor(org.eclipse.jdt.core.search.SearchRequestor) SearchMatch(org.eclipse.jdt.core.search.SearchMatch) SearchEngine(org.eclipse.jdt.core.search.SearchEngine) RefactoringSearchEngine(org.eclipse.jdt.internal.corext.refactoring.RefactoringSearchEngine) IJavaSearchScope(org.eclipse.jdt.core.search.IJavaSearchScope) SearchPattern(org.eclipse.jdt.core.search.SearchPattern) IMember(org.eclipse.jdt.core.IMember) HashSet(java.util.HashSet) IType(org.eclipse.jdt.core.IType)

Example 29 with SearchMatch

use of org.eclipse.jdt.core.search.SearchMatch in project che by eclipse.

the class RippleMethodFinder2 method findAllDeclarations.

private void findAllDeclarations(IProgressMonitor monitor, WorkingCopyOwner owner) throws CoreException {
    fDeclarations = new ArrayList<IMethod>();
    class MethodRequestor extends SearchRequestor {

        @Override
        public void acceptSearchMatch(SearchMatch match) throws CoreException {
            IMethod method = (IMethod) match.getElement();
            boolean isBinary = method.isBinary();
            if (fBinaryRefs != null || !(fExcludeBinaries && isBinary)) {
                fDeclarations.add(method);
            }
            if (isBinary && fBinaryRefs != null) {
                fDeclarationToMatch.put(method, match);
            }
        }
    }
    int limitTo = IJavaSearchConstants.DECLARATIONS | IJavaSearchConstants.IGNORE_DECLARING_TYPE | IJavaSearchConstants.IGNORE_RETURN_TYPE;
    int matchRule = SearchPattern.R_ERASURE_MATCH | SearchPattern.R_CASE_SENSITIVE;
    SearchPattern pattern = SearchPattern.createPattern(fMethod, limitTo, matchRule);
    SearchParticipant[] participants = SearchUtils.getDefaultSearchParticipants();
    IJavaSearchScope scope = RefactoringScopeFactory.createRelatedProjectsScope(fMethod.getJavaProject(), IJavaSearchScope.SOURCES | IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SYSTEM_LIBRARIES);
    MethodRequestor requestor = new MethodRequestor();
    SearchEngine searchEngine = owner != null ? new SearchEngine(owner) : new SearchEngine();
    searchEngine.search(pattern, participants, scope, requestor, monitor);
}
Also used : SearchRequestor(org.eclipse.jdt.core.search.SearchRequestor) SearchMatch(org.eclipse.jdt.core.search.SearchMatch) SearchEngine(org.eclipse.jdt.core.search.SearchEngine) IJavaSearchScope(org.eclipse.jdt.core.search.IJavaSearchScope) SearchPattern(org.eclipse.jdt.core.search.SearchPattern) IMethod(org.eclipse.jdt.core.IMethod) SearchParticipant(org.eclipse.jdt.core.search.SearchParticipant)

Example 30 with SearchMatch

use of org.eclipse.jdt.core.search.SearchMatch in project che by eclipse.

the class RenameTypeProcessor method addReferenceUpdates.

private void addReferenceUpdates(TextChangeManager manager, IProgressMonitor pm) {
    //$NON-NLS-1$
    pm.beginTask("", fReferences.length);
    for (int i = 0; i < fReferences.length; i++) {
        ICompilationUnit cu = fReferences[i].getCompilationUnit();
        if (cu == null)
            continue;
        String name = RefactoringCoreMessages.RenameTypeRefactoring_update_reference;
        SearchMatch[] results = fReferences[i].getSearchResults();
        for (int j = 0; j < results.length; j++) {
            SearchMatch match = results[j];
            ReplaceEdit replaceEdit = new ReplaceEdit(match.getOffset(), match.getLength(), getNewElementName());
            TextChangeCompatibility.addTextEdit(manager.get(cu), name, replaceEdit, CATEGORY_TYPE_RENAME);
        }
        pm.worked(1);
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) SearchMatch(org.eclipse.jdt.core.search.SearchMatch) ReplaceEdit(org.eclipse.text.edits.ReplaceEdit)

Aggregations

SearchMatch (org.eclipse.jdt.core.search.SearchMatch)35 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)16 SearchPattern (org.eclipse.jdt.core.search.SearchPattern)13 SearchResultGroup (org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup)12 SearchEngine (org.eclipse.jdt.core.search.SearchEngine)10 ArrayList (java.util.ArrayList)8 CoreException (org.eclipse.core.runtime.CoreException)8 IJavaSearchScope (org.eclipse.jdt.core.search.IJavaSearchScope)8 SearchRequestor (org.eclipse.jdt.core.search.SearchRequestor)8 IJavaElement (org.eclipse.jdt.core.IJavaElement)7 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)5 ReplaceEdit (org.eclipse.text.edits.ReplaceEdit)5 HashMap (java.util.HashMap)4 IResource (org.eclipse.core.resources.IResource)4 IMethod (org.eclipse.jdt.core.IMethod)4 RefactoringSearchEngine (org.eclipse.jdt.internal.corext.refactoring.RefactoringSearchEngine)4 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)4 HashSet (java.util.HashSet)3 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)3 IType (org.eclipse.jdt.core.IType)3