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; }