Search in sources :

Example 56 with ITextRegionAccess

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

the class RegionAccessBuilderTest method assertLinesAreConsistent.

private void assertLinesAreConsistent(final ITextRegionAccess access) {
    final Function1<ILineRegion, String> _function = (ILineRegion it) -> {
        int _offset = it.getOffset();
        String _plus = (Integer.valueOf(_offset) + ":");
        int _length = it.getLength();
        return (_plus + Integer.valueOf(_length));
    };
    final Set<String> lines = IterableExtensions.<String>toSet(ListExtensions.<ILineRegion, String>map(access.regionForDocument().getLineRegions(), _function));
    final String text = access.regionForDocument().getText();
    for (int i = 0; (i < text.length()); i++) {
        {
            final ILineRegion line = access.regionForLineAtOffset(i);
            int _offset = line.getOffset();
            String _plus = (Integer.valueOf(_offset) + ":");
            int _length = line.getLength();
            final String lineStr = (_plus + Integer.valueOf(_length));
            Assert.assertTrue(lines.contains(lineStr));
        }
    }
}
Also used : ILineRegion(org.eclipse.xtext.formatting2.regionaccess.ILineRegion) TextRegionAccessToString(org.eclipse.xtext.formatting2.debug.TextRegionAccessToString)

Example 57 with ITextRegionAccess

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

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

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

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

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