All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.hm.hafner.analysis.parser.checkstyle.config_blocks.xml Maven / Gradle / Ivy

<?xml version="1.0" encoding="UTF-8"?>

<document xmlns="http://maven.apache.org/XDOC/2.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/XDOC/2.0 http://maven.apache.org/xsd/xdoc-2.0.xsd">

  <head>
    <title>Block Checks</title>
    <script type="text/javascript"
            src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"/>
    <script type="text/javascript" src="js/anchors.js"/>
    <script type="text/javascript" src="js/google-analytics.js"/>
    <link rel="icon" href="images/favicon.png" type="image/x-icon" />
    <link rel="shortcut icon" href="images/favicon.ico" type="image/ico" />
  </head>

  <body>
    <section name="Content">
      <macro name="toc">
        <param name="fromDepth" value="1"/>
        <param name="toDepth" value="1"/>
      </macro>
    </section>

    <section name="AvoidNestedBlocks">
      <subsection name="Description" id="AvoidNestedBlocks_Description">
        <p>Since Checkstyle 3.1</p>
        <p>
          Finds nested blocks, i.e. blocks that are used freely in the code.
        </p>

        <p>
          Rationale: Nested blocks are often leftovers from the
          debugging process, they confuse the reader.
        </p>

        <p>
          For example this Check finds the obsolete braces in
        </p>
        <source>
public void guessTheOutput()
{
  int whichIsWhich = 0;
  {
      int whichIsWhich = 2;
  }
  System.out.println("value = " + whichIsWhich);
}
        </source>

        <p> and debugging / refactoring leftovers such as </p>
        <source>
// if (conditionThatIsNotUsedAnyLonger)
{
  System.out.println("unconditional");
}
        </source>

        <p>
          A case in a switch statement does not implicitly form a block.
          Thus to be able to introduce local variables that have case
          scope it is necessary to open a nested block. This is
          supported, set the allowInSwitchCase property to true and
          include all statements of the case in the block.
        </p>
        <source>
switch (a)
{
  case 0:
    // Never OK, break outside block
    {
      x = 1;
    }
    break;
  case 1:
    // Never OK, statement outside block
    System.out.println("Hello");
    {
      x = 2;
      break;
    }
  case 1:
    // OK if allowInSwitchCase is true
    {
      System.out.println("Hello");
      x = 2;
      break;
    }
}
        </source>
      </subsection>

      <subsection name="Properties" id="AvoidNestedBlocks_Properties">
        <table>
          <tr>
            <th>name</th>
            <th>description</th>
            <th>type</th>
            <th>default value</th>
            <th>since</th>
          </tr>
          <tr>
            <td>allowInSwitchCase</td>
            <td>Allow nested blocks in case statements</td>
            <td><a href="property_types.html#boolean">Boolean</a></td>
            <td><code>false</code></td>
            <td>3.2</td>
          </tr>
        </table>
      </subsection>

      <subsection name="Examples" id="AvoidNestedBlocks_Examples">
        <p> To configure the check: </p>
        <source>
&lt;module name=&quot;AvoidNestedBlocks&quot;/&gt;
        </source>
      </subsection>

      <subsection name="Example of Usage" id="AvoidNestedBlocks_Example_of_Usage">
        <ul>
          <li>
            <a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources+filename%3Asun_checks.xml+repo%3Acheckstyle%2Fcheckstyle+AvoidNestedBlocks">
            Sun Style</a>
          </li>
          <li>
            <a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+AvoidNestedBlocks">
            Checkstyle Style</a>
          </li>
        </ul>
      </subsection>

      <subsection name="Error Messages" id="AvoidNestedBlocks_Error_Messages">
        <ul>
          <li>
            <a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fblocks+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22block.nested%22">
            block.nested</a>
          </li>
        </ul>
        <p>
          All messages can be customized if the default message doesn't suit you.
          Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
        </p>
      </subsection>

      <subsection name="Package" id="AvoidNestedBlocks_Package">
        <p> com.puppycrawl.tools.checkstyle.checks.blocks </p>
      </subsection>

      <subsection name="Parent Module" id="AvoidNestedBlocks_Parent_Module">
        <p> <a href="config.html#TreeWalker">TreeWalker</a> </p>
      </subsection>
    </section>

    <section name="EmptyBlock">
      <subsection name="Description" id="EmptyBlock_Description">
        <p>Since Checkstyle 3.0</p>
        <p> Checks for empty blocks. This check does not validate sequential blocks. </p>

        <p> Sequential blocks won't be checked. Also, no violations for fallthrough: </p>
        <source>
