Search in sources :

Example 11 with ITextRegionDiffBuilder

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

the class RegionAccessCommentsTest method testDeleteFirstRegion4.

@Test
public void testDeleteFirstRegion4() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("/*h*/");
    _builder.newLine();
    _builder.append("/*81*/");
    _builder.newLine();
    _builder.append("/*82*/");
    _builder.newLine();
    _builder.newLine();
    _builder.append("8 //8");
    _builder.newLine();
    _builder.append("/*a*/");
    _builder.newLine();
    _builder.append("a");
    _builder.newLine();
    final ITextRegionAccess access = this._regionAccessTestHelper.toTextRegionAccess(_builder);
    final Procedure1<ITextRegionDiffBuilder> _function = (ITextRegionDiffBuilder it) -> {
        final ISemanticRegion foo = access.regionForRootEObject().getAllRegionsFor().keyword("8");
        it.remove(foo);
    };
    ITextRegionAccess _modify = this._regionAccessTestHelper.modify(access, _function);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append(" ");
    _builder_1.append("0    1 H \"/*h*/\"    Comment:TerminalRule\'ML_COMMENT\' Association:CONTAINER");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("\"\\n\"       Whitespace:TerminalRule\'WS\'");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("\"/*81*/\"   Comment:TerminalRule\'ML_COMMENT\' Association:CONTAINER");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("\"\\n\"       Whitespace:TerminalRule\'WS\'");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("\"/*82*/\"   Comment:TerminalRule\'ML_COMMENT\' Association:CONTAINER");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("\"\\n\\n\"     Whitespace:TerminalRule\'WS\'");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("\"/*a*/\"    Comment:TerminalRule\'ML_COMMENT\' Association:NEXT");
    _builder_1.newLine();
    _builder_1.append("   ");
    _builder_1.append("27   \"\\n\"       Whitespace:TerminalRule\'WS\'");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("B ValueList\'[a]\' Root");
    _builder_1.newLine();
    _builder_1.append("27  1    S \"a\"        ValueList:name+=ID");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("E ValueList\'[a]\' Root");
    _builder_1.newLine();
    _builder_1.append("28  0   H");
    _builder_1.newLine();
    _builder_1.append("------------ diff 1 ------------");
    _builder_1.newLine();
    _builder_1.append(" ");
    _builder_1.append("0    H \"/*h*/\"    Comment:TerminalRule\'ML_COMMENT\' Association:CONTAINER");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("\"\\n\"       Whitespace:TerminalRule\'WS\'");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("\"/*81*/\"   Comment:TerminalRule\'ML_COMMENT\' Association:CONTAINER");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("\"\\n\"       Whitespace:TerminalRule\'WS\'");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("\"/*82*/\"   Comment:TerminalRule\'ML_COMMENT\' Association:CONTAINER");
    _builder_1.newLine();
    _builder_1.append("   ");
    _builder_1.append("21   \"\\n\\n\"     Whitespace:TerminalRule\'WS\'");
    _builder_1.newLine();
    _builder_1.append("21  1 S \"8\"        Root:\'8\'");
    _builder_1.newLine();
    _builder_1.append("22    H \" \"        Whitespace:TerminalRule\'WS\'");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("\"//8\\n\"    Comment:TerminalRule\'SL_COMMENT\' Association:PREVIOUS");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("\"/*a*/\"    Comment:TerminalRule\'ML_COMMENT\' Association:NEXT");
    _builder_1.newLine();
    _builder_1.append("   ");
    _builder_1.append("11   \"\\n\"       Whitespace:TerminalRule\'WS\'");
    _builder_1.newLine();
    this._regionAccessTestHelper.operator_tripleEquals(_modify, _builder_1);
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) ITextRegionDiffBuilder(org.eclipse.xtext.formatting2.regionaccess.ITextRegionDiffBuilder) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion) Test(org.junit.Test)

Example 12 with ITextRegionDiffBuilder

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

the class RegionAccessCommentsTest method testMove.

