Search in sources :

Example 6 with ResourceImpl

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

the class OnChangeEvictingCacheAdapterTest method testCacheSurvivesChangeToDiagnostics.

@Test
public void testCacheSurvivesChangeToDiagnostics() 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<Diagnostic> errors = resource.getErrors();
    assertIsSet(ca);
    errors.clear();
    assertIsSet(ca);
}
Also used : EClass(org.eclipse.emf.ecore.EClass) ResourceImpl(org.eclipse.emf.ecore.resource.impl.ResourceImpl) EcoreFactory(org.eclipse.emf.ecore.EcoreFactory) Resource(org.eclipse.emf.ecore.resource.Resource) CacheAdapter(org.eclipse.xtext.util.OnChangeEvictingCache.CacheAdapter) Diagnostic(org.eclipse.emf.ecore.resource.Resource.Diagnostic) Test(org.junit.Test)

Example 7 with ResourceImpl

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

the class OnChangeEvictingCacheAdapterTest method testAdapterIsCleared.

@Test
public void testAdapterIsCleared() 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);
    EAttribute attribute = factory.createEAttribute();
    assertIsSet(ca);
    eClass.getEStructuralFeatures().add(attribute);
    assertIsNull(ca);
    setValue(ca);
    attribute.setName("Foo");
    assertIsNull(ca);
    setValue(ca);
}
Also used : EClass(org.eclipse.emf.ecore.EClass) EAttribute(org.eclipse.emf.ecore.EAttribute) ResourceImpl(org.eclipse.emf.ecore.resource.impl.ResourceImpl) EcoreFactory(org.eclipse.emf.ecore.EcoreFactory) Resource(org.eclipse.emf.ecore.resource.Resource) CacheAdapter(org.eclipse.xtext.util.OnChangeEvictingCache.CacheAdapter) Test(org.junit.Test)

Example 8 with ResourceImpl

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

the class EcoreUtil2Test method testPathFragment.

@Test
public void testPathFragment() {
    EClass foo = EcoreFactory.eINSTANCE.createEClass();
    foo.setName("foo");
    EClass bar = EcoreFactory.eINSTANCE.createEClass();
    foo.setName("bar");
    EPackage p = EcoreFactory.eINSTANCE.createEPackage();
    bar.setName("p");
    p.getEClassifiers().add(foo);
    p.getEClassifiers().add(bar);
    assertEquals("/-1", EcoreUtil2.getFragmentPath(foo));
    assertEquals("/-1", EcoreUtil2.getFragmentPath(bar));
    assertEquals("/-1", EcoreUtil2.getFragmentPath(p));
    Resource resource = new ResourceImpl(URI.createURI("platform:/resource/res"));
    resource.getContents().add(p);
    assertEquals(URI.createURI("platform:/resource/res#//@eClassifiers.0"), EcoreUtil2.getFragmentPathURI(foo));
    assertEquals(URI.createURI("platform:/resource/res#//@eClassifiers.1"), EcoreUtil2.getFragmentPathURI(bar));
    assertEquals(URI.createURI("platform:/resource/res#/"), EcoreUtil2.getFragmentPathURI(p));
    assertEquals(resource.getEObject("//@eClassifiers.0"), foo);
    assertEquals(resource.getEObject("//@eClassifiers.1"), bar);
    assertEquals(resource.getEObject("/"), p);
}
Also used : EClass(org.eclipse.emf.ecore.EClass) ResourceImpl(org.eclipse.emf.ecore.resource.impl.ResourceImpl) DerivedStateAwareResource(org.eclipse.xtext.resource.DerivedStateAwareResource) Resource(org.eclipse.emf.ecore.resource.Resource) EPackage(org.eclipse.emf.ecore.EPackage) Test(org.junit.Test)

Example 9 with ResourceImpl

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

the class DefaultResourceDescriptionManagerTest method setUp.

@Before
public void setUp() throws Exception {
    EObject copy = EcoreUtil.copy(EcorePackage.eINSTANCE);
    resource = new ResourceImpl();
    resource.getContents().add(copy);
    IQualifiedNameProvider nameProvider = new IQualifiedNameProvider.AbstractImpl() {

        @Override
        public QualifiedName getFullyQualifiedName(EObject obj) {
            if (obj instanceof ENamedElement)
                return QualifiedName.create(((ENamedElement) obj).getName());
            return null;
        }
    };
    DefaultResourceDescriptionStrategy descriptionStrategy = new DefaultResourceDescriptionStrategy();
    descriptionStrategy.setQualifiedNameProvider(nameProvider);
    resourceDescription = new DefaultResourceDescription(resource, descriptionStrategy) {

        @Override
        public Iterable<QualifiedName> getImportedNames() {
            return importedNames;
        }
    };
    manager = new DefaultResourceDescriptionManager();
    importedNames = Collections.emptySet();
}
Also used : ResourceImpl(org.eclipse.emf.ecore.resource.impl.ResourceImpl) IQualifiedNameProvider(org.eclipse.xtext.naming.IQualifiedNameProvider) DefaultResourceDescription(org.eclipse.xtext.resource.impl.DefaultResourceDescription) EObject(org.eclipse.emf.ecore.EObject) ENamedElement(org.eclipse.emf.ecore.ENamedElement) DefaultResourceDescriptionManager(org.eclipse.xtext.resource.impl.DefaultResourceDescriptionManager) DefaultResourceDescriptionStrategy(org.eclipse.xtext.resource.impl.DefaultResourceDescriptionStrategy) Before(org.junit.Before)

Example 10 with ResourceImpl

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

the class AbstractScopeTest method setUp.

@Before
public void setUp() throws Exception {
    resource = new ResourceImpl(URI.createURI("uri"));
    annotationA = EcoreFactory.eINSTANCE.createEAnnotation();
    annotationB = EcoreFactory.eINSTANCE.createEAnnotation();
    resource.getContents().add(annotationA);
    resource.getContents().add(annotationB);
    descriptionA = EObjectDescription.create("a", annotationA);
    descriptionA_aliased = EObjectDescription.create("aliasedA", annotationA);
    descriptionB = EObjectDescription.create("b", annotationB);
    descriptionB_as_A = EObjectDescription.create("a", annotationB);
}
Also used : ResourceImpl(org.eclipse.emf.ecore.resource.impl.ResourceImpl) Before(org.junit.Before)

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