switch (a) {
  case 1:                          // no violation
  case 2:                          // no violation
  case 3: someMethod(); { }        // no violation
  default: break;
}
        </source>

        <p>
          This check processes LITERAL_CASE and LITERAL_DEFAULT separately.
          So, if tokens=LITERAL_DEFAULT, following code will not trigger any violation,
          as the empty block belongs to LITERAL_CASE:
        </p>
        <p> Configuration: </p>
        <source>
&lt;module name=&quot;EmptyBlock&quot;&gt;
  &lt;property name=&quot;tokens&quot; value=&quot;LITERAL_DEFAULT&quot;/&gt;
&lt;/module&gt;
        </source>
        <p> Result: </p>
        <source>
switch (a) {
  default:        // no violation for "default:" as empty block belong to "case 1:"
  case 1: { }
}
        </source>
      </subsection>

      <subsection name="Properties" id="EmptyBlock_Properties">
        <table>
          <tr>
            <th>name</th>
            <th>description</th>
            <th>type</th>
            <th>default value</th>
            <th>since</th>
          </tr>
          <tr>
            <td>option</td>
            <td>policy on block contents</td>
            <td><a href="property_types.html#block">Block Policy</a></td>
            <td><code>statement</code></td>
            <td>3.0</td>
          </tr>
          <tr>
            <td>tokens</td>
            <td>tokens to check</td>

            <td>
              subset of tokens
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_WHILE">
                LITERAL_WHILE</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_TRY">
                LITERAL_TRY</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_CATCH">
                LITERAL_CATCH</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_FINALLY">
                LITERAL_FINALLY</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_DO">
                LITERAL_DO</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_IF">
                LITERAL_IF</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_ELSE">
                LITERAL_ELSE</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_FOR">
                LITERAL_FOR</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#INSTANCE_INIT">
                INSTANCE_INIT</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#STATIC_INIT">
                STATIC_INIT</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_SWITCH">
                LITERAL_SWITCH</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_SYNCHRONIZED">
                LITERAL_SYNCHRONIZED</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_CASE">
                LITERAL_CASE</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_DEFAULT">
                LITERAL_DEFAULT</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#ARRAY_INIT">
                ARRAY_INIT</a>.
            </td>
            <td>
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_WHILE">
                LITERAL_WHILE</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_TRY">
                LITERAL_TRY</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_FINALLY">
                LITERAL_FINALLY</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_DO">
                LITERAL_DO</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_IF">
                LITERAL_IF</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_ELSE">
                LITERAL_ELSE</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_FOR">
                LITERAL_FOR</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#INSTANCE_INIT">
                INSTANCE_INIT</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#STATIC_INIT">
                STATIC_INIT</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_SWITCH">
                LITERAL_SWITCH</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_SYNCHRONIZED">
                LITERAL_SYNCHRONIZED</a>.
            </td>
            <td>3.0</td>
          </tr>
        </table>
      </subsection>

      <subsection name="Examples" id="EmptyBlock_Examples">
        <p> To configure the check: </p>
        <source>
&lt;module name=&quot;EmptyBlock&quot;/&gt;
        </source>

        <p>
          To configure the check for the <code>text</code>
          policy and only <code> try</code> blocks:
        </p>
        <source>
&lt;module name=&quot;EmptyBlock&quot;&gt;
  &lt;property name=&quot;option&quot; value=&quot;text&quot;/&gt;
  &lt;property name=&quot;tokens&quot; value=&quot;LITERAL_TRY&quot;/&gt;
