Marking call() method of generated closures with @Generated?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Marking call() method of generated closures with @Generated?

Damir Murat
As far as I understand, closures generated by the Groovy compiler contain 
both doCall() and call() methods, where call() always delegate to doCall().

Typically, users will use a short form of closure invocation, which Groovy 
translates to direct call of doCall(). This means that in a typical scenario
 the generated call() method will never get invoked.

When using JaCoCo for code coverage, it will report call() method as unused. 
For these reasons, it looks sensible to me to annotate call() with @Generated. 
That way call() method will not be in the coverage report, while the doCall(), 
which contains the implementation of a closure body, will be reported as covered.

Tnx
Reply | Threaded
Open this post in threaded view
|

Re: Marking call() method of generated closures with @Generated?

Damir Murat
Any thought on this?

I can see that many false negatives from my code could disappear from a code coverage report. But I might be missing something.

Tnx
MG
Reply | Threaded
Open this post in threaded view
|

Re: Marking call() method of generated closures with @Generated?

MG
Hi Damir,

the question you posed might have been asked before on
[hidden email], not entirely sure, in any case it seems more
suited for the developer ML, so you might check the archives or try
reposting it there.

Cheers,
mg

On 12/12/2020 17:53, Damir Murat wrote:
> Any thought on this?
>
> I can see that many false negatives from my code could disappear from
> a code coverage report. But I might be missing something.
>
> Tnx

Reply | Threaded
Open this post in threaded view
|

Re: Marking call() method of generated closures with @Generated?

paulk_asert
Administrator
Seems like a good idea to me. Want to create an issue? PR?

Cheers, Paul.

On Sun, Dec 13, 2020 at 6:11 AM MG <[hidden email]> wrote:
Hi Damir,

the question you posed might have been asked before on
[hidden email], not entirely sure, in any case it seems more
suited for the developer ML, so you might check the archives or try
reposting it there.

Cheers,
mg

On 12/12/2020 17:53, Damir Murat wrote:
> Any thought on this?
>
> I can see that many false negatives from my code could disappear from
> a code coverage report. But I might be missing something.
>
> Tnx

Reply | Threaded
Open this post in threaded view
|

Re: Marking call() method of generated closures with @Generated?

Damir Murat
In reply to this post by Damir Murat
Here is an issue: https://issues.apache.org/jira/browse/GROOVY-9858

I can try to do something about PR, but will need some starting pointers if possible :-)

Tnx.
Reply | Threaded
Open this post in threaded view
|

Re: Marking call() method of generated closures with @Generated?

Damir Murat
In reply to this post by Damir Murat
It looks like I managed to create a working solution, but I also have several questions :-)

Regarding the solution, it was not too complicated. I modified ClosureWriter and StaticTypesClosureWriter 
to annotate generated call methods with @Generated.

Regarding questions. Modification started to work on an external project only after I locally installed a 
non-snapshot version of Groovy. I didn't manage to make it work with the snapshot version. It can be related 
to Gradle scripts that the external project uses, but I wonder if it has something with Groovy itself or its 
install/release process?

As another puzzle, I noticed that some generated closure classes already have "doCall" method annotated 
with @Generated. I wasn't able to find who is creating that method. Although it doesn't conflict with 
modifications in any way, I will like to know who created it?

Tnx