Search in sources :

Example 16 with SearchResultGroup

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

the class RenameAnalyzeUtil method analyzeRenameChanges.

static RefactoringStatus analyzeRenameChanges(TextChangeManager manager, SearchResultGroup[] oldOccurrences, SearchResultGroup[] newOccurrences) {
    RefactoringStatus result = new RefactoringStatus();
    for (int i = 0; i < oldOccurrences.length; i++) {
        SearchResultGroup oldGroup = oldOccurrences[i];
        SearchMatch[] oldSearchResults = oldGroup.getSearchResults();
        ICompilationUnit cunit = oldGroup.getCompilationUnit();
        if (cunit == null)
            continue;
        for (int j = 0; j < oldSearchResults.length; j++) {
            SearchMatch oldSearchResult = oldSearchResults[j];
            if (!RenameAnalyzeUtil.existsInNewOccurrences(oldSearchResult, newOccurrences, manager)) {
                addShadowsError(cunit, oldSearchResult, result);
            }
        }
    }
    return result;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) SearchMatch(org.eclipse.jdt.core.search.SearchMatch) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) SearchResultGroup(org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup)

Example 17 with SearchResultGroup

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

the class RenameAnalyzeUtil method analyzeRenameChanges2.

//--- find missing changes in BOTH directions
//TODO: Currently filters out declarations (MethodDeclarationMatch, FieldDeclarationMatch).
//Long term solution: only pass reference search results in.
static RefactoringStatus analyzeRenameChanges2(TextChangeManager manager, SearchResultGroup[] oldReferences, SearchResultGroup[] newReferences, String newElementName) {
    RefactoringStatus result = new RefactoringStatus();
    HashMap<ICompilationUnit, SearchMatch[]> cuToNewResults = new HashMap<ICompilationUnit, SearchMatch[]>(newReferences.length);
    for (int i1 = 0; i1 < newReferences.length; i1++) {
        ICompilationUnit cu = newReferences[i1].getCompilationUnit();
        if (cu != null)
            cuToNewResults.put(cu.getPrimary(), newReferences[i1].getSearchResults());
    }
    for (int i = 0; i < oldReferences.length; i++) {
        SearchResultGroup oldGroup = oldReferences[i];
        SearchMatch[] oldMatches = oldGroup.getSearchResults();
        ICompilationUnit cu = oldGroup.getCompilationUnit();
        if (cu == null)
            continue;
        SearchMatch[] newSearchMatches = cuToNewResults.remove(cu);
        if (newSearchMatches == null) {
            for (int j = 0; j < oldMatches.length; j++) {
                SearchMatch oldMatch = oldMatches[j];
                addShadowsError(cu, oldMatch, result);
            }
        } else {
            analyzeChanges(cu, manager.get(cu), oldMatches, newSearchMatches, newElementName, result);
        }
    }
    for (Iterator<Entry<ICompilationUnit, SearchMatch[]>> iter = cuToNewResults.entrySet().iterator(); iter.hasNext(); ) {
        Entry<ICompilationUnit, SearchMatch[]> entry = iter.next();
        ICompilationUnit cu = entry.getKey();
        SearchMatch[] newSearchMatches = entry.getValue();
        for (int i = 0; i < newSearchMatches.length; i++) {
            SearchMatch newMatch = newSearchMatches[i];
            addReferenceShadowedError(cu, newMatch, newElementName, result);
        }
    }
    return result;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) SearchMatch(org.eclipse.jdt.core.search.SearchMatch) RefactoringStatusEntry(org.eclipse.ltk.core.refactoring.RefactoringStatusEntry) Entry(java.util.Map.Entry) HashMap(java.util.HashMap) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) SearchResultGroup(org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup)

Example 18 with SearchResultGroup

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

the class RenameFieldProcessor method analyzeRenameChanges.

