use of org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Add in project xtext-core by eclipse.
the class PartialSerializerTest method testOptionalChildListInsertIntoFirst.
@Test
public void testOptionalChildListInsertIntoFirst() {
ITextRegionAccess diff = recordDiff(OptionalChildList.class, "#13 x2", (OptionalChildList it) -> {
MandatoryValue newMandatoryValue = fac.createMandatoryValue();
newMandatoryValue.setName("x1");
it.getChildren().add(0, newMandatoryValue);
});
String expectation = "0 0 H\n" + " B OptionalChildList Model\n" + "0 3 S \"#13\" Model:'#13'\n" + "3 1 1 H \" \" Whitespace:TerminalRule'WS'\n" + " B MandatoryValue'x1' MandatoryValue path:OptionalChildList/children[0]\n" + "4 2 1 S \"x1\" MandatoryValue:name=ID\n" + " E MandatoryValue'x1' MandatoryValue path:OptionalChildList/children[0]\n" + "6 0 1 H\n" + " B MandatoryValue'x2' OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[1]\n" + "6 2 S \"x2\" MandatoryValue:name=ID\n" + " E MandatoryValue'x2' OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[1]\n" + " E OptionalChildList Model\n" + "8 0 H\n" + "------------ diff 1 ------------\n" + "3 1 H \" \" Whitespace:TerminalRule'WS'\n" + "4 2 S \"x2\" MandatoryValue:name=ID\n";
changeSerializerTestHelper.operator_tripleEquals(diff, expectation);
}
use of org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Add in project xtext-core by eclipse.
the class PartialSerializerTest method testOptionalChildListInsertIntoEmpty.
@Test
public void testOptionalChildListInsertIntoEmpty() {
ITextRegionAccess diff = recordDiff(OptionalChildList.class, "#13", (OptionalChildList it) -> {
MandatoryValue newMandatoryValue = fac.createMandatoryValue();
newMandatoryValue.setName("foo");
it.getChildren().add(newMandatoryValue);
});
String expectation = "0 0 H\n" + " B OptionalChildList Model\n" + "0 3 1 S \"#13\" Model:'#13'\n" + "3 0 1 H\n" + " B MandatoryValue'foo' MandatoryValue path:OptionalChildList/children[0]\n" + "3 3 1 S \"foo\" MandatoryValue:name=ID\n" + " E MandatoryValue'foo' MandatoryValue path:OptionalChildList/children[0]\n" + " E OptionalChildList Model\n" + "6 0 1 H\n" + "------------ diff 1 ------------\n" + "0 3 S \"#13\" Model:'#13'\n" + "3 0 H\n";
changeSerializerTestHelper.operator_tripleEquals(diff, expectation);
}
use of org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Add in project xtext-core by eclipse.
the class ChangeSerializerTestHelper method operator_tripleEquals.
public void operator_tripleEquals(Collection<IEmfResourceChange> actual, CharSequence expected) {
String actualString = new TextDocumentChangeToString().add(actual).toString();
Assert.assertEquals(Strings.toPlatformLineSeparator(expected).trim(), Strings.toPlatformLineSeparator(actualString).trim());
}
use of org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Add in project xtext-core by eclipse.
the class FormattableDocumentTest method shouldFormat.
/**
* see https://bugs.eclipse.org/bugs/show_bug.cgi?id=482110
*/
@Test
public void shouldFormat() {
genericFormatterTester.assertFormatted((GenericFormatterTestRequest it) -> {
it.getRequest().getRegions().add(new TextRegion(0, 6));
String model = "idlist";
it.setToBeFormatted(model);
it.setFormatter(new GenericFormatter<EObject>() {
@Override
protected void format(EObject model, ITextRegionExtensions regionAccess, IFormattableDocument document) {
throw new IllegalStateException("this method should never be called");
}
@Override
public boolean shouldFormat(Object obj, IFormattableDocument document) {
return false;
}
});
String expectation = "idlist";
it.setExpectation(expectation);
});
}
use of org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Add in project xtext-core by eclipse.
the class HiddenRegionReplacer method applyPriorityAndDefaultFormatting.
/**
* @since 2.23
*/
protected void applyPriorityAndDefaultFormatting(List<ITextReplacer> replacers, IHiddenRegionFormatting separator) {
for (int i = 0; i < replacers.size(); i++) {
ITextReplacer replacer = replacers.get(i);
if (replacer instanceof WhitespaceReplacer) {
IHiddenRegionFormatting formatting2 = ((WhitespaceReplacer) replacer).getFormatting();
formatting2.setPriority(formatting.getPriority());
if (formatting2 != separator) {
ITextReplacer previous = (i == 0) ? null : replacers.get(i - 1);
ITextReplacer next = (i + 1 >= replacers.size()) ? null : replacers.get(i + 1);
// Don't add single spaces after comments
if (previous == null || !(previous instanceof CommentReplacer)) {
// starts with a space
if (next == null || !(next instanceof MultilineCommentReplacer)) {
formatting2.setSpace(replacer.getRegion().getOffset() > 0 ? " " : "");
}
}
formatting2.setNewLinesMin(0);
formatting2.setNewLinesMax(1);
}
}
}
}
Aggregations