Search in sources :

Example 21 with ISemanticRegion

use of org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion 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 22 with ISemanticRegion

use of org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion 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)

Example 23 with ISemanticRegion

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

the class RegionAccessCommentsTest method testDeleteFirstRegion3.

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

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

the class RegionAccessDiffTest method testMove.

@Test
public void testMove() throws Exception {
    String model = "8 a b 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 \" \"        Whitespace:TerminalRule'WS'\n" + "  2    \" \"        Whitespace:TerminalRule'WS'\n" + "3 1    S \"b\"        ValueList:name+=ID\n" + "4 1 2  H \" \"        Whitespace:TerminalRule'WS'\n" + "5 1 2  S \"a\"        ValueList:name+=ID\n" + "6 0 2  H\n" + "6 1    S \"c\"        ValueList:name+=ID\n" + "      E ValueList'[a, b, c]' Root\n" + "7 0   H\n" + "------------ diff 1 ------------\n" + "1 1 H \" \"        Whitespace:TerminalRule'WS'\n" + "2 1 S \"a\"        ValueList:name+=ID\n" + "3 1 H \" \"        Whitespace:TerminalRule'WS'\n" + "------------ diff 2 ------------\n" + "5 1 H \" \"        Whitespace:TerminalRule'WS'\n" + "6 1 S \"c\"        ValueList:name+=ID\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 25 with ISemanticRegion

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

the class TextRegionAccessToString method toString.

@Override
public String toString() {
    List<ITextSegment> list = toTokenAndGapList();
    if (list.isEmpty())
        return "(empty)";
    ITextRegionAccess access = list.get(0).getTextRegionAccess();
    DiffColumn diff = new DiffColumn(access);
    TextRegionListToString result = new TextRegionListToString();
    if (!hideColumnExplanation) {
        if (diff.isDiff()) {
            result.add("Columns: 1:offset 2:length 3:diff 4:kind 5: text 6:grammarElement", false);
        } else {
            result.add("Columns: 1:offset 2:length 3:kind 4: text 5:grammarElement", false);
        }
        result.add("Kind: H=IHiddenRegion S=ISemanticRegion B/E=IEObjectRegion", false);
        result.add("", false);
    }
    appendRegions(result, list, diff, false);
    diff.appendDiffs(result, this);
    return result.toString();
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) ITextSegment(org.eclipse.xtext.formatting2.regionaccess.ITextSegment)

Aggregations

ISemanticRegion (org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)59 Test (org.junit.Test)30 ISemanticRegionsFinder (org.eclipse.xtext.formatting2.regionaccess.ISemanticRegionsFinder)18 ITextRegionAccess (org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess)15 IHiddenRegionFormatter (org.eclipse.xtext.formatting2.IHiddenRegionFormatter)14 ITextRegionDiffBuilder (org.eclipse.xtext.formatting2.regionaccess.ITextRegionDiffBuilder)13 Mixed (org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Mixed)12 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)9 IHiddenRegion (org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion)7 ITextRegionExtensions (org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions)7 EObject (org.eclipse.emf.ecore.EObject)4 IEObjectRegion (org.eclipse.xtext.formatting2.regionaccess.IEObjectRegion)4 AssignedAction (org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.AssignedAction)4 XExpression (org.eclipse.xtext.xbase.XExpression)4 JvmTypeParameter (org.eclipse.xtext.common.types.JvmTypeParameter)3 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)3 ValueList (org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.ValueList)3 LinkedList (java.util.LinkedList)2 EReference (org.eclipse.emf.ecore.EReference)2 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)2