use of org.eclipse.xtext.formatting2.debug.TextRegionsToString in project xtext-core by eclipse.
the class FormatterTestHelper method assertAllWhitespaceIsFormatted.
protected void assertAllWhitespaceIsFormatted(ITextRegionAccess access, List<ITextReplacement> replacements) {
List<ITextSegment> expected = Lists.newArrayList();
IHiddenRegion current = access.regionForRootEObject().getPreviousHiddenRegion();
while (current != null) {
expected.addAll(current.getMergedSpaces());
current = current.getNextHiddenRegion();
}
List<ITextSegment> missing = TextRegions.difference(expected, replacements);
if (!missing.isEmpty()) {
TextRegionsToString toString = new TextRegionsToString().setTextRegionAccess(access);
for (ITextSegment region : missing) toString.add(region, region.getClass().getSimpleName());
String msg = "The following regions are not formatted:\n" + toString;
System.err.println(msg);
Assert.fail(msg);
}
}
use of org.eclipse.xtext.formatting2.debug.TextRegionsToString in project xtext-core by eclipse.
the class FormatterTestHelper method assertReplacementsAreInRegion.
protected void assertReplacementsAreInRegion(List<ITextReplacement> rep, Collection<ITextRegion> regions, String doc) {
Set<ITextReplacement> invalid = Sets.newHashSet();
ALLOWED: for (ITextRegion allowed : regions) for (ITextReplacement r : rep) {
if (allowed.contains(r))
continue ALLOWED;
invalid.add(r);
}
if (!invalid.isEmpty()) {
String visualized = new TextRegionsToString().addAllReplacements(invalid).toString();
fail("One or more TextReplacements are outside of the allowed region. Region: " + regions, visualized);
}
}
use of org.eclipse.xtext.formatting2.debug.TextRegionsToString in project xtext-core by eclipse.
the class TextRegionsToStringTest method init.
@Before
public void init() {
TextRegionsToString _textRegionsToString = new TextRegionsToString();
this.textRegionsToString = _textRegionsToString;
this.textRegionsToString.setIgnoreCarriageReturnInQuotes(true);
}
use of org.eclipse.xtext.formatting2.debug.TextRegionsToString in project xtext-core by eclipse.
the class TextDocumentChangeToString method toString.
@Override
public String toString() {
List<String> result = Lists.newArrayList();
for (IEmfResourceChange c : changes) {
String title = getTitle(c);
if (c instanceof ITextDocumentChange) {
ITextDocumentChange change = (ITextDocumentChange) c;
TextRegionsToString textRegionsToString = new TextRegionsToString();
textRegionsToString.setIgnoreCarriageReturnInQuotes(true);
textRegionsToString.addAllReplacements(change.getReplacements());
textRegionsToString.setTitle(title);
result.add(textRegionsToString.toString());
} else {
String box = box(title, c.toString());
result.add(box);
}
}
return Joiner.on("\n").join(result);
}
use of org.eclipse.xtext.formatting2.debug.TextRegionsToString in project xtext-core by eclipse.
the class FormattableDocument method toString.
@Override
public String toString() {
TextRegionsToString toString = new TextRegionsToString();
toString.setFrame(this.getRegion());
toString.setTitle(getClass().getSimpleName() + " with ITextReplacers");
for (ITextReplacer repl : getReplacers()) toString.add(repl.getRegion(), repl.getClass().getSimpleName() + ": " + repl.toString());
return toString.toString();
}
Aggregations