Search in sources :

Example 1 with Root

use of org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Root in project xtext-core by eclipse.

the class PartialSerializerTest method testMoveInList1.

@Test
public void testMoveInList1() {
    ITextRegionAccess diff = recordDiff(Node.class, "#1 root { Foo; Bar; }", (Node it) -> {
        it.getChildren().move(0, 1);
    });
    String expectation = "0 0   H\n" + "       B Node'root'           Model\n" + " 0 2    S \"#1\"                 Model:'#1'\n" + " 2 1    H \" \"                  Whitespace:TerminalRule'WS'\n" + " 3 4    S \"root\"               Node:name=ID\n" + " 7 1    H \" \"                  Whitespace:TerminalRule'WS'\n" + " 8 1    S \"{\"                  Node:'{'\n" + " 9 1 1  H \" \"                  Whitespace:TerminalRule'WS'\n" + "        B Node'Bar'            Node:children+=Node path:Node'root'/children[0]\n" + "10 3 1   S \"Bar\"                Node:name=ID\n" + "13 0 1   H\n" + "13 1 1   S \";\"                  Node:';'\n" + "        E Node'Bar'            Node:children+=Node path:Node'root'/children[0]\n" + "14 0 1  H\n" + "        B Node'Foo'            Node:children+=Node path:Node'root'/children[1]\n" + "14 3     S \"Foo\"                Node:name=ID\n" + "17 0     H\n" + "17 1     S \";\"                  Node:';'\n" + "        E Node'Foo'            Node:children+=Node path:Node'root'/children[1]\n" + "18   2  H \" \"                  Whitespace:TerminalRule'WS'\n" + "   2    \" \"                  Whitespace:TerminalRule'WS'\n" + "20 1    S \"}\"                  Node:'}'\n" + "       E Node'root'           Model\n" + "21 0   H\n" + "------------ diff 1 ------------\n" + " 9 1 H \" \"                  Whitespace:TerminalRule'WS'\n" + "10 3 S \"Foo\"                Node:name=ID\n" + "------------ diff 2 ------------\n" + "14 1  H \" \"                  Whitespace:TerminalRule'WS'\n" + "15 3  S \"Bar\"                Node:name=ID\n" + "18 0  H\n" + "18 1  S \";\"                  Node:';'\n" + "19 1  H \" \"                  Whitespace:TerminalRule'WS'\n";
    changeSerializerTestHelper.operator_tripleEquals(diff, expectation);
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) Node(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Node) Test(org.junit.Test)

Example 2 with Root

use of org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Root in project xtext-core by eclipse.

the class SemanticRegionFinderTest method parseAs.

private <T extends EObject> T parseAs(CharSequence seq, Class<T> cls) throws Exception {
    Root result = parseHelper.parse(seq);
    validationTestHelper.assertNoErrors(result);
    return cls.cast(result);
}
Also used : Root(org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Root)

Example 3 with Root

use of org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Root in project xtext-core by eclipse.

the class RegionAccessCommentsTest method testDeleteFirstRegion1.

