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());
}
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));
}
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;
}
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());
}
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());
}
Aggregations