Search in sources :

Example 21 with ITextRegionAccess

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

the class PartialSerializerTest method testOptionalChildListInsertIntoMiddle.

@Test
public void testOptionalChildListInsertIntoMiddle() {
    final IChangeSerializer.IModification<OptionalChildList> _function = (OptionalChildList it) -> {
        EList<MandatoryValue> _children = it.getChildren();
        MandatoryValue _createMandatoryValue = this.fac.createMandatoryValue();
        final Procedure1<MandatoryValue> _function_1 = (MandatoryValue it_1) -> {
            it_1.setName("x2");
        };
        MandatoryValue _doubleArrow = ObjectExtensions.<MandatoryValue>operator_doubleArrow(_createMandatoryValue, _function_1);
        _children.add(1, _doubleArrow);
    };
    ITextRegionAccess _recordDiff = this.<OptionalChildList>recordDiff(OptionalChildList.class, "#13 x1 x3", _function);
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("0 0   H");
    _builder.newLine();
    _builder.append("       ");
    _builder.append("B OptionalChildList    Model");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("0 3    S \"#13\"                Model:\'#13\'");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("3 1    H \" \"                  Whitespace:TerminalRule\'WS\'");
    _builder.newLine();
    _builder.append("        ");
    _builder.append("B MandatoryValue\'x1\'   OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[0]");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("4 2     S \"x1\"                 MandatoryValue:name=ID");
    _builder.newLine();
    _builder.append("        ");
    _builder.append("E MandatoryValue\'x1\'   OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[0]");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("6 1 1  H \" \"                  Whitespace:TerminalRule\'WS\'");
    _builder.newLine();
    _builder.append("        ");
    _builder.append("B MandatoryValue\'x2\'   MandatoryValue path:OptionalChildList/children[1]");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("7 2 1   S \"x2\"                 MandatoryValue:name=ID");
    _builder.newLine();
    _builder.append("        ");
    _builder.append("E MandatoryValue\'x2\'   MandatoryValue path:OptionalChildList/children[1]");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("9 0 1  H");
    _builder.newLine();
    _builder.append("        ");
    _builder.append("B MandatoryValue\'x3\'   OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[2]");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("9 2     S \"x3\"                 MandatoryValue:name=ID");
    _builder.newLine();
    _builder.append("        ");
    _builder.append("E MandatoryValue\'x3\'   OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[2]");
    _builder.newLine();
    _builder.append("       ");
    _builder.append("E OptionalChildList    Model");
    _builder.newLine();
    _builder.append("11 0   H");
    _builder.newLine();
    _builder.append("------------ diff 1 ------------");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("6 1  H \" \"                  Whitespace:TerminalRule\'WS\'");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("7 2  S \"x3\"                 MandatoryValue:name=ID");
    _builder.newLine();
    this._changeSerializerTestHelper.operator_tripleEquals(_recordDiff, _builder);
}
Also used : OptionalChildList(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.OptionalChildList) MandatoryValue(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.MandatoryValue) ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) EList(org.eclipse.emf.common.util.EList) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 22 with ITextRegionAccess

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

the class PartialSerializerTest method testOptionalChildRemoveListAllOne.

@Test
public void testOptionalChildRemoveListAllOne() {
    final IChangeSerializer.IModification<OptionalChildList> _function = (OptionalChildList it) -> {
        EcoreUtil.remove(it.getChildren().get(0));
    };
    ITextRegionAccess _recordDiff = this.<OptionalChildList>recordDiff(OptionalChildList.class, "#13 x1", _function);
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("0 0   H");
    _builder.newLine();
    _builder.append("      ");
    _builder.append("B OptionalChildList    Model");
    _builder.newLine();
    _builder.append("0 3    S \"#13\"                Model:\'#13\'");
    _builder.newLine();
    _builder.append("      ");
    _builder.append("E OptionalChildList    Model");
    _builder.newLine();
    _builder.append("3 1 1 H \" \"                  Whitespace:TerminalRule\'WS\'");
    _builder.newLine();
    _builder.append("------------ diff 1 ------------");
    _builder.newLine();
    _builder.append("3 1  H \" \"                  Whitespace:TerminalRule\'WS\'");
    _builder.newLine();
    _builder.append("4 2  S \"x1\"                 MandatoryValue:name=ID");
    _builder.newLine();
    _builder.append("6 0  H");
    _builder.newLine();
    this._changeSerializerTestHelper.operator_tripleEquals(_recordDiff, _builder);
}
Also used : OptionalChildList(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.OptionalChildList) ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 23 with ITextRegionAccess

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

