use of org.eclipse.jdt.core.search.SearchEngine in project che by eclipse.
the class ReferenceFinderUtil method getFieldReferencesIn.
private static List<SearchMatch> getFieldReferencesIn(IJavaElement element, WorkingCopyOwner owner, IProgressMonitor pm) throws JavaModelException {
CollectingSearchRequestor requestor = new CollectingSearchRequestor();
SearchEngine engine = owner != null ? new SearchEngine(owner) : new SearchEngine();
engine.searchDeclarationsOfAccessedFields(element, requestor, pm);
return requestor.getResults();
}
use of org.eclipse.jdt.core.search.SearchEngine in project che by eclipse.
the class JavaContext method findAllTypes.
/*
* Finds a type by the simple name. From AddImportsOperation
*/
private TypeNameMatch[] findAllTypes(String simpleTypeName, IJavaSearchScope searchScope, SimpleName nameNode, IProgressMonitor monitor, ICompilationUnit cu) throws JavaModelException {
boolean is50OrHigher = JavaModelUtil.is50OrHigher(cu.getJavaProject());
int typeKinds = SimilarElementsRequestor.ALL_TYPES;
if (nameNode != null) {
typeKinds = ASTResolving.getPossibleTypeKinds(nameNode, is50OrHigher);
}
ArrayList<TypeNameMatch> typeInfos = new ArrayList<TypeNameMatch>();
TypeNameMatchCollector requestor = new TypeNameMatchCollector(typeInfos);
new SearchEngine().searchAllTypeNames(null, 0, simpleTypeName.toCharArray(), SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE, getSearchForConstant(typeKinds), searchScope, requestor, IJavaSearchConstants.FORCE_IMMEDIATE_SEARCH, monitor);
ArrayList<TypeNameMatch> typeRefsFound = new ArrayList<TypeNameMatch>(typeInfos.size());
for (int i = 0, len = typeInfos.size(); i < len; i++) {
TypeNameMatch curr = typeInfos.get(i);
if (curr.getPackageName().length() > 0) {
// do not suggest imports from the default package
if (isOfKind(curr, typeKinds, is50OrHigher) && isVisible(curr, cu)) {
typeRefsFound.add(curr);
}
}
}
return typeRefsFound.toArray(new TypeNameMatch[typeRefsFound.size()]);
}
use of org.eclipse.jdt.core.search.SearchEngine 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()]);
}
use of org.eclipse.jdt.core.search.SearchEngine in project che by eclipse.
the class RippleMethodFinder2 method findAllDeclarations.
private void findAllDeclarations(IProgressMonitor monitor, WorkingCopyOwner owner) throws CoreException {
fDeclarations = new ArrayList<IMethod>();
class MethodRequestor extends SearchRequestor {
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
IMethod method = (IMethod) match.getElement();
boolean isBinary = method.isBinary();
if (fBinaryRefs != null || !(fExcludeBinaries && isBinary)) {
fDeclarations.add(method);
}
if (isBinary && fBinaryRefs != null) {
fDeclarationToMatch.put(method, match);
}
}
}
int limitTo = IJavaSearchConstants.DECLARATIONS | IJavaSearchConstants.IGNORE_DECLARING_TYPE | IJavaSearchConstants.IGNORE_RETURN_TYPE;
int matchRule = SearchPattern.R_ERASURE_MATCH | SearchPattern.R_CASE_SENSITIVE;
SearchPattern pattern = SearchPattern.createPattern(fMethod, limitTo, matchRule);
SearchParticipant[] participants = SearchUtils.getDefaultSearchParticipants();
IJavaSearchScope scope = RefactoringScopeFactory.createRelatedProjectsScope(fMethod.getJavaProject(), IJavaSearchScope.SOURCES | IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SYSTEM_LIBRARIES);
MethodRequestor requestor = new MethodRequestor();
SearchEngine searchEngine = owner != null ? new SearchEngine(owner) : new SearchEngine();
searchEngine.search(pattern, participants, scope, requestor, monitor);
}
use of org.eclipse.jdt.core.search.SearchEngine 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);
}
Aggregations