Search in sources :

Example 96 with ResourceSet

use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-core by eclipse.

the class ConcurrentAccessTest method testMultiThreaded.

@Ignore
@Test
public void testMultiThreaded() throws InterruptedException {
    ResourceSet resourceSet = new XtextResourceSet();
    resourceSet.getResources().add(resource);
    boolean wasOk = resolveAllReferencesMultithreaded((EPackage) resource.getContents().get(0));
    if (wasOk)
        assertFalse(101 == resourceSet.getResources().size());
    assertFalse("unresolvedProxy", wasOk);
}
Also used : ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 97 with ResourceSet

use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-core by eclipse.

the class AbstractLiveContainerTest method testContainerAddRemove.

@Test
public void testContainerAddRemove() throws Exception {
    ResourceSet resourceSet = new XtextResourceSet();
    Resource res = parse("local", resourceSet).eResource();
    parse("other", resourceSet);
    IResourceDescription resourceDescription = descriptionManager.getResourceDescription(res);
    IResourceDescriptions resourceDescriptions = descriptionsProvider.getResourceDescriptions(res);
    List<IContainer> containers = containerManager.getVisibleContainers(resourceDescription, resourceDescriptions);
    assertEquals(1, containers.size());
    IContainer container = containers.get(0);
    assertEquals("local, other", format(container.getExportedObjects()));
    Resource foo = parse("foo", resourceSet).eResource();
    assertEquals("foo, local, other", format(container.getExportedObjects()));
    resourceSet.getResources().remove(foo);
    assertEquals("local, other", format(container.getExportedObjects()));
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) IResourceDescriptions(org.eclipse.xtext.resource.IResourceDescriptions) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) IContainer(org.eclipse.xtext.resource.IContainer) Test(org.junit.Test)

Example 98 with ResourceSet

use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-core by eclipse.

the class AbstractLiveContainerTest method testNonNormalizedURIs.

@Test
public // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=382555
void testNonNormalizedURIs() throws Exception {
    ResourceSet resourceSet = new XtextResourceSet();
    parser.parse("B", URI.createURI("a." + parser.fileExtension), resourceSet);
    parser.parse("B", URI.createURI("b." + parser.fileExtension), resourceSet);
    IResourceDescriptions index = descriptionsProvider.getResourceDescriptions(resourceSet);
    IResourceDescription rd = index.getResourceDescription(URI.createURI("a." + parser.fileExtension));
    List<IContainer> containers = containerManager.getVisibleContainers(rd, index);
    List<IEObjectDescription> objects = Lists.newArrayList();
    EClass type = (EClass) grammarAccess.getGrammar().getRules().get(0).getType().getClassifier();
    for (IContainer container : containers) Iterables.addAll(objects, container.getExportedObjects(type, QualifiedName.create("B"), false));
    assertEquals(2, objects.size());
}
Also used : EClass(org.eclipse.emf.ecore.EClass) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) IResourceDescriptions(org.eclipse.xtext.resource.IResourceDescriptions) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) IContainer(org.eclipse.xtext.resource.IContainer) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) Test(org.junit.Test)

Example 99 with ResourceSet

use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-core by eclipse.

the class DefaultReferenceDescriptionTest method testLazyLinkingProxyReferences.

/**
 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=330812
 */