the class PartialSerializerTest method testOptionalChildListInsertIntoEndOne.

@Test
public void testOptionalChildListInsertIntoEndOne() {
    final IChangeSerializer.IModification<OptionalChildList> _function = (OptionalChildList it) -> {
        EList<MandatoryValue> _children = it.getChildren();
        MandatoryValue _createMandatoryValue = this.fac.createMandatoryValue();
        final Procedure1<MandatoryValue> _function_1 = (MandatoryValue it_1) -> {
            it_1.setName("x2");
        };
        MandatoryValue _doubleArrow = ObjectExtensions.<MandatoryValue>operator_doubleArrow(_createMandatoryValue, _function_1);
        _children.add(_doubleArrow);
    };
    ITextRegionAccess _recordDiff = this.<OptionalChildList>recordDiff(OptionalChildList.class, "#13 x1", _function);
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("0 0   H");
    _builder.newLine();
    _builder.append("      ");
    _builder.append("B OptionalChildList    Model");
    _builder.newLine();
    _builder.append("0 3    S \"#13\"                Model:\'#13\'");
    _builder.newLine();
    _builder.append("3 1    H \" \"                  Whitespace:TerminalRule\'WS\'");
    _builder.newLine();
    _builder.append("       ");
    _builder.append("B MandatoryValue\'x1\'   OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[0]");
    _builder.newLine();
    _builder.append("4 2 1   S \"x1\"                 MandatoryValue:name=ID");
    _builder.newLine();
    _builder.append("       ");
    _builder.append("E MandatoryValue\'x1\'   OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[0]");
    _builder.newLine();
    _builder.append("6 0 1  H");
    _builder.newLine();
    _builder.append("       ");
    _builder.append("B MandatoryValue\'x2\'   MandatoryValue path:OptionalChildList/children[1]");
    _builder.newLine();
    _builder.append("6 2 1   S \"x2\"                 MandatoryValue:name=ID");
    _builder.newLine();
    _builder.append("       ");
    _builder.append("E MandatoryValue\'x2\'   MandatoryValue path:OptionalChildList/children[1]");
    _builder.newLine();
    _builder.append("      ");
    _builder.append("E OptionalChildList    Model");
    _builder.newLine();
    _builder.append("8 0 1 H");
    _builder.newLine();
    _builder.append("------------ diff 1 ------------");
    _builder.newLine();
    _builder.append("4 2   S \"x1\"                 MandatoryValue:name=ID");
    _builder.newLine();
    _builder.append("6 0   H");
    _builder.newLine();
    this._changeSerializerTestHelper.operator_tripleEquals(_recordDiff, _builder);
}
Also used : OptionalChildList(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.OptionalChildList) MandatoryValue(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.MandatoryValue) ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) EList(org.eclipse.emf.common.util.EList) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 24 with ITextRegionAccess

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

the class ImportTestHelper method operator_tripleEquals.

public void operator_tripleEquals(final ITextRegionAccess actual, final CharSequence expected) {
    final String actualString = new TextRegionAccessToString().withRegionAccess(actual).hideColumnExplanation().toString();
    Assert.assertEquals(expected.toString().trim(), actualString.trim());
}
Also used : TextRegionAccessToString(org.eclipse.xtext.formatting2.debug.TextRegionAccessToString) TextDocumentChangeToString(org.eclipse.xtext.ide.serializer.debug.TextDocumentChangeToString) TextRegionAccessToString(org.eclipse.xtext.formatting2.debug.TextRegionAccessToString)

Example 25 with ITextRegionAccess

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

the class RegionAccessBuilderTest method assertToStringDoesNotCrash.

private void assertToStringDoesNotCrash(final ITextRegionAccess access) {
    IHiddenRegion _previousHiddenRegion = access.regionForRootEObject().getPreviousHiddenRegion();
    ISequentialRegion current = ((ISequentialRegion) _previousHiddenRegion);
    while ((current != null)) {
        {
            Assert.assertNotNull(current.toString());
            boolean _matched = false;
            if (current instanceof IHiddenRegion) {
                _matched = true;
                current = ((IHiddenRegion) current).getNextSemanticRegion();
            }
            if (!_matched) {
                if (current instanceof ISemanticRegion) {
                    _matched = true;
                    Assert.assertNotNull(((ISemanticRegion) current).getEObjectRegion().toString());
                    current = ((ISemanticRegion) current).getNextHiddenRegion();
                }
            }
        }
    }
}
Also used : ISequentialRegion(org.eclipse.xtext.formatting2.regionaccess.ISequentialRegion) IHiddenRegion(org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)

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