<?xml version="1.0"?>

<ruleset name="Design Rules" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="../etc/ruleset_xml_schema.xml">
  <description>
The Design Ruleset contains a collection of rules that find questionable designs.
  </description>

  <rule name="UseSingleton"
        message="All methods are static.  Consider using Singleton instead.  Alternatively, you could add a private constructor or make the class abstract to silence this warning."
        class="net.sourceforge.pmd.rules.design.UseSingleton"
          externalInfoUrl="http://pmd.sourceforge.net/rules/design.html#UseSingleton">
    <description>
If you have a class that has nothing but static methods, consider making it a Singleton.
Note that this doesn't apply to abstract classes, since their subclasses may
well include non-static methods.  Also, if you want this class to be a Singleton,
remember to add a private constructor to prevent instantiation.
    </description>
      <priority>3</priority>
    <example>
<![CDATA[
public class MaybeASingleton {
 public static void foo() {}
 public static void bar() {}
}
]]>
    </example>
  </rule>


  <rule name="SimplifyBooleanReturns"
        message="Avoid unnecessary if..then..else statements when returning a boolean"
        class="net.sourceforge.pmd.rules.SimplifyBooleanReturns"
          externalInfoUrl="http://pmd.sourceforge.net/rules/design.html#SimplifyBooleanReturns">
    <description>
Avoid unnecessary if..then..else statements when returning a boolean
    </description>
      <priority>3</priority>
    <example>
<![CDATA[
public class Foo {
  private int bar =2;
  public boolean isBarEqualsTo(int x) {
    // this bit of code
    if (bar == x) {
     return true;
    } else {
     return false;
    }
    // can be replaced with a simple
    // return bar == x;
  }
}
]]>
    </example>
  </rule>

    <rule name="SimplifyBooleanExpressions"
          message="Avoid unnecessary comparisons in boolean expressions"
          class="net.sourceforge.pmd.rules.XPathRule"
          externalInfoUrl="http://pmd.sourceforge.net/rules/design.html#SimplifyBooleanExpressions">
      <description>
Avoid unnecessary comparisons in boolean expressions - this makes simple code seem complicated.
      </description>
      <properties>
          <property name="xpath">
              <value>
<![CDATA[
//EqualityExpression/PrimaryExpression
 /PrimaryPrefix/Literal/BooleanLiteral
]]>
              </value>
          </property>
      </properties>
        <priority>3</priority>
      <example>
  <![CDATA[
public class Bar {
 // can be simplified to
 // bar = isFoo();
 private boolean bar = (isFoo() == true);

 public isFoo() { return false;}
}
  ]]>
      </example>
    </rule>

  <rule name="SwitchStmtsShouldHaveDefault"
        message="Switch statements should have a default label"
        class="net.sourceforge.pmd.rules.XPathRule"
          externalInfoUrl="http://pmd.sourceforge.net/rules/design.html#SwitchStmtsShouldHaveDefault">
    <description>
Switch statements should have a default label.
    </description>
      <properties>
          <property name="xpath">
              <value>
                  <![CDATA[
//SwitchStatement[not(SwitchLabel[@Default='true'])]
                  ]]>
              </value>
          </property>
      </properties>
      <priority>3</priority>
    <example>
<![CDATA[
public class Foo {
 public void bar() {
  int x = 2;
  switch (x) {
   case 2: int j = 8;
  }
 }
}
]]>
    </example>
    </rule>

  <rule name="AvoidDeeplyNestedIfStmts"
        message="Deeply nested if..then statements are hard to read"
        class="net.sourceforge.pmd.rules.AvoidDeeplyNestedIfStmtsRule"
          externalInfoUrl="http://pmd.sourceforge.net/rules/design.html#AvoidDeeplyNestedIfStmts">
    <description>
Deeply nested if..then statements are hard to read.
    </description>
      <priority>3</priority>
   <properties>
    <property name="problemDepth" description="The if statement depth reporting threshold" value="3"/>
   </properties>
    <example>
<![CDATA[
public class Foo {
 public void bar(int x, int y, int z) {
  if (x>y) {
   if (y>z) {
    if (z==x) {
     // whew, too deep
    }
   }
  }
 }
}
]]>
    </example>
    </rule>


    <rule name="AvoidReassigningParameters"
        message="Avoid reassigning parameters such as ''{0}''"
        class="net.sourceforge.pmd.rules.AvoidReassigningParameters"
          externalInfoUrl="http://pmd.sourceforge.net/rules/design.html#AvoidReassigningParameters">
    <description>
Reassigning values to parameters is a questionable practice.  Use a temporary local variable instead.
    </description>
        <priority>2</priority>
    <example>
