Search in sources :

Example 1 with DisplayRunnable

use of org.eclipse.xtext.ui.util.DisplayRunnable in project xtext-eclipse by eclipse.

the class SaveHelper method saveEditors.

public void saveEditors(final IRenameElementContext context) {
    new DisplayRunnable() {

        @Override
        protected void run() throws Exception {
            workspace.run(new IWorkspaceRunnable() {

                @Override
                public void run(IProgressMonitor monitor) throws CoreException {
                    IWorkbenchPage workbenchPage = getWorkbenchPage(context);
                    if (prefs.isSaveAllBeforeRefactoring())
                        workbenchPage.saveAllEditors(false);
                    else
                        saveDeclaringEditor(context, workbenchPage);
                }
            }, new NullProgressMonitor());
        }
    }.syncExec();
    syncUtil.waitForBuild(null);
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) DisplayRunnable(org.eclipse.xtext.ui.util.DisplayRunnable) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) CoreException(org.eclipse.core.runtime.CoreException)

Example 2 with DisplayRunnable

use of org.eclipse.xtext.ui.util.DisplayRunnable in project xtext-eclipse by eclipse.

the class XtextReconcilerDebugger method assertResouceParsedCorrectly.

public void assertResouceParsedCorrectly(XtextResource resource, final ReconcilerReplaceRegion region) {
    IParseResult parseResult = resource.getParseResult();
    if (parseResult != null) {
        ICompositeNode rootNode = parseResult.getRootNode();
        final String resourceContent = rootNode.getText();
        IParseResult reparseResult = parser.parse(new StringReader(resourceContent));
        if (!emfStructureComparator.isSameStructure(parseResult.getRootASTElement(), reparseResult.getRootASTElement())) {
            new DisplayRunnable() {

                @Override
                protected void run() throws Exception {
                    LOG.error("PartialParsing produced wrong model");
                    LOG.error("Events: \n\t" + Joiner.on("\n\t").join(region.getDocumentEvents()));
                    LOG.error("ReplaceRegion: \n\t'" + region + "'");
                    MessageDialog.openError(Display.getCurrent().getActiveShell(), "XtextReconcilerDebugger", "PartialParsing produced wrong model." + "\n\nSee log for details.");
                }
            };
        }
    }
}
Also used : StringReader(java.io.StringReader) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) DisplayRunnable(org.eclipse.xtext.ui.util.DisplayRunnable) IParseResult(org.eclipse.xtext.parser.IParseResult)

Example 3 with DisplayRunnable

use of org.eclipse.xtext.ui.util.DisplayRunnable in project xtext-eclipse by eclipse.

the class XtextReconcilerDebugger method assertModelInSyncWithDocument.

public void assertModelInSyncWithDocument(IDocument document, XtextResource resource, final ReconcilerReplaceRegion region) {
    if (document instanceof IDocumentExtension4 && resource != null) {
        long beforeGet = ((IDocumentExtension4) document).getModificationStamp();
        final String documentContent = document.get();
        long afterGet = ((IDocumentExtension4) document).getModificationStamp();
        if (beforeGet == afterGet && beforeGet == resource.getModificationStamp()) {
            IParseResult parseResult = resource.getParseResult();
            if (parseResult != null) {
                ICompositeNode rootNode = parseResult.getRootNode();
                final String resourceContent = rootNode.getText();
                if (!resourceContent.equals(documentContent)) {
                    new DisplayRunnable() {

                        @Override
                        protected void run() throws Exception {
                            LOG.error("XtextDocument and XtextResource have run out of sync:\n" + DiffUtil.diff(documentContent, resourceContent));
                            LOG.error("Events: \n\t" + Joiner.on("\n\t").join(region.getDocumentEvents()));
                            LOG.error("ReplaceRegion: \n\t'" + region + "'");
                            MessageDialog.openError(Display.getCurrent().getActiveShell(), "XtextReconcilerDebugger", "XtextDocument and XtextResource have run out of sync." + "\n\nSee log for details.");
                        }
                    }.syncExec();
                } else {
                    if (LOG.isDebugEnabled())
                        LOG.debug("Model and document are in sync");
                }
            }
        }
    }
}
Also used : IDocumentExtension4(org.eclipse.jface.text.IDocumentExtension4) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) DisplayRunnable(org.eclipse.xtext.ui.util.DisplayRunnable) IParseResult(org.eclipse.xtext.parser.IParseResult)

Aggregations

DisplayRunnable (org.eclipse.xtext.ui.util.DisplayRunnable)3 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)2 IParseResult (org.eclipse.xtext.parser.IParseResult)2 StringReader (java.io.StringReader)1 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 IDocumentExtension4 (org.eclipse.jface.text.IDocumentExtension4)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1