@Test
public void testLazyLinkingProxyReferences() {
    URI resourceUri = URI.createPlatformResourceURI("test.ecore", true);
    LazyURIEncoder lazyURIEncoder = new LazyURIEncoder();
    ResourceSet resourceSet = new ResourceSetImpl();
    Resource testResource = resourceSet.createResource(resourceUri);
    EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
    ePackage.setName("test");
    ePackage.setNsPrefix("test");
    ePackage.setNsURI("test");
    testResource.getContents().add(ePackage);
    EClass eClass = EcoreFactory.eINSTANCE.createEClass();
    eClass.setName("Test");
    ePackage.getEClassifiers().add(eClass);
    EClass multiRefType = EcoreFactory.eINSTANCE.createEClass();
    ((InternalEObject) multiRefType).eSetProxyURI(EcoreUtil.getURI(EcorePackage.Literals.EPACKAGE));
    eClass.getESuperTypes().add(multiRefType);
    EClass multiRefType2 = EcoreFactory.eINSTANCE.createEClass();
    URI dummyProxyUri = resourceUri.appendFragment(lazyURIEncoder.encode(eClass, EcorePackage.Literals.ECLASS__ESUPER_TYPES, null));
    ((InternalEObject) multiRefType2).eSetProxyURI(dummyProxyUri);
    eClass.getESuperTypes().add(multiRefType2);
    EAttribute nameAttribute = EcoreFactory.eINSTANCE.createEAttribute();
    nameAttribute.setName("name");
    eClass.getEStructuralFeatures().add(nameAttribute);
    EDataType singleRefType = EcoreFactory.eINSTANCE.createEDataType();
    ((InternalEObject) singleRefType).eSetProxyURI(EcoreUtil.getURI(EcorePackage.Literals.ESTRING));
    nameAttribute.setEType(singleRefType);
    assertTrue(multiRefType.eIsProxy());
    assertTrue(multiRefType2.eIsProxy());
    assertTrue(lazyURIEncoder.isCrossLinkFragment(testResource, EcoreUtil.getURI(multiRefType2).fragment()));
    assertTrue(singleRefType.eIsProxy());
    IResourceDescription resourceDescription = createResourceDescription(testResource);
    Iterable<IReferenceDescription> referenceDescriptions = resourceDescription.getReferenceDescriptions();
    assertEquals("Unexpected additional resources were loaded", 1, resourceSet.getResources().size());
    assertEquals("Unexpected reference was exported", 3, Iterables.size(referenceDescriptions));
    IReferenceDescription referenceDescription = Iterables.get(referenceDescriptions, 0);
    assertEquals(0, referenceDescription.getIndexInList());
    assertEquals(EcoreUtil.getURI(eClass), referenceDescription.getSourceEObjectUri());
    assertEquals(EcorePackage.Literals.ECLASS__ESUPER_TYPES, referenceDescription.getEReference());
    assertEquals(EcoreUtil.getURI(EcorePackage.Literals.EPACKAGE), referenceDescription.getTargetEObjectUri());
    referenceDescription = Iterables.get(referenceDescriptions, 1);
    assertEquals(-1, referenceDescription.getIndexInList());
    assertEquals(EcoreUtil.getURI(nameAttribute.getEGenericType()), referenceDescription.getSourceEObjectUri());
    assertEquals(EcorePackage.Literals.EGENERIC_TYPE__ECLASSIFIER, referenceDescription.getEReference());
    assertEquals(EcoreUtil.getURI(EcorePackage.Literals.ESTRING), referenceDescription.getTargetEObjectUri());
    referenceDescription = Iterables.get(referenceDescriptions, 2);
    assertEquals(-1, referenceDescription.getIndexInList());
    assertEquals(EcoreUtil.getURI(eClass.getEGenericSuperTypes().get(0)), referenceDescription.getSourceEObjectUri());
    assertEquals(EcorePackage.Literals.EGENERIC_TYPE__ECLASSIFIER, referenceDescription.getEReference());
    assertEquals(EcoreUtil.getURI(EcorePackage.Literals.EPACKAGE), referenceDescription.getTargetEObjectUri());
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) EDataType(org.eclipse.emf.ecore.EDataType) LazyURIEncoder(org.eclipse.xtext.linking.lazy.LazyURIEncoder) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) URI(org.eclipse.emf.common.util.URI) EPackage(org.eclipse.emf.ecore.EPackage) EClass(org.eclipse.emf.ecore.EClass) EAttribute(org.eclipse.emf.ecore.EAttribute) InternalEObject(org.eclipse.emf.ecore.InternalEObject) IReferenceDescription(org.eclipse.xtext.resource.IReferenceDescription) Test(org.junit.Test)

Example 100 with ResourceSet

use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-core by eclipse.

the class DefaultReferenceDescriptionTest method testCrossResourceContainment.

