Search in sources :

Example 1 with InMemoryURIHandler

use of org.eclipse.xtext.testing.util.InMemoryURIHandler in project xtext-core by eclipse.

the class PartialSerializerTest method recordDiff.

private <T extends EObject> ITextRegionAccess recordDiff(final Class<T> modelType, final CharSequence modelText, final IChangeSerializer.IModification<T> modification) {
    final InMemoryURIHandler fs = new InMemoryURIHandler();
    String _string = modelText.toString();
    Pair<String, String> _mappedTo = Pair.<String, String>of("inmemory:/file1.pstl", _string);
    this._changeSerializerTestHelper.operator_add(fs, _mappedTo);
    final ResourceSet rs = this._changeSerializerTestHelper.createResourceSet(fs);
    final T model = this._changeSerializerTestHelper.<T>contents(rs, "inmemory:/file1.pstl", modelType);
    final ChangeSerializer serializer = this.serializerProvider.get();
    serializer.<T>addModification(model, modification);
    return this._changeSerializerTestHelper.endRecordChangesToTextRegions(serializer);
}
Also used : IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) ChangeSerializer(org.eclipse.xtext.ide.serializer.impl.ChangeSerializer) InMemoryURIHandler(org.eclipse.xtext.testing.util.InMemoryURIHandler) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet)

Example 2 with InMemoryURIHandler

use of org.eclipse.xtext.testing.util.InMemoryURIHandler 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 3 with InMemoryURIHandler

use of org.eclipse.xtext.testing.util.InMemoryURIHandler in project xtext-core by eclipse.

the class ChangeSerializerTest method testSimple.

@Test
public void testSimple() {
    InMemoryURIHandler fs = new InMemoryURIHandler();
    changeSerializerTestHelper.operator_add(fs, Pair.of("inmemory:/file1.pstl", "#2 foo"));
    ResourceSet rs = changeSerializerTestHelper.createResourceSet(fs);
    MandatoryValue model = changeSerializerTestHelper.findFirstOfTypeInFile(rs, "inmemory:/file1.pstl", MandatoryValue.class);
    IChangeSerializer serializer = changeSerializerTestHelper.newChangeSerializer();
    serializer.addModification(model.eResource(), (Resource it) -> {
        model.setName("bar");
    });
    Collection<IEmfResourceChange> changes = changeSerializerTestHelper.endRecordChangesToTextDocuments(serializer);
    String expectation = "----------------- inmemory:/file1.pstl (syntax: <offset|text>) -----------------\n" + "#2 <3:3|bar>\n" + "--------------------------------------------------------------------------------\n" + "3 3 \"foo\" -> \"bar\"\n";
    changeSerializerTestHelper.operator_tripleEquals(changes, expectation);
}
Also used : MandatoryValue(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.MandatoryValue) IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) InMemoryURIHandler(org.eclipse.xtext.testing.util.InMemoryURIHandler) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IEmfResourceChange(org.eclipse.xtext.ide.serializer.IEmfResourceChange) Test(org.junit.Test)

Example 4 with InMemoryURIHandler

use of org.eclipse.xtext.testing.util.InMemoryURIHandler in project xtext-core by eclipse.

the class ChangeSerializerTest method testMoveElement_2.

@Test
public void testMoveElement_2() {
    InMemoryURIHandler fs = new InMemoryURIHandler();
    String content = "#22 {\n" + "	child1\n" + "	children1 {\n" + "		child2 jumper\n" + "	}\n" + "}";
    changeSerializerTestHelper.operator_add(fs, Pair.of("inmemory:/file-move.pstl", content));
    ResourceSet rs = changeSerializerTestHelper.createResourceSet(fs);
    TwoChildLists model = changeSerializerTestHelper.findFirstOfTypeInFile(rs, "inmemory:/file-move.pstl", TwoChildLists.class);
    IChangeSerializer serializer = changeSerializerTestHelper.newChangeSerializer();
    serializer.addModification(model.eResource(), (Resource it) -> {
        model.getDirectChildren().add(0, IterableExtensions.findFirst(model.getChildsList().getChildren(), (MandatoryValue v) -> "jumper".equals(v.getName())));
    });
    Collection<IEmfResourceChange> changes = changeSerializerTestHelper.endRecordChangesToTextDocuments(serializer);
    String expectation = "--------------- inmemory:/file-move.pstl (syntax: <offset|text>) ---------------\n" + "#22 {<5:0| jumper>\n" + "	child1\n" + "	children1 {\n" + "		child2 <36:6|>\n" + "	}\n" + "}\n" + "--------------------------------------------------------------------------------\n" + " 5 0 \"\" -> \" jumper\"\n" + "36 6 \"jumper\" -> \"\"\n";
    changeSerializerTestHelper.operator_tripleEquals(changes, expectation);
}
Also used : MandatoryValue(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.MandatoryValue) IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) InMemoryURIHandler(org.eclipse.xtext.testing.util.InMemoryURIHandler) TwoChildLists(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.TwoChildLists) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IEmfResourceChange(org.eclipse.xtext.ide.serializer.IEmfResourceChange) Test(org.junit.Test)

