Search in sources :

Example 11 with ITextRegionAccess

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

the class ChangeSerializerTestHelper method operator_tripleEquals.

public void operator_tripleEquals(final ITextRegionAccess actual, final CharSequence expected) {
    final String actualString = new TextRegionAccessToString().withRegionAccess(actual).hideColumnExplanation().toString();
    Assert.assertEquals(Strings.toPlatformLineSeparator(expected).trim(), Strings.toPlatformLineSeparator(actualString).trim());
}
Also used : TextRegionAccessToString(org.eclipse.xtext.formatting2.debug.TextRegionAccessToString) TextDocumentChangeToString(org.eclipse.xtext.ide.serializer.debug.TextDocumentChangeToString) TextRegionAccessToString(org.eclipse.xtext.formatting2.debug.TextRegionAccessToString)

Example 12 with ITextRegionAccess

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

the class PartialSerializerTest method testMoveInList1.

@Test
public void testMoveInList1() {
    final IChangeSerializer.IModification<Node> _function = (Node it) -> {
        it.getChildren().move(0, 1);
    };
    ITextRegionAccess _recordDiff = this.<Node>recordDiff(Node.class, "#1 root { Foo; Bar; }", _function);
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("0 0   H");
    _builder.newLine();
    _builder.append("       ");
    _builder.append("B Node\'root\'           Model");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("0 2    S \"#1\"                 Model:\'#1\'");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("2 1    H \" \"                  Whitespace:TerminalRule\'WS\'");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("3 4    S \"root\"               Node:name=ID");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("7 1    H \" \"                  Whitespace:TerminalRule\'WS\'");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("8 1    S \"{\"                  Node:\'{\'");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("9 1 1  H \" \"                  Whitespace:TerminalRule\'WS\'");
    _builder.newLine();
    _builder.append("        ");
    _builder.append("B Node\'Bar\'            Node:children+=Node path:Node\'root\'/children[0]");
    _builder.newLine();
    _builder.append("10 3 1   S \"Bar\"                Node:name=ID");
    _builder.newLine();
    _builder.append("13 0 1   H");
    _builder.newLine();
    _builder.append("13 1 1   S \";\"                  Node:\';\'");
    _builder.newLine();
    _builder.append("        ");
    _builder.append("E Node\'Bar\'            Node:children+=Node path:Node\'root\'/children[0]");
    _builder.newLine();
    _builder.append("14 0 1  H");
    _builder.newLine();
    _builder.append("        ");
    _builder.append("B Node\'Foo\'            Node:children+=Node path:Node\'root\'/children[1]");
    _builder.newLine();
    _builder.append("14 3     S \"Foo\"                Node:name=ID");
    _builder.newLine();
    _builder.append("17 0     H");
    _builder.newLine();
    _builder.append("17 1     S \";\"                  Node:\';\'");
    _builder.newLine();
    _builder.append("        ");
    _builder.append("E Node\'Foo\'            Node:children+=Node path:Node\'root\'/children[1]");
    _builder.newLine();
    _builder.append("18   2  H \" \"                  Whitespace:TerminalRule\'WS\'");
    _builder.newLine();
    _builder.append("   ");
    _builder.append("2    \" \"                  Whitespace:TerminalRule\'WS\'");
    _builder.newLine();
    _builder.append("20 1    S \"}\"                  Node:\'}\'");
    _builder.newLine();
    _builder.append("       ");
    _builder.append("E Node\'root\'           Model");
    _builder.newLine();
    _builder.append("21 0   H");
    _builder.newLine();
    _builder.append("------------ diff 1 ------------");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("9 1 H \" \"                  Whitespace:TerminalRule\'WS\'");
    _builder.newLine();
    _builder.append("10 3 S \"Foo\"                Node:name=ID");
    _builder.newLine();
    _builder.append("------------ diff 2 ------------");
    _builder.newLine();
    _builder.append("14 1  H \" \"                  Whitespace:TerminalRule\'WS\'");
    _builder.newLine();
    _builder.append("15 3  S \"Bar\"                Node:name=ID");
    _builder.newLine();
    _builder.append("18 0  H");
    _builder.newLine();
    _builder.append("18 1  S \";\"                  Node:\';\'");
    _builder.newLine();
    _builder.append("19 1  H \" \"                  Whitespace:TerminalRule\'WS\'");
    _builder.newLine();
    this._changeSerializerTestHelper.operator_tripleEquals(_recordDiff, _builder);
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) Node(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Node) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 13 with ITextRegionAccess

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

the class PartialSerializerTest method testOptionalChildListInsertIntoEndTwo.

