use of org.eclipse.xtext.ui.editor.model.XtextDocument in project xtext-xtend by eclipse.
the class ReplacingAppendableTest method insertListField.
protected XtextDocument insertListField(final String model, final String fieldName) throws Exception {
final int cursorPosition = model.indexOf('|');
String actualModel = model.replace("|", " ");
final XtendFile file = testHelper.xtendFile("Foo", actualModel);
final XtextDocument document = documentProvider.get();
document.set(actualModel);
XtextResource xtextResource = (XtextResource) file.eResource();
document.setInput(xtextResource);
final EObject context = eObjectAtOffsetHelper.resolveElementAt(xtextResource, cursorPosition);
document.modify(new IUnitOfWork.Void<XtextResource>() {
@Override
public void process(XtextResource state) throws Exception {
ReplacingAppendable a = appendableFactory.create(document, state, cursorPosition, 1);
ITypeReferenceOwner owner = new StandardTypeReferenceOwner(services, context);
LightweightTypeReference typeRef = owner.toLightweightTypeReference(services.getTypeReferences().getTypeForName(List.class, context, typesFactory.createJvmWildcardTypeReference()));
a.append(typeRef);
a.append(" ").append(fieldName);
a.commitChanges();
}
});
return document;
}
use of org.eclipse.xtext.ui.editor.model.XtextDocument in project xtext-xtend by eclipse.
the class ReplacingAppendableTest method testImports_5.
@Test
public void testImports_5() throws Exception {
final XtextDocument document = insertListField("import static java.util.List.* class Foo {|}", "foo");
assertEqualsIgnoreWhitespace("import static java.util.List.*\n" + "import java.util.List\n" + "\n" + "class Foo {List<?> foo}", document.get());
}
use of org.eclipse.xtext.ui.editor.model.XtextDocument in project xtext-xtend by eclipse.
the class PresentationDamagerTest method createDocument.
@Override
public Document createDocument(final String before) throws Exception {
XtextDocument _xblockexpression = null;
{
XtendDocumentTokenSource _xtendDocumentTokenSource = new XtendDocumentTokenSource();
final Procedure1<XtendDocumentTokenSource> _function = (XtendDocumentTokenSource it) -> {
AntlrTokenDefProvider _antlrTokenDefProvider = new AntlrTokenDefProvider();
final Procedure1<AntlrTokenDefProvider> _function_1 = (AntlrTokenDefProvider it_1) -> {
XtendAntlrTokenFileProvider _xtendAntlrTokenFileProvider = new XtendAntlrTokenFileProvider();
it_1.setAntlrTokenFileProvider(_xtendAntlrTokenFileProvider);
};
AntlrTokenDefProvider _doubleArrow = ObjectExtensions.<AntlrTokenDefProvider>operator_doubleArrow(_antlrTokenDefProvider, _function_1);
it.setTokenDefProvider(_doubleArrow);
final Provider<Lexer> _function_2 = () -> {
return this.createLexer();
};
it.setLexer(_function_2);
it.setFlexerFactory(this.flexerFactory);
};
final XtendDocumentTokenSource source = ObjectExtensions.<XtendDocumentTokenSource>operator_doubleArrow(_xtendDocumentTokenSource, _function);
final XtextDocument document = new XtextDocument(source, null, this.outdatedStateManager, this.operationCanceledManager);
document.set(before);
_xblockexpression = document;
}
return _xblockexpression;
}
Aggregations