Java Code Examples for org.eclipse.emf.ecore.EReference#setEOpposite()
The following examples show how to use
org.eclipse.emf.ecore.EReference#setEOpposite() .
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: MetamodelImpl.java From bonita-studio with GNU General Public License v2.0 | 6 votes |
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated NOT */ @Override public void setEOpposite(EReference reference, EReference opposite) { if (reference.getEOpposite() != null) { reference.getEOpposite().setEOpposite(null); } if (opposite != null) { final Model model = getRepository().getModel(); if (model != null) { for (final Instance instance : model.getAllInstances(opposite .getEContainingClass())) { final EList<Instance> inverse = instance.getInverse(reference); if (!inverse.isEmpty()) { final ReferenceSlot referenceSlot = ((InstanceImpl) instance) .getCreateReferenceSlot(opposite); referenceSlot.getValues().clear(); referenceSlot.getValues().addAll(inverse); } } } opposite.setEOpposite(reference); } reference.setEOpposite(opposite); }
Example 2
Source File: Step0029.java From BIMserver with GNU Affero General Public License v3.0 | 5 votes |
@Override public void migrate(Schema schema, DatabaseSession databaseSession) { EClass oAuthAuthorizationCodeClass = schema.getEClass("store", "OAuthAuthorizationCode"); EClass userClass = schema.getEClass("store", "User"); EReference codeToUser = schema.createEReference(oAuthAuthorizationCodeClass, "user", userClass); EReference codes = (EReference) userClass.getEStructuralFeature("oAuthIssuedAuthorizationCodes"); codeToUser.setEOpposite(codes); codes.setEOpposite(codeToUser); }
Example 3
Source File: Express2EMF.java From BIMserver with GNU Affero General Public License v3.0 | 5 votes |
private void addInverseAttribute(Attribute attrib, EClass cls) { InverseAttribute inverseAttribute = (InverseAttribute) attrib; EReference eRef = eFactory.createEReference(); eRef.setUnsettable(true); // Inverses are always optional? eRef.getEAnnotations().add(createInverseAnnotation()); eRef.setName(attrib.getName()); if (inverseAttribute.getMax_cardinality() != null) { IntegerBound max_cardinality = (IntegerBound) inverseAttribute.getMax_cardinality(); if (max_cardinality.getBound_value() == -1) { eRef.setUpperBound(max_cardinality.getBound_value()); } else { eRef.setUpperBound(max_cardinality.getBound_value() + 1); } } String type = (inverseAttribute).getDomain().getName(); EClass classifier = (EClass) schemaPack.getEClassifier(type); eRef.setEType(classifier); String reverseName = inverseAttribute.getInverted_attr().getName(); EReference reference = (EReference) classifier.getEStructuralFeature(reverseName); reference.getEAnnotations().add(createInverseAnnotation()); if (eRef.getEType() == classifier && reference.getEType() == cls) { if (eRef.isMany()) { eRef.setUnique(true); } if (reference.isMany()) { reference.setUnique(true); } reference.setEOpposite(eRef); eRef.setEOpposite(reference); } else { System.out.println("Inverse mismatch"); System.out.println(classifier.getName() + "." + reference.getName() + " => " + cls.getName() + "." + eRef.getName()); } cls.getEStructuralFeatures().add(eRef); }
Example 4
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()); } }
Example 5
Source File: Migration.java From BIMserver with GNU Affero General Public License v3.0 | 4 votes |
protected void link(EReference eReference1, EReference eReference2) { eReference1.setEOpposite(eReference2); eReference2.setEOpposite(eReference1); }