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()]);
}
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;
}
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);
}
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());
}
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);
}
Aggregations