Search in sources :

Example 41 with XtextDocument

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

the class DocumentPartitionerTest method testSimple.

@Test
public void testSimple() throws Exception {
    XtextDocument document = getDocument("/* foo */ bar 345 grammar : so 'baz & so'");
    ITypedRegion partition = document.getPartition(0);
    assertEquals(0, partition.getOffset());
    assertEquals(9, partition.getLength());
    assertEquals(TerminalsTokenTypeToPartitionMapper.COMMENT_PARTITION, partition.getType());
    partition = document.getPartition(9);
    assertEquals(9, partition.getOffset());
    assertEquals(22, partition.getLength());
    assertEquals(IDocument.DEFAULT_CONTENT_TYPE, partition.getType());
    partition = document.getPartition(35);
    assertEquals(31, partition.getOffset());
    assertEquals(10, partition.getLength());
    assertEquals(TerminalsTokenTypeToPartitionMapper.STRING_LITERAL_PARTITION, partition.getType());
}
Also used : ITypedRegion(org.eclipse.jface.text.ITypedRegion) XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument) Test(org.junit.Test)

Example 42 with XtextDocument

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

the class DocumentUtilTest method testSearchInSamePartition_2.

@Test
public void testSearchInSamePartition_2() throws Exception {
    String s = "              ";
    XtextDocument document = getDocument(s);
    assertNull(util.searchInSamePartition("4", document, 0));
}
Also used : XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument) Test(org.junit.Test)

Example 43 with XtextDocument

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

the class AbstractXtextDocumentTest 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, outdatedStateManager, operationCanceledManager);
    document.setDocumentPartitioner(partitioner);
    partitioner.connect(document);
    document.set(s);
    return document;
}
Also used : XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument) TerminalsTokenTypeToPartitionMapper(org.eclipse.xtext.ui.editor.model.TerminalsTokenTypeToPartitionMapper) 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 44 with XtextDocument

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

the class DocumentLockerTest method testPriorityReadOnlyCancelsReaders.

@Test
public void testPriorityReadOnlyCancelsReaders() throws Exception {
    // prevent random test failures: https://github.com/junit-team/junit4/issues/1365
    Thread.interrupted();
    XtextDocument document = new XtextDocument(createTokenSource(), null, outdatedStateManager, operationCanceledManager);
    XtextResource resource = new XtextResource();
    new XtextResourceSet().getResources().add(resource);
    document.setInput(resource);
    CountDownLatch check = new CountDownLatch(1);
    Runnable runnable = new Runnable() {

        @Override
        public void run() {
            document.readOnly(new CancelableUnitOfWork<Object, XtextResource>() {

                @Override
                public Object exec(XtextResource state, CancelIndicator cancelIndicator) throws Exception {
                    check.countDown();
                    int wait = 4000;
                    int i = 0;
                    while (!cancelIndicator.isCanceled()) {
                        Thread.sleep(10L);
                        if (i > wait) {
                            throw new InterruptedException();
                        }
                        i = i + 1;
                    }
                    return null;
                }
            });
        }
    };
    Thread thread = new Thread(runnable);
    thread.start();
    check.await();
    document.priorityReadOnly(r -> null);
    Assert.assertFalse(thread.isInterrupted());
}
Also used : XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument) XtextResource(org.eclipse.xtext.resource.XtextResource) CancelIndicator(org.eclipse.xtext.util.CancelIndicator) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 45 with XtextDocument

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

the class DocumentLockerTest method testReadOnlyDoesntCancelReaders.

@Test
public void testReadOnlyDoesntCancelReaders() {
    XtextDocument document = new XtextDocument(createTokenSource(), null, outdatedStateManager, operationCanceledManager);
    XtextResource resource = new XtextResource();
    new XtextResourceSet().getResources().add(resource);
    document.setInput(resource);
    List<CancelIndicator> cancelIndicators = new ArrayList<>();
    addReaderCancelationListener(document, cancelIndicators);
    Assert.assertTrue(cancelIndicators.isEmpty());
    document.readOnly(r -> null);
    Assert.assertTrue(cancelIndicators.isEmpty());
    document.readOnly(r -> null);
    Assert.assertTrue(cancelIndicators.isEmpty());
}
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) CancelIndicator(org.eclipse.xtext.util.CancelIndicator) Test(org.junit.Test)

Aggregations

XtextDocument (org.eclipse.xtext.ui.editor.model.XtextDocument)48 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 Job (org.eclipse.core.runtime.jobs.Job)3 ITypedRegion (org.eclipse.jface.text.ITypedRegion)3 CancelIndicator (org.eclipse.xtext.util.CancelIndicator)3 StringInputStream (org.eclipse.xtext.util.StringInputStream)3 ArrayList (java.util.ArrayList)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 IStatus (org.eclipse.core.runtime.IStatus)2 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)2 EObject (org.eclipse.emf.ecore.EObject)2 IDocument (org.eclipse.jface.text.IDocument)2