&lt;/module&gt;
        </source>
      </subsection>

      <subsection name="Example of Usage" id="EmptyBlock_Example_of_Usage">
        <ul>
          <li>
            <a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources+filename%3Agoogle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+EmptyBlock">
            Google Style</a>
          </li>
          <li>
            <a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources+filename%3Asun_checks.xml+repo%3Acheckstyle%2Fcheckstyle+EmptyBlock">
            Sun Style</a>
          </li>
          <li>
            <a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+EmptyBlock">
            Checkstyle Style</a>
          </li>
        </ul>
      </subsection>

      <subsection name="Error Messages" id="EmptyBlock_Error_Messages">
        <ul>
          <li>
            <a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fblocks+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22block.empty%22">
            block.empty</a>
          </li>
          <li>
            <a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fblocks+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22block.noStatement%22">
            block.noStatement</a>
          </li>
        </ul>
        <p>
          All messages can be customized if the default message doesn't suit you.
          Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
        </p>
      </subsection>

      <subsection name="Package" id="EmptyBlock_Package">
        <p> com.puppycrawl.tools.checkstyle.checks.blocks </p>
      </subsection>

      <subsection name="Parent Module" id="EmptyBlock_Parent_Module">
        <p> <a href="config.html#TreeWalker">TreeWalker</a> </p>
      </subsection>
    </section>

    <section name="EmptyCatchBlock">
      <subsection name="Description" id="EmptyCatchBlock_Description">
        <p>Since Checkstyle 6.4</p>
        <p>
          Checks for empty catch blocks. There are two options to make validation more precise
          (by default Check allows empty catch block with any comment inside):
        </p>
      </subsection>

      <subsection name="Properties" id="EmptyCatchBlock_Properties">
        <table>
          <tr>
            <th>name</th>
            <th>description</th>
            <th>type</th>
            <th>default value</th>
            <th>since</th>
          </tr>
          <tr>
            <td>exceptionVariableName</td>
            <td>The name of variable associated with exception</td>
            <td><a href="property_types.html#string">String</a></td>
            <td>&quot;^$&quot;</td>
            <td>6.4</td>
          </tr>
          <tr>
            <td>commentFormat</td>
            <td>The format of the first comment inside empty catch</td>
            <td><a href="property_types.html#string">String</a></td>
            <td>&quot;.*&quot;</td>
            <td>6.4</td>
          </tr>
        </table>
      </subsection>

      <subsection name="Examples" id="EmptyCatchBlock_Examples">
        <p>
          To configure the Check to suppress empty catch block if exception's variable name is
           <code>expected</code> or <code>ignore</code> or there's any comment inside:
        </p>
        <source>
&lt;module name=&quot;EmptyCatchBlock&quot;&gt;
  &lt;property name=&quot;exceptionVariableName&quot; value=&quot;expected|ignore&quot;/&gt;
&lt;/module&gt;
        </source>
        <p>
          To configure the Check to suppress empty catch block if single-line comment inside
           is &quot;//This is expected&quot;:
        </p>
        <source>
&lt;module name=&quot;EmptyCatchBlock&quot;&gt;
  &lt;property name=&quot;commentFormat&quot; value=&quot;This is expected&quot;/&gt;
&lt;/module&gt;
        </source>
        <p>
          To configure the Check to suppress empty catch block if single-line comment inside
           is &quot;//This is expected&quot; or exception's
            variable name is &quot;myException&quot; (any option is matching):
        </p>
        <source>
&lt;module name=&quot;EmptyCatchBlock&quot;&gt;
  &lt;property name=&quot;commentFormat&quot; value=&quot;This is expected&quot;/&gt;
  &lt;property name=&quot;exceptionVariableName&quot; value=&quot;myException&quot;/&gt;
&lt;/module&gt;
        </source>
        <p>
          Such empty blocks would be suppressed:
        </p>
        <source>