//----------------
private RefactoringStatus analyzeRenameChanges(IProgressMonitor pm) throws CoreException {
    ICompilationUnit[] newWorkingCopies = null;
    WorkingCopyOwner newWCOwner = new WorkingCopyOwner() {
    };
    try {
        //$NON-NLS-1$
        pm.beginTask("", 2);
        RefactoringStatus result = new RefactoringStatus();
        SearchResultGroup[] oldReferences = fReferences;
        List<ICompilationUnit> compilationUnitsToModify = new ArrayList<ICompilationUnit>();
        if (fIsComposite) {
            // limited change set, no accessors.
            for (int i = 0; i < oldReferences.length; i++) compilationUnitsToModify.add(oldReferences[i].getCompilationUnit());
            compilationUnitsToModify.add(fField.getCompilationUnit());
        } else {
            // include all cus, including accessors
            compilationUnitsToModify.addAll(Arrays.asList(fChangeManager.getAllCompilationUnits()));
        }
        newWorkingCopies = RenameAnalyzeUtil.createNewWorkingCopies(compilationUnitsToModify.toArray(new ICompilationUnit[compilationUnitsToModify.size()]), fChangeManager, newWCOwner, new SubProgressMonitor(pm, 1));
        SearchResultGroup[] newReferences = getNewReferences(new SubProgressMonitor(pm, 1), result, newWCOwner, newWorkingCopies);
        result.merge(RenameAnalyzeUtil.analyzeRenameChanges2(fChangeManager, oldReferences, newReferences, getNewElementName()));
        return result;
    } finally {
        pm.done();
        if (newWorkingCopies != null) {
            for (int i = 0; i < newWorkingCopies.length; i++) {
                newWorkingCopies[i].discardWorkingCopy();
            }
        }
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) WorkingCopyOwner(org.eclipse.jdt.core.WorkingCopyOwner) ArrayList(java.util.ArrayList) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) SearchResultGroup(org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 19 with SearchResultGroup

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

the class RenameNonVirtualMethodProcessor method addReferenceUpdates.

private void addReferenceUpdates(TextChangeManager manager, IProgressMonitor pm) {
    SearchResultGroup[] grouped = getOccurrences();
    for (int i = 0; i < grouped.length; i++) {
        SearchResultGroup group = grouped[i];
        SearchMatch[] results = group.getSearchResults();
        ICompilationUnit cu = group.getCompilationUnit();
        TextChange change = manager.get(cu);
        for (int j = 0; j < results.length; j++) {
            SearchMatch match = results[j];
            if (!(match instanceof MethodDeclarationMatch)) {
                ReplaceEdit replaceEdit = createReplaceEdit(match, cu);
                String editName = RefactoringCoreMessages.RenamePrivateMethodRefactoring_update;
                addTextEdit(change, editName, replaceEdit);
            }
        }
    }
    pm.done();
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) SearchMatch(org.eclipse.jdt.core.search.SearchMatch) ReplaceEdit(org.eclipse.text.edits.ReplaceEdit) TextChange(org.eclipse.ltk.core.refactoring.TextChange) SearchResultGroup(org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup) MethodDeclarationMatch(org.eclipse.jdt.core.search.MethodDeclarationMatch)

Example 20 with SearchResultGroup

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

Aggregations

SearchResultGroup (org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup)23 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)15 SearchMatch (org.eclipse.jdt.core.search.SearchMatch)12 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)8 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)7 ArrayList (java.util.ArrayList)6 SearchPattern (org.eclipse.jdt.core.search.SearchPattern)6 IJavaSearchScope (org.eclipse.jdt.core.search.IJavaSearchScope)5 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)4 IType (org.eclipse.jdt.core.IType)4 ReplaceEdit (org.eclipse.text.edits.ReplaceEdit)4 HashSet (java.util.HashSet)3 RefactoringSearchEngine2 (org.eclipse.jdt.internal.corext.refactoring.RefactoringSearchEngine2)3 TextChange (org.eclipse.ltk.core.refactoring.TextChange)3 HashMap (java.util.HashMap)2 CoreException (org.eclipse.core.runtime.CoreException)2 IMethod (org.eclipse.jdt.core.IMethod)2 ASTNode (org.eclipse.jdt.core.dom.ASTNode)2 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)2 CompilationUnitChange (org.eclipse.jdt.core.refactoring.CompilationUnitChange)2