use of org.eclipse.jdt.core.search.SearchPattern in project che by eclipse.
the class CreateCopyOfCompilationUnitChange method createSearchPattern.
private static SearchPattern createSearchPattern(IType type) throws JavaModelException {
SearchPattern pattern = SearchPattern.createPattern(type, IJavaSearchConstants.ALL_OCCURRENCES, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
IMethod[] constructors = JavaElementUtil.getAllConstructors(type);
if (constructors.length == 0)
return pattern;
SearchPattern constructorDeclarationPattern = RefactoringSearchEngine.createOrPattern(constructors, IJavaSearchConstants.DECLARATIONS);
return SearchPattern.createOrPattern(pattern, constructorDeclarationPattern);
}
use of org.eclipse.jdt.core.search.SearchPattern in project che by eclipse.
the class JavaSearchQuery method run.
public IStatus run(IProgressMonitor monitor) {
final JavaSearchResult textResult = (JavaSearchResult) getSearchResult();
textResult.removeAll();
// Don't need to pass in working copies in 3.0 here
SearchEngine engine = new SearchEngine();
try {
int totalTicks = 1000;
IProject[] projects = JavaSearchScopeFactory.getInstance().getProjects(fPatternData.getScope());
final SearchParticipantRecord[] participantDescriptors = SearchParticipantsExtensionPoint.getInstance().getSearchParticipants(projects);
final int[] ticks = new int[participantDescriptors.length];
for (int i = 0; i < participantDescriptors.length; i++) {
final int iPrime = i;
ISafeRunnable runnable = new ISafeRunnable() {
public void handleException(Throwable exception) {
ticks[iPrime] = 0;
String message = SearchMessages.JavaSearchQuery_error_participant_estimate;
JavaPlugin.log(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, message, exception));
}
public void run() throws Exception {
ticks[iPrime] = participantDescriptors[iPrime].getParticipant().estimateTicks(fPatternData);
}
};
SafeRunner.run(runnable);
totalTicks += ticks[i];
}
SearchPattern pattern;
String stringPattern;
if (fPatternData instanceof ElementQuerySpecification) {
IJavaElement element = ((ElementQuerySpecification) fPatternData).getElement();
stringPattern = JavaElementLabels.getElementLabel(element, JavaElementLabels.ALL_DEFAULT);
if (!element.exists()) {
return new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, Messages.format(SearchMessages.JavaSearchQuery_error_element_does_not_exist, stringPattern), null);
}
pattern = SearchPattern.createPattern(element, fPatternData.getLimitTo(), SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
} else {
PatternQuerySpecification patternSpec = (PatternQuerySpecification) fPatternData;
stringPattern = patternSpec.getPattern();
int matchMode = getMatchMode(stringPattern) | SearchPattern.R_ERASURE_MATCH;
if (patternSpec.isCaseSensitive())
matchMode |= SearchPattern.R_CASE_SENSITIVE;
pattern = SearchPattern.createPattern(patternSpec.getPattern(), patternSpec.getSearchFor(), patternSpec.getLimitTo(), matchMode);
}
if (pattern == null) {
return new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, Messages.format(SearchMessages.JavaSearchQuery_error_unsupported_pattern, stringPattern), null);
}
monitor.beginTask(Messages.format(SearchMessages.JavaSearchQuery_task_label, stringPattern), totalTicks);
IProgressMonitor mainSearchPM = new SubProgressMonitor(monitor, 1000);
boolean ignorePotentials = NewSearchUI.arePotentialMatchesIgnored();
NewSearchResultCollector collector = new NewSearchResultCollector(textResult, ignorePotentials);
engine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, fPatternData.getScope(), collector, mainSearchPM);
for (int i = 0; i < participantDescriptors.length; i++) {
final ISearchRequestor requestor = new SearchRequestor(participantDescriptors[i].getParticipant(), textResult);
final IProgressMonitor participantPM = new SubProgressMonitor(monitor, ticks[i]);
final int iPrime = i;
ISafeRunnable runnable = new ISafeRunnable() {
public void handleException(Throwable exception) {
participantDescriptors[iPrime].getDescriptor().disable();
String message = SearchMessages.JavaSearchQuery_error_participant_search;
JavaPlugin.log(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, message, exception));
}
public void run() throws Exception {
final IQueryParticipant participant = participantDescriptors[iPrime].getParticipant();
final PerformanceStats stats = PerformanceStats.getStats(PERF_SEARCH_PARTICIPANT, participant);
stats.startRun();
participant.search(requestor, fPatternData, participantPM);
stats.endRun();
}
};
SafeRunner.run(runnable);
}
} catch (CoreException e) {
return e.getStatus();
}
String message = Messages.format(SearchMessages.JavaSearchQuery_status_ok_message, String.valueOf(textResult.getMatchCount()));
return new Status(IStatus.OK, JavaPlugin.getPluginId(), 0, message, null);
}
use of org.eclipse.jdt.core.search.SearchPattern in project che by eclipse.
the class RefactoringSearchEngine2 method setPattern.
/**
* Sets the search pattern to be used during search.
* <p>
* This method must be called before {@link RefactoringSearchEngine2#searchPattern(IProgressMonitor)}
*
* @param elements the set of elements
* @param limitTo determines the nature of the expected matches. This is a combination of {@link org.eclipse.jdt.core.search
* .IJavaSearchConstants}.
*/
public final void setPattern(final IJavaElement[] elements, final int limitTo) {
Assert.isNotNull(elements);
Assert.isTrue(elements.length > 0);
SearchPattern pattern = SearchPattern.createPattern(elements[0], limitTo, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
IJavaElement element = null;
for (int index = 1; index < elements.length; index++) {
element = elements[index];
pattern = SearchPattern.createOrPattern(pattern, SearchPattern.createPattern(element, limitTo, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE));
}
setPattern(pattern);
}
use of org.eclipse.jdt.core.search.SearchPattern in project che by eclipse.
the class RenameFieldProcessor method addAccessorOccurrences.
private void addAccessorOccurrences(IProgressMonitor pm, IMethod accessor, String editName, String newAccessorName, RefactoringStatus status) throws CoreException {
Assert.isTrue(accessor.exists());
IJavaSearchScope scope = RefactoringScopeFactory.create(accessor);
SearchPattern pattern = SearchPattern.createPattern(accessor, IJavaSearchConstants.ALL_OCCURRENCES, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
SearchResultGroup[] groupedResults = RefactoringSearchEngine.search(pattern, scope, new MethodOccurenceCollector(accessor.getElementName()), pm, status);
for (int i = 0; i < groupedResults.length; i++) {
ICompilationUnit cu = groupedResults[i].getCompilationUnit();
if (cu == null)
continue;
SearchMatch[] results = groupedResults[i].getSearchResults();
for (int j = 0; j < results.length; j++) {
SearchMatch searchResult = results[j];
TextEdit edit = new ReplaceEdit(searchResult.getOffset(), searchResult.getLength(), newAccessorName);
addTextEdit(fChangeManager.get(cu), editName, edit);
}
}
}
use of org.eclipse.jdt.core.search.SearchPattern in project che by eclipse.
the class RenameMethodProcessor method searchForOuterTypesOfReferences.
private IType[] searchForOuterTypesOfReferences(IMethod[] newNameMethods, IProgressMonitor pm) throws CoreException {
final Set<IType> outerTypesOfReferences = new HashSet<IType>();
SearchPattern pattern = RefactoringSearchEngine.createOrPattern(newNameMethods, IJavaSearchConstants.REFERENCES);
IJavaSearchScope scope = createRefactoringScope(getMethod());
SearchRequestor requestor = new SearchRequestor() {
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
Object element = match.getElement();
if (!(element instanceof IMember))
// e.g. an IImportDeclaration for a static method import
return;
IMember member = (IMember) element;
IType declaring = member.getDeclaringType();
if (declaring == null)
return;
IType outer = declaring.getDeclaringType();
if (outer != null)
outerTypesOfReferences.add(declaring);
}
};
new SearchEngine().search(pattern, SearchUtils.getDefaultSearchParticipants(), scope, requestor, pm);
return outerTypesOfReferences.toArray(new IType[outerTypesOfReferences.size()]);
}
Aggregations