Search in sources :

Example 21 with SearchMatch

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

the class SearchResultGroup method toString.

@Override
public String toString() {
    StringBuffer buf = new StringBuffer(fResouce.getFullPath().toString());
    buf.append('\n');
    for (int i = 0; i < fSearchMatches.size(); i++) {
        SearchMatch match = fSearchMatches.get(i);
        //$NON-NLS-1$//$NON-NLS-2$
        buf.append("  ").append(match.getOffset()).append(", ").append(match.getLength());
        //$NON-NLS-1$//$NON-NLS-2$
        buf.append(match.getAccuracy() == SearchMatch.A_ACCURATE ? "; acc" : "; inacc");
        if (match.isInsideDocComment())
            //$NON-NLS-1$
            buf.append("; inDoc");
        if (match.getElement() instanceof IJavaElement)
            //$NON-NLS-1$
            buf.append("; in: ").append(((IJavaElement) match.getElement()).getElementName());
        buf.append('\n');
    }
    return buf.toString();
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) SearchMatch(org.eclipse.jdt.core.search.SearchMatch)

Example 22 with SearchMatch

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

the class RenameAnalyzeUtil method getUpdatedChangeOffsets.

/**
	 *
	 * @param change
	 * @param oldMatches
	 * @return Map &lt;Integer updatedOffset, SearchMatch oldMatch&gt;
	 */
private static Map<Integer, SearchMatch> getUpdatedChangeOffsets(TextChange change, SearchMatch[] oldMatches) {
    Map<Integer, SearchMatch> updatedOffsets = new HashMap<Integer, SearchMatch>();
    Map<Integer, Integer> oldToUpdatedOffsets = getEditChangeOffsetUpdates(change);
    for (int i = 0; i < oldMatches.length; i++) {
        SearchMatch oldMatch = oldMatches[i];
        Integer updatedOffset = oldToUpdatedOffsets.get(new Integer(oldMatch.getOffset()));
        if (updatedOffset == null)
            //match not updated
            updatedOffset = new Integer(-1);
        updatedOffsets.put(updatedOffset, oldMatch);
    }
    return updatedOffsets;
}
Also used : SearchMatch(org.eclipse.jdt.core.search.SearchMatch) HashMap(java.util.HashMap)

Example 23 with SearchMatch

use of org.eclipse.jdt.core.search.SearchMatch 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 24 with SearchMatch

use of org.eclipse.jdt.core.search.SearchMatch 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 25 with SearchMatch

use of org.eclipse.jdt.core.search.SearchMatch 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)

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