use of org.eclipse.xtext.ui.editor.model.IXtextDocument 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.IXtextDocument in project xtext-eclipse by eclipse.
the class XtextDocumentModifyTest method testSemanticModification.
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=406811
@Test
public void testSemanticModification() throws Exception {
// @formatter:off
String grammar = text("grammar foo.Foo", "generate foo \"http://foo.net/foo\"", "Foo: 'foo';");
// @formatter:on
IXtextDocument document = createDocument(grammar);
document.modify(new IUnitOfWork.Void<XtextResource>() {
@Override
public void process(XtextResource state) throws Exception {
Grammar grammar = (Grammar) state.getContents().get(0);
grammar.setName("foo.Bar");
}
});
assertEquals(grammar.replace("foo.Foo", "foo.Bar"), document.get());
}
use of org.eclipse.xtext.ui.editor.model.IXtextDocument in project xtext-eclipse by eclipse.
the class XtextDocumentModifyTest method testTextualModification.
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=406811
@Test
public void testTextualModification() throws Exception {
// @formatter:off
final String grammar = text("grammar foo.Foo", "generate foo \"http://foo.net/foo\"", "Foo: 'foo';");
// @formatter:on
final IXtextDocument document = createDocument(grammar);
document.modify(new IUnitOfWork.Void<XtextResource>() {
@Override
public void process(XtextResource state) throws Exception {
document.replace(grammar.indexOf("Foo"), 3, "Bar");
}
});
assertEquals(grammar.replace("foo.Foo", "foo.Bar"), document.get());
}
use of org.eclipse.xtext.ui.editor.model.IXtextDocument in project xtext-eclipse by eclipse.
the class DefaultFoldingRegionProviderTest method openFileAndReturnDocument.
protected IXtextDocument openFileAndReturnDocument(IFile iFile) throws Exception {
XtextEditor editor = openEditor(iFile);
IXtextDocument document = editor.getDocument();
return document;
}
use of org.eclipse.xtext.ui.editor.model.IXtextDocument in project xtext-eclipse by eclipse.
the class DefaultFoldingRegionProviderTest method testShouldProcessContent.
@SuppressWarnings("deprecation")
@Test
public void testShouldProcessContent() throws Exception {
IFile iFile = createFile("foo/bar.foldingtestlanguage", "element foo \n" + "element bar \n" + "end \n" + "end");
IXtextDocument document = openFileAndReturnDocument(iFile);
DefaultFoldingRegionProvider reg = new DefaultFoldingRegionProvider(new DefaultLocationInFileProvider()) {
@Override
protected boolean shouldProcessContent(EObject object) {
if (object instanceof Element) {
return !"foo".equals(((Element) object).getName());
}
return super.shouldProcessContent(object);
}
};
Collection<FoldedPosition> regions = reg.getFoldingRegions(document);
assertEquals(1, regions.size());
assertEquals(0, regions.iterator().next().getOffset());
}
Aggregations