Search in sources :

Example 1 with DocumentTokenSource

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

the class DocumentLockerTest method testModifySetsOutdatedFalse.

@Test
public void testModifySetsOutdatedFalse() {
    DocumentTokenSource _createTokenSource = this.createTokenSource();
    ITextEditComposer _createTextEditComposer = this.createTextEditComposer();
    final XtextDocument document = new XtextDocument(_createTokenSource, _createTextEditComposer, this.outdatedStateManager, this.operationCanceledManager);
    XtextResource _xtextResource = new XtextResource();
    final Procedure1<XtextResource> _function = (XtextResource it) -> {
        EList<Resource> _resources = new XtextResourceSet().getResources();
        _resources.add(it);
    };
    final XtextResource resource = ObjectExtensions.<XtextResource>operator_doubleArrow(_xtextResource, _function);
    document.setInput(resource);
    final IUnitOfWork<Object, XtextResource> _function_1 = (XtextResource it) -> {
        Object _xblockexpression = null;
        {
            Assert.assertFalse(document.getCancelIndicator().isCanceled());
            _xblockexpression = null;
        }
        return _xblockexpression;
    };
    document.<Object>internalModify(_function_1);
    final CancelIndicator indicator = document.getCancelIndicator();
    Assert.assertFalse(indicator.isCanceled());
    document.set("fupp");
    Assert.assertTrue(indicator.isCanceled());
    final IUnitOfWork<Object, XtextResource> _function_2 = (XtextResource it) -> {
        Object _xblockexpression = null;
        {
            Assert.assertFalse(document.getCancelIndicator().isCanceled());
            _xblockexpression = null;
        }
        return _xblockexpression;
    };
    document.<Object>internalModify(_function_2);
}
Also used : EList(org.eclipse.emf.common.util.EList) DocumentTokenSource(org.eclipse.xtext.ui.editor.model.DocumentTokenSource) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) XtextResource(org.eclipse.xtext.resource.XtextResource) CancelIndicator(org.eclipse.xtext.util.CancelIndicator) ITextEditComposer(org.eclipse.xtext.ui.editor.model.edit.ITextEditComposer) AbstractXtextDocumentTest(org.eclipse.xtext.ui.tests.editor.model.AbstractXtextDocumentTest) Test(org.junit.Test)

Example 2 with DocumentTokenSource

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

the class DocumentLockerTest method testNoUpdateContentProcessOnReentrant.

@Test
public void testNoUpdateContentProcessOnReentrant() {
    final ArrayList<String> s = CollectionLiterals.<String>newArrayList();
    DocumentTokenSource _createTokenSource = this.createTokenSource();
    ITextEditComposer _createTextEditComposer = this.createTextEditComposer();
    final XtextDocument document = new XtextDocument(_createTokenSource, _createTextEditComposer, this.outdatedStateManager, this.operationCanceledManager) {

        @Override
        protected boolean updateContentBeforeRead() {
            return s.add("x");
        }
    };
    XtextResource _xtextResource = new XtextResource();
    final Procedure1<XtextResource> _function = (XtextResource it) -> {
        EList<Resource> _resources = new XtextResourceSet().getResources();
        _resources.add(it);
    };
    XtextResource _doubleArrow = ObjectExtensions.<XtextResource>operator_doubleArrow(_xtextResource, _function);
    document.setInput(_doubleArrow);
    Assert.assertEquals(0, s.size());
    final IUnitOfWork<Object, XtextResource> _function_1 = (XtextResource it) -> {
        Assert.assertEquals(1, s.size());
        final IUnitOfWork<Object, XtextResource> _function_2 = (XtextResource it_1) -> {
            Assert.assertEquals(1, s.size());
            final IUnitOfWork<Object, XtextResource> _function_3 = (XtextResource it_2) -> {
                Assert.assertEquals(1, s.size());
                return null;
            };
            document.<Object>readOnly(_function_3);
            return null;
        };
        document.<Object>readOnly(_function_2);
        return null;
    };
    document.<Object>readOnly(_function_1);
    Assert.assertEquals(1, s.size());
}
Also used : IUnitOfWork(org.eclipse.xtext.util.concurrent.IUnitOfWork) EList(org.eclipse.emf.common.util.EList) DocumentTokenSource(org.eclipse.xtext.ui.editor.model.DocumentTokenSource) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) XtextResource(org.eclipse.xtext.resource.XtextResource) ITextEditComposer(org.eclipse.xtext.ui.editor.model.edit.ITextEditComposer) AbstractXtextDocumentTest(org.eclipse.xtext.ui.tests.editor.model.AbstractXtextDocumentTest) Test(org.junit.Test)

Example 3 with DocumentTokenSource

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

the class XtextDocumentModifyTest method createDocument.

