Search in sources :

Example 21 with SearchResultGroup

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

the class RenameMethodProcessor method analyzeRenameChanges.

//-------
private RefactoringStatus analyzeRenameChanges(IProgressMonitor pm) throws CoreException {
    ICompilationUnit[] newDeclarationWCs = null;
    try {
        //$NON-NLS-1$
        pm.beginTask("", 4);
        RefactoringStatus result = new RefactoringStatus();
        ICompilationUnit[] declarationCUs = getDeclarationCUs();
        newDeclarationWCs = RenameAnalyzeUtil.createNewWorkingCopies(declarationCUs, fChangeManager, fWorkingCopyOwner, new SubProgressMonitor(pm, 1));
        IMethod[] wcOldMethods = new IMethod[fMethodsToRename.size()];
        IMethod[] wcNewMethods = new IMethod[fMethodsToRename.size()];
        int i = 0;
        for (Iterator<IMethod> iter = fMethodsToRename.iterator(); iter.hasNext(); i++) {
            IMethod method = iter.next();
            ICompilationUnit newCu = RenameAnalyzeUtil.findWorkingCopyForCu(newDeclarationWCs, method.getCompilationUnit());
            IType typeWc = (IType) JavaModelUtil.findInCompilationUnit(newCu, method.getDeclaringType());
            if (typeWc == null) {
                // should not happen
                i--;
                wcOldMethods = CollectionsUtil.toArray(Arrays.asList(wcOldMethods).subList(0, wcOldMethods.length - 1), IMethod.class);
                wcNewMethods = CollectionsUtil.toArray(Arrays.asList(wcNewMethods).subList(0, wcNewMethods.length - 1), IMethod.class);
                continue;
            }
            wcOldMethods[i] = getMethodInWorkingCopy(method, getCurrentElementName(), typeWc);
            wcNewMethods[i] = getMethodInWorkingCopy(method, getNewElementName(), typeWc);
        }
        //			SearchResultGroup[] newOccurrences= findNewOccurrences(newMethods, newDeclarationWCs, new SubProgressMonitor(pm, 3));
        SearchResultGroup[] newOccurrences = batchFindNewOccurrences(wcNewMethods, wcOldMethods, newDeclarationWCs, new SubProgressMonitor(pm, 3), result);
        result.merge(RenameAnalyzeUtil.analyzeRenameChanges2(fChangeManager, fOccurrences, newOccurrences, getNewElementName()));
        return result;
    } finally {
        pm.done();
        if (newDeclarationWCs != null) {
            for (int i = 0; i < newDeclarationWCs.length; i++) {
                newDeclarationWCs[i].discardWorkingCopy();
            }
        }
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) SearchResultGroup(org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup) IMethod(org.eclipse.jdt.core.IMethod) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IType(org.eclipse.jdt.core.IType)

Example 22 with SearchResultGroup

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

the class MoveCuUpdateCreator method getReferences.

private static SearchResultGroup[] getReferences(ICompilationUnit unit, IProgressMonitor pm, RefactoringStatus status) throws CoreException {
    final SearchPattern pattern = RefactoringSearchEngine.createOrPattern(unit.getTypes(), IJavaSearchConstants.REFERENCES);
    if (pattern != null) {
        String binaryRefsDescription = Messages.format(RefactoringCoreMessages.ReferencesInBinaryContext_ref_in_binaries_description, BasicElementLabels.getFileName(unit));
        ReferencesInBinaryContext binaryRefs = new ReferencesInBinaryContext(binaryRefsDescription);
        Collector requestor = new Collector(((IPackageFragment) unit.getParent()), binaryRefs);
        IJavaSearchScope scope = RefactoringScopeFactory.create(unit, true, false);
        SearchResultGroup[] result = RefactoringSearchEngine.search(pattern, scope, requestor, new SubProgressMonitor(pm, 1), status);
        binaryRefs.addErrorIfNecessary(status);
        return result;
    }
    return new SearchResultGroup[] {};
}
Also used : ReferencesInBinaryContext(org.eclipse.jdt.internal.corext.refactoring.base.ReferencesInBinaryContext) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IJavaSearchScope(org.eclipse.jdt.core.search.IJavaSearchScope) SearchPattern(org.eclipse.jdt.core.search.SearchPattern) SearchResultGroup(org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 23 with SearchResultGroup

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

the class IntroduceFactoryRefactoring method excludeBinaryUnits.

/**
	 * @param groups
	 * @return an array of <code>SearchResultGroup</code>'s like the argument,
	 * but omitting those groups that have no corresponding compilation unit
	 * (i.e. are binary and therefore can't be modified).
	 */
private SearchResultGroup[] excludeBinaryUnits(SearchResultGroup[] groups) {
    Collection<SearchResultGroup> result = new ArrayList<SearchResultGroup>();
    for (int i = 0; i < groups.length; i++) {
        SearchResultGroup rg = groups[i];
        ICompilationUnit unit = rg.getCompilationUnit();
        if (// ignore hits within a binary unit
        unit != null)
            result.add(rg);
        else
            fCallSitesInBinaryUnits = true;
    }
    return result.toArray(new SearchResultGroup[result.size()]);
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) ArrayList(java.util.ArrayList) 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