Search in sources :

Example 11 with SearchMatch

use of org.eclipse.jdt.core.search.SearchMatch in project che by eclipse.

the class RefactoringSearchEngine method findAffectedCompilationUnits.

//TODO: throw CoreException
public static ICompilationUnit[] findAffectedCompilationUnits(SearchPattern pattern, IJavaSearchScope scope, final IProgressMonitor pm, RefactoringStatus status, final boolean tolerateInAccurateMatches) throws JavaModelException {
    boolean hasNonCuMatches = false;
    class ResourceSearchRequestor extends SearchRequestor {

        boolean hasPotentialMatches = false;

        Set<IResource> resources = new HashSet<IResource>(5);

        private IResource fLastResource;

        @Override
        public void acceptSearchMatch(SearchMatch match) {
            if (!tolerateInAccurateMatches && match.getAccuracy() == SearchMatch.A_INACCURATE) {
                hasPotentialMatches = true;
            }
            if (fLastResource != match.getResource()) {
                fLastResource = match.getResource();
                resources.add(fLastResource);
            }
        }
    }
    ResourceSearchRequestor requestor = new ResourceSearchRequestor();
    try {
        new SearchEngine().search(pattern, SearchUtils.getDefaultSearchParticipants(), scope, requestor, pm);
    } catch (CoreException e) {
        throw new JavaModelException(e);
    }
    List<IJavaElement> result = new ArrayList<IJavaElement>(requestor.resources.size());
    for (Iterator<IResource> iter = requestor.resources.iterator(); iter.hasNext(); ) {
        IResource resource = iter.next();
        IJavaElement element = JavaCore.create(resource);
        if (element instanceof ICompilationUnit) {
            result.add(element);
        } else {
            hasNonCuMatches = true;
        }
    }
    addStatusErrors(status, requestor.hasPotentialMatches, hasNonCuMatches);
    return result.toArray(new ICompilationUnit[result.size()]);
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) SearchMatch(org.eclipse.jdt.core.search.SearchMatch) JavaModelException(org.eclipse.jdt.core.JavaModelException) HashSet(java.util.HashSet) Set(java.util.Set) ArrayList(java.util.ArrayList) SearchRequestor(org.eclipse.jdt.core.search.SearchRequestor) SearchEngine(org.eclipse.jdt.core.search.SearchEngine) CoreException(org.eclipse.core.runtime.CoreException) IResource(org.eclipse.core.resources.IResource)

Example 12 with SearchMatch

use of org.eclipse.jdt.core.search.SearchMatch in project che by eclipse.

the class RefactoringSearchEngine2 method getUngroupedMatches.

/**
	 * Returns the found search matches in no particular order.
	 *
	 * @return the found search matches
	 */
private SearchMatch[] getUngroupedMatches() {
    Collection<?> results = null;
    if (fBinary) {
        results = new LinkedList<Object>(getSearchMatches());
        final Collection<IResource> collection = getCollector().getBinaryResources();
        SearchMatch match = null;
        for (final Iterator<?> iterator = results.iterator(); iterator.hasNext(); ) {
            match = (SearchMatch) iterator.next();
            if (collection.contains(match.getResource()))
                iterator.remove();
        }
    } else
        results = getSearchMatches();
    final SearchMatch[] matches = new SearchMatch[results.size()];
    results.toArray(matches);
    return matches;
}
Also used : SearchMatch(org.eclipse.jdt.core.search.SearchMatch) IResource(org.eclipse.core.resources.IResource)

Example 13 with SearchMatch

use of org.eclipse.jdt.core.search.SearchMatch in project che by eclipse.

the class MemberVisibilityAdjustor method adjustOutgoingVisibility.

/**
	 * Adjusts the visibilities of the outgoing references from the member represented by the specified search result groups.
	 *
	 * @param groups the search result groups representing the references
	 * @param monitor the progress monitor to us
	 * @throws JavaModelException if the visibility could not be determined
	 */
