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;
}
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;
}
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();
}
}
}
}
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();
}
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);
}
}
}
Aggregations