private IXtextDocument createDocument(String model) throws Exception {
    resource = getResource(new StringInputStream(model));
    DocumentTokenSource tokenSource = new DocumentTokenSource();
    tokenSource.setLexer(new Provider<Lexer>() {

        @Override
        public Lexer get() {
            return new InternalXtextLexer();
        }
    });
    final XtextDocument document = new XtextDocument(tokenSource, get(ITextEditComposer.class), new OutdatedStateManager(), new OperationCanceledManager()) {

        @Override
        public <T> T internalModify(IUnitOfWork<T, XtextResource> work) {
            try {
                return work.exec((XtextResource) resource);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    };
    document.set(model);
    return document;
}
Also used : OutdatedStateManager(org.eclipse.xtext.resource.OutdatedStateManager) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument) ITextEditComposer(org.eclipse.xtext.ui.editor.model.edit.ITextEditComposer) OperationCanceledManager(org.eclipse.xtext.service.OperationCanceledManager) IUnitOfWork(org.eclipse.xtext.util.concurrent.IUnitOfWork) StringInputStream(org.eclipse.xtext.util.StringInputStream) InternalXtextLexer(org.eclipse.xtext.parser.antlr.internal.InternalXtextLexer) Lexer(org.eclipse.xtext.parser.antlr.Lexer) DocumentTokenSource(org.eclipse.xtext.ui.editor.model.DocumentTokenSource) InternalXtextLexer(org.eclipse.xtext.parser.antlr.internal.InternalXtextLexer)

Example 4 with DocumentTokenSource

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

the class DocumentPartitionerTest method getDocument.

public XtextDocument getDocument(String s) {
    TerminalsTokenTypeToPartitionMapper mapper = new TerminalsTokenTypeToPartitionMapper() {

        {
            setTokenDefProvider(new AntlrTokenDefProvider() {

                {
                    setAntlrTokenFileProvider(new XtextAntlrTokenFileProvider());
                }
            });
        }
    };
    PartitionTokenScanner scanner = new PartitionTokenScanner();
    scanner.setMapper(mapper);
    DocumentPartitioner partitioner = new DocumentPartitioner(scanner, mapper);
    DocumentTokenSource tokenSource = new DocumentTokenSource();
    tokenSource.setLexer(new Provider<Lexer>() {

        @Override
        public Lexer get() {
            return new org.eclipse.xtext.parser.antlr.internal.InternalXtextLexer();
        }
    });
    XtextDocument document = new XtextDocument(tokenSource, null, new OutdatedStateManager(), new OperationCanceledManager());
    document.setDocumentPartitioner(partitioner);
    partitioner.connect(document);
    document.set(s);
    return document;
}
Also used : OutdatedStateManager(org.eclipse.xtext.resource.OutdatedStateManager) XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument) TerminalsTokenTypeToPartitionMapper(org.eclipse.xtext.ui.editor.model.TerminalsTokenTypeToPartitionMapper) OperationCanceledManager(org.eclipse.xtext.service.OperationCanceledManager) AntlrTokenDefProvider(org.eclipse.xtext.parser.antlr.AntlrTokenDefProvider) XtextAntlrTokenFileProvider(org.eclipse.xtext.parser.antlr.XtextAntlrTokenFileProvider) Lexer(org.eclipse.xtext.parser.antlr.Lexer) DocumentTokenSource(org.eclipse.xtext.ui.editor.model.DocumentTokenSource) PartitionTokenScanner(org.eclipse.xtext.ui.editor.model.PartitionTokenScanner) DocumentPartitioner(org.eclipse.xtext.ui.editor.model.DocumentPartitioner)

Example 5 with DocumentTokenSource

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

the class DocumentTokenSourceTest method setUp.

@Before
public void setUp() throws Exception {
    tokenSource = new DocumentTokenSource();
    tokenSource.setLexer(new Provider<Lexer>() {

        @Override
        public Lexer get() {
            return new org.eclipse.xtext.parser.antlr.internal.InternalXtextLexer();
        }
    });
    document = new Document("");
    document.addDocumentListener(new IDocumentListener() {

        @Override
        public void documentChanged(DocumentEvent event) {
            tokenSource.updateStructure(event);
        }

        @Override
        public void documentAboutToBeChanged(DocumentEvent event) {
        }
    });
}
Also used : Lexer(org.eclipse.xtext.parser.antlr.Lexer) DocumentTokenSource(org.eclipse.xtext.ui.editor.model.DocumentTokenSource) IDocumentListener(org.eclipse.jface.text.IDocumentListener) Document(org.eclipse.jface.text.Document) DocumentEvent(org.eclipse.jface.text.DocumentEvent) Before(org.junit.Before)

Aggregations

DocumentTokenSource (org.eclipse.xtext.ui.editor.model.DocumentTokenSource)14 XtextDocument (org.eclipse.xtext.ui.editor.model.XtextDocument)12 Lexer (org.eclipse.xtext.parser.antlr.Lexer)8 IXtextDocument (org.eclipse.xtext.ui.editor.model.IXtextDocument)6 XtextResource (org.eclipse.xtext.resource.XtextResource)5 EList (org.eclipse.emf.common.util.EList)4 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)4 AbstractXtextDocumentTest (org.eclipse.xtext.ui.tests.editor.model.AbstractXtextDocumentTest)4 Test (org.junit.Test)4 DocumentEvent (org.eclipse.jface.text.DocumentEvent)3 OutdatedStateManager (org.eclipse.xtext.resource.OutdatedStateManager)3 OperationCanceledManager (org.eclipse.xtext.service.OperationCanceledManager)3 ITextEditComposer (org.eclipse.xtext.ui.editor.model.edit.ITextEditComposer)3 CancelIndicator (org.eclipse.xtext.util.CancelIndicator)3 AntlrTokenDefProvider (org.eclipse.xtext.parser.antlr.AntlrTokenDefProvider)2 XtextAntlrTokenFileProvider (org.eclipse.xtext.parser.antlr.XtextAntlrTokenFileProvider)2 InternalXtextLexer (org.eclipse.xtext.parser.antlr.internal.InternalXtextLexer)2 DocumentPartitioner (org.eclipse.xtext.ui.editor.model.DocumentPartitioner)2 PartitionTokenScanner (org.eclipse.xtext.ui.editor.model.PartitionTokenScanner)2 TerminalsTokenTypeToPartitionMapper (org.eclipse.xtext.ui.editor.model.TerminalsTokenTypeToPartitionMapper)2