Why do Clover for IntelliJ IDEA class metrics include filtered methods.

My project contains a class with a private constructor, five getter methods, and an override of toString(). I have configured a Method filter to exclude toString methods. In Metrics in the Cloverage tool window, the value of the Methods metric is 7. In the editor window, the toString method is shown in a grey colour.

Why isn't the value of this metric 6?

Another thing I've noticed is that, after I run all the unit tests in the module that contains my class using a JUnit run configuration, the value of the Methods metric changes to 6. If I then click on the Refresh Coverage button in the Cloverage tool window, the value changes to 7.

Environment: Windows 7 Professional SP1, IntelliJ IDEA 2016.2, Clover plugin version: idea-4.1.1.v20151207000000

2 answers

1 accepted

0 vote

Thank you very much for providing code sample. I reproduced the problem. After configuring the method context filter in IDEA, I can see that toString method is excluded in the source view, but not excluded in metrics. It also does not use method filters when exporting it to HTML report. I reported an issue here:

https://jira.atlassian.com/browse/CLOV-1964

0 vote
  1. Which IDEA version and Clover version do you have?
  2. Class metrics should omit methods which are filtered-out. Can you confirm that configured an exclusion filter based on the method signature and not the statement? In other words that you do exclude the entire method and not just its body?
  3. Class metrics take into account also methods declared inside other methods (for instance a method may returns an anonymous inline class containing other methods - they are counted too). Can you confirm that your getters have no anonymous inline classes and no lambda functions?

 

  1. I've added environment information to my original topic. 
  2. In Clover (project settings) > Contexts > Custom Contexts, I've added a custom context called "toString" of type "Method" and regexp "(.* )?public String toString\(\).*" In the class editor, the whole toString method is highlighted in grey.
  3. I can confirm that the getters have no anonymous inline classes and no lambda functions.

The project is a Maven project and we also use the Maven Clover plugin to check test coverage and generate a test coverage report. In the Maven report, the value of the Methods metric is 6 and not 7, which is why I started looking into this.

The class is ...

 

public enum EditedOperandEnum implements ValuedEnum<String>
{
// Elements
  LT( "LT", "<" ),
LE( "LE", "<=" ),
EQ( "EQ", "=" ),
GE( "GE", ">=" ),
GT( "GT", ">" );

/** Default Valued Enumeration */
  private static final EditedOperandEnum mDefault = GE;

/** Valued Enumeration Value */
  private final String mValue;

/** Valued Enumeration Label */
  private final String mLabel;

private EditedOperandEnum( final String value, final String label )
{
mValue = value;
mLabel = label;
}

public String getLabel()
{
return mLabel;
}

public String getName()
{
return name();
}

public int getOrdinal()
{
return ordinal();
}

public String getValue()
{
return mValue;
}

public boolean isDefault()
{
return equals(mDefault);
}

public String toString()
{
return ValuedEnumUtil.toString(this);
}
}

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published 7 hours ago in Hipchat

Moving from Hipchat to Stride? Here’s what you’ll love

Heya, Hipchat friends! We’re so happy you’re checking out   Stride. Whether you know it or not, you have been instrumental in making Stride come to life. Every feature, design, and functionality...

30 views 0 3
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you