Customizing Editor Code Generation for Connected Metamodel Editors #86
Unanswered
NeumannDirk
asked this question in
Q&A
Replies: 1 comment
-
|
Now I'm digging up old blogs: https://ed-merks.blogspot.com/2008/01/creating-children-you-didnt-know.html No, you don't want to set anything in an object upon creation. Trust me, you don't want that. New objects are created when you deserialize and when you copy. They should be bare objects. UML2 has some template customization: https://github.com/eclipse-uml2/uml2/tree/master/plugins/org.eclipse.uml2 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
TL;DR: Cannot create instances of a referenced metamodel(-editor); Cannot override JET templates to modify code generation.
Hello,
I am not completely new to EMF, but recently I encountered multiple problems for which I hope I can find some answers here. I plan to split them into multiple parts, each addressing a specific issue. They will share the same topic of reusing metamodels in other metamodels, and I also created an example project, which can be found here. I will keep it there and add possible answers to it in case somebody will have similar issues.
This is the second part, addressing issues with the custom generation of editor code. You can find the first one here.
I have a metamodel libraryWithBooksAsLoadedResource.ecore which references the class from another metamodel book.ecore. Now I want to create instances for it using the eclipse editor that I can generate with a genmodel. Now, I have a book.genmodel and a libraryWithBooksAsLoadedResource.genmodel, where the latter reuses the first.
1. Reuse across Multiple Editors
Can I set up the libraryWithBooksAsLoadedResource.genmodel such that its generated editor-code uses the editor-code of the book.genmodel? This already works for the "normal" generated model code. But concerning generated editor code, for example, I can create a new library and set its values but I cannot create a
Bookas a new child element. Is there a way to do this without putting everything into one metamodel as I currently do in a workaround?2. Modifying the Code Generation
I want to default-set an ID attribute to a new ID with
EcoreUtil.generateUUID()upon creation. Also, I want to modify the toString-methods or label-methods for better readability in the editor (similar to this). I do not want to modify generated code (as I will do this repeatedly for multiple different metamodels) but modify the code generation itself. I read that I can override the templates by setting the right options in the genmodel like this:dynamicTemplates="true" + templateDirectory="..."and putting a modified copy of the .javajet-template in a directory structure equal to the structure from my eclipses "org.eclipse.emf.codegen.ecore_.jar". I did this in myx-custom-templatesdirectory for the FactoryClass.javajet with some dummy Hello-World-code. It seems that this template is ignored. What do I have to change? (I also had the issue that the Header.javajetinc-file which is normally imported in this template causes some errors, which is why I simply copy-pasted its content over there.)I hope I explained the issue clearly. Thanks a lot for any help!
If these features do not exist yet, I’d also be happy to help with implementing them with some guidance. Also, I have not found any tutorial on how to modify the code generation templates. Maybe this is something to showcase somewhere in more detail (and I am happy to help with that as well).
Best Regards
Dirk
Beta Was this translation helpful? Give feedback.
All reactions