@Test
public void testMove() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("8//8");
    _builder.newLine();
    _builder.append("/*a*/");
    _builder.newLine();
    _builder.append("a//a");
    _builder.newLine();
    _builder.append("/*b*/");
    _builder.newLine();
    _builder.append("b//b");
    _builder.newLine();
    _builder.append("/*c*/");
    _builder.newLine();
    _builder.append("c");
    _builder.newLine();
    final ITextRegionAccess access = this._regionAccessTestHelper.toTextRegionAccess(_builder);
    final Procedure1<ITextRegionDiffBuilder> _function = (ITextRegionDiffBuilder it) -> {
        final List<ISemanticRegion> regions = access.regionForRootEObject().getAllRegionsFor().features(RegionaccesstestlanguagePackage.Literals.VALUE_LIST__NAME);
        final ISemanticRegion a = regions.get(0);
        final ISemanticRegion b = regions.get(1);
        it.move(b.getNextHiddenRegion(), a.getPreviousHiddenRegion(), a.getNextHiddenRegion());
    };
    ITextRegionAccess _modify = this._regionAccessTestHelper.modify(access, _function);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append(" ");
    _builder_1.append("0  0   H");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("B ValueList\'[a, b, c]\' Root");
    _builder_1.newLine();
    _builder_1.append(" ");
    _builder_1.append("0  1    S \"8\"        Root:\'8\'");
    _builder_1.newLine();
    _builder_1.append(" ");
    _builder_1.append("1    1  H \"//8\\n\"    Comment:TerminalRule\'SL_COMMENT\' Association:PREVIOUS");
    _builder_1.newLine();
    _builder_1.append("         ");
    _builder_1.append("\"/*b*/\"    Comment:TerminalRule\'ML_COMMENT\' Association:NEXT");
    _builder_1.newLine();
    _builder_1.append("   ");
    _builder_1.append("10    \"\\n\"       Whitespace:TerminalRule\'WS\'");
    _builder_1.newLine();
    _builder_1.append("11  1    S \"b\"        ValueList:name+=ID");
    _builder_1.newLine();
    _builder_1.append("12    2  H \"//b\\n\"    Comment:TerminalRule\'SL_COMMENT\' Association:PREVIOUS");
    _builder_1.newLine();
    _builder_1.append("         ");
    _builder_1.append("\"/*a*/\"    Comment:TerminalRule\'ML_COMMENT\' Association:NEXT");
    _builder_1.newLine();
    _builder_1.append("   ");
    _builder_1.append("10    \"\\n\"       Whitespace:TerminalRule\'WS\'");
    _builder_1.newLine();
    _builder_1.append("22  1 2  S \"a\"        ValueList:name+=ID");
    _builder_1.newLine();
    _builder_1.append("23    2  H \"//a\\n\"    Comment:TerminalRule\'SL_COMMENT\' Association:PREVIOUS");
    _builder_1.newLine();
    _builder_1.append("         ");
    _builder_1.append("\"/*c*/\"    Comment:TerminalRule\'ML_COMMENT\' Association:NEXT");
    _builder_1.newLine();
    _builder_1.append("   ");
    _builder_1.append("10    \"\\n\"       Whitespace:TerminalRule\'WS\'");
    _builder_1.newLine();
    _builder_1.append("33  1    S \"c\"        ValueList:name+=ID");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("E ValueList\'[a, b, c]\' Root");
    _builder_1.newLine();
    _builder_1.append("34  0   H");
    _builder_1.newLine();
    _builder_1.append("------------ diff 1 ------------");
    _builder_1.newLine();
    _builder_1.append(" ");
    _builder_1.append("1    H \"//8\\n\"    Comment:TerminalRule\'SL_COMMENT\' Association:PREVIOUS");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("\"/*a*/\"    Comment:TerminalRule\'ML_COMMENT\' Association:NEXT");
    _builder_1.newLine();
    _builder_1.append("   ");
    _builder_1.append("10   \"\\n\"       Whitespace:TerminalRule\'WS\'");
    _builder_1.newLine();
    _builder_1.append("11  1 S \"a\"        ValueList:name+=ID");
    _builder_1.newLine();
    _builder_1.append("12    H \"//a\\n\"    Comment:TerminalRule\'SL_COMMENT\' Association:PREVIOUS");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("\"/*b*/\"    Comment:TerminalRule\'ML_COMMENT\' Association:NEXT");
    _builder_1.newLine();
    _builder_1.append("   ");
    _builder_1.append("10   \"\\n\"       Whitespace:TerminalRule\'WS\'");
    _builder_1.newLine();
    _builder_1.append("------------ diff 2 ------------");
    _builder_1.newLine();
    _builder_1.append("23    H \"//b\\n\"    Comment:TerminalRule\'SL_COMMENT\' Association:PREVIOUS");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("\"/*c*/\"    Comment:TerminalRule\'ML_COMMENT\' Association:NEXT");
    _builder_1.newLine();
    _builder_1.append("   ");
    _builder_1.append("10   \"\\n\"       Whitespace:TerminalRule\'WS\'");
    _builder_1.newLine();
    this._regionAccessTestHelper.operator_tripleEquals(_modify, _builder_1);
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) ITextRegionDiffBuilder(org.eclipse.xtext.formatting2.regionaccess.ITextRegionDiffBuilder) List(java.util.List) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion) Test(org.junit.Test)

