|
Re: What is the best practice to keep the generated and handmade code in separate files ? [message #630445 is a reply to message #630440] |
Sat, 02 October 2010 15:53 |
Ed Merks Messages: 33140 Registered: July 2009 |
Senior Member |
|
|
Stanislav,
Comments below.
Stanislav wrote:
> Hi
>
> I have a requirement to keep the generated and handmade code in a
> separate java files (in separate source folders).
Sounds like
http://ed-merks.blogspot.com/2008/10/hand-written-and-genera ted-code-never.html
> What I want to achieve is that it should be possible to delete all
> generated code and regenerate it again from an ecore model while
> keeping all handmade code untouched.
You might look at how the Xtext folks manage this.
> That is, I would like to extend a generated class AGen with a class
> AImpl extends AGen, override some of the methods of the AGen (for
> example all derived features) or provide implementation of new
> methods. Further, I want to use AImpl class in the generated .edit
> and .editor code.
That's not directly supported by EMF's generator.
>
> For that purpose, I annotated my ecore model attaching
> annotation source="mysource"
> key="extendingClass" body="SomeExtendingClassName"
>
> to each EMF class that I want to extend.
>
> Next, I changed the template for the generation of the Factory class
> to create my extending class instead of the class defined in the ecore
> model, for example
>
> AGen createAGen() {
> ..
> AGen aGen = new AImpl();
> return aGen;
> ..
>
> instead of ..
> AGen aGen = new AGen();
> return aGen;
> ..
>
> I use the same approach to separate the generated and the handmade
> code of the ItemProviders in the .edit plugin.
>
> Are there any issues with this approach?
Sounds okay. I've suggested in the past that we could provide a feature
that basically is only the sweep phase of our merging step--- it would
leave behind only the non-generated artifacts---but purists will always
need to be even more pure than that.
> Is there a better way to keep the generated and handmade code
> separately while being able to reuse all the generated code for .edit
> and .editor plugins?
It's fine, but I wonder what are the big advantages of this additional
complexity? Mint already provides filters that let's you view just the
non-generated stuff so the need for actual physical separation seems
marginal.
>
> Regards,
> Stanislav
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
Powered by
FUDForum. Page generated in 0.03627 seconds