Search in sources :

Example 36 with ISemanticRegion

use of org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion in project xtext-xtend by eclipse.

the class XtendFormatter method _format.

protected void _format(final XtendFile xtendFile, @Extension final IFormattableDocument format) {
    final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
        it.noSpace();
    };
    format.<XtendFile>prepend(xtendFile, _function);
    final ISemanticRegion pkg = this.textRegionExtensions.regionFor(xtendFile).feature(XtendPackage.Literals.XTEND_FILE__PACKAGE);
    if ((pkg != null)) {
        final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
            it.oneSpace();
        };
        format.prepend(pkg, _function_1);
        final ISemanticRegion pkgSemicolon = pkg.immediatelyFollowing().keyword(";");
        if ((pkgSemicolon != null)) {
            final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it) -> {
                it.noSpace();
            };
            format.append(pkg, _function_2);
            format.append(pkgSemicolon, XtendFormatterPreferenceKeys.blankLinesAfterPackageDecl);
        } else {
            format.append(pkg, XtendFormatterPreferenceKeys.blankLinesAfterPackageDecl);
        }
    }
    XImportSection _importSection = xtendFile.getImportSection();
    if (_importSection != null) {
        format.<XImportSection>format(_importSection);
    }
    EList<XtendTypeDeclaration> _xtendTypes = xtendFile.getXtendTypes();
    for (final XtendTypeDeclaration clazz : _xtendTypes) {
        {
            format.<XtendTypeDeclaration>format(clazz);
            XtendTypeDeclaration _last = IterableExtensions.<XtendTypeDeclaration>last(xtendFile.getXtendTypes());
            boolean _notEquals = (!Objects.equal(clazz, _last));
            if (_notEquals) {
                format.<XtendTypeDeclaration>append(clazz, XtendFormatterPreferenceKeys.blankLinesBetweenClasses);
            }
        }
    }
    final Procedure1<IHiddenRegionFormatter> _function_3 = (IHiddenRegionFormatter it) -> {
        it.newLine();
    };
    format.<XtendFile>append(xtendFile, _function_3);
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) XImportSection(org.eclipse.xtext.xtype.XImportSection) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)

Example 37 with ISemanticRegion

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

the class RegionAccessDiffTest method testDeleteOne.

@Test
public void testDeleteOne() throws Exception {
    String model = "4/*1*/prefix/*2*/foo\n";
    ITextRegionAccess access = regionAccessTestHelper.toTextRegionAccess(model);
    ITextRegionAccess modifiedAccess = regionAccessTestHelper.modify(access, (ITextRegionDiffBuilder it) -> {
        ITextRegionExtensions ext = access.getExtensions();
        PrefixedUnassigned rootObj = (PrefixedUnassigned) access.regionForRootEObject().getSemanticElement();
        ISemanticRegion prefix = ext.regionFor(rootObj.getDelegate()).keyword("prefix");
        it.remove(prefix);
    });
    String expectation = " 0  0   H\n" + "        B PrefixedUnassigned Root\n" + " 0  1    S \"4\"        PrefixedUnassigned:'4'\n" + " 1    1  H \"/*1*/\"    Comment:TerminalRule'ML_COMMENT' Association:CONTAINER\n" + "   10    \"/*2*/\"    Comment:TerminalRule'ML_COMMENT' Association:CONTAINER\n" + "         B Delegate'foo' PrefixedUnassigned:delegate=PrefixedDelegate path:PrefixedUnassigned/delegate\n" + "11  3     S \"foo\"      Delegate:name=ID\n" + "         E Delegate'foo' PrefixedUnassigned:delegate=PrefixedDelegate path:PrefixedUnassigned/delegate\n" + "        E PrefixedUnassigned Root\n" + "14  0   H\n" + "------------ diff 1 ------------\n" + " 1  5 H \"/*1*/\"    Comment:TerminalRule'ML_COMMENT' Association:CONTAINER\n" + " 6  6 S \"prefix\"   PrefixedDelegate:'prefix'\n" + "12  5 H \"/*2*/\"    Comment:TerminalRule'ML_COMMENT' Association:CONTAINER\n";
    regionAccessTestHelper.assertRegions(modifiedAccess, expectation);
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) 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 38 with ISemanticRegion

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

the class RegionAccessDiffTest method testInsertReplaceReplace.

@Test
public void testInsertReplaceReplace() throws Exception {
    String model = "8 a\n";
    ITextRegionAccess access = regionAccessTestHelper.toTextRegionAccess(model);
    ITextRegionAccess modifiedAccess = regionAccessTestHelper.modify(access, (ITextRegionDiffBuilder it) -> {
        ITextRegionExtensions ext = access.getExtensions();
        ValueList rootObj = (ValueList) access.regionForRootEObject().getSemanticElement();
        ISemanticRegion a = ext.regionFor(rootObj).keyword("8").getNextSemanticRegion();
        it.replace(a, "b");
        it.replace(a, "c");
    });
    String expectation = "0 0   H\n" + "      B ValueList'[a]' Root\n" + "0 1    S \"8\"        Root:'8'\n" + "1 1    H \" \"        Whitespace:TerminalRule'WS'\n" + "2 1 1  S \"c\"        ValueList:name+=ID\n" + "      E ValueList'[a]' Root\n" + "3 0   H\n" + "------------ diff 1 ------------\n" + "2 1 S \"a\"        ValueList:name+=ID\n";
    regionAccessTestHelper.assertRegions(modifiedAccess, expectation);
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) ValueList(org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.ValueList) 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 39 with ISemanticRegion

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

