Search in sources :

Example 1 with Simple

use of org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Simple in project xtext-core by eclipse.

the class RegionAccessBuilderTest method testSimple.

@Test
public void testSimple() throws Exception {
    String model = "1 foo\n".trim();
    String expectation = "0 0 H\n" + "    B Simple'foo' Root\n" + "0 1  S \"1\"        Simple:'1'\n" + "1 1  H \" \"        Whitespace:TerminalRule'WS'\n" + "2 3  S \"foo\"      Simple:name=ID\n" + "    E Simple'foo' Root\n" + "5 0 H\n";
    assertRegions(model, expectation);
}
Also used : TextRegionAccessToString(org.eclipse.xtext.formatting2.debug.TextRegionAccessToString) Test(org.junit.Test)

Example 2 with Simple

use of org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Simple in project xtext-core by eclipse.

the class RegionAccessDiffTest method testEmptyModification.

@Test
public void testEmptyModification() throws Exception {
    String model = "1 foo\n";
    ITextRegionAccess access = regionAccessTestHelper.toTextRegionAccess(model);
    String expectation1 = "0 0 H\n" + "    B Simple'foo' Root\n" + "0 1  S \"1\"        Simple:'1'\n" + "1 1  H \" \"        Whitespace:TerminalRule'WS'\n" + "2 3  S \"foo\"      Simple:name=ID\n" + "    E Simple'foo' Root\n" + "5 0 H\n";
    regionAccessTestHelper.assertRegions(access, expectation1);
    ITextRegionAccess modifiedAccess = regionAccessTestHelper.modify(access, (ITextRegionDiffBuilder it) -> {
    });
    String expectation2 = "0 0 H\n" + "    B Simple'foo' Root\n" + "0 1  S \"1\"        Simple:'1'\n" + "1 1  H \" \"        Whitespace:TerminalRule'WS'\n" + "2 3  S \"foo\"      Simple:name=ID\n" + "    E Simple'foo' Root\n" + "5 0 H\n";
    regionAccessTestHelper.assertRegions(modifiedAccess, expectation2);
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) ITextRegionDiffBuilder(org.eclipse.xtext.formatting2.regionaccess.ITextRegionDiffBuilder) Test(org.junit.Test)

Example 3 with Simple

use of org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Simple in project xtext-core by eclipse.

the class RegionAccessTestLanguageSemanticSequencer method sequence.

@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
    EPackage epackage = semanticObject.eClass().getEPackage();
    ParserRule rule = context.getParserRule();
    Action action = context.getAssignedAction();
    Set<Parameter> parameters = context.getEnabledBooleanParameters();
    if (epackage == RegionaccesstestlanguagePackage.eINSTANCE)
        switch(semanticObject.eClass().getClassifierID()) {
            case RegionaccesstestlanguagePackage.ACTION:
                sequence_Fragment_Mixed(context, (org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Action) semanticObject);
                return;
            case RegionaccesstestlanguagePackage.ADD:
                sequence_Expression(context, (Add) semanticObject);
                return;
            case RegionaccesstestlanguagePackage.ASSIGNED_ACTION:
                sequence_Mixed(context, (AssignedAction) semanticObject);
                return;
            case RegionaccesstestlanguagePackage.DELEGATE:
                sequence_Delegate(context, (Delegate) semanticObject);
                return;
            case RegionaccesstestlanguagePackage.DELEGATION:
                sequence_Delegation(context, (Delegation) semanticObject);
                return;
            case RegionaccesstestlanguagePackage.MIXED:
                sequence_Mixed(context, (Mixed) semanticObject);
                return;
            case RegionaccesstestlanguagePackage.NAMED:
                sequence_Primary(context, (Named) semanticObject);
                return;
            case RegionaccesstestlanguagePackage.PREFIXED_UNASSIGNED:
                sequence_PrefixedUnassigned(context, (PrefixedUnassigned) semanticObject);
                return;
            case RegionaccesstestlanguagePackage.ROOT:
                sequence_Root(context, (Root) semanticObject);
                return;
            case RegionaccesstestlanguagePackage.ROOT_ACTION:
                sequence_Root(context, (RootAction) semanticObject);
                return;
            case RegionaccesstestlanguagePackage.SIMPLE:
                sequence_Simple(context, (Simple) semanticObject);
                return;
            case RegionaccesstestlanguagePackage.VALUE_LIST:
                sequence_ValueList(context, (ValueList) semanticObject);
                return;
        }
    if (errorAcceptor != null)
        errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
