Search in sources :

Example 1 with CollectingSearchRequestor

use of org.eclipse.jdt.internal.corext.refactoring.CollectingSearchRequestor in project che by eclipse.

the class RenameFieldProcessor method getNewReferences.

private SearchResultGroup[] getNewReferences(IProgressMonitor pm, RefactoringStatus status, WorkingCopyOwner owner, ICompilationUnit[] newWorkingCopies) throws CoreException {
    //$NON-NLS-1$
    pm.beginTask("", 2);
    ICompilationUnit declaringCuWorkingCopy = RenameAnalyzeUtil.findWorkingCopyForCu(newWorkingCopies, fField.getCompilationUnit());
    if (declaringCuWorkingCopy == null)
        return new SearchResultGroup[0];
    IField field = getFieldInWorkingCopy(declaringCuWorkingCopy, getNewElementName());
    if (field == null || !field.exists())
        return new SearchResultGroup[0];
    CollectingSearchRequestor requestor = null;
    if (fDelegateUpdating && RefactoringAvailabilityTester.isDelegateCreationAvailable(getField())) {
        // There will be two new matches inside the delegate (the invocation
        // and the javadoc) which are OK and must not be reported.
        final IField oldField = getFieldInWorkingCopy(declaringCuWorkingCopy, getCurrentElementName());
        requestor = new CollectingSearchRequestor() {

            @Override
            public void acceptSearchMatch(SearchMatch match) throws CoreException {
                if (!oldField.equals(match.getElement()))
                    super.acceptSearchMatch(match);
            }
        };
    } else
        requestor = new CollectingSearchRequestor();
    SearchPattern newPattern = SearchPattern.createPattern(field, IJavaSearchConstants.REFERENCES);
    IJavaSearchScope scope = RefactoringScopeFactory.create(fField, true, true);
    return RefactoringSearchEngine.search(newPattern, owner, scope, requestor, new SubProgressMonitor(pm, 1), status);
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) SearchMatch(org.eclipse.jdt.core.search.SearchMatch) CoreException(org.eclipse.core.runtime.CoreException) IJavaSearchScope(org.eclipse.jdt.core.search.IJavaSearchScope) SearchPattern(org.eclipse.jdt.core.search.SearchPattern) CuCollectingSearchRequestor(org.eclipse.jdt.internal.corext.refactoring.CuCollectingSearchRequestor) CollectingSearchRequestor(org.eclipse.jdt.internal.corext.refactoring.CollectingSearchRequestor) IField(org.eclipse.jdt.core.IField) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 2 with CollectingSearchRequestor

use of org.eclipse.jdt.internal.corext.refactoring.CollectingSearchRequestor in project che by eclipse.

the class ReferenceFinderUtil method getTypeReferencesIn.

private static List<SearchMatch> getTypeReferencesIn(IJavaElement element, WorkingCopyOwner owner, IProgressMonitor pm) throws JavaModelException {
    CollectingSearchRequestor requestor = new CollectingSearchRequestor();
    SearchEngine engine = owner != null ? new SearchEngine(owner) : new SearchEngine();
    engine.searchDeclarationsOfReferencedTypes(element, requestor, pm);
    return requestor.getResults();
}
Also used : SearchEngine(org.eclipse.jdt.core.search.SearchEngine) CollectingSearchRequestor(org.eclipse.jdt.internal.corext.refactoring.CollectingSearchRequestor)

Example 3 with CollectingSearchRequestor

use of org.eclipse.jdt.internal.corext.refactoring.CollectingSearchRequestor in project che by eclipse.

the class ReferenceFinderUtil method getMethodReferencesIn.

private static List<SearchMatch> getMethodReferencesIn(IJavaElement element, WorkingCopyOwner owner, IProgressMonitor pm) throws JavaModelException {
    CollectingSearchRequestor requestor = new CollectingSearchRequestor();
    SearchEngine engine = owner != null ? new SearchEngine(owner) : new SearchEngine();
    engine.searchDeclarationsOfSentMessages(element, requestor, pm);
    return requestor.getResults();
}
Also used : SearchEngine(org.eclipse.jdt.core.search.SearchEngine) CollectingSearchRequestor(org.eclipse.jdt.internal.corext.refactoring.CollectingSearchRequestor)

Example 4 with CollectingSearchRequestor

use of org.eclipse.jdt.internal.corext.refactoring.CollectingSearchRequestor in project che by eclipse.

the class ReferenceFinderUtil method getFieldReferencesIn.

private static List<SearchMatch> getFieldReferencesIn(IJavaElement element, WorkingCopyOwner owner, IProgressMonitor pm) throws JavaModelException {
    CollectingSearchRequestor requestor = new CollectingSearchRequestor();
    SearchEngine engine = owner != null ? new SearchEngine(owner) : new SearchEngine();
    engine.searchDeclarationsOfAccessedFields(element, requestor, pm);
    return requestor.getResults();
}
Also used : SearchEngine(org.eclipse.jdt.core.search.SearchEngine) CollectingSearchRequestor(org.eclipse.jdt.internal.corext.refactoring.CollectingSearchRequestor)

Aggregations

CollectingSearchRequestor (org.eclipse.jdt.internal.corext.refactoring.CollectingSearchRequestor)4 SearchEngine (org.eclipse.jdt.core.search.SearchEngine)3 CoreException (org.eclipse.core.runtime.CoreException)1 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)1 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1 IField (org.eclipse.jdt.core.IField)1 IJavaSearchScope (org.eclipse.jdt.core.search.IJavaSearchScope)1 SearchMatch (org.eclipse.jdt.core.search.SearchMatch)1 SearchPattern (org.eclipse.jdt.core.search.SearchPattern)1 CuCollectingSearchRequestor (org.eclipse.jdt.internal.corext.refactoring.CuCollectingSearchRequestor)1