Search in sources :

Example 66 with ITextRegionAccess

use of org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess in project xtext-core by eclipse.

the class RegionAccessDiffTest method testSerializeChildObject.

@Test
public void testSerializeChildObject() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("2 foo");
    _builder.newLine();
    final ITextRegionAccess access = this._regionAccessTestHelper.toTextRegionAccess(_builder);
    final Procedure1<ITextRegionDiffBuilder> _function = (ITextRegionDiffBuilder it) -> {
        EObject _semanticElement = access.regionForRootEObject().getSemanticElement();
        final Delegate child = ((Delegation) _semanticElement).getDelegate();
        final IEObjectRegion childRegion = access.regionForEObject(child);
        child.setName("baaaz");
        final ITextRegionAccess textRegions = this.serializer.serializeToRegions(child);
        it.replace(childRegion.getPreviousHiddenRegion(), childRegion.getNextHiddenRegion(), textRegions);
    };
    ITextRegionAccess _modify = this._regionAccessTestHelper.modify(access, _function);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("0 0   H");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("B Delegation Root");
    _builder_1.newLine();
    _builder_1.append("0 1    S \"2\"        Delegation:\'2\'");
    _builder_1.newLine();
    _builder_1.append("1 1 1  H \" \"        Whitespace:TerminalRule\'WS\'");
    _builder_1.newLine();
    _builder_1.append("       ");
    _builder_1.append("B Delegate\'baaaz\' Delegate path:Delegation/delegate");
    _builder_1.newLine();
    _builder_1.append("2 5 1   S \"baaaz\"    Delegate:name=ID");
    _builder_1.newLine();
    _builder_1.append("       ");
    _builder_1.append("E Delegate\'baaaz\' Delegate path:Delegation/delegate");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("E Delegation Root");
    _builder_1.newLine();
    _builder_1.append("7 0 1 H");
    _builder_1.newLine();
    _builder_1.append("------------ diff 1 ------------");
    _builder_1.newLine();
    _builder_1.append("1 1  H \" \"        Whitespace:TerminalRule\'WS\'");
    _builder_1.newLine();
    _builder_1.append("2 3  S \"foo\"      Delegate:name=ID");
    _builder_1.newLine();
    _builder_1.append("5 0  H");
    _builder_1.newLine();
    this._regionAccessTestHelper.operator_tripleEquals(_modify, _builder_1);
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) Delegate(org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Delegate) IEObjectRegion(org.eclipse.xtext.formatting2.regionaccess.IEObjectRegion) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) ITextRegionDiffBuilder(org.eclipse.xtext.formatting2.regionaccess.ITextRegionDiffBuilder) Test(org.junit.Test)

Example 67 with ITextRegionAccess

use of org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess in project xtext-core by eclipse.

the class RegionAccessTestHelper method operator_tripleEquals.

public void operator_tripleEquals(final ITextRegionAccess access, final CharSequence expectation) {
    if ((access instanceof ITextRegionAccessDiff)) {
        this.assertDiffs(((ITextRegionAccessDiff) access));
    }
    TextRegionAccessToString _cfg = this.cfg(new TextRegionAccessToString().withRegionAccess(access));
    final String tra1 = (_cfg + "\n");
    Assert.assertEquals(Strings.toPlatformLineSeparator(expectation), Strings.toPlatformLineSeparator(tra1));
}
Also used : ITextRegionAccessDiff(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccessDiff) TextRegionAccessToString(org.eclipse.xtext.formatting2.debug.TextRegionAccessToString) TextRegionAccessToString(org.eclipse.xtext.formatting2.debug.TextRegionAccessToString)

Example 68 with ITextRegionAccess

use of org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess in project xtext-core by eclipse.

the class RegionAccessTestHelper method modify.

public ITextRegionAccess modify(final ITextRegionAccess base, final Procedure1<? super ITextRegionDiffBuilder> modify) {
    final StringBasedTextRegionAccessDiffBuilder fac = new StringBasedTextRegionAccessDiffBuilder(base);
    modify.apply(fac);
    final StringBasedTextRegionAccessDiff modified = fac.create();
    return modified;
}
Also used : StringBasedTextRegionAccessDiffBuilder(org.eclipse.xtext.formatting2.regionaccess.internal.StringBasedTextRegionAccessDiffBuilder) StringBasedTextRegionAccessDiff(org.eclipse.xtext.formatting2.regionaccess.internal.StringBasedTextRegionAccessDiff)

Example 69 with ITextRegionAccess

use of org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess in project xtext-core by eclipse.

the class TextRegionsInTextToString method getFrame.

public ITextSegment getFrame() {
    if (this.frame != null)
        return this.frame;
    ITextRegionAccess access = getTextRegionAccess();
    if (access != null) {
        ITextSegment impactRegion = TextRegions.merge(this.items);
        List<ILineRegion> expandToLines = TextRegions.expandToLines(impactRegion, getLeadingLines(), getTrailingLines());
        return TextRegions.merge(expandToLines);
    }
    return null;
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) ILineRegion(org.eclipse.xtext.formatting2.regionaccess.ILineRegion) ITextSegment(org.eclipse.xtext.formatting2.regionaccess.ITextSegment)

Example 70 with ITextRegionAccess

use of org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess in project xtext-core by eclipse.

the class TextRegionsWithTitleToString method getFrame.

public ITextSegment getFrame() {
    if (this.frame != null)
        return this.frame;
    ITextRegionAccess access = getTextRegionAccess();
    if (access != null) {
        List<ITextSegment> segments = Lists.newArrayList();
        for (Item item : items) segments.add(item.getRegion());
        ITextSegment impactRegion = merge(segments);
        List<ILineRegion> expandToLines = expandToLines(impactRegion, getLeadingLines(), getTrailingLines());
        return merge(expandToLines);
    }
    return null;
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) ILineRegion(org.eclipse.xtext.formatting2.regionaccess.ILineRegion) ITextSegment(org.eclipse.xtext.formatting2.regionaccess.ITextSegment)

Aggregations

ITextRegionAccess (org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess)65 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)37 Test (org.junit.Test)37 IChangeSerializer (org.eclipse.xtext.ide.serializer.IChangeSerializer)21 ITextRegionDiffBuilder (org.eclipse.xtext.formatting2.regionaccess.ITextRegionDiffBuilder)17 ISemanticRegion (org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)16 EObject (org.eclipse.emf.ecore.EObject)13 OptionalChildList (org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.OptionalChildList)12 ITextSegment (org.eclipse.xtext.formatting2.regionaccess.ITextSegment)11 MandatoryValue (org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.MandatoryValue)11 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)10 ITextReplacement (org.eclipse.xtext.formatting2.regionaccess.ITextReplacement)9 EList (org.eclipse.emf.common.util.EList)8 TextRegionAccessToString (org.eclipse.xtext.formatting2.debug.TextRegionAccessToString)7 FormatterRequest (org.eclipse.xtext.formatting2.FormatterRequest)6 IEObjectRegion (org.eclipse.xtext.formatting2.regionaccess.IEObjectRegion)6 IHiddenRegion (org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion)6 ITextRegionExtensions (org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions)6 ILineRegion (org.eclipse.xtext.formatting2.regionaccess.ILineRegion)5 XtextResource (org.eclipse.xtext.resource.XtextResource)5