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