<![CDATA[
public class Foo {
 private void foo(String bar) {
  bar = "something else";
 }
}
]]>
    </example>
  </rule>

    <rule name="SwitchDensity"
          message="A high ratio of statements to labels in a switch statement.  Consider refactoring."
          class="net.sourceforge.pmd.rules.design.SwitchDensityRule"
          externalInfoUrl="http://pmd.sourceforge.net/rules/design.html#SwitchDensity">
      <description>
 A high ratio of statements to labels in a switch statement implies that the switch
 statement is doing too much work.  Consider moving the statements either into new
 methods, or creating subclasses based on the switch variable.
      </description>
        <priority>3</priority>
        <properties>
         <property name="minimum" description="The switch statement ratio reporting threshold" value="10"/>
        </properties>
      <example>
 <![CDATA[
public class Foo {
 public void bar(int x) {
   switch (x) {
     case 1: {
       // lots of statements
       break;
     } case 2: {
       // lots of statements
       break;
     }
   }
 }
}
 ]]>
      </example>
    </rule>

    <rule name="ConstructorCallsOverridableMethod"
          message="Overridable {0} called during object construction"
          class="net.sourceforge.pmd.rules.ConstructorCallsOverridableMethod"
          externalInfoUrl="http://pmd.sourceforge.net/rules/design.html#ConstructorCallsOverridableMethod">
      <description>
Calling overridable methods during construction poses a risk of invoking methods on an
incompletely constructed object.  This situation can be difficult to discern.
It may leave the sub-class unable to construct its superclass or forced to
replicate the construction process completely within itself, losing the ability to call
super().  If the default constructor contains a call to an overridable method,
the subclass may be completely uninstantiable.   Note that this includes method calls
throughout the control flow graph - i.e., if a constructor Foo() calls a private method
bar() that calls a public method buz(), there's a problem.
      </description>
        <priority>1</priority>
      <example>
  <![CDATA[
public class SeniorClass {
  public SeniorClass(){
      toString(); //may throw NullPointerException if overridden
  }
  public String toString(){
    return "IAmSeniorClass";
  }
}
public class JuniorClass extends SeniorClass {
  private String name;
  public JuniorClass(){
    super(); //Automatic call leads to NullPointerException
    name = "JuniorClass";
  }
  public String toString(){
    return name.toUpperCase();
  }
}
  ]]>
      </example>
    </rule>

    <rule name="AccessorClassGeneration"
          message="Avoid instantiation through private constructors from outside of the constructor's class."
          class="net.sourceforge.pmd.rules.AccessorClassGeneration"
          externalInfoUrl="http://pmd.sourceforge.net/rules/design.html#AccessorClassGeneration">
      <description>
Instantiation by way of private constructors from outside of the constructor's class often causes the generation of an accessor.
A factory method, or non-privitization of the constructor can eliminate this situation.
The generated class file is actually an interface.  It gives the accessing class the ability to invoke a new hidden package
scope constructor that takes the interface as a supplementary parameter.  This turns a private constructor effectively into
one with package scope, though not visible to the naked eye.
      </description>
      <priority>3</priority>
      <example>
  <![CDATA[
public class Outer {
 void method(){
  Inner ic = new Inner();//Causes generation of accessor class
 }
 public class Inner {
  private Inner(){}
 }
}
  ]]>
      </example>
    </rule>

    <rule name="FinalFieldCouldBeStatic"
          message="This final field could be made static"
          class="net.sourceforge.pmd.rules.XPathRule"
          externalInfoUrl="http://pmd.sourceforge.net/rules/design.html#FinalFieldCouldBeStatic">
      <description>
If a final field is assigned to a compile-time constant, it could be
made static, thus saving overhead in each object
      </description>
        <properties>
            <property name="xpath">
                <value>
                    <![CDATA[
//FieldDeclaration
 [@Final='true' and @Static='false']
 [not (../../../../ClassOrInterfaceDeclaration[@Interface='true'])]
   /VariableDeclarator/VariableInitializer/Expression
    /PrimaryExpression/PrimaryPrefix/Literal
                    ]]>
                </value>
            </property>
        </properties>
        <priority>3</priority>
      <example>
  <![CDATA[
public class Foo {
 public final int BAR = 42; // this could be static and save some space
}
  ]]>
      </example>
    </rule>


  <rule name="CloseResource"
        message="Ensure that resources like this {0} object are closed after use"
        class="net.sourceforge.pmd.rules.CloseResource"
          externalInfoUrl="http://pmd.sourceforge.net/rules/design.html#CloseResource">
    <description>
