Search in sources :

Example 86 with IStatus

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());
            }
        }
    });
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) ILogListener(org.eclipse.core.runtime.ILogListener)

Example 87 with IStatus

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"));
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) StringInputStream(org.eclipse.xtext.util.StringInputStream) XtextDocumentReconcileStrategy(org.eclipse.xtext.ui.editor.reconciler.XtextDocumentReconcileStrategy) ReconcilerReplaceRegion(org.eclipse.xtext.ui.editor.reconciler.ReconcilerReplaceRegion) Injector(com.google.inject.Injector) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument) XtextResource(org.eclipse.xtext.resource.XtextResource) ParseException(org.eclipse.xtext.parser.ParseException) Job(org.eclipse.core.runtime.jobs.Job) Test(org.junit.Test)

Example 88 with IStatus

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());
        }
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) JavaModelException(org.eclipse.jdt.core.JavaModelException) SimpleName(org.eclipse.jdt.core.dom.SimpleName) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) MethodInvocation(org.eclipse.jdt.core.dom.MethodInvocation) SuperMethodInvocation(org.eclipse.jdt.core.dom.SuperMethodInvocation) SuperMethodInvocation(org.eclipse.jdt.core.dom.SuperMethodInvocation) IType(org.eclipse.jdt.core.IType) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) SearchParticipant(org.eclipse.jdt.core.search.SearchParticipant) SearchEngine(org.eclipse.jdt.core.search.SearchEngine) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) ASTNode(org.eclipse.jdt.core.dom.ASTNode) SearchPattern(org.eclipse.jdt.core.search.SearchPattern) IMethod(org.eclipse.jdt.core.IMethod) PartInitException(org.eclipse.ui.PartInitException) ISourceRange(org.eclipse.jdt.core.ISourceRange) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IJavaElement(org.eclipse.jdt.core.IJavaElement) SearchMatch(org.eclipse.jdt.core.search.SearchMatch) MethodDeclaration(org.eclipse.jdt.core.dom.MethodDeclaration) ITypeRoot(org.eclipse.jdt.core.ITypeRoot) InvocationTargetException(java.lang.reflect.InvocationTargetException) SearchRequestor(org.eclipse.jdt.core.search.SearchRequestor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) Expression(org.eclipse.jdt.core.dom.Expression)

Example 89 with IStatus

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;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) SubMonitor(org.eclipse.core.runtime.SubMonitor) MultiStatus(org.eclipse.core.runtime.MultiStatus) ISearchQuery(org.eclipse.search.ui.ISearchQuery)

Example 90 with IStatus

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;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) MonitorDashboardPreference(com.cubrid.cubridmanager.ui.mondashboard.preference.MonitorDashboardPreference) ITask(com.cubrid.common.core.task.ITask) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) GetDatabaseListTask(com.cubrid.cubridmanager.core.cubrid.database.task.GetDatabaseListTask) MonitoringTask(com.cubrid.cubridmanager.core.common.task.MonitoringTask) CommonUpdateTask(com.cubrid.cubridmanager.core.common.task.CommonUpdateTask) Display(org.eclipse.swt.widgets.Display)

Aggregations

IStatus (org.eclipse.core.runtime.IStatus)1423 Status (org.eclipse.core.runtime.Status)500 CoreException (org.eclipse.core.runtime.CoreException)369 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)270 File (java.io.File)169 IOException (java.io.IOException)154 ArrayList (java.util.ArrayList)141 IPath (org.eclipse.core.runtime.IPath)138 IFile (org.eclipse.core.resources.IFile)130 Job (org.eclipse.core.runtime.jobs.Job)123 MultiStatus (org.eclipse.core.runtime.MultiStatus)113 InvocationTargetException (java.lang.reflect.InvocationTargetException)106 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)85 IProject (org.eclipse.core.resources.IProject)84 List (java.util.List)83 Path (org.eclipse.core.runtime.Path)52 Test (org.junit.Test)52 IResource (org.eclipse.core.resources.IResource)51 SubMonitor (org.eclipse.core.runtime.SubMonitor)51 Composite (org.eclipse.swt.widgets.Composite)44