Search in sources :

Example 16 with ResourceImpl

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

the class OnChangeEvictingCacheAdapterTest method testCacheSurvivesChangesToAdapters.

@Test
public void testCacheSurvivesChangesToAdapters() throws Exception {
    EcoreFactory factory = EcoreFactory.eINSTANCE;
    EClass eClass = factory.createEClass();
    Resource resource = new ResourceImpl();
    resource.getContents().add(eClass);
    CacheAdapter ca = new OnChangeEvictingCache().getOrCreate(resource);
    setValue(ca);
    List<Adapter> adapters = resource.eAdapters();
    assertIsSet(ca);
    AdapterImpl adapter = new AdapterImpl();
    adapters.add(adapter);
    assertIsSet(ca);
    adapters.remove(adapter);
    assertIsSet(ca);
}
Also used : EClass(org.eclipse.emf.ecore.EClass) ResourceImpl(org.eclipse.emf.ecore.resource.impl.ResourceImpl) AdapterImpl(org.eclipse.emf.common.notify.impl.AdapterImpl) EcoreFactory(org.eclipse.emf.ecore.EcoreFactory) Resource(org.eclipse.emf.ecore.resource.Resource) CacheAdapter(org.eclipse.xtext.util.OnChangeEvictingCache.CacheAdapter) CacheAdapter(org.eclipse.xtext.util.OnChangeEvictingCache.CacheAdapter) Adapter(org.eclipse.emf.common.notify.Adapter) Test(org.junit.Test)

Example 17 with ResourceImpl

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

the class LazyLinkerTest method testManyValuedResolveProxiesReference.

@Test
public void testManyValuedResolveProxiesReference() throws Exception {
    final EObject foo = newEObject("Foo");
    final List<EObject> bars = Lists.newArrayList(newEObject("Bar"), newEObject("Bar"));
    final Iterator<EObject> barsIterator = bars.iterator();
    final Resource resource = new ResourceImpl(URI.createURI("http://foo/bar.ecore")) {

        @Override
        public EObject getEObject(String uriFragment) {
            return barsIterator.next();
        }
    };
    resourceSet.getResources().add(resource);
    resource.getContents().add(foo);
    final EReference eReference = (EReference) foo.eClass().getEStructuralFeature("many");
    assertFalse(eReference.isResolveProxies());
    final INode leafNode = newCrossReferenceAssignmentNode(eReference.getName());
    final INode leafNode2 = newCrossReferenceAssignmentNode(eReference.getName());
    final ICompositeNode adapter = newSimpleNodeAdapter(leafNode, leafNode2);
    foo.eAdapters().add((Adapter) adapter);
    linker.linkModel(foo, new ListBasedDiagnosticConsumer());
    assertEquals(bars, foo.eGet(eReference, false));
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) ResourceImpl(org.eclipse.emf.ecore.resource.impl.ResourceImpl) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) ListBasedDiagnosticConsumer(org.eclipse.xtext.resource.impl.ListBasedDiagnosticConsumer) EReference(org.eclipse.emf.ecore.EReference) Test(org.junit.Test)

Example 18 with ResourceImpl

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

the class LazyLinkerTest method testSingleValuedResolveProxiesReference.

@Test
public void testSingleValuedResolveProxiesReference() throws Exception {
    final EObject foo = newEObject("Foo");
    final EObject bar = newEObject("Bar");
    final Resource resource = new ResourceImpl(URI.createURI("http://foo/bar.ecore")) {

        @Override
        public EObject getEObject(String uriFragment) {
            return bar;
        }
    };
    resourceSet.getResources().add(resource);
    resource.getContents().add(foo);
    final EReference eReference = (EReference) foo.eClass().getEStructuralFeature("single");
    assertFalse(eReference.isResolveProxies());
    final INode leafNode = newCrossReferenceAssignmentNode(eReference.getName());
    final ICompositeNode adapter = newSimpleNodeAdapter(leafNode);
    foo.eAdapters().add((Adapter) adapter);
    linker.linkModel(foo, new ListBasedDiagnosticConsumer());
    assertEquals(bar, foo.eGet(eReference, false));
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) ResourceImpl(org.eclipse.emf.ecore.resource.impl.ResourceImpl) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) ListBasedDiagnosticConsumer(org.eclipse.xtext.resource.impl.ListBasedDiagnosticConsumer) EReference(org.eclipse.emf.ecore.EReference) Test(org.junit.Test)

Aggregations

ResourceImpl (org.eclipse.emf.ecore.resource.impl.ResourceImpl)18 Resource (org.eclipse.emf.ecore.resource.Resource)12 Test (org.junit.Test)11 EObject (org.eclipse.emf.ecore.EObject)9 EClass (org.eclipse.emf.ecore.EClass)5 BasicDiagnostic (org.eclipse.emf.common.util.BasicDiagnostic)3 EcoreFactory (org.eclipse.emf.ecore.EcoreFactory)3 CacheAdapter (org.eclipse.xtext.util.OnChangeEvictingCache.CacheAdapter)3 Before (org.junit.Before)3 BugTest (com.avaloq.tools.ddk.test.core.BugTest)2 AbstractTest (com.avaloq.tools.ddk.xtext.test.AbstractTest)2 Map (java.util.Map)2 EReference (org.eclipse.emf.ecore.EReference)2 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)2 IQualifiedNameProvider (org.eclipse.xtext.naming.IQualifiedNameProvider)2 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)2 INode (org.eclipse.xtext.nodemodel.INode)2 DefaultResourceDescription (org.eclipse.xtext.resource.impl.DefaultResourceDescription)2 DefaultResourceDescriptionManager (org.eclipse.xtext.resource.impl.DefaultResourceDescriptionManager)2 DefaultResourceDescriptionStrategy (org.eclipse.xtext.resource.impl.DefaultResourceDescriptionStrategy)2