private void adjustOutgoingVisibility(final SearchResultGroup[] groups, final IProgressMonitor monitor) throws JavaModelException {
    try {
        //$NON-NLS-1$
        monitor.beginTask("", groups.length);
        monitor.setTaskName(RefactoringCoreMessages.MemberVisibilityAdjustor_checking);
        IJavaElement element = null;
        SearchMatch[] matches = null;
        SearchResultGroup group = null;
        for (int index = 0; index < groups.length; index++) {
            group = groups[index];
            element = JavaCore.create(group.getResource());
            if (element instanceof ICompilationUnit) {
                matches = group.getSearchResults();
                for (int offset = 0; offset < matches.length; offset++) adjustOutgoingVisibility(matches[offset], new SubProgressMonitor(monitor, 1));
            }
            // else if (element != null)
            // fStatus.merge(RefactoringStatus.createStatus(fFailureSeverity, RefactoringCoreMessages.getFormattedString
            // ("MemberVisibilityAdjustor.binary.outgoing.project", new String[] { element.getJavaProject().getElementName(), getLabel
            // (fReferenced)}), null, null, RefactoringStatusEntry.NO_CODE, null)); //$NON-NLS-1$
            // else if (group.getResource() != null)
            // fStatus.merge(RefactoringStatus.createStatus(fFailureSeverity, RefactoringCoreMessages.getFormattedString
            // ("MemberVisibilityAdjustor.binary.outgoing.resource", new String[] { group.getResource().getName(), getLabel
            // (fReferenced)}), null, null, RefactoringStatusEntry.NO_CODE, null)); //$NON-NLS-1$
            // TW: enable when bug 78387 is fixed
            monitor.worked(1);
        }
    } finally {
        monitor.done();
    }
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) SearchMatch(org.eclipse.jdt.core.search.SearchMatch) SearchResultGroup(org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 14 with SearchMatch

use of org.eclipse.jdt.core.search.SearchMatch 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;
}
Also used : SearchMatch(org.eclipse.jdt.core.search.SearchMatch) SearchPattern(org.eclipse.jdt.core.search.SearchPattern) SearchResultGroup(org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup) RefactoringSearchEngine2(org.eclipse.jdt.internal.corext.refactoring.RefactoringSearchEngine2) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 15 with SearchMatch

use of org.eclipse.jdt.core.search.SearchMatch in project che by eclipse.

the class InlineConstantRefactoring method findReferences.

private SearchResultGroup[] findReferences(IProgressMonitor pm, RefactoringStatus status) throws JavaModelException {
    final RefactoringSearchEngine2 engine = new RefactoringSearchEngine2(SearchPattern.createPattern(fField, IJavaSearchConstants.REFERENCES));
    engine.setFiltering(true, true);
    engine.setScope(RefactoringScopeFactory.create(fField));
    engine.setStatus(status);
    engine.setRequestor(new IRefactoringSearchRequestor() {

        public SearchMatch acceptSearchMatch(SearchMatch match) {
            return match.isInsideDocComment() ? null : match;
        }
    });
    engine.searchPattern(new SubProgressMonitor(pm, 1));
    return (SearchResultGroup[]) engine.getResults();
}
Also used : IRefactoringSearchRequestor(org.eclipse.jdt.internal.corext.refactoring.IRefactoringSearchRequestor) SearchMatch(org.eclipse.jdt.core.search.SearchMatch) RefactoringSearchEngine2(org.eclipse.jdt.internal.corext.refactoring.RefactoringSearchEngine2) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Aggregations

SearchMatch (org.eclipse.jdt.core.search.SearchMatch)35 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)16 SearchPattern (org.eclipse.jdt.core.search.SearchPattern)13 SearchResultGroup (org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup)12 SearchEngine (org.eclipse.jdt.core.search.SearchEngine)10 ArrayList (java.util.ArrayList)8 CoreException (org.eclipse.core.runtime.CoreException)8 IJavaSearchScope (org.eclipse.jdt.core.search.IJavaSearchScope)8 SearchRequestor (org.eclipse.jdt.core.search.SearchRequestor)8 IJavaElement (org.eclipse.jdt.core.IJavaElement)7 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)5 ReplaceEdit (org.eclipse.text.edits.ReplaceEdit)5 HashMap (java.util.HashMap)4 IResource (org.eclipse.core.resources.IResource)4 IMethod (org.eclipse.jdt.core.IMethod)4 RefactoringSearchEngine (org.eclipse.jdt.internal.corext.refactoring.RefactoringSearchEngine)4 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)4 HashSet (java.util.HashSet)3 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)3 IType (org.eclipse.jdt.core.IType)3