Search in sources :

Example 51 with ITextRegionAccess

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

the class PartialSerializerTest method testOptionalValueChange.

@Test
public void testOptionalValueChange() {
    final IChangeSerializer.IModification<OptionalValue> _function = (OptionalValue it) -> {
        it.setName("baz");
    };
    ITextRegionAccess _recordDiff = this.<OptionalValue>recordDiff(OptionalValue.class, "#3 foo", _function);
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("0 0   H");
    _builder.newLine();
    _builder.append("      ");
    _builder.append("B OptionalValue\'baz\'   Model");
    _builder.newLine();
    _builder.append("0 2    S \"#3\"                 Model:\'#3\'");
    _builder.newLine();
    _builder.append("2 1    H \" \"                  Whitespace:TerminalRule\'WS\'");
    _builder.newLine();
    _builder.append("3 3 1  S \"baz\"                OptionalValue:name=ID");
    _builder.newLine();
    _builder.append("      ");
    _builder.append("E OptionalValue\'baz\'   Model");
    _builder.newLine();
    _builder.append("6 0   H");
    _builder.newLine();
    _builder.append("------------ diff 1 ------------");
    _builder.newLine();
    _builder.append("3 3 S \"foo\"                OptionalValue:name=ID");
    _builder.newLine();
    this._changeSerializerTestHelper.operator_tripleEquals(_recordDiff, _builder);
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) OptionalValue(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.OptionalValue) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 52 with ITextRegionAccess

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

the class PartialSerializerTest method testOptionalChildRemove.

@Test
public void testOptionalChildRemove() {
    final IChangeSerializer.IModification<OptionalChild> _function = (OptionalChild it) -> {
        it.setChild(null);
    };
    ITextRegionAccess _recordDiff = this.<OptionalChild>recordDiff(OptionalChild.class, "#5 foo", _function);
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("0 0   H");
    _builder.newLine();
    _builder.append("      ");
    _builder.append("B OptionalChild        Model");
    _builder.newLine();
    _builder.append("0 2    S \"#5\"                 Model:\'#5\'");
    _builder.newLine();
    _builder.append("      ");
    _builder.append("E OptionalChild        Model");
    _builder.newLine();
    _builder.append("2 1 1 H \" \"                  Whitespace:TerminalRule\'WS\'");
    _builder.newLine();
    _builder.append("------------ diff 1 ------------");
    _builder.newLine();
    _builder.append("2 1  H \" \"                  Whitespace:TerminalRule\'WS\'");
    _builder.newLine();
    _builder.append("3 3  S \"foo\"                MandatoryValue:name=ID");
    _builder.newLine();
    _builder.append("6 0  H");
    _builder.newLine();
    this._changeSerializerTestHelper.operator_tripleEquals(_recordDiff, _builder);
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) OptionalChild(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.OptionalChild) IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 53 with ITextRegionAccess

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

the class PartialSerializerTest method testOptionalChildRemoveListFirstTwo.