Ensure that resources (like Connection, Statement, and ResultSet objects) are always closed after use
    </description>
      <properties>
          <property name="types" value="Connection,Statement,ResultSet"/>
      </properties>
    <priority>3</priority>
    <example>
<![CDATA[
public class Bar {
 public void foo() {
  Connection c = pool.getConnection();
  try {
    // do stuff
  } catch (SQLException ex) {
    // handle exception
  } finally {
    // oops, should close the connection using 'close'!
    // c.close();
  }
 }
}
]]>
    </example>
  </rule>

    <rule name="NonStaticInitializer"
           message="Non-static initializers are confusing"
           class="net.sourceforge.pmd.rules.XPathRule"
          externalInfoUrl="http://pmd.sourceforge.net/rules/design.html#NonStaticInitializer">
       <description>
A nonstatic initializer block will be called any time a constructor
is invoked (just prior to invoking the constructor).  While this
is a valid language construct, it is rarely used and is confusing.
       </description>
         <properties>
             <property name="xpath">
                 <value>
<![CDATA[
//ClassOrInterfaceBodyDeclaration/Initializer[@Static='false']
]]>
                 </value>
             </property>
         </properties>
         <priority>3</priority>
       <example>
   <![CDATA[
public class MyClass {
 // this block gets run before any call to a constructor
 {
  System.out.println("I am about to construct myself");
 }
}
   ]]>
       </example>
     </rule>

    <rule name="DefaultLabelNotLastInSwitchStmt"
           message="The default label should be the last label in a switch statement"
           class="net.sourceforge.pmd.rules.XPathRule"
          externalInfoUrl="http://pmd.sourceforge.net/rules/design.html#DefaultLabelNotLastInSwitchStmt">
       <description>
By convention, the default label should be the last label in a switch statement.
       </description>
         <properties>
             <property name="xpath">
                 <value>
<![CDATA[
//SwitchStatement
 [not(SwitchLabel[position() = last()][@Default='true'])]
 [SwitchLabel[@Default='true']]
]]>
                 </value>
             </property>
         </properties>
         <priority>3</priority>
       <example>
   <![CDATA[
public class Foo {
 void bar(int a) {
  switch (a) {
   case 1:  // do something
      break;
   default:  // the default case should be last, by convention
      break;
   case 2:
      break;
  }
 }
}   ]]>
       </example>
     </rule>

    <rule name="NonCaseLabelInSwitchStatement"
           message="A non-case label was present in a switch statement"
           class="net.sourceforge.pmd.rules.XPathRule"
          externalInfoUrl="http://pmd.sourceforge.net/rules/design.html#NonCaseLabelInSwitchStatement">
       <description>
A non-case label (e.g. a named break/continue label) was present in a switch statement.
This legal, but confusing. It is easy to mix up the case labels and the non-case labels.
       </description>
         <properties>
             <property name="xpath">
                 <value>
 <![CDATA[
//SwitchStatement//BlockStatement/Statement/LabeledStatement
 ]]>
                 </value>
             </property>
         </properties>
         <priority>3</priority>
       <example>
   <![CDATA[
public class Foo {
 void bar(int a) {
  switch (a) {
   case 1:
      // do something
      break;
   mylabel: // this is legal, but confusing!
      break;
   default:
      break;
  }
 }
}
   ]]>
       </example>
     </rule>

    <rule name="OptimizableToArrayCall"
          message="This call to Collection.toArray() may be optimizable"
          class="net.sourceforge.pmd.rules.XPathRule"
          externalInfoUrl="http://pmd.sourceforge.net/rules/design.html#OptimizableToArrayCall">
      <description>
A call to Collection.toArray can use the Collection's size vs an empty Array of the desired type.
      </description>
      <properties>
          <property name="xpath">
              <value>
                  <![CDATA[
//PrimaryExpression
[PrimaryPrefix/Name[ends-with(@Image, 'toArray')]]
[
PrimarySuffix/Arguments/ArgumentList/Expression
 /PrimaryExpression/PrimaryPrefix/AllocationExpression
 /ArrayDimsAndInits/Expression/PrimaryExpression/PrimaryPrefix/Literal[@Image='0']
]

                  ]]>
              </value>
          </property>
      </properties>
        <priority>3</priority>
      <example>
  <![CDATA[
class Foo {
 void bar(Collection x) {
   // A bit inefficient
   x.toArray(new Foo[0]);
   // Much better; this one sizes the destination array, avoiding
   // a reflection call in some Collection implementations
   x.toArray(new Foo[x.size()]);
 }
}
  ]]>
      </example>
    </rule>


    <rule name="BadComparison"
          message="Avoid equality comparisons with Double.NaN"
          class="net.sourceforge.pmd.rules.XPathRule"
          externalInfoUrl="http://pmd.sourceforge.net/rules/design.html#BadComparison">
      <description>
