Search in sources :

Example 1 with TextRegionsToString

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);
    }
}
Also used : IHiddenRegion(org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion) ITextSegment(org.eclipse.xtext.formatting2.regionaccess.ITextSegment) TextRegionAccessToString(org.eclipse.xtext.formatting2.debug.TextRegionAccessToString) TextRegionsToString(org.eclipse.xtext.formatting2.debug.TextRegionsToString) TextRegionsToString(org.eclipse.xtext.formatting2.debug.TextRegionsToString)

Example 2 with TextRegionsToString

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);
    }
}
Also used : ITextReplacement(org.eclipse.xtext.formatting2.regionaccess.ITextReplacement) ITextRegion(org.eclipse.xtext.util.ITextRegion) TextRegionAccessToString(org.eclipse.xtext.formatting2.debug.TextRegionAccessToString) TextRegionsToString(org.eclipse.xtext.formatting2.debug.TextRegionsToString) TextRegionsToString(org.eclipse.xtext.formatting2.debug.TextRegionsToString)

Example 3 with TextRegionsToString

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);
}
Also used : TextRegionsToString(org.eclipse.xtext.formatting2.debug.TextRegionsToString) Before(org.junit.Before)

Example 4 with TextRegionsToString

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);
}
Also used : ITextDocumentChange(org.eclipse.xtext.ide.serializer.ITextDocumentChange) TextRegionsToString(org.eclipse.xtext.formatting2.debug.TextRegionsToString) TextRegionsToString(org.eclipse.xtext.formatting2.debug.TextRegionsToString) IEmfResourceChange(org.eclipse.xtext.ide.serializer.IEmfResourceChange)

Example 5 with TextRegionsToString

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();
}
Also used : ITextReplacer(org.eclipse.xtext.formatting2.ITextReplacer) TextRegionsToString(org.eclipse.xtext.formatting2.debug.TextRegionsToString)

Aggregations

TextRegionsToString (org.eclipse.xtext.formatting2.debug.TextRegionsToString)6 TextRegionAccessToString (org.eclipse.xtext.formatting2.debug.TextRegionAccessToString)2 ITextReplacer (org.eclipse.xtext.formatting2.ITextReplacer)1 IHiddenRegion (org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion)1 ITextReplacement (org.eclipse.xtext.formatting2.regionaccess.ITextReplacement)1 ITextSegment (org.eclipse.xtext.formatting2.regionaccess.ITextSegment)1 IEmfResourceChange (org.eclipse.xtext.ide.serializer.IEmfResourceChange)1 ITextDocumentChange (org.eclipse.xtext.ide.serializer.ITextDocumentChange)1 ITextRegion (org.eclipse.xtext.util.ITextRegion)1 Before (org.junit.Before)1