Search in sources :

Example 11 with InMemoryURIHandler

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

the class FileAwareTestLanguageImportTest method testNestedPackage.

@Test
public void testNestedPackage() {
    InMemoryURIHandler fs = new InMemoryURIHandler();
    String content1 = "package foo \n" + "element X {}\n";
    importTestHelper.operator_add(fs, Pair.of("inmemory:/foo/X.fileawaretestlanguage", content1));
    String content2 = "package foo.bar \n" + "element Y { ref foo.X }\n";
    importTestHelper.operator_add(fs, Pair.of("inmemory:/foo/bar/Y.fileawaretestlanguage", content2));
    ResourceSet rs = importTestHelper.createResourceSet(fs);
    PackageDeclaration model1 = importTestHelper.contents(rs, "inmemory:/foo/X.fileawaretestlanguage", PackageDeclaration.class);
    PackageDeclaration model2 = importTestHelper.contents(rs, "inmemory:/foo/bar/Y.fileawaretestlanguage", PackageDeclaration.class);
    ChangeSerializer serializer = serializerProvider.get();
    serializer.addModification(model1, (PackageDeclaration it) -> {
        it.setName("foo2");
    });
    serializer.addModification(model2, (PackageDeclaration it) -> {
        // was this way in the original test
        it.setName("foo2.bar");
        it.setName("foo2.bar");
    });
    Collection<IEmfResourceChange> changes = importTestHelper.endRecordChangesToTextDocuments(serializer);
    String expectation = "-------- inmemory:/foo/X.fileawaretestlanguage (syntax: <offset|text>) ---------\n" + "package <8:3|foo2> \n" + "element X {}\n" + "--------------------------------------------------------------------------------\n" + "8 3 \"foo\" -> \"foo2\"\n" + "------ inmemory:/foo/bar/Y.fileawaretestlanguage (syntax: <offset|text>) -------\n" + "package <8:7|foo2.bar> \n" + "<17:0|import foo2.X\n" + "\n" + ">element Y { ref <33:5|X> }\n" + "--------------------------------------------------------------------------------\n" + " 8 7 \"foo.bar\" -> \"foo2.bar\"\n" + "17 0 \"\" -> \"import foo2.X\\n" + "\\n" + "\"\n" + "33 5 \"foo.X\" -> \"X\"\n";
    importTestHelper.operator_tripleEquals(changes, expectation);
}
Also used : ChangeSerializer(org.eclipse.xtext.ide.serializer.impl.ChangeSerializer) InMemoryURIHandler(org.eclipse.xtext.testing.util.InMemoryURIHandler) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) PackageDeclaration(org.eclipse.xtext.testlanguages.fileAware.fileAware.PackageDeclaration) IEmfResourceChange(org.eclipse.xtext.ide.serializer.IEmfResourceChange) Test(org.junit.Test)

Example 12 with InMemoryURIHandler

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

the class FileAwareTestLanguageImportTest method testRenameGlobal1.

@Test
public void testRenameGlobal1() {
    InMemoryURIHandler fs = new InMemoryURIHandler();
    String content1 = "package pkg1\n" + "\n" + "element Foo {\n" + "}\n";
    importTestHelper.operator_add(fs, Pair.of("inmemory:/file1.fileawaretestlanguage", content1));
    String content2 = "package pkg2\n" + "\n" + "import pkg1.Foo\n" + "\n" + "element Bar {\n" + "	ref Foo\n" + "}\n";
    importTestHelper.operator_add(fs, Pair.of("inmemory:/file2.fileawaretestlanguage", content2));
    ResourceSet rs = importTestHelper.createResourceSet(fs);
    PackageDeclaration model = importTestHelper.contents(rs, "inmemory:/file1.fileawaretestlanguage", PackageDeclaration.class);
    ChangeSerializer serializer = serializerProvider.get();
    serializer.addModification(model, (PackageDeclaration it) -> {
        it.setName("newpackage");
    });
    Assert.assertEquals(1, model.eResource().getResourceSet().getResources().size());
    Collection<IEmfResourceChange> changes = importTestHelper.endRecordChangesToTextDocuments(serializer);
    String expectation = "-------- inmemory:/file1.fileawaretestlanguage (syntax: <offset|text>) ---------\n" + "package <8:4|newpackage>\n" + "\n" + "element Foo {\n" + "}\n" + "--------------------------------------------------------------------------------\n" + "8 4 \"pkg1\" -> \"newpackage\"\n" + "-------- inmemory:/file2.fileawaretestlanguage (syntax: <offset|text>) ---------\n" + "package pkg2\n" + "\n" + "import <21:8|newpackage.Foo>\n" + "\n" + "element Bar {\n" + "	ref Foo\n" + "}\n" + "--------------------------------------------------------------------------------\n" + "21 8 \"pkg1.Foo\" -> \"newpackage.Foo\"\n";
    importTestHelper.operator_tripleEquals(changes, expectation);
}
Also used : ChangeSerializer(org.eclipse.xtext.ide.serializer.impl.ChangeSerializer) InMemoryURIHandler(org.eclipse.xtext.testing.util.InMemoryURIHandler) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) PackageDeclaration(org.eclipse.xtext.testlanguages.fileAware.fileAware.PackageDeclaration) IEmfResourceChange(org.eclipse.xtext.ide.serializer.IEmfResourceChange) Test(org.junit.Test)

Example 13 with InMemoryURIHandler

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

the class ChangeSerializerTestHelper 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);
    return r;
}
Also used : ResourceDescriptionsData(org.eclipse.xtext.resource.impl.ResourceDescriptionsData) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) InMemoryURIHandler(org.eclipse.xtext.testing.util.InMemoryURIHandler) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) ArrayList(java.util.ArrayList) XtextResource(org.eclipse.xtext.resource.XtextResource)

Example 14 with InMemoryURIHandler

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

the class AbstractIdeQuickfixTest method createInMemoryFile.

@SuppressWarnings("unchecked")
private <T> T createInMemoryFile(CharSequence content, EClass type) {
    InMemoryURIHandler fs = new InMemoryURIHandler();
    String fileName = "inmemory:/file1." + fileExtensionProvider.getPrimaryFileExtension();
    quickFixTestHelper.operator_add(fs, Pair.of(fileName, content.toString()));
    ResourceSet rs = quickFixTestHelper.createResourceSet(fs);
    Map<String, ResourceDescriptionsData> dataMap = new HashMap<>();
    dataMap.put("project", ResourceDescriptionsData.ResourceSetAdapter.findResourceDescriptionsData(rs));
    new ChunkedResourceDescriptions(dataMap, rs);
    return (T) quickFixTestHelper.findFirstOfTypeInFile(rs, fileName, type.getInstanceClass());
}
Also used : ResourceDescriptionsData(org.eclipse.xtext.resource.impl.ResourceDescriptionsData) HashMap(java.util.HashMap) InMemoryURIHandler(org.eclipse.xtext.testing.util.InMemoryURIHandler) ChunkedResourceDescriptions(org.eclipse.xtext.resource.impl.ChunkedResourceDescriptions) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet)

Example 15 with InMemoryURIHandler

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

the class AbstractIncrementalBuilderTest method setUp.

@Before
@BeforeEach
public void setUp() {
    clean();
    inMemoryURIHandler = new InMemoryURIHandler();
}
Also used : InMemoryURIHandler(org.eclipse.xtext.testing.util.InMemoryURIHandler) Before(org.junit.Before) BeforeEach(org.junit.jupiter.api.BeforeEach)

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