use of org.eclipse.xtext.formatting2.IFormattableDocument in project xtext-core by eclipse.
the class FormatterReplacementsTest method testIdentityEditsAreFiltered.
@Test
public void testIdentityEditsAreFiltered() {
try {
final GenericFormatter<IDList> _function = new GenericFormatter<IDList>() {
@Override
protected void format(final IDList model, @Extension final ITextRegionExtensions regions, @Extension final IFormattableDocument document) {
final Consumer<ISemanticRegion> _function = (ISemanticRegion it) -> {
final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it_1) -> {
it_1.autowrap();
it_1.oneSpace();
};
document.prepend(it, _function_1);
};
regions.regionFor(model).ruleCallsTo(FormatterReplacementsTest.this._formatterTestLanguageGrammarAccess.getIDRule()).forEach(_function);
}
};
final GenericFormatter<IDList> formatter = _function;
final IDList parsed = this.parseHelper.parse("idlist aaa bbb");
final FormatterRequest request = this.requestProvider.get();
request.setAllowIdentityEdits(false);
Resource _eResource = parsed.eResource();
request.setTextRegionAccess(this.regionBuilder.forNodeModel(((XtextResource) _eResource)).create());
final List<ITextReplacement> replacements = formatter.format(request);
final Function1<ITextReplacement, String> _function_1 = (ITextReplacement it) -> {
StringConcatenation _builder = new StringConcatenation();
_builder.append("\"");
String _text = it.getText();
_builder.append(_text);
_builder.append("\" -> \"");
String _replacementText = it.getReplacementText();
_builder.append(_replacementText);
_builder.append("\"");
_builder.append("\n");
return _builder.toString();
};
final String actual = IterableExtensions.join(ListExtensions.<ITextReplacement, String>map(replacements, _function_1));
StringConcatenation _builder = new StringConcatenation();
_builder.append("\" \" -> \" \"");
_builder.newLine();
final String expected = _builder.toString();
Assert.assertEquals(expected, actual);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.formatting2.IFormattableDocument in project xtext-core by eclipse.
the class FormattingConflictTest method enableDebugTracingFalse.
@Test
public void enableDebugTracingFalse() {
final Wrapper<Throwable> wrapper = new Wrapper<Throwable>();
final Wrapper<Integer> execution = new Wrapper<Integer>(Integer.valueOf(0));
final Procedure1<GenericFormatterTestRequest> _function = (GenericFormatterTestRequest it) -> {
StringConcatenation _builder = new StringConcatenation();
_builder.append("idlist a");
_builder.newLine();
it.setToBeFormatted(_builder);
final GenericFormatter<IDList> _function_1 = new GenericFormatter<IDList>() {
@Override
protected void format(final IDList model, @Extension final ITextRegionExtensions regions, @Extension final IFormattableDocument document) {
Integer _get = execution.get();
int _plus = ((_get).intValue() + 1);
execution.set(Integer.valueOf(_plus));
final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it_1) -> {
it_1.setSpace(" ");
};
document.append(regions.regionFor(model).keyword("idlist"), _function);
final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it_1) -> {
it_1.setSpace("\t");
};
document.append(regions.regionFor(model).keyword("idlist"), _function_1);
}
};
it.setFormatter(_function_1);
FormatterRequest _request = it.getRequest();
_request.setEnableDebugTracing(false);
FormatterRequest _request_1 = it.getRequest();
final IAcceptor<Exception> _function_2 = (Exception e) -> {
wrapper.set(e);
};
_request_1.setExceptionHandler(_function_2);
};
this._genericFormatterTester.assertFormatted(_function);
Throwable _get = wrapper.get();
final ConflictingRegionsException exception = ((ConflictingRegionsException) _get);
Assert.assertEquals(2, (execution.get()).intValue());
Assert.assertEquals(2, exception.getTraces().size());
}
use of org.eclipse.xtext.formatting2.IFormattableDocument in project xtext-core by eclipse.
the class FormattingConflictTest method enableDebugTracingTrue.
@Test
public void enableDebugTracingTrue() {
final Wrapper<Throwable> wrapper = new Wrapper<Throwable>();
final Wrapper<Integer> execution = new Wrapper<Integer>(Integer.valueOf(0));
final Procedure1<GenericFormatterTestRequest> _function = (GenericFormatterTestRequest it) -> {
StringConcatenation _builder = new StringConcatenation();
_builder.append("idlist a");
_builder.newLine();
it.setToBeFormatted(_builder);
final GenericFormatter<IDList> _function_1 = new GenericFormatter<IDList>() {
@Override
protected void format(final IDList model, @Extension final ITextRegionExtensions regions, @Extension final IFormattableDocument document) {
Integer _get = execution.get();
int _plus = ((_get).intValue() + 1);
execution.set(Integer.valueOf(_plus));
final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it_1) -> {
it_1.setSpace(" ");
};
document.append(regions.regionFor(model).keyword("idlist"), _function);
final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it_1) -> {
it_1.setSpace("\t");
};
document.append(regions.regionFor(model).keyword("idlist"), _function_1);
}
};
it.setFormatter(_function_1);
FormatterRequest _request = it.getRequest();
_request.setEnableDebugTracing(true);
FormatterRequest _request_1 = it.getRequest();
final IAcceptor<Exception> _function_2 = (Exception e) -> {
wrapper.set(e);
};
_request_1.setExceptionHandler(_function_2);
};
this._genericFormatterTester.assertFormatted(_function);
Throwable _get = wrapper.get();
final ConflictingRegionsException exception = ((ConflictingRegionsException) _get);
Assert.assertEquals(1, (execution.get()).intValue());
Assert.assertEquals(2, exception.getTraces().size());
}
use of org.eclipse.xtext.formatting2.IFormattableDocument in project xtext-xtend by eclipse.
the class RichStringFormatter method setSpace.
protected void setSpace(final IFormattableDocument doc, final int offset, final int length, final String space) {
IHiddenRegionFormatting _createHiddenRegionFormatting = doc.getFormatter().createHiddenRegionFormatting();
final Procedure1<IHiddenRegionFormatting> _function = (IHiddenRegionFormatting it) -> {
it.setSpace(space);
};
final IHiddenRegionFormatting fmt = ObjectExtensions.<IHiddenRegionFormatting>operator_doubleArrow(_createHiddenRegionFormatting, _function);
AbstractFormatter2 _formatter = doc.getFormatter();
ITextRegionAccess _textRegionAccess = this._iTextRegionExtensions.getTextRegionAccess();
TextSegment _textSegment = new TextSegment(_textRegionAccess, offset, length);
final ITextReplacer replacer = _formatter.createWhitespaceReplacer(_textSegment, fmt);
doc.addReplacer(replacer);
}
use of org.eclipse.xtext.formatting2.IFormattableDocument in project xtext-xtend by eclipse.
the class RichStringFormatter method _format.
protected void _format(final RichStringIf expr, @Extension final IFormattableDocument doc) {
final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
it.noSpace();
};
final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
it.oneSpace();
};
doc.append(doc.prepend(this._iTextRegionExtensions.regionFor(expr).keyword("IF"), _function), _function_1);
final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it) -> {
it.noSpace();
};
doc.<RichStringElseIf>append(IterableExtensions.<RichStringElseIf>last(expr.getElseIfs()), _function_2);
this.formatIntoSingleLine(doc, expr.getIf());
this.format(expr.getThen(), doc);
EList<RichStringElseIf> _elseIfs = expr.getElseIfs();
for (final RichStringElseIf elseif : _elseIfs) {
this.format(elseif, doc);
}
final Procedure1<IHiddenRegionFormatter> _function_3 = (IHiddenRegionFormatter it) -> {
it.noSpace();
};
doc.surround(this._iTextRegionExtensions.regionFor(expr).keyword("ELSE"), _function_3);
this.format(expr.getElse(), doc);
final Procedure1<IHiddenRegionFormatter> _function_4 = (IHiddenRegionFormatter it) -> {
it.noSpace();
};
doc.surround(this._iTextRegionExtensions.regionFor(expr).keyword("ENDIF"), _function_4);
}
Aggregations