Java Code Examples for org.eclipse.emf.ecore.EReference#setTransient()

The following examples show how to use org.eclipse.emf.ecore.EReference#setTransient() . 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: SerializationUtilTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
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 2
Source File: DefaultReferenceDescriptionTest.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@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());
}