use of org.eclipse.core.runtime.IStatus in project xtext-eclipse by eclipse.
the class SimpleEditorTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
// listen to CoreLog use RuntimeLog to hear more
TestsActivator.getInstance().getLog().addLogListener(new ILogListener() {
@Override
public void logging(IStatus status, String plugin) {
if (IStatus.ERROR == status.getSeverity()) {
fail(status.getMessage());
}
}
});
}
use of org.eclipse.core.runtime.IStatus in project xtext-eclipse by eclipse.
the class Bug297909Test method testReconcileDocument.
@Test
public void testReconcileDocument() throws Exception {
Injector injector = doGetSetup().createInjectorAndDoEMFRegistration();
XtextDocument document = injector.getInstance(XtextDocument.class);
document.setValidationJob(new Job("Job") {
@Override
protected IStatus run(IProgressMonitor monitor) {
return Status.OK_STATUS;
}
});
XtextResource resource = injector.getInstance(XtextResource.class);
XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
resourceSet.getResources().add(resource);
resource.load(new StringInputStream(""), Collections.singletonMap(XtextResource.OPTION_ENCODING, Charset.defaultCharset().name()));
document.setInput(resource);
document.set("abstract rules firstRule");
XtextDocumentReconcileStrategy strategy = injector.getInstance(XtextDocumentReconcileStrategy.class);
strategy.setDocument(document);
strategy.setResource(resource);
try {
strategy.reconcile(new ReconcilerReplaceRegion(0, document.getLength(), document.get()));
fail("Expected ParseException");
} catch (ParseException expected) {
assertTrue(expected.getMessage().contains("Make sure the EPackage has been registered"));
}
}
use of org.eclipse.core.runtime.IStatus in project xtext-eclipse by eclipse.
the class JvmImplementationOpener method openImplementations.
/**
* Main parts of the logic is taken from {@link org.eclipse.jdt.internal.ui.javaeditor.JavaElementImplementationHyperlink}
*
* @param element - Element to show implementations for
* @param textviewer - Viewer to show hierarchy view on
* @param region - Region where to show hierarchy view
*/
public void openImplementations(final IJavaElement element, ITextViewer textviewer, IRegion region) {
if (element instanceof IMethod) {
ITypeRoot typeRoot = ((IMethod) element).getTypeRoot();
CompilationUnit ast = SharedASTProvider.getAST(typeRoot, SharedASTProvider.WAIT_YES, null);
if (ast == null) {
openQuickHierarchy(textviewer, element, region);
return;
}
try {
ISourceRange nameRange = ((IMethod) element).getNameRange();
ASTNode node = NodeFinder.perform(ast, nameRange);
ITypeBinding parentTypeBinding = null;
if (node instanceof SimpleName) {
ASTNode parent = node.getParent();
if (parent instanceof MethodInvocation) {
Expression expression = ((MethodInvocation) parent).getExpression();
if (expression == null) {
parentTypeBinding = Bindings.getBindingOfParentType(node);
} else {
parentTypeBinding = expression.resolveTypeBinding();
}
} else if (parent instanceof SuperMethodInvocation) {
// Directly go to the super method definition
openEditor(element);
return;
} else if (parent instanceof MethodDeclaration) {
parentTypeBinding = Bindings.getBindingOfParentType(node);
}
}
final IType type = parentTypeBinding != null ? (IType) parentTypeBinding.getJavaElement() : null;
if (type == null) {
openQuickHierarchy(textviewer, element, region);
return;
}
final String earlyExitIndicator = "EarlyExitIndicator";
final ArrayList<IJavaElement> links = Lists.newArrayList();
IRunnableWithProgress runnable = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
try {
String methodLabel = JavaElementLabels.getElementLabel(element, JavaElementLabels.DEFAULT_QUALIFIED);
monitor.beginTask(Messages.format("Searching for implementors of ''{0}''", methodLabel), 100);
SearchRequestor requestor = new SearchRequestor() {
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
if (match.getAccuracy() == SearchMatch.A_ACCURATE) {
IJavaElement element = (IJavaElement) match.getElement();
if (element instanceof IMethod && !JdtFlags.isAbstract((IMethod) element)) {
links.add(element);
if (links.size() > 1) {
throw new OperationCanceledException(earlyExitIndicator);
}
}
}
}
};
int limitTo = IJavaSearchConstants.DECLARATIONS | IJavaSearchConstants.IGNORE_DECLARING_TYPE | IJavaSearchConstants.IGNORE_RETURN_TYPE;
SearchPattern pattern = SearchPattern.createPattern(element, limitTo);
Assert.isNotNull(pattern);
SearchParticipant[] participants = new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() };
SearchEngine engine = new SearchEngine();
engine.search(pattern, participants, SearchEngine.createHierarchyScope(type), requestor, SubMonitor.convert(monitor, 100));
if (monitor.isCanceled()) {
throw new InterruptedException();
}
} catch (OperationCanceledException e) {
throw new InterruptedException(e.getMessage());
} catch (CoreException e) {
throw new InvocationTargetException(e);
} finally {
monitor.done();
}
}
};
try {
PlatformUI.getWorkbench().getProgressService().busyCursorWhile(runnable);
} catch (InvocationTargetException e) {
IStatus status = new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IStatus.OK, Messages.format("An error occurred while searching for implementations of method ''{0}''. See error log for details.", element.getElementName()), e.getCause());
JavaPlugin.log(status);
ErrorDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Open Implementation", "Problems finding implementations.", status);
} catch (InterruptedException e) {
if (e.getMessage() != earlyExitIndicator) {
return;
}
}
if (links.size() == 1) {
openEditor(links.get(0));
} else {
openQuickHierarchy(textviewer, element, region);
}
} catch (JavaModelException e) {
log.error("An error occurred while searching for implementations", e.getCause());
} catch (PartInitException e) {
log.error("An error occurred while searching for implementations", e.getCause());
}
}
}
use of org.eclipse.core.runtime.IStatus in project xtext-eclipse by eclipse.
the class CompositeSearchQuery method run.
@Override
public IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
SubMonitor progress = SubMonitor.convert(monitor, children.size());
MultiStatus multiStatus = new MultiStatus(getPluginId(), IStatus.OK, "Composite search state", null);
for (ISearchQuery child : children) {
IStatus status = child.run(progress.newChild(1));
multiStatus.add(status);
if (progress.isCanceled()) {
return Status.CANCEL_STATUS;
}
}
return multiStatus;
}
use of org.eclipse.core.runtime.IStatus in project cubrid-manager by CUBRID.
the class CreateReplicationJobExecutor method createDistributor.
/**
* create distributor database
*
* @param dbName String
* @param monitor IProgressMonitor
* @param taskList List<ITask>
* @return status
*/
private IStatus createDistributor(String dbName, final IProgressMonitor monitor, List<ITask> taskList) {
monitor.subTask(Messages.bind(Messages.createDistJobName, dbName));
Display display = Display.getDefault();
MonitoringTask monitoringTask = null;
boolean isExecuteStopDbTask = true;
MonitorDashboardPreference monPref = new MonitorDashboardPreference();
for (ITask task : taskList) {
if (task instanceof MonitoringTask) {
monitoringTask = (MonitoringTask) task;
ServerInfo serverInfo = monitoringTask.getServerInfo();
CMHostNodePersistManager.getInstance().addServer(serverInfo.getHostAddress(), serverInfo.getHostMonPort(), serverInfo.getUserName(), serverInfo);
monitoringTask.connectServer(Version.releaseVersion, monPref.getHAHeartBeatTimeout());
} else if (task instanceof CommonUpdateTask && task.getTaskname().equals(CommonTaskName.STOP_DB_TASK_NAME)) {
if (isDeleteDb && isExecuteStopDbTask) {
task.execute();
} else {
continue;
}
} else if (task instanceof CommonUpdateTask && task.getTaskname().equals(CommonTaskName.DELETE_DATABASE_TASK_NAME)) {
if (isDeleteDb) {
task.execute();
} else {
continue;
}
} else {
task.execute();
}
if (monitor.isCanceled()) {
disConnect(monitoringTask);
return Status.CANCEL_STATUS;
}
final String msg = task.getErrorMsg();
if (msg != null && msg.length() > 0 && !monitor.isCanceled()) {
disConnect(monitoringTask);
return new Status(IStatus.ERROR, CubridManagerUIPlugin.PLUGIN_ID, msg);
}
if (task instanceof GetDatabaseListTask) {
GetDatabaseListTask getDatabaseListTask = (GetDatabaseListTask) task;
final String distdbName = (String) getDatabaseListTask.getData("dbName");
List<DatabaseInfo> dbInfoList = getDatabaseListTask.loadDatabaseInfo();
boolean isDbExist = false;
for (int i = 0; i < dbInfoList.size(); i++) {
DatabaseInfo dbInfo = dbInfoList.get(i);
if (dbName.equalsIgnoreCase(dbInfo.getDbName())) {
isDbExist = true;
display.syncExec(new Runnable() {
public void run() {
isDeleteDb = CommonUITool.openConfirmBox(Messages.bind(Messages.msgConfirmDeleteDb, distdbName));
}
});
if (dbInfo.getRunningType() == DbRunningType.CS) {
isExecuteStopDbTask = true;
}
break;
}
}
if (isDbExist && !isDeleteDb) {
disConnect(monitoringTask);
return Status.CANCEL_STATUS;
}
}
}
disConnect(monitoringTask);
isDeleteDb = false;
return Status.OK_STATUS;
}
Aggregations