@Test
public void testDeleteFirstRegion1() throws Exception {
    String model = "/*h*/\n" + "\n" + "/*8*/\n" + "8 //8\n" + "/*a*/\n" + "a\n";
    ITextRegionAccess access = regionAccessTestHelper.toTextRegionAccess(model);
    ITextRegionAccess modifiedAccess = regionAccessTestHelper.modify(access, (ITextRegionDiffBuilder it) -> {
        ISemanticRegion foo = access.regionForRootEObject().getAllRegionsFor().keyword("8");
        it.remove(foo);
    });
    String expectation = " 0    1 H \"/*h*/\"    Comment:TerminalRule'ML_COMMENT' Association:CONTAINER\n" + "        \"\\n" + "\\n" + "\"     Whitespace:TerminalRule'WS'\n" + "        \"/*a*/\"    Comment:TerminalRule'ML_COMMENT' Association:NEXT\n" + "   13   \"\\n" + "\"       Whitespace:TerminalRule'WS'\n" + "        B ValueList'[a]' Root\n" + "13  1    S \"a\"        ValueList:name+=ID\n" + "        E ValueList'[a]' Root\n" + "14  0   H\n" + "------------ diff 1 ------------\n" + " 0    H \"/*h*/\"    Comment:TerminalRule'ML_COMMENT' Association:CONTAINER\n" + "        \"\\n" + "\\n" + "\"     Whitespace:TerminalRule'WS'\n" + "        \"/*8*/\"    Comment:TerminalRule'ML_COMMENT' Association:NEXT\n" + "   13   \"\\n" + "\"       Whitespace:TerminalRule'WS'\n" + "13  1 S \"8\"        Root:'8'\n" + "14    H \" \"        Whitespace:TerminalRule'WS'\n" + "        \"//8\\n" + "\"    Comment:TerminalRule'SL_COMMENT' Association:PREVIOUS\n" + "        \"/*a*/\"    Comment:TerminalRule'ML_COMMENT' Association:NEXT\n" + "   11   \"\\n" + "\"       Whitespace:TerminalRule'WS'\n";
    regionAccessTestHelper.assertRegions(modifiedAccess, expectation);
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) ITextRegionDiffBuilder(org.eclipse.xtext.formatting2.regionaccess.ITextRegionDiffBuilder) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion) Test(org.junit.Test)

Example 4 with Root

use of org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Root in project xtext-core by eclipse.

the class RegionAccessCommentsTest method testDeleteFirstRegion2.

@Test
public void testDeleteFirstRegion2() throws Exception {
    String model = "/*h*/\n" + "\n" + "/*81*/\n" + "/*82*/\n" + "8 //8\n" + "/*a*/\n" + "a\n";
    ITextRegionAccess access = regionAccessTestHelper.toTextRegionAccess(model);
    ITextRegionAccess modifiedAccess = regionAccessTestHelper.modify(access, (ITextRegionDiffBuilder it) -> {
        ISemanticRegion foo = access.regionForRootEObject().getAllRegionsFor().keyword("8");
        it.remove(foo);
    });
    String expectation = " 0    1 H \"/*h*/\"    Comment:TerminalRule'ML_COMMENT' Association:CONTAINER\n" + "        \"\\n" + "\\n" + "\"     Whitespace:TerminalRule'WS'\n" + "        \"/*a*/\"    Comment:TerminalRule'ML_COMMENT' Association:NEXT\n" + "   13   \"\\n" + "\"       Whitespace:TerminalRule'WS'\n" + "        B ValueList'[a]' Root\n" + "13  1    S \"a\"        ValueList:name+=ID\n" + "        E ValueList'[a]' Root\n" + "14  0   H\n" + "------------ diff 1 ------------\n" + " 0    H \"/*h*/\"    Comment:TerminalRule'ML_COMMENT' Association:CONTAINER\n" + "        \"\\n" + "\\n" + "\"     Whitespace:TerminalRule'WS'\n" + "        \"/*81*/\"   Comment:TerminalRule'ML_COMMENT' Association:NEXT\n" + "        \"\\n" + "\"       Whitespace:TerminalRule'WS'\n" + "        \"/*82*/\"   Comment:TerminalRule'ML_COMMENT' Association:NEXT\n" + "   21   \"\\n" + "\"       Whitespace:TerminalRule'WS'\n" + "21  1 S \"8\"        Root:'8'\n" + "22    H \" \"        Whitespace:TerminalRule'WS'\n" + "        \"//8\\n" + "\"    Comment:TerminalRule'SL_COMMENT' Association:PREVIOUS\n" + "        \"/*a*/\"    Comment:TerminalRule'ML_COMMENT' Association:NEXT\n" + "   11   \"\\n" + "\"       Whitespace:TerminalRule'WS'\n";
    regionAccessTestHelper.assertRegions(modifiedAccess, expectation);
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) ITextRegionDiffBuilder(org.eclipse.xtext.formatting2.regionaccess.ITextRegionDiffBuilder) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion) Test(org.junit.Test)