Example 13 with ITextRegionDiffBuilder

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

the class RegionAccessDiffTest method testInsertReplaceReplace.

@Test
public void testInsertReplaceReplace() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("8 a");
    _builder.newLine();
    final ITextRegionAccess access = this._regionAccessTestHelper.toTextRegionAccess(_builder);
    final Procedure1<ITextRegionDiffBuilder> _function = (ITextRegionDiffBuilder it) -> {
        @Extension final ITextRegionExtensions ext = access.getExtensions();
        EObject _semanticElement = access.regionForRootEObject().getSemanticElement();
        final ValueList rootObj = ((ValueList) _semanticElement);
        final ISemanticRegion a = ext.regionFor(rootObj).keyword("8").getNextSemanticRegion();
        it.replace(a, "b");
        it.replace(a, "c");
    };
    ITextRegionAccess _modify = this._regionAccessTestHelper.modify(access, _function);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("0 0   H");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("B ValueList\'[a]\' Root");
    _builder_1.newLine();
    _builder_1.append("0 1    S \"8\"        Root:\'8\'");
    _builder_1.newLine();
    _builder_1.append("1 1    H \" \"        Whitespace:TerminalRule\'WS\'");
    _builder_1.newLine();
    _builder_1.append("2 1 1  S \"c\"        ValueList:name+=ID");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("E ValueList\'[a]\' Root");
    _builder_1.newLine();
    _builder_1.append("3 0   H");
    _builder_1.newLine();
    _builder_1.append("------------ diff 1 ------------");
    _builder_1.newLine();
    _builder_1.append("2 1 S \"a\"        ValueList:name+=ID");
    _builder_1.newLine();
    this._regionAccessTestHelper.operator_tripleEquals(_modify, _builder_1);
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) ValueList(org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.ValueList) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) ITextRegionDiffBuilder(org.eclipse.xtext.formatting2.regionaccess.ITextRegionDiffBuilder) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion) ITextRegionExtensions(org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions) Test(org.junit.Test)

Example 14 with ITextRegionDiffBuilder

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

the class RegionAccessDiffTest method testSingleSemanticToken.

@Test
public void testSingleSemanticToken() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("1 foo");
    _builder.newLine();
    final ITextRegionAccess access = this._regionAccessTestHelper.toTextRegionAccess(_builder);
    final Procedure1<ITextRegionDiffBuilder> _function = (ITextRegionDiffBuilder it) -> {
        @Extension final ITextRegionExtensions ext = access.getExtensions();
        final EObject root = access.regionForRootEObject().getSemanticElement();
        final ISemanticRegion foo = ext.allRegionsFor(root).feature(RegionaccesstestlanguagePackage.Literals.SIMPLE__NAME);
        it.replace(foo, "baaar");
    };
    ITextRegionAccess _modify = this._regionAccessTestHelper.modify(access, _function);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("0 0   H");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("B Simple\'foo\' Root");
    _builder_1.newLine();
    _builder_1.append("0 1    S \"1\"        Simple:\'1\'");
    _builder_1.newLine();
    _builder_1.append("1 1    H \" \"        Whitespace:TerminalRule\'WS\'");
    _builder_1.newLine();
    _builder_1.append("2 5 1  S \"baaar\"    Simple:name=ID");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("E Simple\'foo\' Root");
    _builder_1.newLine();
    _builder_1.append("7 0   H");
    _builder_1.newLine();
    _builder_1.append("------------ diff 1 ------------");
    _builder_1.newLine();
    _builder_1.append("2 3 S \"foo\"      Simple:name=ID");
    _builder_1.newLine();
    this._regionAccessTestHelper.operator_tripleEquals(_modify, _builder_1);
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) ITextRegionDiffBuilder(org.eclipse.xtext.formatting2.regionaccess.ITextRegionDiffBuilder) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion) ITextRegionExtensions(org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions) Test(org.junit.Test)

Example 15 with ITextRegionDiffBuilder

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

the class RegionAccessDiffTest method testDeleteOne.

