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();
}
use of org.eclipse.jdt.core.search.SearchMatch in project che by eclipse.
the class RenameAnalyzeUtil method getUpdatedChangeOffsets.
/**
*
* @param change
* @param oldMatches
* @return Map <Integer updatedOffset, SearchMatch oldMatch>
*/
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;
}
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;
}
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;
}
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();
}
Aggregations