<?xml version="1.0"?>
<!-- 
/*
 * Copyright 2001-2004 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 -->


<ruleset name="Controversial Rules">
  <description>
The Controversial Ruleset contains rules that, for whatever reason, are considered controversial.  They
are separated out here to allow people to include as they see fit via custom rulesets.  This ruleset was
initially created in response to discussions over UnnecessaryConstructorRule which Tom likes but
most people really dislike :-)
  </description>

    <rule name="UnnecessaryConstructorRule"
          message="Avoid unnecessary constructors - the compiler will generate these for you"
          class="net.sourceforge.pmd.rules.XPathRule">
      <description>
  Unnecessary constructor detects when a constructor is not necessary; i.e., when there's only one constructor,
  it's public, has an empty body, and takes no arguments.
      </description>
        <properties>
            <property name="xpath">
                <value>
                    <![CDATA[
    //ConstructorDeclaration[1][position() = last()][@Public='true'][not(FormalParameters/*)][not(BlockStatement)]
                    ]]>
                </value>
            </property>
        </properties>
        <priority>3</priority>
      <example>
  <![CDATA[
  public class Foo {
   public Foo() {}
  }
  ]]>
      </example>
    </rule>



    <rule name="NullAssignment"
          message="Assigning an Object to null is a code smell.  Consider refactoring."
          class="net.sourceforge.pmd.rules.design.NullAssignmentRule">
      <description>
 Assigning a "null" to a variable (outside of its declaration) is usually in
 bad form.  Some times, the assignment is an indication that the programmer doesn't
 completely understand what is going on in the code.  NOTE: This sort of assignment
 may in rare cases be useful to encourage garbage collection.  If that's what you're using
 it for, by all means, disregard this rule :-)
      </description>
        <priority>3</priority>
      <example>
 <![CDATA[
 public class Foo {
   public void bar() {
     Object x = null; // This is OK.
     x = new Object();
     // Big, complex piece of code here.
     x = null; // This is BAD.
     // Big, complex piece of code here.
   }
 }

 ]]>
      </example>

    </rule>
    <rule name="OnlyOneReturn"
         message="A method should have only one exit point, and that should be the last statement in the method"
         class="net.sourceforge.pmd.rules.design.OnlyOneReturnRule">
     <description>
     A method should have only one exit point, and that should be the last statement in the method.
     </description>
        <priority>3</priority>

     <example>
 <![CDATA[
 public class OneReturnOnly1 {
  public void foo(int x) {
   if (x > 0) {
    return "hey";   // oops, multiple exit points!
   }
   return "hi";
  }
 }
 ]]>
     </example>
     </rule>

    <rule name="UnusedModifier"
         message="Unused modifiers are, well, unused"
         class="net.sourceforge.pmd.rules.XPathRule">
     <description>
     Unused modifiers are, well, unused.
     </description>
        <properties>
            <property name="xpath">
                <value>
                    <![CDATA[
    //InterfaceDeclaration//MethodDeclaration[@Public='true' or @Abstract = 'true']
                    ]]>
                </value>
            </property>
        </properties>
        <priority>3</priority>
     <example>
 <![CDATA[
    public interface Foo {
     public abstract void bar(); // both abstract and public are ignored by the compiler
    }
 ]]>
     </example>
     </rule>

    <rule name="AssignmentInOperandRule"
      message="Avoid assigments in operands"
      class="net.sourceforge.pmd.rules.XPathRule">
  <description>
  Avoid assigments in operands; this can make code more complicated and harder to read.
  </description>
        <properties>
            <property name="xpath">
                <value>
                    <![CDATA[
    //*[name()='WhileStatement' or name()='IfStatement'][Expression//AssignmentOperator]
                    ]]>
                </value>
            </property>
         </properties>
    <priority>3</priority>
  <example>
  <![CDATA[
  public class Foo {
   public void bar() {
int x = 2;
if ((x = getX()) == 3) {
 System.out.println("3!");
}
   }
   private int getX() {
return 3;
   }
  }

  ]]>
  </example>
</rule>

    <rule name="AtLeastOneConstructor"
      message="Each class should declare at least one constructor"
      class="net.sourceforge.pmd.rules.AtLeastOneConstructorRule">
  <description>
  Each class should declare at least one constructor.  Note that this rule is the
      opposite of UnnecessaryConstructorRule, so running them at the same time will
      result on a rule violation on every class.
  </description>
    <priority>3</priority>

  <example>
  <![CDATA[
  public class Foo {
   // no constructor!  not good!
  }
  ]]>
  </example>
</rule>

</ruleset>