try {
  throw new RuntimeException();
} catch (RuntimeException e) {
  //This is expected
}
...
try {
  throw new RuntimeException();
} catch (RuntimeException e) {
  //   This is expected
}
...
try {
  throw new RuntimeException();
} catch (RuntimeException e) {
  // This is expected
  // some another comment
}
...
try {
  throw new RuntimeException();
} catch (RuntimeException e) {
  /* This is expected */
}
...
try {
  throw new RuntimeException();
} catch (RuntimeException e) {
  /*
  *
  * This is expected
  * some another comment
  */
}
...
try {
  throw new RuntimeException();
} catch (RuntimeException myException) {

}
        </source>
      </subsection>

      <subsection name="Example of Usage" id="EmptyCatchBlock_Example_of_Usage">
        <ul>
          <li>
            <a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources+filename%3Agoogle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+EmptyCatchBlock">
            Google Style</a>
          </li>
          <li>
            <a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+EmptyCatchBlock">
            Checkstyle Style</a>
          </li>
        </ul>
      </subsection>

      <subsection name="Error Messages" id="EmptyCatchBlock_Error_Messages">
        <ul>
          <li>
            <a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fblocks+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22catch.block.empty%22">
            catch.block.empty</a>
          </li>
        </ul>
        <p>
          All messages can be customized if the default message doesn't suit you.
          Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
        </p>
      </subsection>

      <subsection name="Package" id="EmptyCatchBlock_Package">
        <p> com.puppycrawl.tools.checkstyle.checks.blocks </p>
      </subsection>

      <subsection name="Parent Module" id="EmptyCatchBlock_Parent_Module">
        <p> <a href="config.html#TreeWalker">TreeWalker</a> </p>
      </subsection>
    </section>

    <section name="LeftCurly">
      <subsection name="Description" id="LeftCurly_Description">
        <p>Since Checkstyle 3.0</p>
        <p>
          Checks for the placement of left curly braces
          (<code>'{'</code>) for code blocks.  The policy to verify is
          specified using the property <code>option</code>.
        </p>
      </subsection>

      <subsection name="Properties" id="LeftCurly_Properties">
        <table>
          <tr>
            <th>name</th>
            <th>description</th>
            <th>type</th>
            <th>default value</th>
            <th>since</th>
          </tr>
          <tr>
            <td>option</td>
            <td>policy on placement of a left curly brace (<code>'{'</code>)</td>
            <td><a href="property_types.html#lcurly">Left Curly Brace Policy</a></td>
            <td><code>eol</code></td>
            <td>3.0</td>
          </tr>
          <tr>
            <td>ignoreEnums</td>
            <td>If true, Check will ignore enums when left curly brace policy is EOL</td>
            <td><a href="property_types.html#boolean">Boolean</a></td>
            <td>true</td>
            <td>6.9</td>
          </tr>
          <tr>
            <td>tokens</td>
            <td>tokens to check</td>

            <td>subset of tokens
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#ANNOTATION_DEF">
                ANNOTATION_DEF</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#CLASS_DEF">
                CLASS_DEF</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#CTOR_DEF">
                CTOR_DEF</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#ENUM_CONSTANT_DEF">
                ENUM_CONSTANT_DEF</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#ENUM_DEF">
                ENUM_DEF</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#INTERFACE_DEF">
                INTERFACE_DEF</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LAMBDA">
                LAMBDA</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_CASE">
                LITERAL_CASE</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_CATCH">
                LITERAL_CATCH</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_DEFAULT">
                LITERAL_DEFAULT</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_DO">
                LITERAL_DO</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_ELSE">
                LITERAL_ELSE</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_FINALLY">
                LITERAL_FINALLY</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_FOR">
                LITERAL_FOR</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_IF">
                LITERAL_IF</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_SWITCH">
                LITERAL_SWITCH</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_SYNCHRONIZED">
                LITERAL_SYNCHRONIZED</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_TRY">
                LITERAL_TRY</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_WHILE">
                LITERAL_WHILE</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#METHOD_DEF">
                METHOD_DEF</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#OBJBLOCK">
                OBJBLOCK</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#STATIC_INIT">
                STATIC_INIT</a>.
            </td>

            <td>
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#ANNOTATION_DEF">
                ANNOTATION_DEF</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#CLASS_DEF">
                CLASS_DEF</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#CTOR_DEF">
                CTOR_DEF</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#ENUM_CONSTANT_DEF">
                ENUM_CONSTANT_DEF</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#ENUM_DEF">
                ENUM_DEF</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#INTERFACE_DEF">
                INTERFACE_DEF</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LAMBDA">
                LAMBDA</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_CASE">
                LITERAL_CASE</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_CATCH">
                LITERAL_CATCH</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_DEFAULT">
                LITERAL_DEFAULT</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_DO">
                LITERAL_DO</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_ELSE">
                LITERAL_ELSE</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_FINALLY">
                LITERAL_FINALLY</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_FOR">
                LITERAL_FOR</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_IF">
                LITERAL_IF</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_SWITCH">
                LITERAL_SWITCH</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_SYNCHRONIZED">
                LITERAL_SYNCHRONIZED</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_TRY">
                LITERAL_TRY</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_WHILE">
                LITERAL_WHILE</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#METHOD_DEF">
                METHOD_DEF</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#OBJBLOCK">
                OBJBLOCK</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#STATIC_INIT">
                STATIC_INIT</a>.
            </td>
            <td>3.0</td>
          </tr>
        </table>
      </subsection>

      <subsection name="Examples" id="LeftCurly_Examples">
        <p> To configure the check: </p>
        <source>