@Test
public void testDeleteOne() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("4/*1*/prefix/*2*/foo");
    _builder.newLine();
    final ITextRegionAccess access = this._regionAccessTestHelper.toTextRegionAccess(_builder);
    final Procedure1<ITextRegionDiffBuilder> _function = (ITextRegionDiffBuilder it) -> {
        @Extension final ITextRegionExtensions ext = access.getExtensions();
        EObject _semanticElement = access.regionForRootEObject().getSemanticElement();
        final PrefixedUnassigned rootObj = ((PrefixedUnassigned) _semanticElement);
        final ISemanticRegion prefix = ext.regionFor(rootObj.getDelegate()).keyword("prefix");
        it.remove(prefix);
    };
    ITextRegionAccess _modify = this._regionAccessTestHelper.modify(access, _function);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append(" ");
    _builder_1.append("0  0   H");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("B PrefixedUnassigned Root");
    _builder_1.newLine();
    _builder_1.append(" ");
    _builder_1.append("0  1    S \"4\"        PrefixedUnassigned:\'4\'");
    _builder_1.newLine();
    _builder_1.append(" ");
    _builder_1.append("1    1  H \"/*1*/\"    Comment:TerminalRule\'ML_COMMENT\' Association:CONTAINER");
    _builder_1.newLine();
    _builder_1.append("   ");
    _builder_1.append("10    \"/*2*/\"    Comment:TerminalRule\'ML_COMMENT\' Association:CONTAINER");
    _builder_1.newLine();
    _builder_1.append("         ");
    _builder_1.append("B Delegate\'foo\' PrefixedUnassigned:delegate=PrefixedDelegate path:PrefixedUnassigned/delegate");
    _builder_1.newLine();
    _builder_1.append("11  3     S \"foo\"      Delegate:name=ID");
    _builder_1.newLine();
    _builder_1.append("         ");
    _builder_1.append("E Delegate\'foo\' PrefixedUnassigned:delegate=PrefixedDelegate path:PrefixedUnassigned/delegate");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("E PrefixedUnassigned Root");
    _builder_1.newLine();
    _builder_1.append("14  0   H");
    _builder_1.newLine();
    _builder_1.append("------------ diff 1 ------------");
    _builder_1.newLine();
    _builder_1.append(" ");
    _builder_1.append("1  5 H \"/*1*/\"    Comment:TerminalRule\'ML_COMMENT\' Association:CONTAINER");
    _builder_1.newLine();
    _builder_1.append(" ");
    _builder_1.append("6  6 S \"prefix\"   PrefixedDelegate:\'prefix\'");
    _builder_1.newLine();
    _builder_1.append("12  5 H \"/*2*/\"    Comment:TerminalRule\'ML_COMMENT\' Association:CONTAINER");
    _builder_1.newLine();
    this._regionAccessTestHelper.operator_tripleEquals(_modify, _builder_1);
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) PrefixedUnassigned(org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.PrefixedUnassigned) ITextRegionDiffBuilder(org.eclipse.xtext.formatting2.regionaccess.ITextRegionDiffBuilder) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion) ITextRegionExtensions(org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions) Test(org.junit.Test)

Aggregations

ITextRegionAccess (org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess)17 ITextRegionDiffBuilder (org.eclipse.xtext.formatting2.regionaccess.ITextRegionDiffBuilder)17 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)16 Test (org.junit.Test)16 ISemanticRegion (org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)14 EObject (org.eclipse.emf.ecore.EObject)9 ITextRegionExtensions (org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions)6 ValueList (org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.ValueList)4 IEObjectRegion (org.eclipse.xtext.formatting2.regionaccess.IEObjectRegion)3 StringBasedTextRegionAccessDiffBuilder (org.eclipse.xtext.formatting2.regionaccess.internal.StringBasedTextRegionAccessDiffBuilder)3 List (java.util.List)2 ChangeRecorder (org.eclipse.emf.ecore.change.util.ChangeRecorder)2 Delegate (org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Delegate)2 PrefixedUnassigned (org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.PrefixedUnassigned)2 IUpdatableReference (org.eclipse.xtext.ide.serializer.hooks.IUpdatableReference)2 ChangeDescription (org.eclipse.emf.ecore.change.ChangeDescription)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 ITextRegionAccessDiff (org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccessDiff)1 ITextReplacement (org.eclipse.xtext.formatting2.regionaccess.ITextReplacement)1 StringBasedTextRegionAccessDiff (org.eclipse.xtext.formatting2.regionaccess.internal.StringBasedTextRegionAccessDiff)1