[ pmd-Feature Requests-2871343 ] configuration for OnlyOneReturn

View: New views
1 Messages — Rating Filter:   Alert me  

[ pmd-Feature Requests-2871343 ] configuration for OnlyOneReturn

by SourceForge.net :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Feature Requests item #2871343, was opened at 2009-10-01 16:53
Message generated for change (Comment added) made by ndox
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=479924&aid=2871343&group_id=56262

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: rules
Group: PMD-0.4
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Nicolas  Dordet (ndox)
Assigned to: Nobody/Anonymous (nobody)
Summary: configuration for OnlyOneReturn

Initial Comment:
Hi all,


I assume this rule is here to make code more readable, but in some case it's not usefull.
For exemple, for auto-generated equals and hashCode methods within eclipse, you break 5 times the rule OnlyOneReturn (i.e example)
but you are not going to read them !

So, may the OnlyOneReturn rule be configurable?
I was thinking of let user give a list of method not to check.
What do you think about it?

example generated by Eclipse :
public class TestEq
{
    String str = "test";

    @Override
    public int hashCode()
    {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((str == null) ? 0 : str.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj)
    {
        if (this == obj)
        {
            return true;
        }
        if (obj == null)
        {
            return false;
        }
        if (getClass() != obj.getClass())
        {
            return false;
        }
        TestEq other = (TestEq) obj;
        if (str == null)
        {
            if (other.str != null)
            {
                return false;
            }
        }
        else if (!str.equals(other.str))
        {
            return false;
        }
        return true;
    }
}


----------------------------------------------------------------------

>Comment By: Nicolas  Dordet (ndox)
Date: 2009-10-01 17:49

Message:
Note that you can by pass this problem by creating a new template in
eclipse :  

 public boolean equals(Object obj)
    {
        boolean result;
        if (this == obj)
        {
            result = true;
         }
        else if (!(obj instanceof ${enclosing_type}))
        {
            result = false;
         }
        else
        {
        ${enclosing_type} other = (${enclosing_type}) obj;
        // TODO complete by adding other call to append
        result =
        new EqualsBuilder()
        .append(${getter:field}, other.${getter:field})
        ${cursor}
        .isEquals();
        }
        return result;
       }
       
       
   public int hashCode()
    {
        // TODO complete by adding other call to append  
        return new HashCodeBuilder()
        .append(${getter:field})
        ${cursor}
        .toHashCode();
    }

----------------------------------------------------------------------

You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=479924&aid=2871343&group_id=56262

------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Pmd-devel mailing list
Pmd-devel@...
https://lists.sourceforge.net/lists/listinfo/pmd-devel