Search in sources :

Example 46 with ITextRegionAccess

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

the class PartialSerializerTest method testOptionalValueRemove.

@Test
public void testOptionalValueRemove() {
    final IChangeSerializer.IModification<OptionalValue> _function = (OptionalValue it) -> {
        it.setName(null);
    };
    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        Model");
    _builder.newLine();
    _builder.append("0 2    S \"#3\"                 Model:\'#3\'");
    _builder.newLine();
    _builder.append("      ");
    _builder.append("E OptionalValue        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\"                OptionalValue: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) 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 47 with ITextRegionAccess

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

the class PartialSerializerTest method testOptionalChildListInsertIntoFirst.

@Test
public void testOptionalChildListInsertIntoFirst() {
    final IChangeSerializer.IModification<OptionalChildList> _function = (OptionalChildList it) -> {
        EList<MandatoryValue> _children = it.getChildren();
        MandatoryValue _createMandatoryValue = this.fac.createMandatoryValue();
        final Procedure1<MandatoryValue> _function_1 = (MandatoryValue it_1) -> {
            it_1.setName("x1");
        };
        MandatoryValue _doubleArrow = ObjectExtensions.<MandatoryValue>operator_doubleArrow(_createMandatoryValue, _function_1);
        _children.add(0, _doubleArrow);
    };
    ITextRegionAccess _recordDiff = this.<OptionalChildList>recordDiff(OptionalChildList.class, "#13 x2", _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 1 1  H \" \"                  Whitespace:TerminalRule\'WS\'");
    _builder.newLine();
    _builder.append("       ");
    _builder.append("B MandatoryValue\'x1\'   MandatoryValue path:OptionalChildList/children[0]");
    _builder.newLine();
    _builder.append("4 2 1   S \"x1\"                 MandatoryValue:name=ID");
    _builder.newLine();
    _builder.append("       ");
    _builder.append("E MandatoryValue\'x1\'   MandatoryValue path:OptionalChildList/children[0]");
    _builder.newLine();
    _builder.append("6 0 1  H");
    _builder.newLine();
    _builder.append("       ");
    _builder.append("B MandatoryValue\'x2\'   OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[1]");
    _builder.newLine();
    _builder.append("6 2     S \"x2\"                 MandatoryValue:name=ID");
    _builder.newLine();
    _builder.append("       ");
    _builder.append("E MandatoryValue\'x2\'   OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[1]");
    _builder.newLine();
    _builder.append("      ");
    _builder.append("E OptionalChildList    Model");
    _builder.newLine();
    _builder.append("8 0   H");
    _builder.newLine();
    _builder.append("------------ diff 1 ------------");
    _builder.newLine();
    _builder.append("3 1 H \" \"                  Whitespace:TerminalRule\'WS\'");
    _builder.newLine();
    _builder.append("4 2 S \"x2\"                 MandatoryValue:name=ID");
    _builder.newLine();
    this._changeSerializerTestHelper.operator_tripleEquals(_recordDiff, _builder);
}
Also used : OptionalChildList(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.OptionalChildList) MandatoryValue(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.MandatoryValue) ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) EList(org.eclipse.emf.common.util.EList) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 48 with ITextRegionAccess

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

the class PartialSerializerTest method testOptionalChildChange.

@Test
public void testOptionalChildChange() {
    final IChangeSerializer.IModification<OptionalChild> _function = (OptionalChild it) -> {
        MandatoryValue _createMandatoryValue = this.fac.createMandatoryValue();
        final Procedure1<MandatoryValue> _function_1 = (MandatoryValue it_1) -> {
            it_1.setName("baz");
        };
        MandatoryValue _doubleArrow = ObjectExtensions.<MandatoryValue>operator_doubleArrow(_createMandatoryValue, _function_1);
        it.setChild(_doubleArrow);
    };
    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("2 1 1  H \" \"                  Whitespace:TerminalRule\'WS\'");
    _builder.newLine();
    _builder.append("       ");
    _builder.append("B MandatoryValue\'baz\'  MandatoryValue path:OptionalChild/child");
    _builder.newLine();
    _builder.append("3 3 1   S \"baz\"                MandatoryValue:name=ID");
    _builder.newLine();
    _builder.append("       ");
    _builder.append("E MandatoryValue\'baz\'  MandatoryValue path:OptionalChild/child");
    _builder.newLine();
    _builder.append("      ");
    _builder.append("E OptionalChild        Model");
    _builder.newLine();
    _builder.append("6 0 1 H");
    _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 : MandatoryValue(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.MandatoryValue) ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) OptionalChild(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.OptionalChild) IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 49 with ITextRegionAccess

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

the class PartialSerializerTest method testOptionalChildRemoveListMiddleTwo.

@Test
public void testOptionalChildRemoveListMiddleTwo() {
    final IChangeSerializer.IModification<OptionalChildList> _function = (OptionalChildList it) -> {
        EcoreUtil.remove(it.getChildren().get(2));
        EcoreUtil.remove(it.getChildren().get(1));
    };
    ITextRegionAccess _recordDiff = this.<OptionalChildList>recordDiff(OptionalChildList.class, "#13 a b c d", _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 1    H \" \"                  Whitespace:TerminalRule\'WS\'");
    _builder.newLine();
    _builder.append("       ");
    _builder.append("B MandatoryValue\'a\'    OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[0]");
    _builder.newLine();
    _builder.append("4 1     S \"a\"                  MandatoryValue:name=ID");
    _builder.newLine();
    _builder.append("       ");
    _builder.append("E MandatoryValue\'a\'    OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[0]");
    _builder.newLine();
    _builder.append("5   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\'d\'    OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[1]");
    _builder.newLine();
    _builder.append("8 1     S \"d\"                  MandatoryValue:name=ID");
    _builder.newLine();
    _builder.append("       ");
    _builder.append("E MandatoryValue\'d\'    OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[1]");
    _builder.newLine();
    _builder.append("      ");
    _builder.append("E OptionalChildList    Model");
    _builder.newLine();
    _builder.append("9 0   H");
    _builder.newLine();
    _builder.append("------------ diff 1 ------------");
    _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();
    _builder.append("------------ diff 2 ------------");
    _builder.newLine();
    _builder.append("7 1 H \" \"                  Whitespace:TerminalRule\'WS\'");
    _builder.newLine();
    _builder.append("8 1 S \"c\"                  MandatoryValue:name=ID");
    _builder.newLine();
    _builder.append("9 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 50 with ITextRegionAccess

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

the class PartialSerializerTest method testOptionalChildListInsertIntoEmpty2.

@Test
public void testOptionalChildListInsertIntoEmpty2() {
    final IChangeSerializer.IModification<OptionalChildList> _function = (OptionalChildList it) -> {
        EList<MandatoryValue> _children = it.getChildren();
        MandatoryValue _createMandatoryValue = this.fac.createMandatoryValue();
        final Procedure1<MandatoryValue> _function_1 = (MandatoryValue it_1) -> {
            it_1.setName("foo");
        };
        MandatoryValue _doubleArrow = ObjectExtensions.<MandatoryValue>operator_doubleArrow(_createMandatoryValue, _function_1);
        _children.add(_doubleArrow);
        EList<MandatoryValue> _children_1 = it.getChildren();
        MandatoryValue _createMandatoryValue_1 = this.fac.createMandatoryValue();
        final Procedure1<MandatoryValue> _function_2 = (MandatoryValue it_1) -> {
            it_1.setName("bar");
        };
        MandatoryValue _doubleArrow_1 = ObjectExtensions.<MandatoryValue>operator_doubleArrow(_createMandatoryValue_1, _function_2);
        _children_1.add(_doubleArrow_1);
    };
    ITextRegionAccess _recordDiff = this.<OptionalChildList>recordDiff(OptionalChildList.class, "#13", _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 1  S \"#13\"                Model:\'#13\'");
    _builder.newLine();
    _builder.append("3 0 1  H");
    _builder.newLine();
    _builder.append("       ");
    _builder.append("B MandatoryValue\'foo\'  MandatoryValue path:OptionalChildList/children[0]");
    _builder.newLine();
    _builder.append("3 3 1   S \"foo\"                MandatoryValue:name=ID");
    _builder.newLine();
    _builder.append("       ");
    _builder.append("E MandatoryValue\'foo\'  MandatoryValue path:OptionalChildList/children[0]");
    _builder.newLine();
    _builder.append("6 0 1  H");
    _builder.newLine();
    _builder.append("       ");
    _builder.append("B MandatoryValue\'bar\'  MandatoryValue path:OptionalChildList/children[1]");
    _builder.newLine();
    _builder.append("6 3 1   S \"bar\"                MandatoryValue:name=ID");
    _builder.newLine();
    _builder.append("       ");
    _builder.append("E MandatoryValue\'bar\'  MandatoryValue path:OptionalChildList/children[1]");
    _builder.newLine();
    _builder.append("      ");
    _builder.append("E OptionalChildList    Model");
    _builder.newLine();
    _builder.append("9 0 1 H");
    _builder.newLine();
    _builder.append("------------ diff 1 ------------");
    _builder.newLine();
    _builder.append("0 3  S \"#13\"                Model:\'#13\'");
    _builder.newLine();
    _builder.append("3 0  H");
    _builder.newLine();
    this._changeSerializerTestHelper.operator_tripleEquals(_recordDiff, _builder);
}
Also used : OptionalChildList(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.OptionalChildList) MandatoryValue(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.MandatoryValue) ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) EList(org.eclipse.emf.common.util.EList) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

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