<?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="Braces Rules">
  <description>
The Braces Ruleset contains a collection of braces rules.
  </description>

   <rule name="IfStmtsMustUseBraces"
         message="Avoid using if statements without curly braces"
         class="net.sourceforge.pmd.rules.XPathRule">
     <description>
     Avoid using if statements without using curly braces
     </description>
       <properties>
           <property name="xpath">
               <value>
                   <![CDATA[
    //IfStatement[count(*) < 3][not(Statement/Block)]
                   ]]>
               </value>
           </property>
       </properties>
       <priority>3</priority>

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

    <rule name="WhileLoopsMustUseBracesRule"
          message="Avoid using 'while' statements without curly braces"
          class="net.sourceforge.pmd.rules.XPathRule">
      <description>
      Avoid using 'while' statements without using curly braces
      </description>
        <properties>
            <property name="xpath">
                <value>
                    <![CDATA[
    //WhileStatement[not(Statement/Block)]
                    ]]>
                </value>
            </property>
        </properties>
        <priority>3</priority>

      <example>
  <![CDATA[
    public void doSomething() {
      while (true)
          x++;
    }
  ]]>
      </example>
    </rule>

      <rule name="IfElseStmtsMustUseBracesRule"
           message="Avoid using 'if...else' statements without curly braces"
           class="net.sourceforge.pmd.rules.XPathRule">
       <description>
       Avoid using if..else statements without using curly braces
       </description>
         <properties>
             <property name="xpath">
                 <value>
                     <![CDATA[
    //IfStatement[count(*) > 2][not(Statement/Block)]
                     ]]>
                 </value>
             </property>
         </properties>
         <priority>3</priority>

       <example>
   <![CDATA[

     public void doSomething() {
       // this is OK
       if (foo) x++;

       // but this is not
       if (foo)
           x=x+1;
       else
           x=x-1;
     }
   ]]>
       </example>
     </rule>

     <rule name="ForLoopsMustUseBracesRule"
           message="Avoid using 'for' statements without curly braces"
           class="net.sourceforge.pmd.rules.XPathRule">
       <description>
       Avoid using 'for' statements without using curly braces
       </description>
         <properties>
             <property name="xpath">
                 <value>
                     <![CDATA[
    //ForStatement[not(Statement/Block)]
                     ]]>
                 </value>
             </property>
         </properties>
         <priority>3</priority>

       <example>
   <![CDATA[
     public void foo() {
       for (int i=0; i<42;i++)
           foo();
     }
   ]]>
       </example>
     </rule>

</ruleset>



