Specifies a method Context definition. See Using Coverage Contexts for more information.
The name for this context. Must be unique, and not be one of the reserved context names (see Using Coverage Contexts).
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 normalized and comments are ignored.
|maxComplexity||Match 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.|
|maxStatements||Match 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.|
|maxAggregatedComplexity||Since 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.|
|maxAggregatedStatements||Since 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:
and a single-statement method which actually returns more complex data, like:
If you would use a method context filter with maxStatements attribute, like the following:
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:
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:
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:
will filter-out all methods having not more than one statement, except those which are named getRunnable or getListener.