[code-gen] How to make EMF to add extra comments to the generated code [message #1392746] |
Wed, 02 July 2014 19:55 |
Silvestre Martins 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 |
Ed Merks Messages: 33142 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.
>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
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 |
Ed Merks Messages: 33142 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.
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.02905 seconds