Example 5 with Root

use of org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Root in project xtext-core by eclipse.

the class RegionAccessCommentsTest method testDeleteMiddleRegion.

@Test
public void testDeleteMiddleRegion() throws Exception {
    String model = "8\n" + "a /*a*/ //a\n" + "/*b1*/\n" + "/*b2*/\n" + "b\n";
    ITextRegionAccess access = regionAccessTestHelper.toTextRegionAccess(model);
    ITextRegionAccess modifiedAccess = regionAccessTestHelper.modify(access, (ITextRegionDiffBuilder it) -> {
        ISemanticRegion foo = Iterables.getFirst(access.regionForRootEObject().getAllRegionsFor().features(RegionaccesstestlanguagePackage.Literals.VALUE_LIST__NAME), null);
        it.remove(foo);
    });
    String expectation = " 0  0   H\n" + "        B ValueList'[a, b]' Root\n" + " 0  1    S \"8\"        Root:'8'\n" + " 1    1  H \"\\n" + "\"       Whitespace:TerminalRule'WS'\n" + "         \"/*b1*/\"   Comment:TerminalRule'ML_COMMENT' Association:NEXT\n" + "         \"\\n" + "\"       Whitespace:TerminalRule'WS'\n" + "         \"/*b2*/\"   Comment:TerminalRule'ML_COMMENT' Association:NEXT\n" + "   15    \"\\n" + "\"       Whitespace:TerminalRule'WS'\n" + "16  1    S \"b\"        ValueList:name+=ID\n" + "        E ValueList'[a, b]' Root\n" + "17  0   H\n" + "------------ diff 1 ------------\n" + " 1  1 H \"\\n" + "\"       Whitespace:TerminalRule'WS'\n" + " 2  1 S \"a\"        ValueList:name+=ID\n" + " 3    H \" \"        Whitespace:TerminalRule'WS'\n" + "        \"/*a*/\"    Comment:TerminalRule'ML_COMMENT' Association:PREVIOUS\n" + "        \" \"        Whitespace:TerminalRule'WS'\n" + "        \"//a\\n" + "\"    Comment:TerminalRule'SL_COMMENT' Association:PREVIOUS\n" + "        \"/*b1*/\"   Comment:TerminalRule'ML_COMMENT' Association:NEXT\n" + "        \"\\n" + "\"       Whitespace:TerminalRule'WS'\n" + "        \"/*b2*/\"   Comment:TerminalRule'ML_COMMENT' Association:NEXT\n" + "   25   \"\\n" + "\"       Whitespace:TerminalRule'WS'\n";
    regionAccessTestHelper.assertRegions(modifiedAccess, expectation);
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) ITextRegionDiffBuilder(org.eclipse.xtext.formatting2.regionaccess.ITextRegionDiffBuilder) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)47 TextRegionAccessToString (org.eclipse.xtext.formatting2.debug.TextRegionAccessToString)32 ITextRegionAccess (org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess)21 ITextRegionDiffBuilder (org.eclipse.xtext.formatting2.regionaccess.ITextRegionDiffBuilder)16 ISemanticRegion (org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)14 ITextRegionExtensions (org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions)6 Root (org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Root)5 IEObjectRegion (org.eclipse.xtext.formatting2.regionaccess.IEObjectRegion)4 ValueList (org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.ValueList)4 EObject (org.eclipse.emf.ecore.EObject)3 Delegate (org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Delegate)3 PrefixedUnassigned (org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.PrefixedUnassigned)3 Delegation (org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Delegation)2 EPackage (org.eclipse.emf.ecore.EPackage)1 EReference (org.eclipse.emf.ecore.EReference)1 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)1 Action (org.eclipse.xtext.Action)1 Parameter (org.eclipse.xtext.Parameter)1 ParserRule (org.eclipse.xtext.ParserRule)1 IHiddenRegion (org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion)1