Java Code Examples for org.eclipse.emf.ecore.EReference#setContainment()
The following examples show how to use
org.eclipse.emf.ecore.EReference#setContainment() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EClassifierInfo.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
private EStructuralFeature createFeatureWith(String featureName, EClassifier featureClassifier, boolean isMultivalue, boolean isContainment) { EStructuralFeature newFeature; if (featureClassifier instanceof EClass) { EReference reference = EcoreFactory.eINSTANCE.createEReference(); reference.setContainment(isContainment); newFeature = reference; } else { newFeature = EcoreFactory.eINSTANCE.createEAttribute(); } newFeature.setName(featureName); newFeature.setEType(featureClassifier); newFeature.setLowerBound(0); newFeature.setUpperBound(isMultivalue ? -1 : 1); newFeature.setUnique(!isMultivalue || (isContainment && featureClassifier instanceof EClass)); if (newFeature.getEType() instanceof EEnum) { newFeature.setDefaultValue(null); } return newFeature; }
Example 2
Source File: TypeHierarchyHelperTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Test public void testConfigurationOfLiftedReference() throws Exception { EClassInfo a = addClass("a"); EClassInfo b = addClass("b"); EClassInfo c = addClass("c"); b.addSupertype(a); c.addSupertype(a); EReference refB = addReference(b, a, "ref"); refB.setContainment(true); EReference refC = addReference(c, a, "ref"); refC.setContainment(true); assertEquals(0, a.getEClass().getEStructuralFeatures().size()); assertEquals(1, b.getEClass().getEStructuralFeatures().size()); assertEquals(1, c.getEClass().getEStructuralFeatures().size()); liftUpFeatures(); assertEquals(1, a.getEClass().getEStructuralFeatures().size()); assertEquals(0, b.getEClass().getEStructuralFeatures().size()); assertEquals(0, c.getEClass().getEStructuralFeatures().size()); EReference refA = (EReference) a.getEClass().getEStructuralFeatures().get(0); assertTrue(refA.isContainment()); }
Example 3
Source File: SerializationUtilTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
private EReference addEReference(EClass from, EClass to, String name, boolean isTransient) { EReference ref = EcoreFactory.eINSTANCE.createEReference(); ref.setName("ref2"); ref.setEType(to); ref.setContainment(true); if (isTransient) { ref.setTransient(true); ref.setDerived(true); } ref.setChangeable(true); from.getEStructuralFeatures().add(ref); return ref; }
Example 4
Source File: EClassInfoTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
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())); }
Example 5
Source File: DefaultReferenceDescriptionTest.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
@Test public void testSpecialReferences() { EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage(); ePackage.setName("test"); ePackage.setNsPrefix("test"); ePackage.setNsURI("test"); EClass eClass = EcoreFactory.eINSTANCE.createEClass(); eClass.setName("Test"); eClass.getESuperTypes().add(EcorePackage.Literals.EPACKAGE); ePackage.getEClassifiers().add(eClass); EReference eReference1 = EcoreFactory.eINSTANCE.createEReference(); eReference1.setContainment(false); eReference1.setName("onlyExportedRef"); eReference1.setEType(EcorePackage.Literals.EPACKAGE); eClass.getEStructuralFeatures().add(eReference1); EReference eReference2 = EcoreFactory.eINSTANCE.createEReference(); eReference2.setContainment(true); eReference2.setName("containmentRef"); eReference2.setEType(EcorePackage.Literals.EPACKAGE); eClass.getEStructuralFeatures().add(eReference2); EReference eReference3 = EcoreFactory.eINSTANCE.createEReference(); eReference3.setContainment(false); eReference3.setTransient(true); eReference3.setName("transientRef"); eReference3.setEType(EcorePackage.Literals.EPACKAGE); eClass.getEStructuralFeatures().add(eReference3); EReference eReference4 = EcoreFactory.eINSTANCE.createEReference(); eReference4.setContainment(false); eReference4.setVolatile(true); eReference4.setName("volatileRef"); eReference4.setEType(EcorePackage.Literals.EPACKAGE); eClass.getEStructuralFeatures().add(eReference4); EReference eReference5 = EcoreFactory.eINSTANCE.createEReference(); eReference5.setContainment(false); eReference5.setDerived(true); eReference5.setName("derivedRef"); eReference5.setEType(EcorePackage.Literals.EPACKAGE); eClass.getEStructuralFeatures().add(eReference5); EObject object = ePackage.getEFactoryInstance().create(eClass); object.eSet(EcorePackage.Literals.ENAMED_ELEMENT__NAME, "testname"); object.eSet(eReference1, EcorePackage.eINSTANCE); object.eSet(eReference2, ePackage.getEFactoryInstance().create(eClass)); object.eSet(eReference3, EcorePackage.eINSTANCE); object.eSet(eReference4, EcorePackage.eINSTANCE); object.eSet(eReference5, EcorePackage.eINSTANCE); Resource testResource = new XMIResourceImpl(URI.createPlatformResourceURI("test.ecore", true)); testResource.getContents().add(object); IResourceDescription resourceDescription = createResourceDescription(testResource); assertEquals("Only one external reference expected", 1, size(resourceDescription.getReferenceDescriptions())); IReferenceDescription referenceDescription = resourceDescription.getReferenceDescriptions().iterator().next(); assertEquals(-1, referenceDescription.getIndexInList()); assertEquals(EcoreUtil.getURI(object), referenceDescription.getSourceEObjectUri()); assertEquals(eReference1, referenceDescription.getEReference()); assertEquals(EcoreUtil.getURI(EcorePackage.eINSTANCE), referenceDescription.getTargetEObjectUri()); assertEquals(EcoreUtil.getURI(object), referenceDescription.getContainerEObjectURI()); }
Example 6
Source File: DefaultReferenceDescriptionTest.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
@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()); } }