Search in sources :

Example 11 with ValueList

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

the class RegionAccessCommentsTest method testDeleteFirstRegion4.

@Test
public void testDeleteFirstRegion4() throws Exception {
    String model = "/*h*/\n" + "/*81*/\n" + "/*82*/\n" + "\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" + "\"       Whitespace:TerminalRule'WS'\n" + "        \"/*81*/\"   Comment:TerminalRule'ML_COMMENT' Association:CONTAINER\n" + "        \"\\n" + "\"       Whitespace:TerminalRule'WS'\n" + "        \"/*82*/\"   Comment:TerminalRule'ML_COMMENT' Association:CONTAINER\n" + "        \"\\n" + "\\n" + "\"     Whitespace:TerminalRule'WS'\n" + "        \"/*a*/\"    Comment:TerminalRule'ML_COMMENT' Association:NEXT\n" + "   27   \"\\n" + "\"       Whitespace:TerminalRule'WS'\n" + "        B ValueList'[a]' Root\n" + "27  1    S \"a\"        ValueList:name+=ID\n" + "        E ValueList'[a]' Root\n" + "28  0   H\n" + "------------ diff 1 ------------\n" + " 0    H \"/*h*/\"    Comment:TerminalRule'ML_COMMENT' Association:CONTAINER\n" + "        \"\\n" + "\"       Whitespace:TerminalRule'WS'\n" + "        \"/*81*/\"   Comment:TerminalRule'ML_COMMENT' Association:CONTAINER\n" + "        \"\\n" + "\"       Whitespace:TerminalRule'WS'\n" + "        \"/*82*/\"   Comment:TerminalRule'ML_COMMENT' Association:CONTAINER\n" + "   21   \"\\n" + "\\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 12 with ValueList

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

the class RegionAccessCommentsTest method testMove.

@Test
public void testMove() throws Exception {
    String model = "8//8\n" + "/*a*/\n" + "a//a\n" + "/*b*/\n" + "b//b\n" + "/*c*/\n" + "c\n";
    ITextRegionAccess access = regionAccessTestHelper.toTextRegionAccess(model);
    ITextRegionAccess modifiedAccess = regionAccessTestHelper.modify(access, (ITextRegionDiffBuilder it) -> {
        List<ISemanticRegion> regions = access.regionForRootEObject().getAllRegionsFor().features(RegionaccesstestlanguagePackage.Literals.VALUE_LIST__NAME);
        ISemanticRegion a = regions.get(0);
        ISemanticRegion b = regions.get(1);
        it.move(b.getNextHiddenRegion(), a.getPreviousHiddenRegion(), a.getNextHiddenRegion());
    });
    String expectation = " 0  0   H\n" + "        B ValueList'[a, b, c]' Root\n" + " 0  1    S \"8\"        Root:'8'\n" + " 1    1  H \"//8\\n" + "\"    Comment:TerminalRule'SL_COMMENT' Association:PREVIOUS\n" + "         \"/*b*/\"    Comment:TerminalRule'ML_COMMENT' Association:NEXT\n" + "   10    \"\\n" + "\"       Whitespace:TerminalRule'WS'\n" + "11  1    S \"b\"        ValueList:name+=ID\n" + "12    2  H \"//b\\n" + "\"    Comment:TerminalRule'SL_COMMENT' Association:PREVIOUS\n" + "         \"/*a*/\"    Comment:TerminalRule'ML_COMMENT' Association:NEXT\n" + "   10    \"\\n" + "\"       Whitespace:TerminalRule'WS'\n" + "22  1 2  S \"a\"        ValueList:name+=ID\n" + "23    2  H \"//a\\n" + "\"    Comment:TerminalRule'SL_COMMENT' Association:PREVIOUS\n" + "         \"/*c*/\"    Comment:TerminalRule'ML_COMMENT' Association:NEXT\n" + "   10    \"\\n" + "\"       Whitespace:TerminalRule'WS'\n" + "33  1    S \"c\"        ValueList:name+=ID\n" + "        E ValueList'[a, b, c]' Root\n" + "34  0   H\n" + "------------ diff 1 ------------\n" + " 1    H \"//8\\n" + "\"    Comment:TerminalRule'SL_COMMENT' Association:PREVIOUS\n" + "        \"/*a*/\"    Comment:TerminalRule'ML_COMMENT' Association:NEXT\n" + "   10   \"\\n" + "\"       Whitespace:TerminalRule'WS'\n" + "11  1 S \"a\"        ValueList:name+=ID\n" + "12    H \"//a\\n" + "\"    Comment:TerminalRule'SL_COMMENT' Association:PREVIOUS\n" + "        \"/*b*/\"    Comment:TerminalRule'ML_COMMENT' Association:NEXT\n" + "   10   \"\\n" + "\"       Whitespace:TerminalRule'WS'\n" + "------------ diff 2 ------------\n" + "23    H \"//b\\n" + "\"    Comment:TerminalRule'SL_COMMENT' Association:PREVIOUS\n" + "        \"/*c*/\"    Comment:TerminalRule'ML_COMMENT' Association:NEXT\n" + "   10   \"\\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)11 ISemanticRegion (org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)10 ITextRegionAccess (org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess)10 ITextRegionDiffBuilder (org.eclipse.xtext.formatting2.regionaccess.ITextRegionDiffBuilder)10 ValueList (org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.ValueList)4 ITextRegionExtensions (org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions)3 EPackage (org.eclipse.emf.ecore.EPackage)1 Action (org.eclipse.xtext.Action)1 Parameter (org.eclipse.xtext.Parameter)1 ParserRule (org.eclipse.xtext.ParserRule)1 TextRegionAccessToString (org.eclipse.xtext.formatting2.debug.TextRegionAccessToString)1 Add (org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Add)1 AssignedAction (org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.AssignedAction)1 Delegate (org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Delegate)1 Delegation (org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Delegation)1 Mixed (org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Mixed)1 Named (org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Named)1 PrefixedUnassigned (org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.PrefixedUnassigned)1 Root (org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Root)1 RootAction (org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.RootAction)1