use of org.eclipse.core.runtime.ISafeRunnable 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.core.runtime.ISafeRunnable in project che by eclipse.
the class UndoManager2 method fireAboutToPerformChange.
//---- event firing methods -------------------------------------------------
private void fireAboutToPerformChange(final Change change) {
if (fListeners == null)
return;
Object[] listeners = fListeners.getListeners();
for (int i = 0; i < listeners.length; i++) {
final IUndoManagerListener listener = (IUndoManagerListener) listeners[i];
SafeRunner.run(new ISafeRunnable() {
public void run() throws Exception {
listener.aboutToPerformChange(UndoManager2.this, change);
}
public void handleException(Throwable exception) {
RefactoringCorePlugin.log(exception);
}
});
}
}
use of org.eclipse.core.runtime.ISafeRunnable in project che by eclipse.
the class DeltaProcessor method notifyListeners.
private void notifyListeners(IJavaElementDelta deltaToNotify, int eventType, IElementChangedListener[] listeners, int[] listenerMask, int listenerCount) {
final ElementChangedEvent extraEvent = new ElementChangedEvent(deltaToNotify, eventType);
for (int i = 0; i < listenerCount; i++) {
if ((listenerMask[i] & eventType) != 0) {
final IElementChangedListener listener = listeners[i];
long start = -1;
if (VERBOSE) {
//$NON-NLS-1$//$NON-NLS-2$
System.out.print("Listener #" + (i + 1) + "=" + listener.toString());
start = System.currentTimeMillis();
}
// wrap callbacks with Safe runnable for subsequent listeners to be called when some are causing grief
SafeRunner.run(new ISafeRunnable() {
public void handleException(Throwable exception) {
//$NON-NLS-1$
Util.log(exception, "Exception occurred in listener of Java element change notification");
}
public void run() throws Exception {
PerformanceStats stats = null;
if (PERF) {
// stats = PerformanceStats.getStats(JavaModelManager.DELTA_LISTENER_PERF, listener);
// stats.startRun();
}
listener.elementChanged(extraEvent);
if (PERF) {
stats.endRun();
}
}
});
if (VERBOSE) {
//$NON-NLS-1$ //$NON-NLS-2$
System.out.println(" -> " + (System.currentTimeMillis() - start) + "ms");
}
}
}
}
use of org.eclipse.core.runtime.ISafeRunnable in project translationstudio8 by heartsome.
the class ProjectSettingHandler method runWizardPageExtension.
/**
* 加载扩展向导页 ;
*/
private void runWizardPageExtension() {
IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor("net.heartsome.cat.ts.ui.extensionpoint.projectsetting");
try {
// 修改术语库重复
extensionPages.clear();
for (IConfigurationElement e : config) {
final Object o = e.createExecutableExtension("class");
if (o instanceof AbstractProjectSettingPage) {
ISafeRunnable runnable = new ISafeRunnable() {
public void handleException(Throwable exception) {
logger.error(Messages.getString("handlers.ProjectSettingHandler.logger1"), exception);
}
public void run() throws Exception {
extensionPages.add((AbstractProjectSettingPage) o);
}
};
SafeRunner.run(runnable);
}
}
} catch (CoreException ex) {
logger.error(Messages.getString("handlers.ProjectSettingHandler.logger1"), ex);
}
}
use of org.eclipse.core.runtime.ISafeRunnable in project che by eclipse.
the class ASTProvider method createAST.
/**
* Creates a new compilation unit AST.
*
* @param input the Java element for which to create the AST
* @param progressMonitor the progress monitor
* @return AST
*/
public static CompilationUnit createAST(final ITypeRoot input, final IProgressMonitor progressMonitor) {
if (!hasSource(input))
return null;
if (progressMonitor != null && progressMonitor.isCanceled())
return null;
final ASTParser parser = ASTParser.newParser(SHARED_AST_LEVEL);
parser.setResolveBindings(true);
parser.setStatementsRecovery(SHARED_AST_STATEMENT_RECOVERY);
parser.setBindingsRecovery(SHARED_BINDING_RECOVERY);
parser.setSource(input);
if (progressMonitor != null && progressMonitor.isCanceled())
return null;
final CompilationUnit[] root = new CompilationUnit[1];
SafeRunner.run(new ISafeRunnable() {
public void run() {
try {
if (progressMonitor != null && progressMonitor.isCanceled())
return;
if (DEBUG)
System.err.println(getThreadName() + " - " + DEBUG_PREFIX + "creating AST for: " + //$NON-NLS-1$ //$NON-NLS-2$
input.getElementName());
root[0] = (CompilationUnit) parser.createAST(progressMonitor);
//mark as unmodifiable
ASTNodes.setFlagsToAST(root[0], ASTNode.PROTECT);
} catch (OperationCanceledException ex) {
return;
}
}
public void handleException(Throwable ex) {
LOG.error(ex.getMessage(), ex);
}
});
return root[0];
}
Aggregations