Search in sources :

Example 1 with XtextDocument

use of org.eclipse.xtext.ui.editor.model.XtextDocument 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 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() {
    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 XtextDocument

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

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

the class DocumentPartitionerTest method testBug401433.

@Test
public void testBug401433() throws Exception {
    XtextDocument document = getDocument("     /* */ ");
    document.replace(10, 1, "");
    ITypedRegion partition = document.getPartition(9);
    assertEquals(5, partition.getOffset());
    assertEquals(5, partition.getLength());
    assertEquals(TerminalsTokenTypeToPartitionMapper.COMMENT_PARTITION, partition.getType());
    document.replace(9, 1, "");
    partition = document.getPartition(8);
    assertEquals(5, partition.getOffset());
    assertEquals(4, partition.getLength());
    assertEquals(IDocument.DEFAULT_CONTENT_TYPE, partition.getType());
    document.replace(8, 1, "");
    partition = document.getPartition(7);
    assertEquals(5, partition.getOffset());
    assertEquals(3, partition.getLength());
    assertEquals(IDocument.DEFAULT_CONTENT_TYPE, partition.getType());
    document.replace(7, 1, "");
    partition = document.getPartition(6);
    assertEquals(5, partition.getOffset());
    assertEquals(2, partition.getLength());
    assertEquals(IDocument.DEFAULT_CONTENT_TYPE, partition.getType());
    document.replace(6, 1, "");
    partition = document.getPartition(5);
    assertEquals(5, partition.getOffset());
    assertEquals(1, partition.getLength());
    assertEquals(IDocument.DEFAULT_CONTENT_TYPE, partition.getType());
}
Also used : ITypedRegion(org.eclipse.jface.text.ITypedRegion) XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument) Test(org.junit.Test)

Example 5 with XtextDocument

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

Aggregations

XtextDocument (org.eclipse.xtext.ui.editor.model.XtextDocument)51 Test (org.junit.Test)22 IXtextDocument (org.eclipse.xtext.ui.editor.model.IXtextDocument)15 XtextResource (org.eclipse.xtext.resource.XtextResource)14 DocumentTokenSource (org.eclipse.xtext.ui.editor.model.DocumentTokenSource)12 Lexer (org.eclipse.xtext.parser.antlr.Lexer)9 IUnitOfWork (org.eclipse.xtext.util.concurrent.IUnitOfWork)7 EList (org.eclipse.emf.common.util.EList)6 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)5 EObject (org.eclipse.emf.ecore.EObject)4 ITypedRegion (org.eclipse.jface.text.ITypedRegion)4 Region (org.eclipse.jface.text.Region)4 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 AbstractXtextDocumentTest (org.eclipse.xtext.ui.tests.editor.model.AbstractXtextDocumentTest)4 IFile (org.eclipse.core.resources.IFile)3 Job (org.eclipse.core.runtime.jobs.Job)3 IRegion (org.eclipse.jface.text.IRegion)3 ITextEditComposer (org.eclipse.xtext.ui.editor.model.edit.ITextEditComposer)3