use of org.eclipse.xtext.formatting2.IAutowrapFormatter in project xtext-core by eclipse.
the class FormattableDocumentTest method autoWrapRewrite.
@Test
public void autoWrapRewrite() {
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 Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it_1) -> {
it_1.autowrap();
final IAutowrapFormatter _function_1 = (ITextSegment region, IHiddenRegionFormatting wrapped, IFormattableDocument doc) -> {
final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it_2) -> {
it_2.setSpace("!");
};
doc.append(regions.regionFor(model).keyword("kw1"), _function_2);
};
it_1.setOnAutowrap(_function_1);
final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it_2) -> {
it_2.setSpace("@");
it_2.lowPriority();
};
document.append(regions.regionFor(model).keyword("kw1"), _function_2);
};
document.append(regions.regionFor(model).keyword("kwlist"), _function);
}
};
it.setFormatter(_function_2);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("kwlist");
_builder_1.newLine();
_builder_1.append("kw1!kw2");
_builder_1.newLine();
it.setExpectation(_builder_1);
};
this._genericFormatterTester.assertFormatted(_function);
}
use of org.eclipse.xtext.formatting2.IAutowrapFormatter in project xtext-core by eclipse.
the class WhitespaceReplacer method createReplacements.
@Override
public ITextReplacerContext createReplacements(ITextReplacerContext context) {
if (formatting.getAutowrap() != null && formatting.getAutowrap() >= 0)
context.setCanAutowrap(formatting.getAutowrap());
String space = formatting.getSpace();
int trailingNewLinesOfPreviousRegion = trailingNewLinesOfPreviousRegion();
int computedNewLineCount = computeNewLineCount(context);
int newLineCount = Math.max(computedNewLineCount - trailingNewLinesOfPreviousRegion, 0);
if (newLineCount == 0 && context.isAutowrap()) {
IAutowrapFormatter onAutowrap = formatting.getOnAutowrap();
if (onAutowrap != null) {
onAutowrap.format(region, formatting, context.getDocument());
}
newLineCount = 1;
}
int indentationCount = computeNewIndentation(context);
if (newLineCount == 0 && trailingNewLinesOfPreviousRegion == 0) {
if (space != null)
context.addReplacement(region.replaceWith(space));
} else {
boolean noIndentation = formatting.getNoIndentation() == Boolean.TRUE;
String newLines = context.getNewLinesString(newLineCount);
String indentation = noIndentation ? "" : context.getIndentationString(indentationCount);
context.addReplacement(region.replaceWith(newLines + indentation));
}
return context.withIndentation(indentationCount);
}
use of org.eclipse.xtext.formatting2.IAutowrapFormatter in project xtext-core by eclipse.
the class FormattableDocumentTest method autoWrapInsert.
@Test
public void autoWrapInsert() {
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 Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it_1) -> {
it_1.autowrap();
final IAutowrapFormatter _function_1 = (ITextSegment region, IHiddenRegionFormatting wrapped, IFormattableDocument doc) -> {
final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it_2) -> {
it_2.setSpace("!");
};
doc.append(regions.regionFor(model).keyword("kw1"), _function_2);
};
it_1.setOnAutowrap(_function_1);
final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it_2) -> {
String _property = System.getProperty("line.separator");
String _plus = ("@" + _property);
it_2.setSpace(_plus);
};
document.append(regions.regionFor(model).keyword("kw2"), _function_2);
};
document.append(regions.regionFor(model).keyword("kwlist"), _function);
}
};
it.setFormatter(_function_2);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("kwlist");
_builder_1.newLine();
_builder_1.append("kw1!kw2@");
_builder_1.newLine();
it.setExpectation(_builder_1);
};
this._genericFormatterTester.assertFormatted(_function);
}
Aggregations