Search in sources :

Example 1 with Add

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

the class ImportTestHelper method createResourceSet.

public ResourceSet createResourceSet(InMemoryURIHandler fs) {
    XtextResourceSet idx = new XtextResourceSet();
    idx.getURIConverter().getURIHandlers().add(0, fs);
    for (InMemoryURIHandler.InMemFile f : fs.getFiles().values()) {
        idx.getResource(f.getUri(), true);
    }
    EcoreUtil.resolveAll(idx);
    for (Resource r : idx.getResources()) {
        if (r instanceof XtextResource) {
            validator.assertNoErrors(r);
        }
    }
    List<IResourceDescription> rsd = new ArrayList<>();
    for (Resource r : idx.getResources()) {
        rsd.add(rdManager.getResourceDescription(r));
    }
    ResourceDescriptionsData data = new ResourceDescriptionsData(rsd);
    XtextResourceSet r = new XtextResourceSet();
    r.getLoadOptions().put(ResourceDescriptionsProvider.LIVE_SCOPE, Boolean.TRUE);
    r.getURIConverter().getURIHandlers().add(0, fs);
    ResourceDescriptionsData.ResourceSetAdapter.installResourceDescriptionsData(r, data);
    Map<String, ResourceDescriptionsData> dataMap = new HashMap<>();
    dataMap.put("egal", data);
    new ChunkedResourceDescriptions(Collections.unmodifiableMap(dataMap), r);
    return r;
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) HashMap(java.util.HashMap) InMemoryURIHandler(org.eclipse.xtext.testing.util.InMemoryURIHandler) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) ArrayList(java.util.ArrayList) ChunkedResourceDescriptions(org.eclipse.xtext.resource.impl.ChunkedResourceDescriptions) XtextResource(org.eclipse.xtext.resource.XtextResource) TextRegionAccessToString(org.eclipse.xtext.formatting2.debug.TextRegionAccessToString) TextDocumentChangeToString(org.eclipse.xtext.ide.serializer.debug.TextDocumentChangeToString) ResourceDescriptionsData(org.eclipse.xtext.resource.impl.ResourceDescriptionsData) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet)

Example 2 with Add

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

the class PartialSerializerTest method testOptionalChildListInsertIntoMiddle.

@Test
public void testOptionalChildListInsertIntoMiddle() {
    ITextRegionAccess diff = recordDiff(OptionalChildList.class, "#13 x1 x3", (OptionalChildList it) -> {
        MandatoryValue newMandatoryValue = fac.createMandatoryValue();
        newMandatoryValue.setName("x2");
        it.getChildren().add(1, newMandatoryValue);
    });
    String expectation = "0 0   H\n" + "       B OptionalChildList    Model\n" + " 0 3    S \"#13\"                Model:'#13'\n" + " 3 1    H \" \"                  Whitespace:TerminalRule'WS'\n" + "        B MandatoryValue'x1'   OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[0]\n" + " 4 2     S \"x1\"                 MandatoryValue:name=ID\n" + "        E MandatoryValue'x1'   OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[0]\n" + " 6 1 1  H \" \"                  Whitespace:TerminalRule'WS'\n" + "        B MandatoryValue'x2'   MandatoryValue path:OptionalChildList/children[1]\n" + " 7 2 1   S \"x2\"                 MandatoryValue:name=ID\n" + "        E MandatoryValue'x2'   MandatoryValue path:OptionalChildList/children[1]\n" + " 9 0 1  H\n" + "        B MandatoryValue'x3'   OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[2]\n" + " 9 2     S \"x3\"                 MandatoryValue:name=ID\n" + "        E MandatoryValue'x3'   OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[2]\n" + "       E OptionalChildList    Model\n" + "11 0   H\n" + "------------ diff 1 ------------\n" + " 6 1  H \" \"                  Whitespace:TerminalRule'WS'\n" + " 7 2  S \"x3\"                 MandatoryValue:name=ID\n";
    changeSerializerTestHelper.operator_tripleEquals(diff, expectation);
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) OptionalChildList(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.OptionalChildList) MandatoryValue(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.MandatoryValue) Test(org.junit.Test)

Example 3 with Add

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

the class PartialSerializerTest method testOptionalChildListInsertIntoEndTwo.

@Test
public void testOptionalChildListInsertIntoEndTwo() {
    ITextRegionAccess diff = recordDiff(OptionalChildList.class, "#13 a", (OptionalChildList it) -> {
        MandatoryValue newMandatoryValue1 = fac.createMandatoryValue();
        newMandatoryValue1.setName("b");
        it.getChildren().add(newMandatoryValue1);
        MandatoryValue newMandatoryValue2 = fac.createMandatoryValue();
        newMandatoryValue2.setName("c");
        it.getChildren().add(newMandatoryValue2);
    });
    String expectation = "0 0   H\n" + "      B OptionalChildList    Model\n" + "0 3    S \"#13\"                Model:'#13'\n" + "3 1    H \" \"                  Whitespace:TerminalRule'WS'\n" + "       B MandatoryValue'a'    OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[0]\n" + "4 1 1   S \"a\"                  MandatoryValue:name=ID\n" + "       E MandatoryValue'a'    OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[0]\n" + "5 0 1  H\n" + "       B MandatoryValue'b'    MandatoryValue path:OptionalChildList/children[1]\n" + "5 1 1   S \"b\"                  MandatoryValue:name=ID\n" + "       E MandatoryValue'b'    MandatoryValue path:OptionalChildList/children[1]\n" + "6 0 1  H\n" + "       B MandatoryValue'c'    MandatoryValue path:OptionalChildList/children[2]\n" + "6 1 1   S \"c\"                  MandatoryValue:name=ID\n" + "       E MandatoryValue'c'    MandatoryValue path:OptionalChildList/children[2]\n" + "      E OptionalChildList    Model\n" + "7 0 1 H\n" + "------------ diff 1 ------------\n" + "4 1   S \"a\"                  MandatoryValue:name=ID\n" + "5 0   H\n";
    changeSerializerTestHelper.operator_tripleEquals(diff, expectation);
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) OptionalChildList(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.OptionalChildList) MandatoryValue(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.MandatoryValue) Test(org.junit.Test)

