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