Example 5 with InMemoryURIHandler

use of org.eclipse.xtext.testing.util.InMemoryURIHandler in project xtext-core by eclipse.

the class ChangeSerializerTest method testRenameFqn1.

@Test
public void testRenameFqn1() {
    InMemoryURIHandler fs = new InMemoryURIHandler();
    String content = "#1 r {\n" + "	X refs a1.a2 X.a1.a2 r.X.a1.a2 { a1 { a2 refs a2 { a3 { ref a3 } } } }\n" + "	Y refs b1.b2 Y.b1.b2 r.Y.b1.b2 { b1 { b2 { ref b2 } } }\n" + "}\n";
    changeSerializerTestHelper.operator_add(fs, Pair.of("inmemory:/file1.pstl", content));
    ResourceSet rs = changeSerializerTestHelper.createResourceSet(fs);
    Node model = changeSerializerTestHelper.findFirstOfTypeInFile(rs, "inmemory:/file1.pstl", Node.class);
    IChangeSerializer serializer = changeSerializerTestHelper.newChangeSerializer();
    serializer.addModification(model.eResource(), (Resource it) -> {
        Node node = model.getChildren().get(0).getChildren().get(0).getChildren().get(0);
        node.setName("b");
    });
    Assert.assertEquals(1, model.eResource().getResourceSet().getResources().size());
    Collection<IEmfResourceChange> changes = changeSerializerTestHelper.endRecordChangesToTextDocuments(serializer);
    String expectation = "----------------- inmemory:/file1.pstl (syntax: <offset|text>) -----------------\n" + "#1 r {\n" + "	X refs <15:5|a1.b> <21:7|a1.b> <29:9|a1.b> { a1 { <46:2|b> refs <54:2|b> { a3 { ref a3 } } } }\n" + "	Y refs b1.b2 Y.b1.b2 r.Y.b1.b2 { b1 { b2 { ref b2 } } }\n" + "}\n" + "--------------------------------------------------------------------------------\n" + "15 5 \"a1.a2\" -> \"a1.b\"\n" + "21 7 \"X.a1.a2\" -> \"a1.b\"\n" + "29 9 \"r.X.a1.a2\" -> \"a1.b\"\n" + "46 2 \"a2\" -> \"b\"\n" + "54 2 \"a2\" -> \"b\"\n";
    changeSerializerTestHelper.operator_tripleEquals(changes, expectation);
}
Also used : IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) InMemoryURIHandler(org.eclipse.xtext.testing.util.InMemoryURIHandler) Node(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Node) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IEmfResourceChange(org.eclipse.xtext.ide.serializer.IEmfResourceChange) Test(org.junit.Test)

Aggregations

InMemoryURIHandler (org.eclipse.xtext.testing.util.InMemoryURIHandler)32 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)29 IEmfResourceChange (org.eclipse.xtext.ide.serializer.IEmfResourceChange)26 Test (org.junit.Test)26 Resource (org.eclipse.emf.ecore.resource.Resource)22 IChangeSerializer (org.eclipse.xtext.ide.serializer.IChangeSerializer)20 Node (org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Node)12 ChangeSerializer (org.eclipse.xtext.ide.serializer.impl.ChangeSerializer)10 MandatoryValue (org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.MandatoryValue)5 TwoChildLists (org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.TwoChildLists)4 PackageDeclaration (org.eclipse.xtext.testlanguages.fileAware.fileAware.PackageDeclaration)4 EClass (org.eclipse.emf.ecore.EClass)3 ResourceDescriptionsData (org.eclipse.xtext.resource.impl.ResourceDescriptionsData)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)2 XtextResource (org.eclipse.xtext.resource.XtextResource)2 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)2 ChunkedResourceDescriptions (org.eclipse.xtext.resource.impl.ChunkedResourceDescriptions)2 EPackage (org.eclipse.emf.ecore.EPackage)1