Example 4 with Add

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

the class PartialSerializerTest method testOptionalChildListInsertIntoEndOne.

@Test
public void testOptionalChildListInsertIntoEndOne() {
    ITextRegionAccess diff = recordDiff(OptionalChildList.class, "#13 x1", (OptionalChildList it) -> {
        MandatoryValue newMandatoryValue = fac.createMandatoryValue();
        newMandatoryValue.setName("x2");
        it.getChildren().add(newMandatoryValue);
    });
    String expectation = "0 0   H\n" + "      B OptionalChildList    Model\n" + "0 3    S \"#13\"                Model:'#13'\n" + "3 1    H \" \"                  Whitespace:TerminalRule'WS'\n" + "       B MandatoryValue'x1'   OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[0]\n" + "4 2 1   S \"x1\"                 MandatoryValue:name=ID\n" + "       E MandatoryValue'x1'   OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[0]\n" + "6 0 1  H\n" + "       B MandatoryValue'x2'   MandatoryValue path:OptionalChildList/children[1]\n" + "6 2 1   S \"x2\"                 MandatoryValue:name=ID\n" + "       E MandatoryValue'x2'   MandatoryValue path:OptionalChildList/children[1]\n" + "      E OptionalChildList    Model\n" + "8 0 1 H\n" + "------------ diff 1 ------------\n" + "4 2   S \"x1\"                 MandatoryValue:name=ID\n" + "6 0   H\n";
    changeSerializerTestHelper.operator_tripleEquals(diff, expectation);
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) OptionalChildList(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.OptionalChildList) MandatoryValue(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.MandatoryValue) Test(org.junit.Test)

Example 5 with Add

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

the class PartialSerializerTest method testOptionalChildListInsertIntoEndThree.

@Test
public void testOptionalChildListInsertIntoEndThree() {
    ITextRegionAccess diff = recordDiff(OptionalChildList.class, "#13 a", (OptionalChildList it) -> {
        MandatoryValue newMandatoryValue1 = fac.createMandatoryValue();
        newMandatoryValue1.setName("b");
        it.getChildren().add(newMandatoryValue1);
        MandatoryValue newMandatoryValue2 = fac.createMandatoryValue();
        newMandatoryValue2.setName("c");
        it.getChildren().add(newMandatoryValue2);
        MandatoryValue newMandatoryValue3 = fac.createMandatoryValue();
        newMandatoryValue3.setName("d");
        it.getChildren().add(newMandatoryValue3);
    });
    String expectation = "0 0   H\n" + "      B OptionalChildList    Model\n" + "0 3    S \"#13\"                Model:'#13'\n" + "3 1    H \" \"                  Whitespace:TerminalRule'WS'\n" + "       B MandatoryValue'a'    OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[0]\n" + "4 1 1   S \"a\"                  MandatoryValue:name=ID\n" + "       E MandatoryValue'a'    OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[0]\n" + "5 0 1  H\n" + "       B MandatoryValue'b'    MandatoryValue path:OptionalChildList/children[1]\n" + "5 1 1   S \"b\"                  MandatoryValue:name=ID\n" + "       E MandatoryValue'b'    MandatoryValue path:OptionalChildList/children[1]\n" + "6 0 1  H\n" + "       B MandatoryValue'c'    MandatoryValue path:OptionalChildList/children[2]\n" + "6 1 1   S \"c\"                  MandatoryValue:name=ID\n" + "       E MandatoryValue'c'    MandatoryValue path:OptionalChildList/children[2]\n" + "7 0 1  H\n" + "       B MandatoryValue'd'    MandatoryValue path:OptionalChildList/children[3]\n" + "7 1 1   S \"d\"                  MandatoryValue:name=ID\n" + "       E MandatoryValue'd'    MandatoryValue path:OptionalChildList/children[3]\n" + "      E OptionalChildList    Model\n" + "8 0 1 H\n" + "------------ diff 1 ------------\n" + "4 1   S \"a\"                  MandatoryValue:name=ID\n" + "5 0   H\n";
    changeSerializerTestHelper.operator_tripleEquals(diff, expectation);
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) OptionalChildList(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.OptionalChildList) MandatoryValue(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.MandatoryValue) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)14 ITextRegionAccess (org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess)7 MandatoryValue (org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.MandatoryValue)7 OptionalChildList (org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.OptionalChildList)7 TextRegionAccessToString (org.eclipse.xtext.formatting2.debug.TextRegionAccessToString)5 IFormattableDocument (org.eclipse.xtext.formatting2.IFormattableDocument)4 ITextRegionExtensions (org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions)4 Resource (org.eclipse.emf.ecore.resource.Resource)3 IDList (org.eclipse.xtext.formatting2.internal.formattertestlanguage.IDList)3 TextRegion (org.eclipse.xtext.util.TextRegion)3 EObject (org.eclipse.emf.ecore.EObject)2 TextDocumentChangeToString (org.eclipse.xtext.ide.serializer.debug.TextDocumentChangeToString)2 XtextResource (org.eclipse.xtext.resource.XtextResource)2 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)2 Joiner (com.google.common.base.Joiner)1 Lists (com.google.common.collect.Lists)1 Inject (com.google.inject.Inject)1 Provider (com.google.inject.Provider)1 BufferedOutputStream (java.io.BufferedOutputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1