Search in sources :

Example 61 with ITextRegionAccess

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

Example 62 with ITextRegionAccess

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

the class RegionAccessDiffTest method testDeleteTwo.

@Test
public void testDeleteTwo() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("4/*1*/prefix/*2*/foo/*3*/");
    _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");
        final ISemanticRegion foo = ext.regionFor(rootObj.getDelegate()).feature(RegionaccesstestlanguagePackage.Literals.DELEGATE__NAME);
        it.remove(prefix.getPreviousHiddenRegion(), foo.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 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("E PrefixedUnassigned Root");
    _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   \"/*3*/\"    Comment:TerminalRule\'ML_COMMENT\' Association:CONTAINER");
    _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();
    _builder_1.append("17  3  S \"foo\"      Delegate:name=ID");
    _builder_1.newLine();
    _builder_1.append("20  5  H \"/*3*/\"    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)

Example 63 with ITextRegionAccess

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

the class RegionAccessDiffTest method testInsertInsertReplace.

@Test
public void testInsertInsertReplace() {
    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.getNextHiddenRegion(), a.getNextHiddenRegion(), a.getPreviousHiddenRegion(), a.getNextHiddenRegion());
        it.replace(a.getNextHiddenRegion(), a.getNextHiddenRegion(), a.getPreviousHiddenRegion(), a.getNextHiddenRegion());
        it.replace(a, "new");
    };
    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]\' 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 \" \"        Whitespace:TerminalRule\'WS\'");
    _builder_1.newLine();
    _builder_1.append(" ");
    _builder_1.append("2 3 2  S \"new\"      ValueList:name+=ID");
    _builder_1.newLine();
    _builder_1.append(" ");
    _builder_1.append("5 0 2  H");
    _builder_1.newLine();
    _builder_1.append(" ");
    _builder_1.append("5 3 2  S \"new\"      ValueList:name+=ID");
    _builder_1.newLine();
    _builder_1.append(" ");
    _builder_1.append("8 0 2  H");
    _builder_1.newLine();
    _builder_1.append(" ");
    _builder_1.append("8 3 2  S \"new\"      ValueList:name+=ID");
    _builder_1.newLine();
    _builder_1.append("       ");
    _builder_1.append("E ValueList\'[a]\' Root");
    _builder_1.newLine();
    _builder_1.append("11 0 2 H");
    _builder_1.newLine();
    _builder_1.append("------------ diff 1 ------------");
    _builder_1.newLine();
    _builder_1.append(" ");
    _builder_1.append("2 1 S \"a\"        ValueList:name+=ID");
    _builder_1.newLine();
    _builder_1.append("------------ diff 2 ------------");
    _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 0  H");
    _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 64 with ITextRegionAccess

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

the class RegionAccessDiffTest method testSerializeRootObject.

@Test
public void testSerializeRootObject() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("3 foo");
    _builder.newLine();
    final ITextRegionAccess access = this._regionAccessTestHelper.toTextRegionAccess(_builder);
    final Procedure1<ITextRegionDiffBuilder> _function = (ITextRegionDiffBuilder it) -> {
        final IEObjectRegion root = access.regionForRootEObject();
        EObject _semanticElement = root.getSemanticElement();
        final Delegate rootObj = ((Delegate) _semanticElement);
        rootObj.setName("baaaz");
        final ITextRegionAccess textRegions = this.serializer.serializeToRegions(rootObj);
        it.replace(root.getPreviousHiddenRegion(), root.getNextHiddenRegion(), textRegions);
    };
    ITextRegionAccess _modify = this._regionAccessTestHelper.modify(access, _function);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("0 0 1 H");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("B Delegate\'baaaz\' Root");
    _builder_1.newLine();
    _builder_1.append("0 1 1  S \"3\"        Unassigned:\'3\'");
    _builder_1.newLine();
    _builder_1.append("1 1 1  H \" \"        Whitespace:TerminalRule\'WS\'");
    _builder_1.newLine();
    _builder_1.append("2 5 1  S \"baaaz\"    Delegate:name=ID");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("E Delegate\'baaaz\' Root");
    _builder_1.newLine();
    _builder_1.append("7 0 1 H");
    _builder_1.newLine();
    _builder_1.append("------------ diff 1 ------------");
    _builder_1.newLine();
    _builder_1.append("0 0 H");
    _builder_1.newLine();
    _builder_1.append("0 1 S \"3\"        Unassigned:\'3\'");
    _builder_1.newLine();
    _builder_1.append("1 1 H \" \"        Whitespace:TerminalRule\'WS\'");
    _builder_1.newLine();
    _builder_1.append("2 3 S \"foo\"      Delegate:name=ID");
    _builder_1.newLine();
    _builder_1.append("5 0 H");
    _builder_1.newLine();
    this._regionAccessTestHelper.operator_tripleEquals(_modify, _builder_1);
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) IEObjectRegion(org.eclipse.xtext.formatting2.regionaccess.IEObjectRegion) Delegate(org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Delegate) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) ITextRegionDiffBuilder(org.eclipse.xtext.formatting2.regionaccess.ITextRegionDiffBuilder) Test(org.junit.Test)