Avoid equality comparisons with Double.NaN - these are
likely to be logic errors.
      </description>
      <properties>
          <property name="xpath">
              <value>
                  <![CDATA[
//EqualityExpression[@Image='==']
 /PrimaryExpression/PrimaryPrefix
 /Name[@Image='Double.NaN' or @Image='Float.NaN']
                  ]]>
              </value>
          </property>
      </properties>
        <priority>3</priority>
      <example>
  <![CDATA[
public class Bar {
 boolean x = (y == Double.NaN);
}
  ]]>
      </example>
    </rule>

    <rule   name="EqualsNull"
            message="Avoid using equals() to compare against null"
            class="net.sourceforge.pmd.rules.XPathRule"
          externalInfoUrl="http://pmd.sourceforge.net/rules/design.html#EqualsNull">
        <description>
Newbie programmers sometimes get the comparison concepts confused
and use equals() to compare to null.
        </description>
        <properties>
            <property name="xpath">
                <value>
    <![CDATA[
//PrimaryExpression
 [
PrimaryPrefix/Name[ends-with(@Image, 'equals')]
or
PrimarySuffix[ends-with(@Image, 'equals')]
]
[PrimarySuffix/Arguments/ArgumentList
  /Expression/PrimaryExpression/PrimaryPrefix
   /Literal/NullLiteral]
    ]]>
                </value>
            </property>
         </properties>
        <priority>1</priority>
    <example>
       <![CDATA[
class Bar {
   void foo() {
       String x = "foo";
       if (x.equals(null)) { // bad!
        doSomething();
       }
   }
}
    ]]>
        </example>
        </rule>

      <rule name="ConfusingTernary"
        message="Avoid if (x != y) ..; else ..;"
        class="net.sourceforge.pmd.rules.design.ConfusingTernary"
          externalInfoUrl="http://pmd.sourceforge.net/rules/design.html#ConfusingTernary">
        <description>
In an "if" expression with an "else" clause, avoid negation in
the test.  For example, rephrase:
if (x != y) diff(); else same();
as:
if (x == y) same(); else diff();
Most "if (x != y)" cases without an "else" are often return
cases, so consistent use of this rule makes the code easier
to read.  Also, this resolves trivial ordering problems, such
as "does the error case go first?" or "does the common case
go first?".
        </description>
        <priority>3</priority>
        <example>
          <![CDATA[
public class Foo {
 boolean bar(int x, int y) {
  return (x != y) ? diff : same;
 }
}          ]]>
        </example>
      </rule>

    <rule name="InstantiationToGetClass"
          message="Avoid instantiating an object just to call getClass() on it; use the .class public member instead"
          class="net.sourceforge.pmd.rules.XPathRule"
          externalInfoUrl="http://pmd.sourceforge.net/rules/design.html#InstantiationToGetClass">
      <description>
Avoid instantiating an object just to call getClass() on it; use the .class public member instead
      </description>
        <example>
    <![CDATA[
public class Foo {
 // Replace this
 Class c = new String().getClass();
 // with this:
 Class c = String.class;
}
    ]]>
        </example>
        <priority>4</priority>
        <properties>
          <property name="xpath">
            <value>
                <![CDATA[
//PrimarySuffix
 [@Image='getClass']
 [parent::PrimaryExpression
  [PrimaryPrefix/AllocationExpression]
  [count(PrimarySuffix) = 2]
 ]
     ]]>
            </value>
          </property>
        </properties>
      </rule>

    <rule name="IdempotentOperations"
          message="Avoid idempotent operations (like assigning a variable to itself)"
          class="net.sourceforge.pmd.rules.IdempotentOperations"
          externalInfoUrl="http://pmd.sourceforge.net/rules/design.html#IdempotentOperations">
      <description>
Avoid idempotent operations - they are silly.
      </description>
        <priority>3</priority>

      <example>
      <![CDATA[
public class Foo {
 public void bar() {
  int x = 2;
  x = x;
 }
}
      ]]>
      </example>
    </rule>

    <rule
        name="SimpleDateFormatNeedsLocale"
        message="When instantiating a SimpleDateFormat object, specify a Locale"
        class="net.sourceforge.pmd.rules.XPathRule"
          externalInfoUrl="http://pmd.sourceforge.net/rules/design.html#SimpleDateFormatNeedsLocale">
        <description>
Be sure to specify a Locale when creating a new instance of SimpleDateFormat.
        </description>
        <properties>
            <property name="xpath">
                <value>
