Using Source Directives

Clover supports a number of inline source directives that you can use in your source to control instrumentation. Directives can be on a line by themselves or part of any valid single or multi-line Java comment.

Clover source directives currently do not support Groovy.

Switching Clover on and off

// CLOVER:ON
// CLOVER:OFF

This directive will switch Clover instrumentation on/off. This might be useful if you don't want Clover to instrument a section of code for some reason. For example, some bytecode-manipulating frameworks require certain sections to be excluded (JMockit for instance). Note that the scope of this directive is the current file only.

Force Clover to flush

// CLOVER:FLUSH

Clover will insert code to flush coverage data to disk. The flush code will be inserted as soon as possible after the directive. See Using a Flush Policy.

Mark lambda expression returning void (since Clover 4.0.5)

// CLOVER:VOID
/* CLOVER:VOID */

This directive will mark lambda expression as returning void. Clover applies heuristic for some of lambda expressions and rewrites them to lambda blocks. In case of unexpected return value compilation errors, it may be necessary to mark some lambda expressions as void to let Clover know it shouldn't instrument it with the return keyword. 

 

For example, the following code:

mapClass.map(internalMap -> internalMap.put("some", "some"));

may fail to compile if put() method returns void with the following error:

src/LambdaAndStreams.java:75: error: incompatible types: bad return type in lambda expression
 mapClass.map(internalMap -> {
			__CLR4_0_500ibutb8q0.R.inc(50);
			return internalMap.put("some", "some");});           
                                                  ^                                                     				
    unexpected return value
1 error

It may be required to mark such lambda expression as void with CLOVER:VOID directive

mapClass.map(internalMap -> /* CLOVER:VOID */ internalMap.put("some", "some"));

 

More information about this compilation error may be found in one of the Clover KB articles

 

The CLOVER:VOID directive outside lambda context does not have any effect.

Last modified on Jul 20, 2015

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.