use of org.eclipse.xtext.formatting2.IFormattableSubDocument in project xtext-core by eclipse.
the class SubDocument method requireFitsInLine.
@Override
public IFormattableSubDocument requireFitsInLine(int offset, int length, int maxLineWidth) {
TextSegment segment = new TextSegment(getTextRegionAccess(), offset, length);
MaxLineWidthDocument document = new MaxLineWidthDocument(segment, this, maxLineWidth);
addReplacer(document);
return document;
}
use of org.eclipse.xtext.formatting2.IFormattableSubDocument in project xtext-core by eclipse.
the class FormattableDocumentTest method conditionalFormatting2.
@Test
public void conditionalFormatting2() {
final Procedure1<GenericFormatterTestRequest> _function = (GenericFormatterTestRequest it) -> {
final Procedure1<MapBasedPreferenceValues> _function_1 = (MapBasedPreferenceValues it_1) -> {
it_1.<Integer>put(FormatterPreferenceKeys.maxLineWidth, Integer.valueOf(30));
};
it.preferences(_function_1);
StringConcatenation _builder = new StringConcatenation();
_builder.append("kwlist kw1 kw2");
_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 ISubFormatter _function = (IFormattableSubDocument doc) -> {
@Extension final IFormattableSubDocument fits = doc.requireFitsInLine();
final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it_1) -> {
it_1.oneSpace();
};
fits.append(regions.regionFor(model).keyword("kwlist"), _function_1);
final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it_1) -> {
it_1.oneSpace();
};
fits.append(regions.regionFor(model).keyword("kw1"), _function_2);
};
final ISubFormatter _function_1 = (IFormattableSubDocument doc) -> {
final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it_1) -> {
it_1.newLine();
};
doc.append(regions.regionFor(model).keyword("kwlist"), _function_2);
final Procedure1<IHiddenRegionFormatter> _function_3 = (IHiddenRegionFormatter it_1) -> {
it_1.newLine();
};
doc.append(regions.regionFor(model).keyword("kw1"), _function_3);
};
document.formatConditionally(model, _function, _function_1);
}
};
it.setFormatter(_function_2);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("kwlist kw1 kw2");
_builder_1.newLine();
it.setExpectation(_builder_1);
};
this._genericFormatterTester.assertFormatted(_function);
}
use of org.eclipse.xtext.formatting2.IFormattableSubDocument in project xtext-core by eclipse.
the class FormattableDocumentTest method conditionalFormatting1.
@Test
public void conditionalFormatting1() {
final Procedure1<GenericFormatterTestRequest> _function = (GenericFormatterTestRequest it) -> {
final Procedure1<MapBasedPreferenceValues> _function_1 = (MapBasedPreferenceValues it_1) -> {
it_1.<Integer>put(FormatterPreferenceKeys.maxLineWidth, Integer.valueOf(10));
};
it.preferences(_function_1);
StringConcatenation _builder = new StringConcatenation();
_builder.append("kwlist kw1 kw2");
_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 ISubFormatter _function = (IFormattableSubDocument doc) -> {
@Extension final IFormattableSubDocument fits = doc.requireFitsInLine();
final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it_1) -> {
it_1.oneSpace();
};
fits.append(regions.regionFor(model).keyword("kwlist"), _function_1);
final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it_1) -> {
it_1.oneSpace();
};
fits.append(regions.regionFor(model).keyword("kw1"), _function_2);
};
final ISubFormatter _function_1 = (IFormattableSubDocument doc) -> {
final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it_1) -> {
it_1.newLine();
};
doc.append(regions.regionFor(model).keyword("kwlist"), _function_2);
final Procedure1<IHiddenRegionFormatter> _function_3 = (IHiddenRegionFormatter it_1) -> {
it_1.newLine();
};
doc.append(regions.regionFor(model).keyword("kw1"), _function_3);
};
document.formatConditionally(model, _function, _function_1);
}
};
it.setFormatter(_function_2);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("kwlist");
_builder_1.newLine();
_builder_1.append("kw1");
_builder_1.newLine();
_builder_1.append("kw2");
_builder_1.newLine();
it.setExpectation(_builder_1);
};
this._genericFormatterTester.assertFormatted(_function);
}
Aggregations