<![CDATA[
//AllocationExpression
 [ClassOrInterfaceType[@Image='SimpleDateFormat']]
 [Arguments[@ArgumentCount=1]]
]]>
                    </value>
                 </property>
              </properties>
        <priority>3</priority>
        <example>
        <![CDATA[
public class Foo {
 // Should specify Locale.US (or whatever)
 private SimpleDateFormat sdf = new SimpleDateFormat("pattern");
}
        ]]>
        </example>
    </rule>

    <rule name="ImmutableField"
          message="Private field could be made final.  It is only initialized in the declaration or constructor."
          class="net.sourceforge.pmd.rules.design.ImmutableField"
          externalInfoUrl="http://pmd.sourceforge.net/rules/design.html#ImmutableField">
      <description>
Identifies private fields whose values never change once they are initialized either in the declaration of the field or by
a constructor.  This aids in converting existing classes to immutable classes.
      </description>
        <priority>3</priority>

      <example>
  <![CDATA[
public class Foo {
  private int x; // could be final
  public Foo() {
      x = 7;
  }
  public void foo() {
     int a = x + 2;
  }
}
  ]]>
      </example>
    </rule>

    <rule name="UseLocaleWithCaseConversions"
          message="When doing a String.toLowerCase()/toUpperCase() call, use a Locale"
          class="net.sourceforge.pmd.rules.XPathRule"
          externalInfoUrl="http://pmd.sourceforge.net/rules/design.html#UseLocaleWithCaseConversions">
      <description>
When doing a String.toLowerCase()/toUpperCase() call, use a Locale.  This avoids
problems with certain locales, i.e. Turkish.
      </description>
        <example>
    <![CDATA[
class Foo {
 // BAD
 if (x.toLowerCase().equals("list"))...
 /*
 This will not match "LIST" when in Turkish locale
 The above could be
 if (x.toLowerCase(Locale.US).equals("list")) ...
 or simply
 if (x.equalsIgnoreCase("list")) ...
 */
 // GOOD
 String z = a.toLowerCase(Locale.EN);
}
    ]]>
        </example>
        <priority>3</priority>
        <properties>
          <property name="xpath">
            <value>
                <![CDATA[
//PrimaryExpression
[PrimaryPrefix/Name
 [ends-with(@Image, 'toLowerCase') or ends-with(@Image,
'toUpperCase')]
 ]
[PrimarySuffix/Arguments[@ArgumentCount=0]]
     ]]>
            </value>
          </property>
        </properties>
      </rule>

    <rule name="AvoidProtectedFieldInFinalClass"
             message="Avoid protected fields in a final class.  Change to private or package access."
             class="net.sourceforge.pmd.rules.XPathRule"
          externalInfoUrl="http://pmd.sourceforge.net/rules/design.html#AvoidProtectedFieldInFinalClass">
         <description>
Do not use protected fields in final classes since they cannot be subclassed.
Clarify your intent by using private or package access modifiers instead.
         </description>
         <properties>
             <property name="xpath">
                 <value>
<![CDATA[
//ClassOrInterfaceDeclaration
 [@Final='true']//FieldDeclaration[@Protected='true']
 ]]>
                 </value>
             </property>
         </properties>
           <priority>3</priority>
        <example>
<![CDATA[
public final class Bar {
 private int x;
 protected int y;  // <-- Bar cannot be subclassed, so is y really private or package visible???
 Bar() {}
}
 ]]>
         </example>
       </rule>
       
     <rule name="AssignmentToNonFinalStatic"
           message="Possible unsafe assignment to a non-final static field in a constructor."
           class="net.sourceforge.pmd.rules.design.AssignmentToNonFinalStatic"
          externalInfoUrl="http://pmd.sourceforge.net/rules/design.html#AssignmentToNonFinalStatic">
       <description>
Identifies a possible unsafe usage of a static field.
       </description>
         <priority>3</priority>
       <example>
   <![CDATA[
public class StaticField {
   static int x;
   public FinalFields(int y) {
    x = y; // unsafe
   }
}
   ]]>
       </example>
     </rule>

    <rule name="MissingStaticMethodInNonInstantiatableClass"
          message="Class cannot be instantiated and does not provide any static methods or fields"
          class="net.sourceforge.pmd.rules.XPathRule"
          externalInfoUrl="http://pmd.sourceforge.net/rules/design.html#MissingStaticMethodInNonInstantiatableClass">
      <description>