@Test
public void testOptionalChildListInsertIntoEndTwo() {
    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("b");
        };
        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("c");
        };
        MandatoryValue _doubleArrow_1 = ObjectExtensions.<MandatoryValue>operator_doubleArrow(_createMandatoryValue_1, _function_2);
        _children_1.add(_doubleArrow_1);
    };
    ITextRegionAccess _recordDiff = this.<OptionalChildList>recordDiff(OptionalChildList.class, "#13 a", _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 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 0 1  H");
    _builder.newLine();
    _builder.append("       ");
    _builder.append("B MandatoryValue\'b\'    MandatoryValue path:OptionalChildList/children[1]");
    _builder.newLine();
    _builder.append("5 1 1   S \"b\"                  MandatoryValue:name=ID");
    _builder.newLine();
    _builder.append("       ");
    _builder.append("E MandatoryValue\'b\'    MandatoryValue path:OptionalChildList/children[1]");
    _builder.newLine();
    _builder.append("6 0 1  H");
    _builder.newLine();
    _builder.append("       ");
    _builder.append("B MandatoryValue\'c\'    MandatoryValue path:OptionalChildList/children[2]");
    _builder.newLine();
    _builder.append("6 1 1   S \"c\"                  MandatoryValue:name=ID");
    _builder.newLine();
    _builder.append("       ");
    _builder.append("E MandatoryValue\'c\'    MandatoryValue path:OptionalChildList/children[2]");
    _builder.newLine();
    _builder.append("      ");
    _builder.append("E OptionalChildList    Model");
    _builder.newLine();
    _builder.append("7 0 1 H");
    _builder.newLine();
    _builder.append("------------ diff 1 ------------");
    _builder.newLine();
    _builder.append("4 1   S \"a\"                  MandatoryValue:name=ID");
    _builder.newLine();
    _builder.append("5 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)

Example 14 with ITextRegionAccess

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

the class PartialSerializerTest method testOptionalChildInsert.

@Test
public void testOptionalChildInsert() {
    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", _function);
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("0 0 1 H");
    _builder.newLine();
    _builder.append("      ");
    _builder.append("B OptionalChild        Model");
    _builder.newLine();
    _builder.append("0 2 1  S \"#5\"                 Model:\'#5\'");
    _builder.newLine();
    _builder.append("2 0 1  H");
    _builder.newLine();
    _builder.append("       ");
    _builder.append("B MandatoryValue\'baz\'  OptionalChild:child=MandatoryValue path:OptionalChild/child");
    _builder.newLine();
    _builder.append("2 3 1   S \"baz\"                MandatoryValue:name=ID");
    _builder.newLine();
    _builder.append("       ");
    _builder.append("E MandatoryValue\'baz\'  OptionalChild:child=MandatoryValue path:OptionalChild/child");
    _builder.newLine();
    _builder.append("      ");
    _builder.append("E OptionalChild        Model");
    _builder.newLine();
    _builder.append("5 0 1 H");
    _builder.newLine();
    _builder.append("------------ diff 1 ------------");
    _builder.newLine();
    _builder.append("0 0 H");
    _builder.newLine();
    _builder.append("0 2 S \"#5\"                 Model:\'#5\'");
    _builder.newLine();
    _builder.append("2 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 15 with ITextRegionAccess

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

the class PartialSerializerTest method testMandatoryValueChange.

@Test
public void testMandatoryValueChange() {
    final IChangeSerializer.IModification<MandatoryValue> _function = (MandatoryValue it) -> {
        it.setName("bar");
    };
    ITextRegionAccess _recordDiff = this.<MandatoryValue>recordDiff(MandatoryValue.class, "#2 foo", _function);
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("0 0   H");
    _builder.newLine();
    _builder.append("      ");
    _builder.append("B MandatoryValue\'bar\'  Model");
    _builder.newLine();
    _builder.append("0 2    S \"#2\"                 Model:\'#2\'");
    _builder.newLine();
    _builder.append("2 1    H \" \"                  Whitespace:TerminalRule\'WS\'");
    _builder.newLine();
    _builder.append("3 3 1  S \"bar\"                MandatoryValue:name=ID");
    _builder.newLine();
    _builder.append("      ");
    _builder.append("E MandatoryValue\'bar\'  Model");
    _builder.newLine();
    _builder.append("6 0   H");
    _builder.newLine();
    _builder.append("------------ diff 1 ------------");
    _builder.newLine();
    _builder.append("3 3 S \"foo\"                MandatoryValue:name=ID");
    _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) IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Aggregations

ITextRegionAccess (org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess)71 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 ITextSegment (org.eclipse.xtext.formatting2.regionaccess.ITextSegment)16 EObject (org.eclipse.emf.ecore.EObject)14 OptionalChildList (org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.OptionalChildList)12 MandatoryValue (org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.MandatoryValue)11 ITextReplacement (org.eclipse.xtext.formatting2.regionaccess.ITextReplacement)10 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)10 TextRegionAccessToString (org.eclipse.xtext.formatting2.debug.TextRegionAccessToString)9 ILineRegion (org.eclipse.xtext.formatting2.regionaccess.ILineRegion)9 EList (org.eclipse.emf.common.util.EList)8 FormatterRequest (org.eclipse.xtext.formatting2.FormatterRequest)7 IHiddenRegion (org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion)7 IEObjectRegion (org.eclipse.xtext.formatting2.regionaccess.IEObjectRegion)6 ITextRegionExtensions (org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions)6 XtextResource (org.eclipse.xtext.resource.XtextResource)5