Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [code-gen] How to make EMF to add extra comments to the generated code
[code-gen] How to make EMF to add extra comments to the generated code [message #1392746] Wed, 02 July 2014 19:55 Go to next message
Silvestre Martins is currently offline Silvestre MartinsFriend
Messages: 84
Registered: July 2009
Member
I would like to make the generated code in EMF, to have extra comments, in specific, by surrounding a method with a special tag in form of a comment, such as BEGIN-GENERATED and END-GENERATED.

The reason: I want to exclude these blocks in Sonar.

An example could be:

    // BEGIN-GENERATED
    /**
     * @Generated
     */ 
    public get getName() {
        return name;
    } 
    // END-GENERATED


It would also be useful if I could also apply the same technique to fields, but having these for methods at least would already be sufficient.

Note 1: I cannot exclude the entire class/file because we have, in our legacy model, a lot of non-generated code mixed in the same class.

Note 2: I know there is a request (here) for Sonar to support the @Generated annotation, but this is still not implemented, and I'm afraid it won't get any priority since Sonar has already several options to exclude blocks using start/end tags and regular expressions.

Is there any way to extend the generator without need to rewrite the JET templates by my own?

[Updated on: Wed, 02 July 2014 21:19]

Report message to a moderator

Re: [code-gen] How to make EMF to add extra comments to the generated code [message #1392963 is a reply to message #1392746] Thu, 03 July 2014 03:39 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30353
Registered: July 2009
Senior Member
Silvestre,

Comments below.

On 02/07/2014 9:55 PM, Silvestre Martins wrote:
>
> I would like to make the generated code in EMF, to have extra
> comments, in specific, by surrounding a method with a special tag in
> form of a comment, such as BEGIN-GENERATED and END-GENERATED.
>
> The reason: I want to exclude these blocks in Sonar.
>
> An example could be:
>
> // BEGIN-GENERATED
> /**
> * @Generated
> */ public get getName() {
> return name;
> } // END-GENERATED
>
> It would also be useful if I could also apply the same technique to
> fields, but having these for methods at least would already be
> sufficient.
You could only do this by modifying the templates, and even then, it's
pretty much impossible to get these to merge properly.
>
> Note 1: I cannot exclude the entire class/file because we have, in our
> legacy model, a lot of non-generated code mixed in the same class.
Can you take an inverse approach of putting // BEGIN_GENERATED at the
start of the class and mark your modified methods with // END-GENERATED
- // BEGIN_GENERATED pairs?
>
> Note 2: I know there is a request for Sonar to support the @Generated
> annotation, but this is still not implemented, and I'm afraid it won't
> get any priority since Sonar has already several options to exclude
> blocks using start/end tags and regular expressions.
>
> Is there any way to extend the generator without need to rewrite the
> JET templates by my own?
No, and as I mentioned such free floating tags won't play nicely with
merging in general.
>
>
Re: [code-gen] How to make EMF to add extra comments to the generated code [message #1393093 is a reply to message #1392963] Thu, 03 July 2014 08:23 Go to previous messageGo to next message
Silvestre Martins is currently offline Silvestre MartinsFriend
Messages: 84
Registered: July 2009
Member
Ed Merks wrote on Wed, 02 July 2014 23:39

...
You could only do this by modifying the templates, and even then, it's
pretty much impossible to get these to merge properly.
...


What you mean by "merging". Do you mean when re-generating the code? I was expecting that the generator was agnostic to the content, and it would be just some extra lines of code.

[Updated on: Thu, 03 July 2014 08:26]

Report message to a moderator

Re: [code-gen] How to make EMF to add extra comments to the generated code [message #1393153 is a reply to message #1393093] Thu, 03 July 2014 10:18 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 30353
Registered: July 2009
Senior Member
Silvestre,

If methods/fields must be deleted because they've been removed from the
model, such tags will remain; maybe that's okay. It's also not clear
what will happen if new methods/fields must be generated that it will
insert that correctly in the "comment white space cloud"; probably that
will work.

On 03/07/2014 10:23 AM, Silvestre Martins wrote:
> What you mean by "merging". Do you mean when re-generating the code? I
> was expecting that the generator was agnostic to the content, and it
> would be just some extra lines of code.
Previous Topic:Generating code for packages that only contain other packages
Next Topic:XMI id attributes not being exported
Goto Forum:
  


Current Time: Tue Aug 20 18:12:38 GMT 2019

Powered by FUDForum. Page generated in 0.01968 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top