This is the documentation for Clover 3.3. View this page for the

Unknown macro: {spacejump}

of Clover, or visit the latest Clover documentation.

<methodContext>

Specifies a method Context definition. See Using Coverage Contexts for more information.

Parameters

Attribute

Description

Required

name

The name for this context. Must be unique, and not be one of the reserved context names (see Using Coverage Contexts).

Yes.

regexp

A Perl 5 Regexp that defines the context. This regexp should match the method signatures of methods you wish to include in this context. Note that when method signatures are tested against this regexp, whitespace is normalised and comments are ignored.

Yes.

maxComplexityMatch a method to this pattern if its cyclomatic complexity is not greater than maxComplexity. In other words - all methods with complexity <= maxComplexity will be filtered out.No.
maxStatementsMatch a method to this pattern if its number of statements is not greater than maxStatements. In other words - all methods with statements <= maxStaments will be filtered out.No.
maxAggregatedComplexitySince 3.1.10. Match a method to this pattern if its aggregated cyclomatic complexity is not greater than maxAggregatedComplexity. In other words - all methods with aggregated complexity <= maxAggregatedComplexity will be filtered out. Aggregated complexity metric is a sum of the method complexity and complexity of all anonymous inline classes declared in the method.No.
maxAggregatedStatementsSince 3.1.10. Match a method to this pattern if its number of aggregated statements is not greater than maxAggregatedStatements. In other words - all methods with aggregated statements <= maxAggregatedStaments will be filtered out. Aggregated statements metric is a sum of the method statements and statements of all anonymous inline classes declared in the method.No.

 

What is the difference between maxComplexity and maxAggregatedComplexity or maxStatements and maxAggregatedStatements?

Aggregated metrics calculate method statements/complexity including the code of all anonymous inline classes declared inside the method. Thanks to this, it is possible to distinguish between a trivial single-statement method like:

int getNumber() {
   return number;
}

and a single-statement method which actually returns more complex data, like:

ActionListener getListener() {
   return new ActionListener() {
       public void actionPerformed(ActionEvent e) {
           System.out.println("statement #1");
           System.out.println("statement #2");
           System.out.println("statement #3");
       }
   };
}

 

If you would use a method context filter with maxStatements attribute, like the following:

<methodContext name="trivial" regexp=".*" maxStatements="1">

then both getNumber() and getListener() methods would be filtered-out, because each of them contains only one statement: "return <xxx>".

 

If you would use new maxAggregatedStatements, for instance:

<methodContext name="trivial" regexp=".*" maxAggregatedStatements="1">

then the getNumber() would be filtered-out and the getListener() method would not be filtered out (because it contains 4 statements in total - 1 "return" statement from the method itself and 3 "System.out.println()" statements from anonymous class).

 

Regular expression tip:

(lightbulb) If you would like to filter-out all methods, except those having a specific name, you could write a negative-look-ahead regular expression. For example:

<methodContext name="trivial" regexp="^(?!.*(getRunnable|getListener)).*$" maxStatements="1"/>

will filter-out all methods having not more than one statement, except those which are named getRunnable or getListener.

 

  • No labels