A class that has private constructors and does not have any static methods or fields cannot be used.
      </description>
      <properties>
          <property name="xpath">
              <value>
    <![CDATA[
//ClassOrInterfaceDeclaration[@Nested='false'][
( count(./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/ConstructorDeclaration)>0
  and count(./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/ConstructorDeclaration) = count(./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/ConstructorDeclaration[@Private='true']) )
and
count(.//MethodDeclaration[@Static='true'])=0
and
count(.//FieldDeclaration[@Public='true'][@Static='true'])=0
]
    ]]>
              </value>
          </property>
      </properties>
        <priority>3</priority>
      <example>
<![CDATA[
/* This class is unusable, since it cannot be
 instantiated (private constructor),
 and no static method can be called.
 */
public class Foo {
 private Foo() {}
 void foo() {}
}

]]>
      </example>
    </rule>


    <rule name="AvoidSynchronizedAtMethodLevel"
          message="Use block level rather than method level synchronization"
          class="net.sourceforge.pmd.rules.XPathRule"
          externalInfoUrl="http://pmd.sourceforge.net/rules/design.html#AvoidSynchronizedAtMethodLevel">
      <description>
  Method level synchronization can backfire when new code is added to the method.  Block-level
  synchronization helps to ensure that only the code that needs synchronization gets it.
      </description>
      <properties>
          <property name="xpath">
              <value>
    <![CDATA[
//MethodDeclaration[@Synchronized='true']
    ]]>
              </value>
          </property>
      </properties>
        <priority>3</priority>
      <example>
<![CDATA[
public class Foo {
 // Try to avoid this
 synchronized void foo() {
 }
 // Prefer this:
 void bar() {
  synchronized(this) {
  }
 }
}
]]>
      </example>
    </rule>

    <rule name="MissingBreakInSwitch"
          message="A switch statement does not contain a break"
          class="net.sourceforge.pmd.rules.XPathRule"
          externalInfoUrl="http://pmd.sourceforge.net/rules/design.html#MissingBreakInSwitch">
      <description>
A switch statement without an enclosed break statement may be a bug.
      </description>
      <properties>
          <property name="xpath">
              <value>
    <![CDATA[
//SwitchStatement
[count(.//BreakStatement)=0]
[count(SwitchLabel) > 0]
[count(BlockStatement/Statement/ReturnStatement) < count (SwitchLabel)]
    ]]>
              </value>
          </property>
      </properties>
        <priority>3</priority>
      <example>
<![CDATA[
public class Foo {
 public void bar(int status) {
  switch(status) {
   case CANCELLED:
    doCancelled();
    // break; hm, should this be commented out?
   case NEW:
    doNew();
   case REMOVED:
    doRemoved();
   }
 }
}
]]>
      </example>
    </rule>


    <rule name="UseNotifyAllInsteadOfNotify"
          message="Call Thread.notifyAll() rather than Thread.notify()"
          class="net.sourceforge.pmd.rules.XPathRule"
          externalInfoUrl="http://pmd.sourceforge.net/rules/design.html#UseNotifyAllInsteadOfNotify">
      <description>
Thread.notify() awakens a thread monitoring the object. If more than one thread is monitoring, then only
one is chosen.  The thread chosen is arbitrary; thus it's usually safer to call notifyAll() instead.
      </description>
      <properties>
          <property name="xpath">
              <value>
    <![CDATA[
//Statement/StatementExpression/PrimaryExpression/PrimaryPrefix
[
./Name[
	@Image='notify'
	or ends-with(@Image,'.notify')
	]
or @Image='notify'
or (  ./AllocationExpression
    and ../PrimarySuffix[@Image='notify'] )
]
    ]]>
              </value>
          </property>
      </properties>
        <priority>3</priority>

      <example>
<![CDATA[
public class Foo {
 void bar() {
  x.notify();
  // If many threads are monitoring x, only one (and you won't know which) will be notified.
  // use instead:
  x.notifyAll();
 }
}
]]>
      </example>
    </rule>

    <rule name="AvoidInstanceofChecksInCatchClause"
          message="An instanceof check is being performed on the caught exception.  Create a separate catch clause for this exception type."
          class="net.sourceforge.pmd.rules.XPathRule"
          externalInfoUrl="http://pmd.sourceforge.net/rules/design.html#AvoidInstanceofChecksInCatchClause">
    <description>
Each caught exception type should be handled in its own catch clause.
      </description>
      <properties>
          <property name="xpath">
              <value>
    <![CDATA[
//CatchStatement/FormalParameter
 /following-sibling::Block//InstanceOfExpression/PrimaryExpression/PrimaryPrefix
  /Name[
   @Image = ./ancestor::Block/preceding-sibling::FormalParameter
    /VariableDeclaratorId/@Image
  ]
    ]]>
              </value>
          </property>
      </properties>
        <priority>3</priority>
      <example>
<![CDATA[
try { // Avoid this
 // do something
} catch (Exception ee) {
 if (ee instanceof IOException) {
  cleanup();
 }
}
try {  // Prefer this:
 // do something
} catch (IOException ee) {
 cleanup();
}
]]>
      </example>
    </rule>

    <rule name="AbstractClassWithoutAbstractMethod"
          message="This abstract class does not have any abstract methods"
          class="net.sourceforge.pmd.rules.XPathRule"
          externalInfoUrl="http://pmd.sourceforge.net/rules/design.html#AbstractClassWithoutAbstractMethod">
      <description>
The abstract class does not contain any abstract methods. An abstract class suggests
an incomplete implementation, which is to be completed by subclasses implementing the
abstract methods. If the class is intended to be used as a base class only (not to be instantiated
direcly) a protected constructor can be provided prevent direct instantiation.
      </description>
      <properties>
          <property name="xpath">
              <value><![CDATA[
//ClassOrInterfaceDeclaration
 [@Abstract='true'
  and count( .//MethodDeclaration[@Abstract='true'] )=0 ]
  [count(ImplementsList)=0]
              ]]>
              </value>
          </property>
      </properties>
        <priority>3</priority>
      <example>
<![CDATA[
public abstract class Foo {
 void int method1() { ... }
 void int method2() { ... }
 // consider using abstract methods or removing
 // the abstract modifier and adding protected constructors
}
]]>
      </example>
    </rule>

    <rule name="SimplifyConditional"
              message="No need to check for null before an instanceof"
              class="net.sourceforge.pmd.rules.XPathRule"
          externalInfoUrl="http://pmd.sourceforge.net/rules/design.html#SimplifyConditional">
           <description>
No need to check for null before an instanceof; the instanceof keyword returns false when given a null argument.
           </description>
          <properties>
              <property name="xpath">
                  <value>
                      <![CDATA[
//Expression
 [ConditionalOrExpression
 [EqualityExpression[@Image='==']
  //NullLiteral
  and
  UnaryExpressionNotPlusMinus
   [@Image='!']//InstanceOfExpression[PrimaryExpression
     //Name/@Image = ancestor::ConditionalOrExpression/EqualityExpression
      //PrimaryPrefix/Name/@Image]]
or
ConditionalAndExpression
 [EqualityExpression[@Image='!=']//NullLiteral
 and
InstanceOfExpression
 [PrimaryExpression[count(PrimarySuffix[@ArrayDereference='true'])=0]
  //Name/@Image = ancestor::ConditionalAndExpression
   /EqualityExpression//PrimaryPrefix/Name/@Image]]]
 ]]>
                  </value>
              </property>
          </properties>
            <priority>3</priority>
           <example>
      <![CDATA[
class Foo {
 void bar(Object x) {
  if (x != null && x instanceof Bar) {
   // just drop the "x != null" check
  }
 }
}      ]]>
           </example>
        </rule>

<rule  name="CompareObjectsWithEquals"
  message="Use equals() to compare object references."
  class="net.sourceforge.pmd.rules.design.CompareObjectsWithEquals"
          externalInfoUrl="http://pmd.sourceforge.net/rules/design.html#CompareObjectsWithEquals">
  <description>
 Use equals() to compare object references; avoid comparing them with ==.
  </description>
  <priority>3</priority>
  <example>
<![CDATA[
class Foo {
 boolean bar(String a, String b) {
  return a == b;
 }
}

]]>
  </example>
</rule>


<rule  name="PositionLiteralsFirstInComparisons"
  message="Position literals first in String comparisons"
  class="net.sourceforge.pmd.rules.design.PositionLiteralsFirstInComparisons"
          externalInfoUrl="http://pmd.sourceforge.net/rules/design.html#PositionLiteralsFirstInComparisons">
  <description>
 Position literals first in String comparisons - that way if the String is null you won't get a NullPointerException, it'll just return false.
  </description>
  <priority>3</priority>
  <example>
<![CDATA[
class Foo {
 boolean bar(String x) {
  return x.equals("2"); // should be "2".equals(x)
 }
}

]]>
  </example>
</rule>

    <rule name="UnnecessaryLocalBeforeReturn"
          message="Consider simply returning the value vs storing it in local variable ''{0}''"
          class="net.sourceforge.pmd.rules.design.UnnecessaryLocalBeforeReturn"
          externalInfoUrl="http://pmd.sourceforge.net/rules/design.html#UnnecessaryLocalBeforeReturn">
      <description>
Avoid unnecessarily creating local variables
      </description>
        <priority>3</priority>
      <example>
  <![CDATA[
  public class Foo {
    public int foo() {
      int x = doSomething();
      return x;  // instead, just 'return doSomething();'
    }
  }
  ]]>
      </example>
    </rule>

    <rule name="NonThreadSafeSingleton"
    message="Singleton is not thread safe"
    class="net.sourceforge.pmd.rules.XPathRule"
          externalInfoUrl="http://pmd.sourceforge.net/rules/design.html#NonThreadSafeSingleton">
        <description>
Non-thread safe singletons can result in bad state changes. If possible,
get rid of static singletons by directly instantiating the object. Static
singletons are usually not needed as only a single instance exists anyway.
Other possible fixes are to synchronize the entire method or to use an
initialize-on-demand holder class (do not use the double-check idiom).

See Effective Java, item 48.
        </description>
        <properties>
            <property name="xpath">
                <value><![CDATA[
//MethodDeclaration[$checkNonStaticMethods='true' or @Static='true'][@Synchronized='false']
//IfStatement[not (ancestor::SynchronizedStatement)]/Expression
 /EqualityExpression
   [PrimaryExpression/PrimaryPrefix/Literal/NullLiteral]
   [PrimaryExpression/PrimaryPrefix
     /Name[@Image=
       //FieldDeclaration[$checkNonStaticFields='true' or @Static='true']
       /VariableDeclarator/VariableDeclaratorId/@Image]
]
                ]]></value>
            </property>
            <property name="checkNonStaticMethods">
                <description>Do not set this to false and checkNonStaticFields to true</description>
                <value>true</value>
            </property>
            <property name="checkNonStaticFields">
                <description>Do not set this to true and checkNonStaticMethods to false</description>
                <value>false</value>
            </property>
        </properties>
        <priority>3</priority>
        <example><![CDATA[
private static Foo foo = null;

//multiple simultaneous callers may see partially initialized objects
public static Foo getFoo() {
    if (foo==null)
        foo = new Foo();
    return foo;
}
        ]]></example>
    </rule>



    <rule name="UncommentedEmptyMethod"
          message="Document empty method"
          class="net.sourceforge.pmd.rules.XPathRule"
          externalInfoUrl="http://pmd.sourceforge.net/rules/design.html#UncommentedEmptyMethod">
      <description>
Uncommented Empty Method finds instances where a method does not contain
statements, but there is no comment. By explicitly commenting empty methods
it is easier to distinguish between intentional (commented) and unintentional
empty methods.
      </description>
      <properties>
          <property name="xpath">
              <value>
    <![CDATA[
//MethodDeclaration/Block[count(BlockStatement) = 0 and @containsComment = 'false']
 ]]>
             </value>
          </property>
      </properties>
      <priority>3</priority>
      <example>
  <![CDATA[
public void doSomething() {
}
 ]]>
      </example>
    </rule>

    <rule name="UncommentedEmptyConstructor"
          message="Document empty constructor"
          class="net.sourceforge.pmd.rules.XPathRule"
          externalInfoUrl="http://pmd.sourceforge.net/rules/design.html#UncommentedEmptyConstructor">
      <description>
Uncommented Empty Constructor finds instances where a constructor does not
contain statements, but there is no comment. By explicitly commenting empty
constructors it is easier to distinguish between intentional (commented)
and unintentional empty constructors.
      </description>
      <properties>
          <property name="xpath">
              <value>
    <![CDATA[
//ConstructorDeclaration[count(BlockStatement) = 0 and ($ignoreExplicitConstructorInvocation = 'true' or not(ExplicitConstructorInvocation)) and @containsComment = 'false']
 ]]>
             </value>
          </property>
          <property name="ignoreExplicitConstructorInvocation" description="Ignore explicit constructor invocation when deciding whether constructor is empty or not">
              <value>false</value>
          </property>
      </properties>
      <priority>3</priority>
      <example>
  <![CDATA[
public Foo() {
  super();
}
 ]]>
      </example>
    </rule>

<rule name="AvoidConstantsInterface"
      message="An Interface should be used only to model a behaviour; consider converting this to a class."
      class="net.sourceforge.pmd.rules.XPathRule">
      <description>
     An interface should be used only to model a behaviour of a
    class: using an interface as a container of constants is a poor usage pattern.
      </description>
      <properties>
        <property name="xpath">
        <value>
    <![CDATA[
    //ClassOrInterfaceDeclaration[@Interface="true"]
    [
     count(//MethodDeclaration)=0
     and
     count(//FieldDeclaration)>0
    ]
    ]]>
        </value>
        </property>
      </properties>
      <priority>3</priority>
      <example>
    <![CDATA[
    public interface ConstantsInterface {
     public static final int CONSTANT1=0;
     public static final String CONSTANT2="1";
    }
    ]]>
      </example>
    </rule>

</ruleset>
