use of org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup in project che by eclipse.
the class RenameMethodProcessor method batchFindNewOccurrences.
//Lower memory footprint than batchFindNewOccurrences. Not used because it is too slow.
//Final solution is maybe to do searches in chunks of ~ 50 CUs.
// private SearchResultGroup[] findNewOccurrences(IMethod[] newMethods, ICompilationUnit[] newDeclarationWCs, IProgressMonitor pm) throws CoreException {
// pm.beginTask("", fOccurrences.length * 2); //$NON-NLS-1$
//
// SearchPattern refsPattern= RefactoringSearchEngine.createOrPattern(newMethods, IJavaSearchConstants.REFERENCES);
// SearchParticipant[] searchParticipants= SearchUtils.getDefaultSearchParticipants();
// IJavaSearchScope scope= RefactoringScopeFactory.create(newMethods);
// MethodOccurenceCollector requestor= new MethodOccurenceCollector(getNewElementName());
// SearchEngine searchEngine= new SearchEngine(fWorkingCopyOwner);
//
// //TODO: should process only references
// for (int j= 0; j < fOccurrences.length; j++) { //should be getReferences()
// //cut memory peak by holding only one reference CU at a time in memory
// ICompilationUnit originalCu= fOccurrences[j].getCompilationUnit();
// ICompilationUnit newWc= null;
// try {
// ICompilationUnit wc= RenameAnalyzeUtil.findWorkingCopyForCu(newDeclarationWCs, originalCu);
// if (wc == null) {
// newWc= RenameAnalyzeUtil.createNewWorkingCopy(originalCu, fChangeManager, fWorkingCopyOwner,
// new SubProgressMonitor(pm, 1));
// }
// searchEngine.search(refsPattern, searchParticipants, scope, requestor, new SubProgressMonitor(pm, 1));
// } finally {
// if (newWc != null)
// newWc.discardWorkingCopy();
// }
// }
// SearchResultGroup[] newResults= RefactoringSearchEngine.groupByResource(requestor.getResults());
// pm.done();
// return newResults;
// }
private SearchResultGroup[] batchFindNewOccurrences(IMethod[] wcNewMethods, final IMethod[] wcOldMethods, ICompilationUnit[] newDeclarationWCs, IProgressMonitor pm, RefactoringStatus status) throws CoreException {
//$NON-NLS-1$
pm.beginTask("", 2);
SearchPattern refsPattern = RefactoringSearchEngine.createOrPattern(wcNewMethods, IJavaSearchConstants.REFERENCES);
SearchParticipant[] searchParticipants = SearchUtils.getDefaultSearchParticipants();
IJavaSearchScope scope = RefactoringScopeFactory.create(wcNewMethods);
MethodOccurenceCollector requestor;
if (getDelegateUpdating()) {
// There will be two new matches inside the delegate(s) (the invocation
// and the javadoc) which are OK and must not be reported.
// Note that except these ocurrences, the delegate bodies are empty
// (as they were created this way).
requestor = new MethodOccurenceCollector(getNewElementName()) {
@Override
public void acceptSearchMatch(ICompilationUnit unit, SearchMatch match) throws CoreException {
for (int i = 0; i < wcOldMethods.length; i++) if (wcOldMethods[i].equals(match.getElement()))
return;
super.acceptSearchMatch(unit, match);
}
};
} else
requestor = new MethodOccurenceCollector(getNewElementName());
SearchEngine searchEngine = new SearchEngine(fWorkingCopyOwner);
ArrayList<ICompilationUnit> needWCs = new ArrayList<ICompilationUnit>();
HashSet<ICompilationUnit> declaringCUs = new HashSet<ICompilationUnit>(newDeclarationWCs.length);
for (int i = 0; i < newDeclarationWCs.length; i++) declaringCUs.add(newDeclarationWCs[i].getPrimary());
for (int i = 0; i < fOccurrences.length; i++) {
ICompilationUnit cu = fOccurrences[i].getCompilationUnit();
if (!declaringCUs.contains(cu))
needWCs.add(cu);
}
ICompilationUnit[] otherWCs = null;
try {
otherWCs = RenameAnalyzeUtil.createNewWorkingCopies(needWCs.toArray(new ICompilationUnit[needWCs.size()]), fChangeManager, fWorkingCopyOwner, new SubProgressMonitor(pm, 1));
searchEngine.search(refsPattern, searchParticipants, scope, requestor, new SubProgressMonitor(pm, 1));
} finally {
pm.done();
if (otherWCs != null) {
for (int i = 0; i < otherWCs.length; i++) {
otherWCs[i].discardWorkingCopy();
}
}
}
SearchResultGroup[] newResults = RefactoringSearchEngine.groupByCu(requestor.getResults(), status);
return newResults;
}
use of org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup in project che by eclipse.
the class RenameFieldProcessor method checkAccessorDeclarations.
private RefactoringStatus checkAccessorDeclarations(IProgressMonitor pm, IMethod existingAccessor) throws CoreException {
RefactoringStatus result = new RefactoringStatus();
SearchPattern pattern = SearchPattern.createPattern(existingAccessor, IJavaSearchConstants.DECLARATIONS, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
IJavaSearchScope scope = SearchEngine.createHierarchyScope(fField.getDeclaringType());
SearchResultGroup[] groupDeclarations = RefactoringSearchEngine.search(pattern, scope, pm, result);
Assert.isTrue(groupDeclarations.length > 0);
if (groupDeclarations.length != 1) {
String message = Messages.format(RefactoringCoreMessages.RenameFieldRefactoring_overridden, JavaElementUtil.createMethodSignature(existingAccessor));
result.addError(message);
} else {
SearchResultGroup group = groupDeclarations[0];
Assert.isTrue(group.getSearchResults().length > 0);
if (group.getSearchResults().length != 1) {
String message = Messages.format(RefactoringCoreMessages.RenameFieldRefactoring_overridden_or_overrides, JavaElementUtil.createMethodSignature(existingAccessor));
result.addError(message);
}
}
return result;
}
use of org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup in project che by eclipse.
the class RenameFieldProcessor method getReferences.
private SearchResultGroup[] getReferences(IProgressMonitor pm, RefactoringStatus status) throws CoreException {
String binaryRefsDescription = Messages.format(RefactoringCoreMessages.ReferencesInBinaryContext_ref_in_binaries_description, BasicElementLabels.getJavaElementName(getCurrentElementName()));
ReferencesInBinaryContext binaryRefs = new ReferencesInBinaryContext(binaryRefsDescription);
SearchResultGroup[] result = RefactoringSearchEngine.search(createSearchPattern(), createRefactoringScope(), new CuCollectingSearchRequestor(binaryRefs), pm, status);
binaryRefs.addErrorIfNecessary(status);
return result;
}
use of org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup in project che by eclipse.
the class RenameAnalyzeUtil method existsInNewOccurrences.
private static boolean existsInNewOccurrences(SearchMatch searchResult, SearchResultGroup[] newOccurrences, TextChangeManager manager) {
SearchResultGroup newGroup = findOccurrenceGroup(searchResult.getResource(), newOccurrences);
if (newGroup == null)
return false;
IRegion oldEditRange = getCorrespondingEditChangeRange(searchResult, manager);
if (oldEditRange == null)
return false;
SearchMatch[] newSearchResults = newGroup.getSearchResults();
int oldRangeOffset = oldEditRange.getOffset();
for (int i = 0; i < newSearchResults.length; i++) {
if (newSearchResults[i].getOffset() == oldRangeOffset)
return true;
}
return false;
}
use of org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup in project che by eclipse.
the class IntroduceFactoryRefactoring method findNonPrimaryType.
private IType findNonPrimaryType(String fullyQualifiedName, IProgressMonitor pm, RefactoringStatus status) throws JavaModelException {
SearchPattern p = SearchPattern.createPattern(fullyQualifiedName, IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
final RefactoringSearchEngine2 engine = new RefactoringSearchEngine2(p);
engine.setFiltering(true, true);
engine.setScope(RefactoringScopeFactory.create(fCtorBinding.getJavaElement().getJavaProject()));
engine.setStatus(status);
engine.searchPattern(new SubProgressMonitor(pm, 1));
SearchResultGroup[] groups = (SearchResultGroup[]) engine.getResults();
if (groups.length != 0) {
for (int i = 0; i < groups.length; i++) {
SearchMatch[] matches = groups[i].getSearchResults();
for (int j = 0; j < matches.length; j++) {
if (matches[j].getAccuracy() == SearchMatch.A_ACCURATE)
return (IType) matches[j].getElement();
}
}
}
return null;
}
Aggregations