New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generate Static Metamodel Code with eGenericSuperTypes #44
Comments
@CrazyAutomotiveHacker Sorry about the late answer. The issue you have here comes from the implementation of the Ecore metamodel which misses some parts which I will add for the next release. To be able to open it and generates code for it, with the current PyEcore version, you need to patch it by hand. The code would be this (for the patching + the code generation) from pyecore.resources import ResourceSet
from pyecore.ecore import EClass, EGenericType, ETypeParameter, EReference, \
EClassifier, ETypeParameter
import pyecore.ecore as Ecore
from pyecoregen.ecore import EcoreGenerator
# Ecore metamodel patch (will be added in PyEcore for the next release)
eGenericSuperTypes = EReference('eGenericSuperTypes', EGenericType,
containment=True, upper=-1)
EClass.eClass.eStructuralFeatures.append(eGenericSuperTypes)
EClass.eGenericSuperTypes = eGenericSuperTypes
eClassifier = EReference('eClassifier', EClassifier)
EGenericType.eClass.eStructuralFeatures.append(eClassifier)
EGenericType.eClassifier = eClassifier
eTypeArguments = EReference('eTypeArguments', EGenericType, containment=True,
upper=-1)
EGenericType.eClass.eStructuralFeatures.append(eTypeArguments)
EGenericType.eTypeArguments = eTypeArguments
eTypeParameter = EReference('eTypeParameter', ETypeParameter,
eOpposite=ETypeParameter.eGenericType)
EGenericType.eClass.eStructuralFeatures.append(eTypeParameter)
EGenericType.eTypeParameter = eTypeParameter
# We open the metamodel
rset = ResourceSet()
mm_root = rset.get_resource('testecore.ecore').contents[0]
# We generate the code using the EcoreGenerator
EcoreGenerator().generate(mm_root, outfolder='.') However, please note that # ... generated code here
from pyecore.ecore import EObject
Building.test.eType = EObject
Test.hallo.eType = EObject
# ... generated code here I will try to find a way of dealing with |
Hello, thanks a lot for the quick response! But now I have the following problem with the example: I created the following 3 classes: If I try to instantiate these classes and set the parameter test (either as String or as BigInteger) in the following way:
I get the error:
Do you maybe have an idea for an workaround to handle these kind of problems, especially for larger models? |
Unfortunately, I think there is no easy solution for you issue (beside modifying the metamodel). The use of Currently, for the case of # before
class Container(EObject, metaclass=MetaEClass):
test = EReference(unique=True, derived=False, ordered=True, containment=True, upper=-1)
# after
class Container(EObject, metaclass=MetaEClass):
test = EAttribute(eType=Ecore.ENativeType, unique=True, derived=False,
ordered=True, upper=-1) This should work, but I'm aware that it is not exactly what you expressed in your metamodel... I'm really sorry for the inconvenience... |
Hello, thank you very much for the support. The workaround works for now. |
I will definitely work on it, I really want to be able to express the same kind of semantic in Python. Actually, I have a genral idea, but I still don't exactly know how I can implement it in a proper/clean way (that will perhaps uses annotations for the generated code, but I will try to avoid if I can). I really need also to check the original EMF Java implementation so PyEcore will have the same behavior. In the Regarding a roadmap, perhaps 1 or 2 months, I'm really under the water at work and this is really a not easy task unless I get the magical idea :) . I'm really sorry about the delay... I would really love to work full time on PyEcore ;) |
Exactly the Feature i am currently missing. I am working in the automotive domain and trying to read, create and update Amalthea files with python/ pyecore. See https://Eclipse.org/app4mc |
@tobias-huermann @CrazyAutomotiveHacker I will try to work on it during christmas holidays! I'm so sorry about the delay. The struggle here is clearly time (and a little bit of manpower), I have some solutions, but they are for the static part only, dynamic part needs more work to ensure that performances are kind of equivalent. |
So, I had time to work a little bit on them, I have a first working version in PyEcore for dynamic metamodels (in the @tobias-huermann I looked to Amalthea ecore metamodel, but I didn't found it. Do you know if there is one somewhere? The only things I found are |
@aranega Sorry i missed to answer. Find the Amalthea ecore attached. I used Eclipse to convert xcore format to ecore. The attached demo_car example model is chipped with APP4MC and covers a lot of the possible entities of Amalthea. The Runnable elements do store for example Weibull Deviation elements which are causing problems when accessing / creating models with PyEcore. We are not able to handle entities/ attributes related to "Deviation" meta-model element. See 3.2.9 Deviation here for Meta-model description. |
@tobias-huermann Thanks a lot for the test case! I will try it asap with the new pyecoregen version I have that partially deals with generics. From what I saw quickly in the |
It looks like pyecoregen doesn't yet support generic types. Can we do anything to help with this? I could work on a PR if I can get some guidance on how to proceed. |
Hi @alessiostalla EDIT> Of course, if you have ideas how to modify/fix/add things in pyecoregen, please feel free to propose PRs with what works with you, I'll review/help with the code and we can try together to reach a fixed point where what's work for you is also tackling most use cases (hopefully all use cases from the first working version!) 🙂 |
Looks cool, I'll try it out asap, probably early next week! |
I want to generate a static metamodel in python from an .ecore file. But when I try to generate the python code with the pyecoregenerator, I get the following error message:
Are there any options to solve this issue? Is it possible to extend / adapt the generator to work with 'eGenericSuperTypes'?
Here is my .ecore file (testecore.ecore):
<?xml version="1.0" encoding="UTF-8"?> <ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="testecore" nsURI="http://www.example.org/testecore" nsPrefix="testecore"> <eClassifiers xsi:type="ecore:EClass" name="Owner"> <eStructuralFeatures xsi:type="ecore:EReference" name="buildings" upperBound="-1" eType="#//Building"/> <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/> </eClassifiers> <eClassifiers xsi:type="ecore:EClass" name="Building" abstract="true"> <eTypeParameters name="T"/> <eStructuralFeatures xsi:type="ecore:EReference" name="test" upperBound="-1" containment="true"> <eGenericType eTypeParameter="#//Building/T"/> </eStructuralFeatures> </eClassifiers> <eClassifiers xsi:type="ecore:EClass" name="House" eSuperTypes="#//Building"> <eStructuralFeatures xsi:type="ecore:EAttribute" name="rooms" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"/> </eClassifiers> <eClassifiers xsi:type="ecore:EClass" name="Test"> <eTypeParameters name="T"/> <eStructuralFeatures xsi:type="ecore:EReference" name="hallo" upperBound="-1" containment="true"> <eGenericType eTypeParameter="#//Test/T"/> </eStructuralFeatures> <eGenericSuperTypes eClassifier="#//Building"> <eTypeArguments eTypeParameter="#//Test/T"/> </eGenericSuperTypes> </eClassifiers> </ecore:EPackage>
testecore.zip
The text was updated successfully, but these errors were encountered: