use of org.eclipse.jdt.core.search.SearchMatch in project che by eclipse.
the class RenameFieldProcessor method addReferenceUpdates.
private void addReferenceUpdates(IProgressMonitor pm) {
//$NON-NLS-1$
pm.beginTask("", fReferences.length);
String editName = RefactoringCoreMessages.RenameFieldRefactoring_Update_field_reference;
for (int i = 0; i < fReferences.length; i++) {
ICompilationUnit cu = fReferences[i].getCompilationUnit();
if (cu == null)
continue;
SearchMatch[] results = fReferences[i].getSearchResults();
for (int j = 0; j < results.length; j++) {
addTextEdit(fChangeManager.get(cu), editName, createTextChange(results[j]));
}
pm.worked(1);
}
}
use of org.eclipse.jdt.core.search.SearchMatch 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);
}
}
}
use of org.eclipse.jdt.core.search.SearchMatch in project che by eclipse.
the class RenameMethodProcessor method searchForOuterTypesOfReferences.
private IType[] searchForOuterTypesOfReferences(IMethod[] newNameMethods, IProgressMonitor pm) throws CoreException {
final Set<IType> outerTypesOfReferences = new HashSet<IType>();
SearchPattern pattern = RefactoringSearchEngine.createOrPattern(newNameMethods, IJavaSearchConstants.REFERENCES);
IJavaSearchScope scope = createRefactoringScope(getMethod());
SearchRequestor requestor = new SearchRequestor() {
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
Object element = match.getElement();
if (!(element instanceof IMember))
// e.g. an IImportDeclaration for a static method import
return;
IMember member = (IMember) element;
IType declaring = member.getDeclaringType();
if (declaring == null)
return;
IType outer = declaring.getDeclaringType();
if (outer != null)
outerTypesOfReferences.add(declaring);
}
};
new SearchEngine().search(pattern, SearchUtils.getDefaultSearchParticipants(), scope, requestor, pm);
return outerTypesOfReferences.toArray(new IType[outerTypesOfReferences.size()]);
}
use of org.eclipse.jdt.core.search.SearchMatch in project che by eclipse.
the class RippleMethodFinder2 method findAllDeclarations.
private void findAllDeclarations(IProgressMonitor monitor, WorkingCopyOwner owner) throws CoreException {
fDeclarations = new ArrayList<IMethod>();
class MethodRequestor extends SearchRequestor {
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
IMethod method = (IMethod) match.getElement();
boolean isBinary = method.isBinary();
if (fBinaryRefs != null || !(fExcludeBinaries && isBinary)) {
fDeclarations.add(method);
}
if (isBinary && fBinaryRefs != null) {
fDeclarationToMatch.put(method, match);
}
}
}
int limitTo = IJavaSearchConstants.DECLARATIONS | IJavaSearchConstants.IGNORE_DECLARING_TYPE | IJavaSearchConstants.IGNORE_RETURN_TYPE;
int matchRule = SearchPattern.R_ERASURE_MATCH | SearchPattern.R_CASE_SENSITIVE;
SearchPattern pattern = SearchPattern.createPattern(fMethod, limitTo, matchRule);
SearchParticipant[] participants = SearchUtils.getDefaultSearchParticipants();
IJavaSearchScope scope = RefactoringScopeFactory.createRelatedProjectsScope(fMethod.getJavaProject(), IJavaSearchScope.SOURCES | IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SYSTEM_LIBRARIES);
MethodRequestor requestor = new MethodRequestor();
SearchEngine searchEngine = owner != null ? new SearchEngine(owner) : new SearchEngine();
searchEngine.search(pattern, participants, scope, requestor, monitor);
}
use of org.eclipse.jdt.core.search.SearchMatch in project che by eclipse.
the class RenameTypeProcessor method addReferenceUpdates.
private void addReferenceUpdates(TextChangeManager manager, IProgressMonitor pm) {
//$NON-NLS-1$
pm.beginTask("", fReferences.length);
for (int i = 0; i < fReferences.length; i++) {
ICompilationUnit cu = fReferences[i].getCompilationUnit();
if (cu == null)
continue;
String name = RefactoringCoreMessages.RenameTypeRefactoring_update_reference;
SearchMatch[] results = fReferences[i].getSearchResults();
for (int j = 0; j < results.length; j++) {
SearchMatch match = results[j];
ReplaceEdit replaceEdit = new ReplaceEdit(match.getOffset(), match.getLength(), getNewElementName());
TextChangeCompatibility.addTextEdit(manager.get(cu), name, replaceEdit, CATEGORY_TYPE_RENAME);
}
pm.worked(1);
}
}
Aggregations