&lt;module name=&quot;LeftCurly&quot;/&gt;
        </source>
        <p>
          To configure the check to apply the <code>nl</code> policy to
          type blocks:
        </p>
        <source>
&lt;module name=&quot;LeftCurly&quot;&gt;
  &lt;property name=&quot;option&quot; value=&quot;nl&quot;/&gt;
  &lt;property name=&quot;tokens&quot; value=&quot;CLASS_DEF,INTERFACE_DEF&quot;/&gt;
&lt;/module&gt;
        </source>
        <p>
          An example of how to configure the check to validate enum definitions:
        </p>
        <source>
&lt;module name="LeftCurly"&gt;
  &lt;property name="ignoreEnums" value="false"/&gt;
&lt;/module&gt;
        </source>
      </subsection>

      <subsection name="Example of Usage" id="LeftCurly_Example_of_Usage">
        <ul>
          <li>
            <a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources+filename%3Agoogle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+LeftCurly">
            Google Style</a>
          </li>
          <li>
            <a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources+filename%3Asun_checks.xml+repo%3Acheckstyle%2Fcheckstyle+LeftCurly">
            Sun Style</a>
          </li>
          <li>
            <a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+LeftCurly">
            Checkstyle Style</a>
          </li>
        </ul>
      </subsection>

      <subsection name="Error Messages" id="LeftCurly_Error_Messages">
        <ul>
          <li>
            <a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fblocks+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22line.break.after%22">
            line.break.after</a>
          </li>
          <li>
            <a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fblocks+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22line.new%22">
            line.new</a>
          </li>
          <li>
            <a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fblocks+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22line.previous%22">
            line.previous</a>
          </li>
        </ul>
        <p>
          All messages can be customized if the default message doesn't suit you.
          Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
        </p>
      </subsection>

      <subsection name="Package" id="LeftCurly_Package">
        <p> com.puppycrawl.tools.checkstyle.checks.blocks </p>
      </subsection>

      <subsection name="Parent Module" id="LeftCurly_Parent_Module">
        <p> <a href="config.html#TreeWalker">TreeWalker</a> </p>
      </subsection>
    </section>

    <section name="NeedBraces">
      <subsection name="Description" id="NeedBraces_Description">
        <p>Since Checkstyle 3.0</p>
        <p> Checks for braces around code blocks. </p>
      </subsection>

      <subsection name="Properties" id="NeedBraces_Properties">
        <table>
          <tr>
            <th>name</th>
            <th>description</th>
            <th>type</th>
            <th>default value</th>
            <th>since</th>
          </tr>
          <tr>
            <td>allowSingleLineStatement</td>
            <td>allows single-line statements without braces</td>
            <td><a href="property_types.html#boolean">Boolean</a></td>
            <td>false</td>
            <td>6.5</td>
          </tr>
          <tr>
            <td>allowEmptyLoopBody</td>
            <td>allows loops with empty bodies</td>
            <td><a href="property_types.html#boolean">Boolean</a></td>
            <td>false</td>
            <td>6.12.1</td>
          </tr>
          <tr>
            <td>tokens</td>
            <td>tokens to check</td>

            <td>subset of tokens
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_DO">
                LITERAL_DO</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_ELSE">
                LITERAL_ELSE</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_FOR">
                LITERAL_FOR</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_IF">
                LITERAL_IF</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_WHILE">
                LITERAL_WHILE</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_CASE">
                LITERAL_CASE</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_DEFAULT">
                LITERAL_DEFAULT</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LAMBDA">
                LAMBDA</a>.
            </td>

            <td>
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_DO">
                LITERAL_DO</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_ELSE">
                LITERAL_ELSE</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_FOR">
                LITERAL_FOR</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_IF">
                LITERAL_IF</a>,
              <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_WHILE">
                LITERAL_WHILE</a>.
            </td>
            <td>3.0</td>
          </tr>
        </table>
      </subsection>

      <subsection name="Examples" id="NeedBraces_Examples">
        <p> To configure the check: </p>
        <source>