the class RegionAccessDiffTest method testDeleteTwo.

@Test
public void testDeleteTwo() throws Exception {
    String model = "4/*1*/prefix/*2*/foo/*3*/\n";
    ITextRegionAccess access = regionAccessTestHelper.toTextRegionAccess(model);
    ITextRegionAccess modifiedAccess = regionAccessTestHelper.modify(access, (ITextRegionDiffBuilder it) -> {
        ITextRegionExtensions ext = access.getExtensions();
        PrefixedUnassigned rootObj = (PrefixedUnassigned) access.regionForRootEObject().getSemanticElement();
        ISemanticRegion prefix = ext.regionFor(rootObj.getDelegate()).keyword("prefix");
        ISemanticRegion foo = ext.regionFor(rootObj.getDelegate()).feature(RegionaccesstestlanguagePackage.Literals.DELEGATE__NAME);
        it.remove(prefix.getPreviousHiddenRegion(), foo.getNextHiddenRegion());
    });
    String expectation = " 0  0   H\n" + "        B PrefixedUnassigned Root\n" + " 0  1    S \"4\"        PrefixedUnassigned:'4'\n" + "        E PrefixedUnassigned Root\n" + " 1    1 H \"/*1*/\"    Comment:TerminalRule'ML_COMMENT' Association:CONTAINER\n" + "   10   \"/*3*/\"    Comment:TerminalRule'ML_COMMENT' Association:CONTAINER\n" + "------------ diff 1 ------------\n" + " 1  5  H \"/*1*/\"    Comment:TerminalRule'ML_COMMENT' Association:CONTAINER\n" + " 6  6  S \"prefix\"   PrefixedDelegate:'prefix'\n" + "12  5  H \"/*2*/\"    Comment:TerminalRule'ML_COMMENT' Association:CONTAINER\n" + "17  3  S \"foo\"      Delegate:name=ID\n" + "20  5  H \"/*3*/\"    Comment:TerminalRule'ML_COMMENT' Association:CONTAINER\n";
    regionAccessTestHelper.assertRegions(modifiedAccess, expectation);
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) 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 40 with ISemanticRegion

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

the class RegionAccessDiffTest method testInsertInsertReplace.

@Test
public void testInsertInsertReplace() throws Exception {
    String model = "8 a\n";
    ITextRegionAccess access = regionAccessTestHelper.toTextRegionAccess(model);
    ITextRegionAccess modifiedAccess = regionAccessTestHelper.modify(access, (ITextRegionDiffBuilder it) -> {
        ITextRegionExtensions ext = access.getExtensions();
        ValueList rootObj = (ValueList) access.regionForRootEObject().getSemanticElement();
        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");
    });
    String expectation = " 0 0   H\n" + "       B ValueList'[a]' Root\n" + " 0 1    S \"8\"        Root:'8'\n" + " 1 1    H \" \"        Whitespace:TerminalRule'WS'\n" + " 2 3 2  S \"new\"      ValueList:name+=ID\n" + " 5 0 2  H\n" + " 5 3 2  S \"new\"      ValueList:name+=ID\n" + " 8 0 2  H\n" + " 8 3 2  S \"new\"      ValueList:name+=ID\n" + "       E ValueList'[a]' Root\n" + "11 0 2 H\n" + "------------ diff 1 ------------\n" + " 2 1 S \"a\"        ValueList:name+=ID\n" + "------------ diff 2 ------------\n" + " 2 1  S \"a\"        ValueList:name+=ID\n" + " 3 0  H\n";
    regionAccessTestHelper.assertRegions(modifiedAccess, expectation);
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) ValueList(org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.ValueList) 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

ISemanticRegion (org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)59 Test (org.junit.Test)30 ISemanticRegionsFinder (org.eclipse.xtext.formatting2.regionaccess.ISemanticRegionsFinder)18 ITextRegionAccess (org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess)15 IHiddenRegionFormatter (org.eclipse.xtext.formatting2.IHiddenRegionFormatter)14 ITextRegionDiffBuilder (org.eclipse.xtext.formatting2.regionaccess.ITextRegionDiffBuilder)13 Mixed (org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Mixed)12 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)9 IHiddenRegion (org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion)7 ITextRegionExtensions (org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions)7 EObject (org.eclipse.emf.ecore.EObject)4 IEObjectRegion (org.eclipse.xtext.formatting2.regionaccess.IEObjectRegion)4 AssignedAction (org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.AssignedAction)4 XExpression (org.eclipse.xtext.xbase.XExpression)4 JvmTypeParameter (org.eclipse.xtext.common.types.JvmTypeParameter)3 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)3 ValueList (org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.ValueList)3 LinkedList (java.util.LinkedList)2 EReference (org.eclipse.emf.ecore.EReference)2 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)2