use of org.eclipse.jdt.core.search.SearchEngine in project eclipse.jdt.ls by eclipse.
the class HoverInfoProvider method isResolved.
private boolean isResolved(IJavaElement element, IProgressMonitor monitor) throws CoreException {
if (!(unit instanceof ICompilationUnit)) {
return true;
}
if (element == null) {
return false;
}
if (element.getElementType() != IJavaElement.TYPE) {
return true;
}
if (unit.getResource() != null && !unit.getResource().exists()) {
return true;
}
SearchPattern pattern = SearchPattern.createPattern(element, IJavaSearchConstants.ALL_OCCURRENCES);
final boolean[] res = new boolean[1];
res[0] = false;
SearchEngine engine = new SearchEngine();
IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { unit }, IJavaSearchScope.SOURCES | IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SYSTEM_LIBRARIES);
try {
engine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, new SearchRequestor() {
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
if (match.getAccuracy() == SearchMatch.A_INACCURATE) {
return;
}
Object o = match.getElement();
if (o instanceof IJavaElement) {
IJavaElement element = (IJavaElement) o;
if (element.getElementType() == IJavaElement.TYPE) {
res[0] = true;
return;
}
ICompilationUnit compilationUnit = (ICompilationUnit) element.getAncestor(IJavaElement.COMPILATION_UNIT);
if (compilationUnit == null) {
return;
}
res[0] = true;
throw new HoverException();
}
}
}, monitor);
} catch (HoverException | OperationCanceledException e) {
// ignore
}
return res[0];
}
use of org.eclipse.jdt.core.search.SearchEngine in project egradle by de-jcup.
the class JDTDataAccess method findType.
/**
* Find type
*
* @param className
* @param monitor
* @return type or <code>null</code>
*/
public IType findType(String className, IProgressMonitor monitor) {
final IType[] result = { null };
TypeNameMatchRequestor nameMatchRequestor = new TypeNameMatchRequestor() {
@Override
public void acceptTypeNameMatch(TypeNameMatch match) {
result[0] = match.getType();
}
};
int lastDot = className.lastIndexOf('.');
char[] packageName = lastDot >= 0 ? className.substring(0, lastDot).toCharArray() : null;
char[] typeName = (lastDot >= 0 ? className.substring(lastDot + 1) : className).toCharArray();
SearchEngine engine = new SearchEngine();
int packageMatchRule = SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE;
try {
engine.searchAllTypeNames(packageName, packageMatchRule, typeName, packageMatchRule, IJavaSearchConstants.TYPE, SearchEngine.createWorkspaceScope(), nameMatchRequestor, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, monitor);
} catch (JavaModelException e) {
EditorUtil.INSTANCE.logError("Was not able to search all type names", e);
}
return result[0];
}
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);
}
use of org.eclipse.jdt.core.search.SearchEngine in project che by eclipse.
the class RefactoringSearchEngine2 method searchPattern.
/**
* Performs the search according to the specified pattern.
*
* @param monitor the progress monitor, or <code>null</code>
* @throws JavaModelException if an error occurs during search
*/
public final void searchPattern(IProgressMonitor monitor) throws JavaModelException {
Assert.isNotNull(fPattern);
if (monitor == null)
monitor = new NullProgressMonitor();
try {
//$NON-NLS-1$
monitor.beginTask("", 1);
monitor.setTaskName(RefactoringCoreMessages.RefactoringSearchEngine_searching_occurrences);
try {
SearchEngine engine = null;
if (fOwner != null)
engine = new SearchEngine(fOwner);
else
engine = new SearchEngine(fWorkingCopies);
engine.search(fPattern, SearchUtils.getDefaultSearchParticipants(), fScope, getCollector(), new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
} catch (CoreException exception) {
throw new JavaModelException(exception);
}
} finally {
monitor.done();
}
}
use of org.eclipse.jdt.core.search.SearchEngine in project che by eclipse.
the class RefactoringSearchEngine2 method searchReferencedFields.
/**
* Performs the search of referenced fields.
*
* @param element the java element whose referenced fields have to be found
* @param monitor the progress monitor, or <code>null</code>
* @throws JavaModelException if an error occurs during search
*/
public final void searchReferencedFields(final IJavaElement element, IProgressMonitor monitor) throws JavaModelException {
Assert.isNotNull(element);
if (monitor == null)
monitor = new NullProgressMonitor();
try {
//$NON-NLS-1$
monitor.beginTask("", 1);
monitor.setTaskName(RefactoringCoreMessages.RefactoringSearchEngine_searching_referenced_fields);
try {
SearchEngine engine = null;
if (fOwner != null)
engine = new SearchEngine(fOwner);
else
engine = new SearchEngine(fWorkingCopies);
engine.searchDeclarationsOfAccessedFields(element, getCollector(), new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
} catch (CoreException exception) {
throw new JavaModelException(exception);
}
} finally {
monitor.done();
}
}
Aggregations