@Test
public void testCrossResourceContainment() {
    EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
    ePackage.setName("test");
    ePackage.setNsPrefix("test");
    ePackage.setNsURI("test");
    EClass eClass = EcoreFactory.eINSTANCE.createEClass();
    eClass.setName("Test");
    ePackage.getEClassifiers().add(eClass);
    EAttribute nameAttribute = EcoreFactory.eINSTANCE.createEAttribute();
    nameAttribute.setName("name");
    nameAttribute.setID(true);
    nameAttribute.setEType(EcorePackage.Literals.ESTRING);
    eClass.getEStructuralFeatures().add(nameAttribute);
    EReference containmentRef = EcoreFactory.eINSTANCE.createEReference();
    containmentRef.setContainment(true);
    containmentRef.setName("crossResourceContainment");
    containmentRef.setEType(eClass);
    containmentRef.setResolveProxies(true);
    eClass.getEStructuralFeatures().add(containmentRef);
    EReference containerRef = EcoreFactory.eINSTANCE.createEReference();
    containerRef.setName("containerRef");
    containerRef.setEType(eClass);
    containerRef.setResolveProxies(true);
    containerRef.setEOpposite(containmentRef);
    containmentRef.setEOpposite(containerRef);
    eClass.getEStructuralFeatures().add(containerRef);
    EObject container = ePackage.getEFactoryInstance().create(eClass);
    EObject child = ePackage.getEFactoryInstance().create(eClass);
    Resource containerResource = new XMIResourceImpl(URI.createPlatformResourceURI("container.ecore", true));
    Resource childResource = new XMIResourceImpl(URI.createPlatformResourceURI("child.ecore", true));
    ResourceSet resourceSet = new ResourceSetImpl();
    resourceSet.getResources().add(containerResource);
    resourceSet.getResources().add(childResource);
    containerResource.getContents().add(container);
    childResource.getContents().add(child);
    container.eSet(containmentRef, child);
    assertTrue(container.eResource() != child.eResource());
    {
        IResourceDescription containerDescription = createResourceDescription(containerResource);
        IReferenceDescription onlyContainerElement = Iterables.getOnlyElement(containerDescription.getReferenceDescriptions());
        assertEquals(-1, onlyContainerElement.getIndexInList());
        assertEquals(EcoreUtil.getURI(container), onlyContainerElement.getSourceEObjectUri());
        assertEquals(containmentRef, onlyContainerElement.getEReference());
        assertEquals(EcoreUtil.getURI(child), onlyContainerElement.getTargetEObjectUri());
    }
    {
        IResourceDescription childDescription = createResourceDescription(childResource);
        IReferenceDescription onlyChildElement = Iterables.getOnlyElement(childDescription.getReferenceDescriptions());
        assertEquals(-1, onlyChildElement.getIndexInList());
        assertEquals(EcoreUtil.getURI(child), onlyChildElement.getSourceEObjectUri());
        assertEquals(containerRef, onlyChildElement.getEReference());
        assertEquals(EcoreUtil.getURI(container), onlyChildElement.getTargetEObjectUri());
    }
}
Also used : EClass(org.eclipse.emf.ecore.EClass) EAttribute(org.eclipse.emf.ecore.EAttribute) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) EReference(org.eclipse.emf.ecore.EReference) XMIResourceImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl) EPackage(org.eclipse.emf.ecore.EPackage) IReferenceDescription(org.eclipse.xtext.resource.IReferenceDescription) Test(org.junit.Test)

Aggregations

ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)123 Resource (org.eclipse.emf.ecore.resource.Resource)71 Test (org.junit.Test)51 EObject (org.eclipse.emf.ecore.EObject)34 URI (org.eclipse.emf.common.util.URI)32 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)32 IChangeSerializer (org.eclipse.xtext.ide.serializer.IChangeSerializer)21 InMemoryURIHandler (org.eclipse.xtext.testing.util.InMemoryURIHandler)21 IEmfResourceChange (org.eclipse.xtext.ide.serializer.IEmfResourceChange)20 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)17 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)17 XtextResource (org.eclipse.xtext.resource.XtextResource)16 EPackage (org.eclipse.emf.ecore.EPackage)12 IFile (org.eclipse.core.resources.IFile)10 Node (org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Node)10 ArrayList (java.util.ArrayList)9 EClass (org.eclipse.emf.ecore.EClass)9 ChangeSerializer (org.eclipse.xtext.ide.serializer.impl.ChangeSerializer)9 IOException (java.io.IOException)8 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)8