Example 65 with ITextRegionAccess

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

the class RegionAccessDiffTest method testInsertBeforeComment.

@Test
public void testInsertBeforeComment() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("8");
    _builder.newLine();
    _builder.append("/**/");
    _builder.newLine();
    _builder.append("a b");
    _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();
        final ISemanticRegion b = a.getNextSemanticRegion();
        it.replace(a.getPreviousHiddenRegion(), a.getPreviousHiddenRegion(), b.getPreviousHiddenRegion(), b.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]\' 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 1  H \"\\n\"       Whitespace:TerminalRule\'WS\'");
    _builder_1.newLine();
    _builder_1.append(" ");
    _builder_1.append("2 1 1  S \"b\"        ValueList:name+=ID");
    _builder_1.newLine();
    _builder_1.append(" ");
    _builder_1.append("3   1  H \"/**/\"     Comment:TerminalRule\'ML_COMMENT\' Association:PREVIOUS");
    _builder_1.newLine();
    _builder_1.append("   ");
    _builder_1.append("5    \"\\n\"       Whitespace:TerminalRule\'WS\'");
    _builder_1.newLine();
    _builder_1.append(" ");
    _builder_1.append("8 1    S \"a\"        ValueList:name+=ID");
    _builder_1.newLine();
    _builder_1.append(" ");
    _builder_1.append("9 1    H \" \"        Whitespace:TerminalRule\'WS\'");
    _builder_1.newLine();
    _builder_1.append("10 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("11 0   H");
    _builder_1.newLine();
    _builder_1.append("------------ diff 1 ------------");
    _builder_1.newLine();
    _builder_1.append(" ");
    _builder_1.append("1   H \"\\n\"       Whitespace:TerminalRule\'WS\'");
    _builder_1.newLine();
    _builder_1.append("       ");
    _builder_1.append("\"/**/\"     Comment:TerminalRule\'ML_COMMENT\' Association:NEXT");
    _builder_1.newLine();
    _builder_1.append("   ");
    _builder_1.append("6   \"\\n\"       Whitespace:TerminalRule\'WS\'");
    _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)

Aggregations

ITextRegionAccess (org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess)65 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 EObject (org.eclipse.emf.ecore.EObject)13 OptionalChildList (org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.OptionalChildList)12 ITextSegment (org.eclipse.xtext.formatting2.regionaccess.ITextSegment)11 MandatoryValue (org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.MandatoryValue)11 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)10 ITextReplacement (org.eclipse.xtext.formatting2.regionaccess.ITextReplacement)9 EList (org.eclipse.emf.common.util.EList)8 TextRegionAccessToString (org.eclipse.xtext.formatting2.debug.TextRegionAccessToString)7 FormatterRequest (org.eclipse.xtext.formatting2.FormatterRequest)6 IEObjectRegion (org.eclipse.xtext.formatting2.regionaccess.IEObjectRegion)6 IHiddenRegion (org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion)6 ITextRegionExtensions (org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions)6 ILineRegion (org.eclipse.xtext.formatting2.regionaccess.ILineRegion)5 XtextResource (org.eclipse.xtext.resource.XtextResource)5