@Test
public void testOptionalChildRemoveListFirstTwo() {
    final IChangeSerializer.IModification<OptionalChildList> _function = (OptionalChildList it) -> {
        EcoreUtil.remove(it.getChildren().get(1));
        EcoreUtil.remove(it.getChildren().get(0));
    };
    ITextRegionAccess _recordDiff = this.<OptionalChildList>recordDiff(OptionalChildList.class, "#13 a b c", _function);
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("0 0   H");
    _builder.newLine();
    _builder.append("      ");
    _builder.append("B OptionalChildList    Model");
    _builder.newLine();
    _builder.append("0 3    S \"#13\"                Model:\'#13\'");
    _builder.newLine();
    _builder.append("3   2  H \" \"                  Whitespace:TerminalRule\'WS\'");
    _builder.newLine();
    _builder.append("       ");
    _builder.append("\" \"                  Whitespace:TerminalRule\'WS\'");
    _builder.newLine();
    _builder.append("  ");
    _builder.append("3    \" \"                  Whitespace:TerminalRule\'WS\'");
    _builder.newLine();
    _builder.append("       ");
    _builder.append("B MandatoryValue\'c\'    OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[0]");
    _builder.newLine();
    _builder.append("6 1     S \"c\"                  MandatoryValue:name=ID");
    _builder.newLine();
    _builder.append("       ");
    _builder.append("E MandatoryValue\'c\'    OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[0]");
    _builder.newLine();
    _builder.append("      ");
    _builder.append("E OptionalChildList    Model");
    _builder.newLine();
    _builder.append("7 0   H");
    _builder.newLine();
    _builder.append("------------ diff 1 ------------");
    _builder.newLine();
    _builder.append("3 1 H \" \"                  Whitespace:TerminalRule\'WS\'");
    _builder.newLine();
    _builder.append("4 1 S \"a\"                  MandatoryValue:name=ID");
    _builder.newLine();
    _builder.append("5 1 H \" \"                  Whitespace:TerminalRule\'WS\'");
    _builder.newLine();
    _builder.append("------------ diff 2 ------------");
    _builder.newLine();
    _builder.append("5 1 H \" \"                  Whitespace:TerminalRule\'WS\'");
    _builder.newLine();
    _builder.append("6 1 S \"b\"                  MandatoryValue:name=ID");
    _builder.newLine();
    _builder.append("7 1 H \" \"                  Whitespace:TerminalRule\'WS\'");
    _builder.newLine();
    this._changeSerializerTestHelper.operator_tripleEquals(_recordDiff, _builder);
}
Also used : OptionalChildList(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.OptionalChildList) ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 54 with ITextRegionAccess

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

the class StringBasedTextRegionAccessDiffBuilder method replace.

@Override
public void replace(IHiddenRegion originalFirst, IHiddenRegion originalLast, ITextRegionAccess acc) {
    checkOriginal(originalFirst);
    checkOriginal(originalLast);
    IEObjectRegion substituteRoot = acc.regionForRootEObject();
    IHiddenRegion substituteFirst = substituteRoot.getPreviousHiddenRegion();
    IHiddenRegion substituteLast = substituteRoot.getNextHiddenRegion();
    replace(originalFirst, originalLast, substituteFirst, substituteLast);
}
Also used : IEObjectRegion(org.eclipse.xtext.formatting2.regionaccess.IEObjectRegion) IHiddenRegion(org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion)

Example 55 with ITextRegionAccess

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

the class RegionAccessBuilderTest method operator_tripleEquals.

private void operator_tripleEquals(final CharSequence file, final CharSequence expectation) {
    try {
        final String exp = expectation.toString();
        final Root obj = this.parseHelper.parse(file);
        this.validationTestHelper.assertNoErrors(obj);
        final ITextRegionAccess access1 = this.createFromNodeModel(obj);
        final ITextRegionAccess access2 = this.serializer.serializeToRegions(obj);
        this.assertToStringDoesNotCrash(access1);
        this.assertToStringDoesNotCrash(access2);
        this.assertLinesAreConsistent(access1);
        this.assertLinesAreConsistent(access2);
        TextRegionAccessToString _cfg = this.cfg(new TextRegionAccessToString().withRegionAccess(access1));
        final String tra1 = (_cfg + "\n");
        TextRegionAccessToString _cfg_1 = this.cfg(new TextRegionAccessToString().withRegionAccess(access2));
        final String tra2 = (_cfg_1 + "\n");
        Assert.assertEquals(Strings.toPlatformLineSeparator(exp), Strings.toPlatformLineSeparator(tra1));
        Assert.assertEquals(Strings.toPlatformLineSeparator(exp), Strings.toPlatformLineSeparator(tra2));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) Root(org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Root) TextRegionAccessToString(org.eclipse.xtext.formatting2.debug.TextRegionAccessToString) TextRegionAccessToString(org.eclipse.xtext.formatting2.debug.TextRegionAccessToString)

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