Search in sources :

Example 21 with XtextDocument

use of org.eclipse.xtext.ui.editor.model.XtextDocument in project xtext-eclipse by eclipse.

the class DocumentLockerTest method testNoUpdateContentProcessOnReentrant.

@Test
public void testNoUpdateContentProcessOnReentrant() {
    List<String> s = new ArrayList<>();
    XtextDocument document = new XtextDocument(createTokenSource(), createTextEditComposer(), outdatedStateManager, operationCanceledManager) {

        @Override
        protected boolean updateContentBeforeRead() {
            return s.add("x");
        }
    };
    XtextResource resource = new XtextResource();
    new XtextResourceSet().getResources().add(resource);
    document.setInput(resource);
    Assert.assertEquals(0, s.size());
    document.readOnly(r1 -> {
        Assert.assertEquals(1, s.size());
        document.readOnly(r2 -> {
            Assert.assertEquals(1, s.size());
            document.readOnly(r3 -> {
                Assert.assertEquals(1, s.size());
                return null;
            });
            return null;
        });
        return null;
    });
    Assert.assertEquals(1, s.size());
}
Also used : XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) ArrayList(java.util.ArrayList) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 22 with XtextDocument

use of org.eclipse.xtext.ui.editor.model.XtextDocument 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 23 with XtextDocument

use of org.eclipse.xtext.ui.editor.model.XtextDocument in project xtext-eclipse by eclipse.

the class StreamContentDocumentProvider method setupDocument.

protected void setupDocument(Object element, IDocument document) {
    String content = getString(element);
    document.set(content);
    IDocumentPartitioner partitioner = documentPartitioner.get();
    partitioner.connect(document);
    document.setDocumentPartitioner(partitioner);
    XtextResource resource = createResource(element);
    loadResource(element, resource);
    if (resource != null) {
        ((XtextDocument) document).setInput(resource);
    }
}
Also used : IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) XtextResource(org.eclipse.xtext.resource.XtextResource) XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument)

Example 24 with XtextDocument

use of org.eclipse.xtext.ui.editor.model.XtextDocument in project xtext-eclipse by eclipse.

the class StreamContentDocumentProvider method disposeElementInfo.

@Override
protected void disposeElementInfo(Object element, ElementInfo info) {
    if (info.fDocument instanceof XtextDocument) {
        XtextDocument document = (XtextDocument) info.fDocument;
        document.disposeInput();
    }
    super.disposeElementInfo(element, info);
}
Also used : XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument)

Example 25 with XtextDocument

use of org.eclipse.xtext.ui.editor.model.XtextDocument in project dsl-devkit by dsldevkit.

the class FixedHighlightingReconciler method uninstall.

/**
 * Uninstall this reconciler from the editor
 */
@Override
public void uninstall() {
    if (presenter != null) {
        presenter.setCanceled(true);
    }
    if (sourceViewer.getDocument() != null) {
        if (oldCalculator != null || newCalculator != null) {
            XtextDocument document = (XtextDocument) sourceViewer.getDocument();
            document.removeModelListener(this);
            sourceViewer.removeTextInputListener(this);
        }
    }
    synchronized (fReconcileLock) {
        if (reconciling) {
            cleanUpAfterReconciliation = true;
        } else {
            editor = null;
            sourceViewer = null;
            presenter = null;
        }
    }
}
Also used : XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument)

Aggregations

XtextDocument (org.eclipse.xtext.ui.editor.model.XtextDocument)50 Test (org.junit.Test)21 IXtextDocument (org.eclipse.xtext.ui.editor.model.IXtextDocument)14 XtextResource (org.eclipse.xtext.resource.XtextResource)13 Lexer (org.eclipse.xtext.parser.antlr.Lexer)9 DocumentTokenSource (org.eclipse.xtext.ui.editor.model.DocumentTokenSource)8 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)5 AntlrTokenDefProvider (org.eclipse.xtext.parser.antlr.AntlrTokenDefProvider)4 DocumentPartitioner (org.eclipse.xtext.ui.editor.model.DocumentPartitioner)4 IOutlineNode (org.eclipse.xtext.ui.editor.outline.IOutlineNode)4 ArrayList (java.util.ArrayList)3 Job (org.eclipse.core.runtime.jobs.Job)3 IDocument (org.eclipse.jface.text.IDocument)3 ITypedRegion (org.eclipse.jface.text.ITypedRegion)3 CancelIndicator (org.eclipse.xtext.util.CancelIndicator)3 StringInputStream (org.eclipse.xtext.util.StringInputStream)3 Injector (com.google.inject.Injector)2 IFile (org.eclipse.core.resources.IFile)2 CoreException (org.eclipse.core.runtime.CoreException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2