Search in sources :

Example 81 with IResource

use of org.eclipse.core.resources.IResource 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 82 with IResource

use of org.eclipse.core.resources.IResource 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 83 with IResource

use of org.eclipse.core.resources.IResource in project che by eclipse.

the class QualifiedNameFinder method createScope.

private static TextSearchScope createScope(String filePatterns, IProject root) {
    HashSet<IProject> res = new HashSet<IProject>();
    res.add(root);
    addReferencingProjects(root, res);
    IResource[] resArr = res.toArray(new IResource[res.size()]);
    Pattern filePattern = getFilePattern(filePatterns);
    return TextSearchScope.newSearchScope(resArr, filePattern, false);
}
Also used : Pattern(java.util.regex.Pattern) IProject(org.eclipse.core.resources.IProject) IResource(org.eclipse.core.resources.IResource) HashSet(java.util.HashSet)

Example 84 with IResource

use of org.eclipse.core.resources.IResource in project che by eclipse.

the class RefactoringFileBuffers method release.

/**
	 * Releases the text file buffer associated with the compilation unit.
	 *
	 * @param unit the compilation unit whose text file buffer has to be released
	 * @throws CoreException if the buffer could not be successfully released
	 */
public static void release(final ICompilationUnit unit) throws CoreException {
    Assert.isNotNull(unit);
    final IResource resource = unit.getResource();
    if (resource != null && resource.getType() == IResource.FILE)
        FileBuffers.getTextFileBufferManager().disconnect(resource.getFullPath(), LocationKind.IFILE, new NullProgressMonitor());
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IResource(org.eclipse.core.resources.IResource)

Example 85 with IResource

use of org.eclipse.core.resources.IResource in project che by eclipse.

the class RefactoringFileBuffers method getTextFileBuffer.

/**
	 * Returns the text file buffer for the specified compilation unit.
	 *
	 * @param unit the compilation unit whose text file buffer to retrieve
	 * @return the associated text file buffer, or <code>null</code> if no text file buffer is managed for the compilation unit
	 */
public static ITextFileBuffer getTextFileBuffer(final ICompilationUnit unit) {
    Assert.isNotNull(unit);
    final IResource resource = unit.getResource();
    if (resource == null || resource.getType() != IResource.FILE)
        return null;
    return FileBuffers.getTextFileBufferManager().getTextFileBuffer(resource.getFullPath(), LocationKind.IFILE);
}
Also used : IResource(org.eclipse.core.resources.IResource)

Aggregations

IResource (org.eclipse.core.resources.IResource)559 CoreException (org.eclipse.core.runtime.CoreException)141 IFile (org.eclipse.core.resources.IFile)140 IPath (org.eclipse.core.runtime.IPath)119 IProject (org.eclipse.core.resources.IProject)104 IContainer (org.eclipse.core.resources.IContainer)88 ArrayList (java.util.ArrayList)84 IFolder (org.eclipse.core.resources.IFolder)64 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)52 IStatus (org.eclipse.core.runtime.IStatus)47 IOException (java.io.IOException)46 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)44 Path (org.eclipse.core.runtime.Path)42 File (java.io.File)39 Status (org.eclipse.core.runtime.Status)38 IJavaProject (org.eclipse.jdt.core.IJavaProject)31 IJavaElement (org.eclipse.jdt.core.IJavaElement)30 ISelection (org.eclipse.jface.viewers.ISelection)26 List (java.util.List)25 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)22