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; }
@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; }
@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)); } }
public void resolve( String identifier, org.emftext.language.petrinets.Setting container, org.eclipse.emf.ecore.EReference reference, int position, boolean resolveFuzzy, final org.emftext.language.petrinets.resource.petrinets.IPetrinetsReferenceResolveResult< org.eclipse.emf.ecore.EStructuralFeature> result) { EClassifier type; if (container.eContainer() instanceof ProducingArc) { ProducingArc arc = (ProducingArc) container.eContainer(); type = FunctionCallAnalysisHelper.getInstance().getType(arc.getOutput()); } else { ConstructorCall cc = (ConstructorCall) container.eContainer(); type = cc.getType(); } List<EStructuralFeature> candidates = new ArrayList<EStructuralFeature>(); if (type != null && type instanceof EClass) { EClass c = (EClass) type; candidates.addAll(c.getEAllStructuralFeatures()); } else if (type instanceof EDataType) { EAttribute dummy = EcoreFactory.eINSTANCE.createEAttribute(); dummy.setName(type.getName()); dummy.setEType(type); dummy.setUpperBound(1); dummy.setLowerBound(1); candidates.add(dummy); } for (EStructuralFeature eStructuralFeature : candidates) { if (resolveFuzzy) { result.addMapping(eStructuralFeature.getName(), eStructuralFeature); } else if (identifier.equals(eStructuralFeature.getName())) { result.addMapping(eStructuralFeature.getName(), eStructuralFeature); } } }
private static EPackage getEmployeePackage() { EcoreFactory ecoreFactory = EcoreFactory.eINSTANCE; EcorePackage ecorePackage = EcorePackage.eINSTANCE; EPackage employeePackage = ecoreFactory.createEPackage(); employeePackage.setName("emp"); employeePackage.setNsPrefix("emp"); employeePackage.setNsURI("http://www.example.com/Emp"); employeeClass = ecoreFactory.createEClass(); employeePackage.getEClassifiers().add(employeeClass); employeeClass.setName("Employee"); EClass poClass = ecoreFactory.createEClass(); employeePackage.getEClassifiers().add(poClass); poClass.setName("PurchaseOrder"); nameAttr = ecoreFactory.createEAttribute(); employeeClass.getEStructuralFeatures().add(nameAttr); nameAttr.setName("name"); nameAttr.setEType(ecorePackage.getEString()); // to test multiplicity-many attributes. ratingsAttr = ecoreFactory.createEAttribute(); employeeClass.getEStructuralFeatures().add(ratingsAttr); ratingsAttr.setName("phoneNumbers"); ratingsAttr.setUpperBound(ETypedElement.UNBOUNDED_MULTIPLICITY); ratingsAttr.setEType(ecorePackage.getEIntegerObject()); // create a one-way reference to an Employee, employeesRef. // This is used to test cases described in cases.gif. employeesRef = ecoreFactory.createEReference(); employeeClass.getEStructuralFeatures().add(employeesRef); employeesRef.setName("employees"); employeesRef.setUpperBound(ETypedElement.UNBOUNDED_MULTIPLICITY); employeesRef.setEType(employeeClass); // to test FeatureMaps with EAttributes Entries ordersAttr = ecoreFactory.createEAttribute(); employeeClass.getEStructuralFeatures().add(ordersAttr); ordersAttr.setName("orders"); ordersAttr.setUpperBound(ETypedElement.UNBOUNDED_MULTIPLICITY); ordersAttr.setEType(ecorePackage.getEFeatureMapEntry()); ExtendedMetaData.INSTANCE.setFeatureKind(ordersAttr, ExtendedMetaData.GROUP_FEATURE); preferredAttr = ecoreFactory.createEAttribute(); employeeClass.getEStructuralFeatures().add(preferredAttr); preferredAttr.setName("preferredOrders"); preferredAttr.setUpperBound(ETypedElement.UNBOUNDED_MULTIPLICITY); preferredAttr.setEType(ecorePackage.getEString()); preferredAttr.setVolatile(true); preferredAttr.setTransient(true); preferredAttr.setDerived(true); ExtendedMetaData.INSTANCE.setGroup(preferredAttr, ordersAttr); standardAttr = ecoreFactory.createEAttribute(); employeeClass.getEStructuralFeatures().add(standardAttr); standardAttr.setName("standardOrders"); standardAttr.setUpperBound(ETypedElement.UNBOUNDED_MULTIPLICITY); standardAttr.setEType(ecorePackage.getEString()); standardAttr.setVolatile(true); standardAttr.setTransient(true); standardAttr.setDerived(true); ExtendedMetaData.INSTANCE.setGroup(standardAttr, ordersAttr); return employeePackage; }
private void addTokensAttribute(EClass eClass) { EAttribute nameAttribute = EcoreFactory.eINSTANCE.createEAttribute(); nameAttribute.setName(INITIAL_TOKENS); nameAttribute.setEType(EcorePackage.eINSTANCE.getEInt()); eClass.getEStructuralFeatures().add(nameAttribute); }
private void addNameAttribute(EClass eClass) { EAttribute nameAttribute = EcoreFactory.eINSTANCE.createEAttribute(); nameAttribute.setName(NAME); nameAttribute.setEType(EcorePackage.eINSTANCE.getEString()); eClass.getEStructuralFeatures().add(nameAttribute); }