use of org.eclipse.xtext.formatting2.FormatterRequest in project xtext-core by eclipse.
the class FormatterReplacementsTest method testUndefinedIdentityEditsAreNotFiltered.
@Test
public void testUndefinedIdentityEditsAreNotFiltered() {
GenericFormatter<IDList> formatter = new GenericFormatter<IDList>() {
@Override
protected void format(IDList model, ITextRegionExtensions regions, IFormattableDocument document) {
regions.regionFor(model).ruleCallsTo(formatterTestLanguageGrammarAccess.getIDRule()).forEach(r -> {
document.prepend(r, it -> it.setSpace(""));
});
}
};
IDList model = fact.createIDList();
model.getIds().add("a");
Resource r = resFact.createResource(URI.createURI("foo.ext"));
new XtextResourceSet().getResources().add(r);
r.getContents().add(model);
FormatterRequest request = requestProvider.get();
request.setAllowIdentityEdits(false);
request.setTextRegionAccess(serializer.serializeToRegions(model));
List<ITextReplacement> replacements = formatter.format(request);
String actual = Joiner.on("").join(Lists.transform(replacements, it -> ("'" + it.getText() + "' -> '" + it.getReplacementText() + "'\n")));
String expected = "'' -> ''\n" + "'' -> ''\n" + "'' -> ''\n";
Assert.assertEquals(expected, actual);
}
use of org.eclipse.xtext.formatting2.FormatterRequest in project xtext-core by eclipse.
the class FormatterReplacementsTest method testIdentityEditsAreFiltered.
@Test
public void testIdentityEditsAreFiltered() throws Exception {
GenericFormatter<IDList> formatter = new GenericFormatter<IDList>() {
@Override
protected void format(IDList model, ITextRegionExtensions regions, IFormattableDocument document) {
regions.regionFor(model).ruleCallsTo(formatterTestLanguageGrammarAccess.getIDRule()).forEach(r -> {
document.prepend(r, it -> {
it.autowrap();
it.oneSpace();
});
});
}
};
IDList parsed = parseHelper.parse("idlist aaa bbb");
FormatterRequest request = requestProvider.get();
request.setAllowIdentityEdits(false);
request.setTextRegionAccess(regionBuilder.forNodeModel((XtextResource) parsed.eResource()).create());
List<ITextReplacement> replacements = formatter.format(request);
String actual = Joiner.on("").join(Lists.transform(replacements, it -> ("'" + it.getText() + "' -> '" + it.getReplacementText() + "'\n")));
String expected = "' ' -> ' '\n";
Assert.assertEquals(expected, actual);
}
use of org.eclipse.xtext.formatting2.FormatterRequest in project xtext-core by eclipse.
the class RegionDiffFormatter method createFormatterRequest.
protected FormatterRequest createFormatterRequest(ITextRegionAccess rewritten) {
FormatterRequest request = formatterRequest.get();
request.setTextRegionAccess(rewritten);
return request;
}
use of org.eclipse.xtext.formatting2.FormatterRequest in project xtext-core by eclipse.
the class RegionDiffFormatter method createFormatterRequest.
protected FormatterRequest createFormatterRequest(ITextRegionAccessDiff rewritten) {
FormatterRequest request = formatterRequest.get();
request.setTextRegionAccess(rewritten);
request.setRegions(collectRegionsToFormat(rewritten));
return request;
}
use of org.eclipse.xtext.formatting2.FormatterRequest in project xtext-core by eclipse.
the class FormattingService method format2.
protected List<ITextReplacement> format2(XtextResource resource, ITextRegion selection, ITypedPreferenceValues preferences) {
FormatterRequest request = formatterRequestProvider.get();
request.setAllowIdentityEdits(false);
request.setFormatUndefinedHiddenRegionsOnly(false);
if (selection != null) {
request.setRegions(Collections.singletonList(selection));
}
if (preferences != null) {
request.setPreferences(preferences);
}
ITextRegionAccess regionAccess = regionBuilder.forNodeModel(resource).create();
request.setTextRegionAccess(regionAccess);
IFormatter2 formatter2 = formatter2Provider.get();
List<ITextReplacement> replacements = formatter2.format(request);
return replacements;
}
Aggregations