&lt;module name=&quot;NeedBraces&quot;/&gt;
        </source>

        <p>
          To configure the check for <code>if</code> and
          <code> else</code> blocks:
        </p>
        <source>
&lt;module name=&quot;NeedBraces&quot;&gt;
  &lt;property name=&quot;tokens&quot; value=&quot;LITERAL_IF, LITERAL_ELSE&quot;/&gt;
&lt;/module&gt;
        </source>

        <p>
          To configure the check to allow single-line statements
          (<code>if, while, do-while, for</code>) without braces:
        </p>
        <source>
&lt;module name=&quot;NeedBraces&quot;&gt;
  &lt;property name=&quot;allowSingleLineStatement&quot; value=&quot;true&quot;/&gt;
&lt;/module&gt;
        </source>

        <p>
          Next statements won't be violated by Check:
        </p>
        <source>
if (obj.isValid()) return true; // OK
while (obj.isValid()) return true; // OK
do this.notify(); while (o != null); // OK
for (int i = 0; ; ) this.notify(); // OK
        </source>

        <p>
          To configure the Check to allow <code>case, default</code> single-line statements
          without braces:
        </p>
        <source>
&lt;module name=&quot;NeedBraces&quot;&gt;
  &lt;property name=&quot;tokens&quot; value=&quot;LITERAL_CASE, LITERAL_DEFAULT&quot;/&gt;
  &lt;property name=&quot;allowSingleLineStatement&quot; value=&quot;true&quot;/&gt;
&lt;/module&gt;
        </source>

        <p>
          Next statements won't be violated by Check:
        </p>
        <source>
switch (num) {
  case 1: counter++; break; // OK
  case 6: counter += 10; break; // OK
  default: counter = 100; break; // OK
}
        </source>
        <p>
          To configure the check to allow loops (<code>while, for</code>) with empty bodies:
        </p>
          <source>
&lt;module name=&quot;NeedBraces&quot;&gt;
  &lt;property name=&quot;allowEmptyLoopBody&quot; value=&quot;true&quot;/&gt;
&lt;/module&gt;
          </source>

          <p>
              Next statements won't be violated by Check:
          </p>
          <source>
while (value.incrementValue() &lt; 5); // OK
for(int i = 0; i &lt; 10; value.incrementValue()); // OK
          </source>
      </subsection>

      <subsection name="Example of Usage" id="NeedBraces_Example_of_Usage">
        <ul>
          <li>
            <a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources+filename%3Agoogle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+NeedBraces">
            Google Style</a>
          </li>
          <li>
            <a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources+filename%3Asun_checks.xml+repo%3Acheckstyle%2Fcheckstyle+NeedBraces">
            Sun Style</a>
          </li>
          <li>
            <a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+NeedBraces">
            Checkstyle Style</a>
          </li>
        </ul>
      </subsection>

      <subsection name="Error Messages" id="NeedBraces_Error_Messages">
        <ul>
          <li>
            <a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fblocks+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22needBraces%22">
            needBraces</a>
          </li>
        </ul>
        <p>
          All messages can be customized if the default message doesn't suit you.
          Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
        </p>
      </subsection>

      <subsection name="Package" id="NeedBraces_Package">
        <p> com.puppycrawl.tools.checkstyle.checks.blocks </p>
      </subsection>

      <subsection name="Parent Module" id="NeedBraces_Parent_Module">
        <p> <a href="config.html#TreeWalker">TreeWalker</a> </p>
      </subsection>
    </section>

    <section name="RightCurly">
      <subsection name="Description" id="RightCurly_Description">
        <p>Since Checkstyle 3.0</p>
        <p>
          Checks the placement of right curly braces (<code>'}'</code>)
          for if-else, try-catch-finally blocks, while-loops, for-loops,
          method definitions, class definitions, constructor definitions,
          instance and static initialization blocks.
          The policy to verify is specified using the property <code> option</code>.
          For right curly brace of expression blocks please follow issue
          <a href="https://github.com/checkstyle/checkstyle/issues/5945">#5945</a>.
        </p>
      </subsection>

      <subsection name="Properties" id="RightCurly_Properties">
        <table>
          <tr>
            <th>name</th>
            <th>description</th>
            <th>type</th>
            <th>default value</th>
            <th>since</th>
          </tr>
          <tr>
            <td>option</td>
            <td>policy on placement of a right curly brace (<code>'}'</code>)</td>
            <td><a href="property_types.html#rcurly">Right Curly Brace Policy</a></td>
            <td><code>same</code></td>
            <td>3.0</td>
          </tr>
          <tr>
            <td>shouldStartLine</td>
            <td>should we check if <code>'}'</code>
            starts line.</td>
            <td><a href="property_types.html#boolean">Boolean</a></td>
            <td><code>true</code></td>
            <td>4.2</td>
          </tr>
          <tr>
            <td>tokens</td>
            <td>tokens to check</td>

            <td>subset of tokens <a
             href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_TRY">
                LITERAL_TRY</a>,
            <a
             href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_CATCH">
                LITERAL_CATCH</a>,
            <a
             href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_FINALLY">
                LITERAL_FINALLY</a>,
            <a
             href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_IF">
                LITERAL_IF</a>,
            <a
             href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_ELSE">
                LITERAL_ELSE</a>,
            <a
             href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#CLASS_DEF">
                CLASS_DEF</a>,
            <a
             href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#METHOD_DEF">
                METHOD_DEF</a>,
            <a
             href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#CTOR_DEF">
                CTOR_DEF</a>,
             <a
             href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_FOR">
                LITERAL_FOR</a>,
            <a
             href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_WHILE">
                LITERAL_WHILE</a>,
            <a
             href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_DO">
                LITERAL_DO</a>,
            <a
             href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#STATIC_INIT">
                STATIC_INIT</a>,
            <a
             href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#INSTANCE_INIT">
                INSTANCE_INIT</a>,
            <a
             href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LAMBDA">
                LAMBDA</a>.</td>

            <td><a
             href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_TRY">
                LITERAL_TRY</a>,
            <a
             href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_CATCH">
                LITERAL_CATCH</a>,
            <a
             href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_FINALLY">
                LITERAL_FINALLY</a>,
            <a
             href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_IF">
                LITERAL_IF</a>,
            <a
             href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_ELSE">
                LITERAL_ELSE</a>.</td>
            <td>3.0</td>
          </tr>
        </table>
      </subsection>

      <subsection name="Examples" id="RightCurly_Examples">
        <p> To configure the check: </p>
        <source>
