use of org.eclipse.xtext.ui.editor.model.XtextDocument in project xtext-xtend by eclipse.
the class XtendFormatterPreview method doUpdate.
@SuppressWarnings("deprecation")
public void doUpdate(final Map<String, String> map) {
checkEditorHandleIsSet();
final MapBasedPreferenceValues values = new MapBasedPreferenceValues(map);
String maxLineWidthValue = values.getPreference(maxLineWidth);
if (maxLineWidthValue != null) {
moveMarginToColumn(maxLineWidthValue);
}
StyledText widget = null;
try {
widget = (StyledText) editorHandle.getViewer().getControl();
// disable redraw, otherwise this would causes funny animation effects during formating.
widget.setRedraw(false);
this.modelAccess.updateModel("", previewContent, "");
XtextDocument document = editorHandle.getDocument();
ContentFormatter formatter = formatterProvider.get();
formatter.setPreferencesProvider(values);
formatter.format(document, new Region(0, document.getLength()));
// reset selection, otherwise the whole new content will be selected
editorHandle.getViewer().setSelection(null);
} finally {
if (widget != null)
widget.setRedraw(true);
}
}
use of org.eclipse.xtext.ui.editor.model.XtextDocument in project xtext-xtend by eclipse.
the class ReplacingAppendableTest method testImports_4.
@Test
public void testImports_4() throws Exception {
final XtextDocument document = insertListField("package test\n" + "/**\n" + "*/\n" + "\n" + "class Foo {|}", "foo");
assertEqualsIgnoreWhitespace("package test\n" + "\n" + "import java.util.List\n" + "\n" + "/**\n" + "*/\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 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 AbstractOutlineTests method newAssertBuilder.
protected AssertBuilder newAssertBuilder(XtendFile xtendFile) throws Exception, CoreException {
XtextDocument document = documentProvider.get();
document.setInput((XtextResource) xtendFile.eResource());
IOutlineNode root = treeProvider.createRoot(document);
AssertBuilder assertBuilder = new AssertBuilder(root);
return assertBuilder;
}
Aggregations