Can I exclude specific methods from Cyclomatic Complexity?

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

Can I exclude specific methods from Cyclomatic Complexity?

Richard Brewster
I have Java Bean classes with equals and hashCode code-generated by my IDE.  When there is a large number of fields to compare, the complexity number for these methods goes through the roof and this class is flagged as a problem, when it really isn't.  Is there a way to exclude these methods from the complexity analysis?

Related:  Is there a way to correlate high cyclomatic complexity with low branch coverage?  I want to see this combination as a potential problem, not just complexity.  A high complexity method with full branch coverage may not be a problem.  The inverse is also true.  If I have a bunch of getter and setter methods that don't have code coverage, I'm not worried about it because the complexity of those methods is zero.
Reply | Threaded
Open this post in threaded view
|

RE: Can I exclude specific methods from Cyclomatic Complexity?

Holmes, Daniel
For your correlation problem, I think you might be interested in a
calculation like a crap4j score. (http://www.crap4j.org/)

Daniel

-----Original Message-----
From: Richard Brewster [mailto:[hidden email]]
Sent: Friday, May 21, 2010 1:58 PM
To: [hidden email]
Subject: [sonar-user] Can I exclude specific methods from Cyclomatic
Complexity?


I have Java Bean classes with equals and hashCode code-generated by my
IDE.
When there is a large number of fields to compare, the complexity number
for
these methods goes through the roof and this class is flagged as a
problem,
when it really isn't.  Is there a way to exclude these methods from the
complexity analysis?

Related:  Is there a way to correlate high cyclomatic complexity with
low
branch coverage?  I want to see this combination as a potential problem,
not
just complexity.  A high complexity method with full branch coverage may
not
be a problem.  The inverse is also true.  If I have a bunch of getter
and
setter methods that don't have code coverage, I'm not worried about it
because the complexity of those methods is zero.
--
View this message in context:
http://old.nabble.com/Can-I-exclude-specific-methods-from-Cyclomatic-Com
plexity--tp28637152p28637152.html
Sent from the Sonar user mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Can I exclude specific methods from Cyclomatic Complexity?

Freddy Mallet SonarSource
In reply to this post by Richard Brewster
Hi Richard,

In fact what you're talking about is the possibility to flag "generated" code. A @generated annotation has been added to java 6 and Julien Henry has created a JIRA ticket SONAR-1042 [1] so that Sonar supports this annotation. Feel free to vote for this ticket which is not so difficult to fix. 

Concerning your second question, the Clouds -> Top Risk feature is certainly what you're looking for :


I agree with Daniel Holmes that the best available tool/technique to identify such crappiest methods (high complexity and low branch coverage) is currently Crap4j. 

regards,
Freddy



----------------------------------------
Freddy Mallet
www.SonarSource.org
www.SonarSource.com
http://twitter.com/FreddyMallet
----------------------------------------


On Fri, May 21, 2010 at 7:58 PM, Richard Brewster <[hidden email]> wrote:

I have Java Bean classes with equals and hashCode code-generated by my IDE.
When there is a large number of fields to compare, the complexity number for
these methods goes through the roof and this class is flagged as a problem,
when it really isn't.  Is there a way to exclude these methods from the
complexity analysis?

Related:  Is there a way to correlate high cyclomatic complexity with low
branch coverage?  I want to see this combination as a potential problem, not
just complexity.  A high complexity method with full branch coverage may not
be a problem.  The inverse is also true.  If I have a bunch of getter and
setter methods that don't have code coverage, I'm not worried about it
because the complexity of those methods is zero.
--
View this message in context: http://old.nabble.com/Can-I-exclude-specific-methods-from-Cyclomatic-Complexity--tp28637152p28637152.html
Sent from the Sonar user mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: Can I exclude specific methods from Cyclomatic Complexity?

Richard Brewster

Freddy Mallet-3 wrote
I agree with Daniel Holmes that the best available tool/technique to
identify such crappiest methods (high complexity and low branch coverage) is
currently Crap4j.
Thanks for reminding me about crap4j.  How can it be integrated with Sonar?
Reply | Threaded
Open this post in threaded view
|

Re: Can I exclude specific methods from Cyclomatic Complexity?

Olivier Gaudin-2
Hi Richard,

It can probably be integrated with a plugin. You might want to switch to development mailing to discuss this.

Olivier


On Mon, May 24, 2010 at 3:04 PM, Richard Brewster <[hidden email]> wrote:



Freddy Mallet-3 wrote:
>
> I agree with Daniel Holmes that the best available tool/technique to
> identify such crappiest methods (high complexity and low branch coverage)
> is
> currently Crap4j.
>

Thanks for reminding me about crap4j.  How can it be integrated with Sonar?

--
View this message in context: http://old.nabble.com/Can-I-exclude-specific-methods-from-Cyclomatic-Complexity--tp28637152p28656721.html
Sent from the Sonar user mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: Can I exclude specific methods from Cyclomatic Complexity?

Ashley Lewis
This post has NOT been accepted by the mailing list yet.
How would you do this with C#?

Crap4C?