&lt;module name=&quot;RightCurly&quot;/&gt;
        </source>

        <p>
          To configure the check with policy <code>alone</code> for <code> else</code> and <a
             href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#METHOD_DEF">
          METHOD_DEF</a>
          tokens:
        </p>
        <source>
&lt;module name=&quot;RightCurly&quot;&gt;
  &lt;property name=&quot;option&quot; value=&quot;alone&quot;/&gt;
  &lt;property name=&quot;tokens&quot; value=&quot;LITERAL_ELSE, METHOD_DEF&quot;/&gt;
&lt;/module&gt;
        </source>
      </subsection>

      <subsection name="Example of Usage" id="RightCurly_Example_of_Usage">
        <ul>
          <li>
            <a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources+filename%3Agoogle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+RightCurly">
            Google Style</a>
          </li>
          <li>
            <a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources+filename%3Asun_checks.xml+repo%3Acheckstyle%2Fcheckstyle+RightCurly">
            Sun Style</a>
          </li>
          <li>
            <a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+RightCurly">
            Checkstyle Style</a>
          </li>
        </ul>
      </subsection>

      <subsection name="Error Messages" id="RightCurly_Error_Messages">
        <ul>
          <li>
            <a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fblocks+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22line.alone%22">
            line.alone</a>
          </li>
          <li>
            <a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fblocks+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22line.break.before%22">
            line.break.before</a>
          </li>
          <li>
            <a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fblocks+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22line.new%22">
            line.new</a>
          </li>
          <li>
            <a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fblocks+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22line.same%22">
            line.same</a>
          </li>
        </ul>
        <p>
          All messages can be customized if the default message doesn't suit you.
          Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
        </p>
      </subsection>

      <subsection name="Package" id="RightCurly_Package">
        <p> com.puppycrawl.tools.checkstyle.checks.blocks </p>
      </subsection>

      <subsection name="Parent Module" id="RightCurly_Parent_Module">
        <p> <a href="config.html#TreeWalker">TreeWalker</a> </p>
      </subsection>
    </section>
  </body>
</document>




© 2015 - 2025 Weber Informatics LLC | Privacy Policy