use of org.eclipse.xtext.formatting2.internal.GenericFormatter in project xtext-core by eclipse.
the class FormattableDocumentTest method shouldFormat_02.
@Test(expected = IllegalStateException.class)
public void shouldFormat_02() {
final Procedure1<GenericFormatterTestRequest> _function = (GenericFormatterTestRequest it) -> {
Collection<ITextRegion> _regions = it.getRequest().getRegions();
TextRegion _textRegion = new TextRegion(0, 6);
_regions.add(_textRegion);
StringConcatenation _builder = new StringConcatenation();
_builder.append("idlist");
it.setToBeFormatted(_builder);
it.setFormatter(new GenericFormatter() {
@Override
protected void format(final EObject model, final ITextRegionExtensions regionAccess, final IFormattableDocument document) {
throw new IllegalStateException("this method should never be called");
}
@Override
public boolean shouldFormat(final Object obj, final IFormattableDocument document) {
return true;
}
});
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("idlist");
it.setExpectation(_builder_1);
};
this._genericFormatterTester.assertFormatted(_function);
}
use of org.eclipse.xtext.formatting2.internal.GenericFormatter in project xtext-core by eclipse.
the class FormattableDocumentTest method autowrapNotInPreviousLineInFormattedRegion.
@Test
public void autowrapNotInPreviousLineInFormattedRegion() {
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 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.newLine();
};
document.append(regions.regionFor(model).keyword("kw1"), _function_1);
final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it_1) -> {
it_1.oneSpace();
};
document.append(regions.regionFor(model).keyword("kw4"), _function_2);
}
};
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.formatting2.internal.GenericFormatter in project xtext-core by eclipse.
the class FormattableDocumentTest method aroundDocument.
@Test
public void aroundDocument() {
final Procedure1<GenericFormatterTestRequest> _function = (GenericFormatterTestRequest it) -> {
Collection<ITextRegion> _regions = it.getRequest().getRegions();
TextRegion _textRegion = new TextRegion(0, 6);
_regions.add(_textRegion);
StringConcatenation _builder = new StringConcatenation();
_builder.append("idlist");
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) {
final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it_1) -> {
it_1.setSpace("!");
};
document.surround(regions.regionFor(model).keyword("idlist"), _function);
}
};
it.setFormatter(_function_1);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("!idlist!");
it.setExpectation(_builder_1);
};
this._genericFormatterTester.assertFormatted(_function);
}
use of org.eclipse.xtext.formatting2.internal.GenericFormatter 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.formatting2.internal.GenericFormatter in project xtext-core by eclipse.
the class FormatterReplacementsTest method testUndefinedIdentityEditsAreNotFiltered.
@Test
public void testUndefinedIdentityEditsAreNotFiltered() {
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.setSpace("");
};
document.prepend(it, _function_1);
};
regions.regionFor(model).ruleCallsTo(FormatterReplacementsTest.this._formatterTestLanguageGrammarAccess.getIDRule()).forEach(_function);
}
};
final GenericFormatter<IDList> formatter = _function;
IDList _createIDList = this.fact.createIDList();
final Procedure1<IDList> _function_1 = (IDList it) -> {
EList<String> _ids = it.getIds();
_ids.add("a");
};
final IDList model = ObjectExtensions.<IDList>operator_doubleArrow(_createIDList, _function_1);
Resource _createResource = this.resFact.createResource(URI.createURI("foo.ext"));
final Procedure1<Resource> _function_2 = (Resource it) -> {
EList<Resource> _resources = new XtextResourceSet().getResources();
_resources.add(it);
EList<EObject> _contents = it.getContents();
_contents.add(model);
};
ObjectExtensions.<Resource>operator_doubleArrow(_createResource, _function_2);
final FormatterRequest request = this.requestProvider.get();
request.setAllowIdentityEdits(false);
request.setTextRegionAccess(this.serializer.serializeToRegions(model));
final List<ITextReplacement> replacements = formatter.format(request);
final Function1<ITextReplacement, String> _function_3 = (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_3));
StringConcatenation _builder = new StringConcatenation();
_builder.append("\"\" -> \"\"");
_builder.newLine();
_builder.append("\"\" -> \"\"");
_builder.newLine();
_builder.append("\"\" -> \"\"");
_builder.newLine();
final String expected = _builder.toString();
Assert.assertEquals(expected, actual);
}
Aggregations