Search in sources :

Example 1 with EcoreFactory

use of org.eclipse.emf.ecore.EcoreFactory 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 2 with EcoreFactory

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

the class EClassInfoTest method testChangeable.

public void testChangeable() {
    EcorePackage pack = EcorePackage.eINSTANCE;
    EClass eClass = pack.getEClass();
    EClassInfo objectUnderTest = new EClassifierInfo.EClassInfo(eClass, false, Collections.<String>emptySet(), null);
    EcoreFactory fac = EcoreFactory.eINSTANCE;
    EReference reference = fac.createEReference();
    reference.setName("newReference");
    reference.setEType(eClass);
    reference.setChangeable(true);
    reference.setContainment(true);
    eClass.getEStructuralFeatures().add(reference);
    assertEquals(true, objectUnderTest.containsCompatibleFeature("newReference", false, true, eClass, new StringBuilder()));
    reference.setChangeable(false);
    assertEquals(false, objectUnderTest.containsCompatibleFeature("newReference", false, true, eClass, new StringBuilder()));
}
Also used : EClass(org.eclipse.emf.ecore.EClass) EClassInfo(org.eclipse.xtext.xtext.ecoreInference.EClassifierInfo.EClassInfo) EcoreFactory(org.eclipse.emf.ecore.EcoreFactory) EcorePackage(org.eclipse.emf.ecore.EcorePackage) EReference(org.eclipse.emf.ecore.EReference)

Example 3 with EcoreFactory

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

the class ResourceSetReferencingResourceSetTest method getResource.

private Resource getResource(String resourceURI, String references) {
    XMIResourceImpl res = new XMIResourceImpl();
    res.setURI(URI.createURI(resourceURI));
    EcoreFactory f = EcoreFactory.eINSTANCE;
    EClass class1 = f.createEClass();
    res.getContents().add(class1);
    class1.setName("mytype");
    if (references != null) {
        EClass referencedProxy = f.createEClass();
        String fragment = res.getURIFragment(class1);
        ((InternalEObject) referencedProxy).eSetProxyURI(URI.createURI(references).appendFragment(fragment));
        class1.getESuperTypes().add(referencedProxy);
    }
    return res;
}
Also used : EClass(org.eclipse.emf.ecore.EClass) EcoreFactory(org.eclipse.emf.ecore.EcoreFactory) XMIResourceImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl) InternalEObject(org.eclipse.emf.ecore.InternalEObject)

Example 4 with EcoreFactory

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

the class DefaultResourceDescriptionTest method setUp.

@Before
public void setUp() throws Exception {
    resource = new XMLResourceImpl();
    resource.setURI(URI.createURI("foo:/test"));
    nameProvider = new IQualifiedNameProvider.AbstractImpl() {

        @Override
        public QualifiedName getFullyQualifiedName(EObject obj) {
            if (obj instanceof ENamedElement)
                return QualifiedName.create(((ENamedElement) obj).getName());
            return null;
        }
    };
    strategy = new DefaultResourceDescriptionStrategy();
    strategy.setQualifiedNameProvider(nameProvider);
    description = new DefaultResourceDescription(resource, strategy);
    EcoreFactory f = EcoreFactory.eINSTANCE;
    pack = f.createEPackage();
    pack.setName("MyPackage");
    eClass = f.createEClass();
    eClass.setName("MyEClass");
    dtype = f.createEDataType();
    dtype.setName("MyDatatype");
    pack.getEClassifiers().add(eClass);
    pack.getEClassifiers().add(dtype);
    resource.getContents().add(pack);
}
Also used : XMLResourceImpl(org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl) IQualifiedNameProvider(org.eclipse.xtext.naming.IQualifiedNameProvider) EObject(org.eclipse.emf.ecore.EObject) QualifiedName(org.eclipse.xtext.naming.QualifiedName) ENamedElement(org.eclipse.emf.ecore.ENamedElement) EcoreFactory(org.eclipse.emf.ecore.EcoreFactory) Before(org.junit.Before)

Aggregations

EcoreFactory (org.eclipse.emf.ecore.EcoreFactory)4 EClass (org.eclipse.emf.ecore.EClass)3 EAttribute (org.eclipse.emf.ecore.EAttribute)1 ENamedElement (org.eclipse.emf.ecore.ENamedElement)1 EObject (org.eclipse.emf.ecore.EObject)1 EReference (org.eclipse.emf.ecore.EReference)1 EcorePackage (org.eclipse.emf.ecore.EcorePackage)1 InternalEObject (org.eclipse.emf.ecore.InternalEObject)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 ResourceImpl (org.eclipse.emf.ecore.resource.impl.ResourceImpl)1 XMIResourceImpl (org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl)1 XMLResourceImpl (org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl)1 IQualifiedNameProvider (org.eclipse.xtext.naming.IQualifiedNameProvider)1 QualifiedName (org.eclipse.xtext.naming.QualifiedName)1 CacheAdapter (org.eclipse.xtext.util.OnChangeEvictingCache.CacheAdapter)1 EClassInfo (org.eclipse.xtext.xtext.ecoreInference.EClassifierInfo.EClassInfo)1 Before (org.junit.Before)1 Test (org.junit.Test)1