Also used : Add(org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Add) ParserRule(org.eclipse.xtext.ParserRule) Named(org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Named) Action(org.eclipse.xtext.Action) RootAction(org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.RootAction) AssignedAction(org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.AssignedAction) Root(org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Root) RootAction(org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.RootAction) ValueList(org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.ValueList) Delegation(org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Delegation) EPackage(org.eclipse.emf.ecore.EPackage) Simple(org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Simple) AssignedAction(org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.AssignedAction) Delegate(org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Delegate) Mixed(org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Mixed) Parameter(org.eclipse.xtext.Parameter) PrefixedUnassigned(org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.PrefixedUnassigned)

Example 4 with Simple

use of org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Simple in project xtext-core by eclipse.

the class FormattableDocumentTest method simple.

@Test
public void simple() {
    final Procedure1<GenericFormatterTestRequest> _function = (GenericFormatterTestRequest it) -> {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("idlist  a");
        _builder.newLine();
        it.setToBeFormatted(_builder);
        final GenericFormatter<IDList> _function_1 = new GenericFormatter<IDList>() {

            @Override
            protected void format(final IDList model, @Extension final ITextRegionExtensions regions, @Extension final IFormattableDocument document) {
                final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it_1) -> {
                    it_1.oneSpace();
                };
                document.append(regions.regionFor(model).keyword("idlist"), _function);
            }
        };
        it.setFormatter(_function_1);
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("idlist a");
        _builder_1.newLine();
        it.setExpectation(_builder_1);
    };
    this._genericFormatterTester.assertFormatted(_function);
}
Also used : GenericFormatterTestRequest(org.eclipse.xtext.formatting2.internal.GenericFormatterTestRequest) GenericFormatter(org.eclipse.xtext.formatting2.internal.GenericFormatter) IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) IFormattableDocument(org.eclipse.xtext.formatting2.IFormattableDocument) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) IDList(org.eclipse.xtext.formatting2.internal.formattertestlanguage.IDList) ITextRegionExtensions(org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions) Test(org.junit.Test)

Example 5 with Simple

use of org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Simple in project xtext-core by eclipse.

the class RegionAccessBuilderTest method testMultiWhitespace1.

@Test
public void testMultiWhitespace1() throws Exception {
    String model = "1 /**/ foo\n".trim();
    String expectation = " 0 0 H\n" + "     B Simple'foo' Root\n" + " 0 1  S \"1\"        Simple:'1'\n" + " 1    H \" \"        Whitespace:TerminalRule'WS'\n" + "        \"/**/\"     Comment:TerminalRule'ML_COMMENT' Association:CONTAINER\n" + "   6    \" \"        Whitespace:TerminalRule'WS'\n" + " 7 3  S \"foo\"      Simple:name=ID\n" + "     E Simple'foo' Root\n" + "10 0 H\n";
    assertRegions(model, expectation);
}
Also used : TextRegionAccessToString(org.eclipse.xtext.formatting2.debug.TextRegionAccessToString) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 TextRegionAccessToString (org.eclipse.xtext.formatting2.debug.TextRegionAccessToString)3 ITextRegionAccess (org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess)2 ITextRegionDiffBuilder (org.eclipse.xtext.formatting2.regionaccess.ITextRegionDiffBuilder)2 ITextRegionExtensions (org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions)2 EObject (org.eclipse.emf.ecore.EObject)1 EPackage (org.eclipse.emf.ecore.EPackage)1 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)1 Action (org.eclipse.xtext.Action)1 Parameter (org.eclipse.xtext.Parameter)1 ParserRule (org.eclipse.xtext.ParserRule)1 IFormattableDocument (org.eclipse.xtext.formatting2.IFormattableDocument)1 IHiddenRegionFormatter (org.eclipse.xtext.formatting2.IHiddenRegionFormatter)1 GenericFormatter (org.eclipse.xtext.formatting2.internal.GenericFormatter)1 GenericFormatterTestRequest (org.eclipse.xtext.formatting2.internal.GenericFormatterTestRequest)1 IDList (org.eclipse.xtext.formatting2.internal.formattertestlanguage.IDList)1 ISemanticRegion (org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)1 Add (org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Add)1 AssignedAction (org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.AssignedAction)1 Delegate (org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Delegate)1