use of org.eclipse.xtext.preferences.MapBasedPreferenceValues in project xtext-core by eclipse.
the class FormattableDocumentTest method autowrapNotInPreviousLineBetweenFormattedRegions.
@Test
public void autowrapNotInPreviousLineBetweenFormattedRegions() {
final Procedure1<GenericFormatterTestRequest> _function = (GenericFormatterTestRequest it) -> {
final Procedure1<MapBasedPreferenceValues> _function_1 = (MapBasedPreferenceValues it_1) -> {
it_1.<Integer>put(FormatterPreferenceKeys.maxLineWidth, Integer.valueOf(5));
};
it.preferences(_function_1);
StringConcatenation _builder = new StringConcatenation();
_builder.append("kwlist kw1");
_builder.newLine();
_builder.append("kw2 kw3 kw4 kw5");
_builder.newLine();
it.setToBeFormatted(_builder);
final GenericFormatter<KWList> _function_2 = new GenericFormatter<KWList>() {
@Override
protected void format(final KWList model, @Extension final ITextRegionExtensions regions, @Extension final IFormattableDocument document) {
final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it_1) -> {
it_1.autowrap();
it_1.oneSpace();
};
document.append(regions.regionFor(model).keyword("kwlist"), _function);
final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it_1) -> {
it_1.oneSpace();
};
document.append(regions.regionFor(model).keyword("kw4"), _function_1);
}
};
it.setFormatter(_function_2);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("kwlist kw1");
_builder_1.newLine();
_builder_1.append("kw2 kw3 kw4 kw5");
_builder_1.newLine();
it.setExpectation(_builder_1);
};
this._genericFormatterTester.assertFormatted(_function);
}
use of org.eclipse.xtext.preferences.MapBasedPreferenceValues 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.preferences.MapBasedPreferenceValues in project xtext-xtend by eclipse.
the class AbstractXtendFormatterTest method assertFormatted.
public void assertFormatted(final Procedure1<? super MapBasedPreferenceValues> cfg, final CharSequence expectation, final CharSequence toBeFormatted, final String prefix, final String postfix, final boolean allowErrors) {
final Procedure1<FormatterTestRequest> _function = (FormatterTestRequest it) -> {
final Procedure1<MapBasedPreferenceValues> _function_1 = (MapBasedPreferenceValues it_1) -> {
it_1.<Integer>put(FormatterPreferenceKeys.maxLineWidth, Integer.valueOf(80));
it_1.<Boolean>put(XtendFormatterPreferenceKeys.keepOneLineMethods, Boolean.valueOf(false));
if (cfg != null) {
cfg.apply(it_1);
}
};
it.preferences(_function_1);
it.setExpectation(((prefix + expectation) + postfix));
it.setToBeFormatted(((prefix + toBeFormatted) + postfix));
Collection<ITextRegion> _regions = it.getRequest().getRegions();
int _length = prefix.length();
int _length_1 = toBeFormatted.length();
TextRegion _textRegion = new TextRegion(_length, _length_1);
_regions.add(_textRegion);
it.setAllowSyntaxErrors(allowErrors);
};
this.tester.assertFormatted(_function);
}
use of org.eclipse.xtext.preferences.MapBasedPreferenceValues in project xtext-xtend by eclipse.
the class AnonymousClassFormatterTest method formatNested.
@Test
public void formatNested() {
final Procedure1<MapBasedPreferenceValues> _function = (MapBasedPreferenceValues it) -> {
it.<Boolean>put(XbaseFormatterPreferenceKeys.bracesInNewLine, Boolean.valueOf(false));
};
StringConcatenation _builder = new StringConcatenation();
_builder.append("import java.util.Iterator");
_builder.newLine();
_builder.newLine();
_builder.append("class Foo {");
_builder.newLine();
_builder.append("\t");
_builder.append("val foo = new Iterable<String>() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("override iterator() {");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("new Iterator<String>() {");
_builder.newLine();
_builder.append("\t\t\t\t");
_builder.append("override hasNext() {");
_builder.newLine();
_builder.append("\t\t\t\t\t");
_builder.append("true");
_builder.newLine();
_builder.append("\t\t\t\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("\t\t\t\t");
_builder.append("override next() {");
_builder.newLine();
_builder.append("\t\t\t\t\t");
_builder.append("null");
_builder.newLine();
_builder.append("\t\t\t\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("\t\t\t\t");
_builder.append("override remove() {");
_builder.newLine();
_builder.append("\t\t\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
this.assertFormatted(_function, _builder);
}
use of org.eclipse.xtext.preferences.MapBasedPreferenceValues in project xtext-xtend by eclipse.
the class XtendAnnotationTypeFormatterTest method formatPublicAbstract.
@Test
public void formatPublicAbstract() {
final Procedure1<MapBasedPreferenceValues> _function = (MapBasedPreferenceValues it) -> {
};
StringConcatenation _builder = new StringConcatenation();
_builder.append("public abstract annotation Bar {");
_builder.newLine();
_builder.append("}");
_builder.newLine();
this.assertFormatted(_function, _builder);
}
Aggregations