@Before public void before() { ePackage = FACTORY.createEPackage(); ePackage.setName("Package"); eClass0 = FACTORY.createEClass(); eClass0.setName("EClass0"); ePackage.getEClassifiers().add(eClass0); eClass1 = FACTORY.createEClass(); eClass1.setName("EClass1"); ePackage.getEClassifiers().add(eClass1); singleRef = FACTORY.createEReference(); singleRef.setName("singleRef"); singleRef.setUpperBound(1); singleRef.setEType(eClass1); singleRef.setContainment(true); eClass0.getEStructuralFeatures().add(singleRef); multiRef = FACTORY.createEReference(); multiRef.setName("multiRef"); multiRef.setUpperBound(-1); multiRef.setEType(eClass0); multiRef.setContainment(true); eClass1.getEStructuralFeatures().add(multiRef); }
private EPackage createDynamicEPackage() { final EcoreFactory efactory = EcoreFactory.eINSTANCE; final EcorePackage epackage = EcorePackage.eINSTANCE; // Create a new EPackage and add the new EClasses EPackage topPackage = efactory.createEPackage(); topPackage.setName("toppackage"); topPackage.setNsPrefix("toppackage"); topPackage.setNsURI("http:///www.elver.org/toppackage"); EPackage subPackage1 = efactory.createEPackage(); subPackage1.setName("subPackage1"); subPackage1.setNsPrefix("subPackage1"); subPackage1.setNsURI("http:///www.elver.org/subPackage1"); { EClass schoolBookEClass = efactory.createEClass(); schoolBookEClass.setName("class1"); // create a new attribute for this EClass EAttribute level = efactory.createEAttribute(); level.setName("level"); level.setEType(epackage.getEInt()); schoolBookEClass.getEStructuralFeatures().add(level); subPackage1.getEClassifiers().add(schoolBookEClass); } { EEnum schoolBookEClass = efactory.createEEnum(); schoolBookEClass.setName("enum"); subPackage1.getEClassifiers().add(schoolBookEClass); } { EClass schoolBookEClass = efactory.createEClass(); schoolBookEClass.setName("class2"); // create a new attribute for this EClass subPackage1.getEClassifiers().add(schoolBookEClass); } { EClass schoolBookEClass = efactory.createEClass(); schoolBookEClass.setName("class3"); // create a new attribute for this EClass EAttribute level = efactory.createEAttribute(); level.setName("level"); level.setEType(epackage.getEInt()); schoolBookEClass.getEStructuralFeatures().add(level); subPackage1.getEClassifiers().add(schoolBookEClass); } EPackage subPackage2 = efactory.createEPackage(); subPackage2.setName("subPackage2"); subPackage2.setNsPrefix("subPackage2"); subPackage2.setNsURI("http:///www.elver.org/subPackage2"); topPackage.getESubpackages().add(subPackage1); return topPackage; }
/** * Collecting all properties from a EMF object, if contansReferences is TRUE, all features should * be contained, otherwise, only EAttrubutes will be returned. */ public static List<EStructuralFeature> collectProperties( EClass eClass, boolean containsSupers, boolean containsReferences, boolean containsUnsettables) { if (eClass == null) { return Collections.emptyList(); } List<EStructuralFeature> properties = new ArrayList<EStructuralFeature>(); List<EStructuralFeature> features = null; if (containsReferences) { features = eClass.getEStructuralFeatures(); } else { features = new ArrayList<EStructuralFeature>(eClass.getEAttributes()); } for (EStructuralFeature sf : features) { try { if (containsUnsettables || eClass.eIsSet(sf)) { properties.add(sf); } } catch (Exception e) { } } if (containsSupers) { EList<EClass> eSuperTypes = eClass.getESuperTypes(); for (EClass eSuperClass : eSuperTypes) { properties.addAll( collectProperties( eSuperClass, containsSupers, containsReferences, containsUnsettables)); } } return properties; }
/** * Dynamically create an {@link EObject} with a collection called <code>children</code> which * contains the given elements. * * @param collection The initial filling of the collection. * @return An {@link EObject} which just has a containment list (named <code>children</code>) of * type {@link EObject}. */ @SuppressWarnings("unchecked") public static EObject wrapInGenericContainer(Collection<? extends EObject> collection) { // create the wrapper containment reference final EReference children = EcoreFactory.eINSTANCE.createEReference(); children.setName("children"); children.setLowerBound(0); children.setUpperBound(ETypedElement.UNBOUNDED_MULTIPLICITY); children.setContainment(true); children.setEType(EcorePackage.Literals.EOBJECT); // create the wrapper class final EClass containerClass = EcoreFactory.eINSTANCE.createEClass(); containerClass.setName("GenericEContainer"); containerClass.getEStructuralFeatures().add(children); // create a package for our wrapper class final EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage(); ePackage.setName("dynamic"); ePackage.setNsPrefix("dynamic"); ePackage.setNsURI("http://www.example.org/dynamic"); ePackage.getEClassifiers().add(containerClass); // validate what we just created if (Diagnostician.INSTANCE.validate(ePackage).getCode() == Diagnostic.OK) { // instantiate our class, fill the children and return it final EObject container = ePackage.getEFactoryInstance().create(containerClass); ((EList<EObject>) container.eGet(children)).addAll(collection); return container; } else { throw new UnknownError( "Dynamic EMF wrapper model creation failed for whatever reason. Developer, please debug better!"); } }
@Override public EClass eClass() { if (eClass == null) { ePackage = EcoreFactory.eINSTANCE.createEPackage(); eClass = EcoreFactory.eINSTANCE.createEClass(); ePackage.getEClassifiers().add(eClass); eClass.setName("StringWrapper"); // $NON-NLS-1$ eClass.getESuperTypes().add(XMLTypePackage.eINSTANCE.getAnyType()); ExtendedMetaData.INSTANCE.setName(eClass, ""); // $NON-NLS-1$ eClass.setInstanceClass(AnyType.class); EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute(); eAttribute.setName("value"); // $NON-NLS-1$ eAttribute.setChangeable(true); eAttribute.setUnsettable(true); eAttribute.setEType(EcorePackage.eINSTANCE.getEClassifier("EString")); // $NON-NLS-1$ eClass.getEStructuralFeatures().add(eAttribute); // ExtendedMetaData.INSTANCE.setNamespace(eAttribute, ePackage.getNsURI()); ExtendedMetaData.INSTANCE.setFeatureKind(eAttribute, ExtendedMetaData.ATTRIBUTE_FEATURE); ExtendedMetaData.INSTANCE.setName(eAttribute, "value"); // $NON-NLS-1$ } return eClass; }
private void addReference(EClass eClass, String name, EClassifier eType, boolean containment) { EReference placesReference = EcoreFactory.eINSTANCE.createEReference(); placesReference.setName(name); placesReference.setLowerBound(0); placesReference.setUpperBound(-1); placesReference.setEType(eType); placesReference.setContainment(containment); eClass.getEStructuralFeatures().add(placesReference); }
private void addOutgoingReference(EClass eClass) { EReference outgoingReference = EcoreFactory.eINSTANCE.createEReference(); outgoingReference.setName(OUTGOING); outgoingReference.setLowerBound(0); outgoingReference.setUpperBound(-1); outgoingReference.setEType(getPlaceClass()); outgoingReference.setContainment(false); eClass.getEStructuralFeatures().add(outgoingReference); }
protected void handleEClassifier( EClassifier classifier, Set<EPackage> visitedPackages, Set<Object> visited) { if (classifier != null && visited.add(classifier)) { handleEPackage(classifier.getEPackage(), visitedPackages); handleETypeParameters(classifier.getETypeParameters(), visitedPackages, visited); if (classifier instanceof EClass) { EClass eClass = (EClass) classifier; handleEStructuralFeatures(eClass.getEStructuralFeatures(), visitedPackages, visited); handleEOperations(eClass.getEOperations(), visitedPackages, visited); handleEGenericTypes(eClass.getEGenericSuperTypes(), visitedPackages, visited); } } }
public void testErrorMessage_04() { EClass eClass = createEClass(); eClass.setName("EClassName"); EAttribute attribute = EcoreFactory.eINSTANCE.createEAttribute(); attribute.setName("Attribute"); eClass.getEStructuralFeatures().add(attribute); IEObjectDescription description = EObjectDescription.create(QualifiedName.create(attribute.getName()), attribute); String errorMessage = helper.getDuplicateNameErrorMessage( description, EcorePackage.Literals.EATTRIBUTE, EcorePackage.Literals.ENAMED_ELEMENT__NAME); assertEquals("Duplicate EAttribute 'Attribute' in EClass 'EClassName'", errorMessage); }
@Override public Object caseEClass(EClass object) { Type type = getType(object); if (object.isInterface()) { } else { // class Class clazz = (Class) type; clazz.setAbstract(object.isAbstract()); } Set<Type> assocAndGen = new HashSet<>(); Set<Type> dependencies = new HashSet<>(); for (EClass eSuperType : object.getESuperTypes()) { Type superType = getType(eSuperType); assocAndGen.add(superType); if (eSuperType.isInterface()) { type.addInterface((Interface) superType); } else { type.addSuperClass((Class) superType); } } for (EStructuralFeature eFeature : object.getEStructuralFeatures()) { Attribute attr = (Attribute) doSwitch(eFeature); type.addAttribute(attr); assocAndGen.add(attr.type); } for (EOperation eOperation : object.getEOperations()) { Operation op = (Operation) doSwitch(eOperation); type.addOperation(op); dependencies.add(op.type); for (TypedElement fpar : op.formalParameters()) { dependencies.add(fpar.type); } } dependencies.removeAll(assocAndGen); for (Type dep : dependencies) { type.addDependency(dep); } return type; }
@Test public void cast() { final EClassifier[] types = new EClassifier[] { EcorePackage.eINSTANCE.getEInt(), EcorePackage.eINSTANCE.getEFloat(), EcorePackage.eINSTANCE.getEDouble() }; final Object[] values = new Object[] {1, 1F, 1D}; for (int i = 0; i < types.length; i++) { EClassifier classifier = types[i]; EAttribute attribute = FACTORY.createEAttribute(); attribute.setEType(classifier); eClass0.getEStructuralFeatures().add(attribute); assertEquals(values[i], EMFUtils.cast(values[(i + 1) % values.length], attribute)); } }
/** @return an new object which is instance of <code>factoryChildClass</code>. */ public EObject createFactoryChildObject() { String superType = ModelUtil.getSuperType(factoryChildClass); IProject project = (IProject) this.getPage().getEditor().getAdapter(IProject.class); String result = DialogUtil.openClassDialog( getSection().getShell(), project, superType, IJavaElementSearchConstants.CONSIDER_ALL_TYPES); if (result != null) { EObject component = FacesConfigFactory.eINSTANCE.create(factoryChildClass); // set the text content value. EStructuralFeature feature = factoryChildClass.getEStructuralFeatures().get(0); component.eSet(feature, result); return component; } return null; }
public EPackage createPackage() { EcoreFactory theCoreFactory = EcoreFactory.eINSTANCE; EcorePackage theCorePackage = EcorePackage.eINSTANCE; mapContainerEClass = theCoreFactory.createEClass(); mapContainerEClass.setName("MapContainer"); EPackage dynamicMapEPackage = createUniquePackage(); dynamicMapEPackage.getEClassifiers().add(mapContainerEClass); EStructuralFeature name = theCoreFactory.createEAttribute(); name.setName("name"); name.setEType(theCorePackage.getEString()); mapContainerEClass.getEStructuralFeatures().add(name); if (!isConfig(LEGACY)) { CDOUtil.prepareDynamicEPackage(dynamicMapEPackage); } return dynamicMapEPackage; }
public void testGetAllReferencedObjects() { EClass a = createEClass("a"); EClass b = createEClass("b"); EPackage pack = EcoreFactory.eINSTANCE.createEPackage(); pack.setName("empty"); pack.setNsPrefix("empty"); pack.setNsURI("empty"); pack.getEClassifiers().add(a); pack.getEClassifiers().add(b); EReference ref = EcoreFactory.eINSTANCE.createEReference(); a.getEStructuralFeatures().add(ref); ref.setUpperBound(1); ref.setEType(b); EObject objA = pack.getEFactoryInstance().create(a); EObject objB = pack.getEFactoryInstance().create(b); List<EObject> res = EcoreUtil2.getAllReferencedObjects(objA, ref); assertNotNull(res); assertTrue(res.isEmpty()); res = EcoreUtil2.getAllReferencedObjects(objA, ref); assertNotNull(res); objA.eSet(ref, objB); }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ public EAttribute getState_Name() { return (EAttribute) stateEClass.getEStructuralFeatures().get(0); }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ public EReference getDevice_States() { return (EReference) deviceEClass.getEStructuralFeatures().get(1); }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ public EAttribute getDevice_Name() { return (EAttribute) deviceEClass.getEStructuralFeatures().get(0); }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ public EReference getModel_Declarations() { return (EReference) modelEClass.getEStructuralFeatures().get(0); }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ public EAttribute getField_Upper() { return (EAttribute) fieldEClass.getEStructuralFeatures().get(5); }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ public EAttribute getField_UpperUnlimited() { return (EAttribute) fieldEClass.getEStructuralFeatures().get(4); }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ public EAttribute getField_Description() { return (EAttribute) fieldEClass.getEStructuralFeatures().get(2); }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ public EAttribute getRule_Description() { return (EAttribute) ruleEClass.getEStructuralFeatures().get(0); }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ public EAttribute getXFunctionTypeRef_InstanceContext() { return (EAttribute) xFunctionTypeRefEClass.getEStructuralFeatures().get(3); }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ public EReference getRule_ThenPart() { return (EReference) ruleEClass.getEStructuralFeatures().get(2); }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ public EReference getRule_DeviceState() { return (EReference) ruleEClass.getEStructuralFeatures().get(1); }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ public EReference getField_Type() { return (EReference) fieldEClass.getEStructuralFeatures().get(1); }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ public EReference getXFunctionTypeRef_Type() { return (EReference) xFunctionTypeRefEClass.getEStructuralFeatures().get(2); }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ public EReference getEntity_Fields() { return (EReference) entityEClass.getEStructuralFeatures().get(0); }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ public EAttribute getXComputedTypeReference_TypeProvider() { return (EAttribute) xComputedTypeReferenceEClass.getEStructuralFeatures().get(0); }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ public EAttribute getField_Name() { return (EAttribute) fieldEClass.getEStructuralFeatures().get(0); }