Search in sources :

Example 26 with ITextRegionAccess

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

the class RegionAccessCommentsTest method testDeleteFirstRegion3.

@Test
public void testDeleteFirstRegion3() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("/*h*/");
    _builder.newLine();
    _builder.append("/*81*/");
    _builder.newLine();
    _builder.newLine();
    _builder.append("/*82*/");
    _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\\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("20   \"\\n\"       Whitespace:TerminalRule\'WS\'");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("B ValueList\'[a]\' Root");
    _builder_1.newLine();
    _builder_1.append("20  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("21  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\\n\"     Whitespace:TerminalRule\'WS\'");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("\"/*82*/\"   Comment:TerminalRule\'ML_COMMENT\' Association:NEXT");
    _builder_1.newLine();
    _builder_1.append("   ");
    _builder_1.append("21   \"\\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 27 with ITextRegionAccess

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

the class RegionAccessCommentsTest method testDeleteFirstRegion1.

@Test
public void testDeleteFirstRegion1() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("/*h*/");
    _builder.newLine();
    _builder.newLine();
    _builder.append("/*8*/");
    _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\\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("13   \"\\n\"       Whitespace:TerminalRule\'WS\'");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("B ValueList\'[a]\' Root");
    _builder_1.newLine();
    _builder_1.append("13  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("14  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\\n\"     Whitespace:TerminalRule\'WS\'");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("\"/*8*/\"    Comment:TerminalRule\'ML_COMMENT\' Association:NEXT");
    _builder_1.newLine();
    _builder_1.append("   ");
    _builder_1.append("13   \"\\n\"       Whitespace:TerminalRule\'WS\'");
    _builder_1.newLine();
    _builder_1.append("13  1 S \"8\"        Root:\'8\'");
    _builder_1.newLine();
    _builder_1.append("14    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 28 with ITextRegionAccess

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

the class RegionAccessCommentsTest method testDeleteFirstRegion2.

@Test
public void testDeleteFirstRegion2() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("/*h*/");
    _builder.newLine();
    _builder.newLine();
    _builder.append("/*81*/");
    _builder.newLine();
    _builder.append("/*82*/");
    _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\\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("13   \"\\n\"       Whitespace:TerminalRule\'WS\'");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("B ValueList\'[a]\' Root");
    _builder_1.newLine();
    _builder_1.append("13  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("14  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\\n\"     Whitespace:TerminalRule\'WS\'");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("\"/*81*/\"   Comment:TerminalRule\'ML_COMMENT\' Association:NEXT");
    _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:NEXT");
    _builder_1.newLine();
    _builder_1.append("   ");
    _builder_1.append("21   \"\\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 29 with ITextRegionAccess

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

the class RegionAccessCommentsTest method testDeleteMiddleRegion.

@Test
public void testDeleteMiddleRegion() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("8");
    _builder.newLine();
    _builder.append("a /*a*/ //a");
    _builder.newLine();
    _builder.append("/*b1*/");
    _builder.newLine();
    _builder.append("/*b2*/");
    _builder.newLine();
    _builder.append("b");
    _builder.newLine();
    final ITextRegionAccess access = this._regionAccessTestHelper.toTextRegionAccess(_builder);
    final Procedure1<ITextRegionDiffBuilder> _function = (ITextRegionDiffBuilder it) -> {
        final ISemanticRegion foo = IterableExtensions.<ISemanticRegion>head(access.regionForRootEObject().getAllRegionsFor().features(RegionaccesstestlanguagePackage.Literals.VALUE_LIST__NAME));
        it.remove(foo);
    };
    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]\' 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 \"\\n\"       Whitespace:TerminalRule\'WS\'");
    _builder_1.newLine();
    _builder_1.append("         ");
    _builder_1.append("\"/*b1*/\"   Comment:TerminalRule\'ML_COMMENT\' Association:NEXT");
    _builder_1.newLine();
    _builder_1.append("         ");
    _builder_1.append("\"\\n\"       Whitespace:TerminalRule\'WS\'");
    _builder_1.newLine();
    _builder_1.append("         ");
    _builder_1.append("\"/*b2*/\"   Comment:TerminalRule\'ML_COMMENT\' Association:NEXT");
    _builder_1.newLine();
    _builder_1.append("   ");
    _builder_1.append("15    \"\\n\"       Whitespace:TerminalRule\'WS\'");
    _builder_1.newLine();
    _builder_1.append("16  1    S \"b\"        ValueList:name+=ID");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("E ValueList\'[a, b]\' Root");
    _builder_1.newLine();
    _builder_1.append("17  0   H");
    _builder_1.newLine();
    _builder_1.append("------------ diff 1 ------------");
    _builder_1.newLine();
    _builder_1.append(" ");
    _builder_1.append("1  1 H \"\\n\"       Whitespace:TerminalRule\'WS\'");
    _builder_1.newLine();
    _builder_1.append(" ");
    _builder_1.append("2  1 S \"a\"        ValueList:name+=ID");
    _builder_1.newLine();
    _builder_1.append(" ");
    _builder_1.append("3    H \" \"        Whitespace:TerminalRule\'WS\'");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("\"/*a*/\"    Comment:TerminalRule\'ML_COMMENT\' Association:PREVIOUS");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("\" \"        Whitespace:TerminalRule\'WS\'");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("\"//a\\n\"    Comment:TerminalRule\'SL_COMMENT\' Association:PREVIOUS");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("\"/*b1*/\"   Comment:TerminalRule\'ML_COMMENT\' Association:NEXT");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("\"\\n\"       Whitespace:TerminalRule\'WS\'");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("\"/*b2*/\"   Comment:TerminalRule\'ML_COMMENT\' Association:NEXT");
    _builder_1.newLine();
    _builder_1.append("   ");
    _builder_1.append("25   \"\\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 30 with ITextRegionAccess

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

the class RegionAccessDiffTest method testEmptyModification.

@Test
public void testEmptyModification() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("1 foo");
    _builder.newLine();
    final ITextRegionAccess access = this._regionAccessTestHelper.toTextRegionAccess(_builder);
    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 3  S \"foo\"      Simple:name=ID");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("E Simple\'foo\' Root");
    _builder_1.newLine();
    _builder_1.append("5 0 H");
    _builder_1.newLine();
    this._regionAccessTestHelper.operator_tripleEquals(access, _builder_1);
    final Procedure1<ITextRegionDiffBuilder> _function = (ITextRegionDiffBuilder it) -> {
    };
    ITextRegionAccess _modify = this._regionAccessTestHelper.modify(access, _function);
    StringConcatenation _builder_2 = new StringConcatenation();
    _builder_2.append("0 0 H");
    _builder_2.newLine();
    _builder_2.append("    ");
    _builder_2.append("B Simple\'foo\' Root");
    _builder_2.newLine();
    _builder_2.append("0 1  S \"1\"        Simple:\'1\'");
    _builder_2.newLine();
    _builder_2.append("1 1  H \" \"        Whitespace:TerminalRule\'WS\'");
    _builder_2.newLine();
    _builder_2.append("2 3  S \"foo\"      Simple:name=ID");
    _builder_2.newLine();
    _builder_2.append("    ");
    _builder_2.append("E Simple\'foo\' Root");
    _builder_2.newLine();
    _builder_2.append("5 0 H");
    _builder_2.newLine();
    this._regionAccessTestHelper.operator_tripleEquals(_modify, _builder_2);
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) ITextRegionDiffBuilder(org.eclipse.xtext.formatting2.regionaccess.ITextRegionDiffBuilder) 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