src/xdocs/property_types.xml (602 lines of code) (raw):

<?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>Property Types</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="Overview"> <p> Checkstyle is configured using properties, which are string representations. This document describes how these string representations are mapped to typed properties. </p> </section> <section name="integer"> <p> This property represents an integer. The string representation is parsed using the <code>java.lang.Integer</code> class. </p> </section> <section name="string"> <p> This property represents a string. The literal string representation is used. </p> </section> <section name="boolean"> <p> This property represents a boolean. The default value is <code>false</code>. The following string representations will map to <code>true</code>: </p> <ul> <li><code>yes</code></li> <li><code>true</code></li> <li><code>on</code></li> </ul> <p>Anything else will map to <code>false</code>.</p> </section> <section name="stringSet"> <p> This property represents a set of strings. The string representation is parsed as a set of comma (',') separated strings. </p> <p> Alternatively, this property can be supplied multiple times which is equivalent to a set of comma separated strings. For example, the following: </p> <source> &lt;property name=&quot;tokens&quot; value=&quot;DIV_ASSIGN,PLUS_ASSIGN&quot;/&gt; </source> <p>can instead be expressed as:</p> <source> &lt;property name=&quot;tokens&quot; value=&quot;DIV_ASSIGN&quot;/&gt; &lt;property name=&quot;tokens&quot; value=&quot;PLUS_ASSIGN&quot;/&gt; </source> </section> <section name="intSet"> <p> This property represents a set of integers. The string representation is parsed as a set of comma (',') separated integers that are parsed using the <code>java.lang.Integer</code> class. </p> <p> Alternatively, this property can be supplied multiple times which is equivalent to a set of comma separated integers. For example, the following: </p> <source> &lt;property name=&quot;tokens&quot; value=&quot;42,666&quot;/&gt; </source> <p>can instead be expressed as:</p> <source> &lt;property name=&quot;tokens&quot; value=&quot;42&quot;/&gt; &lt;property name=&quot;tokens&quot; value=&quot;666&quot;/&gt; </source> </section> <section name="regexp"> <p> This property represents a regular expression. The string representation is parsed using <a href="https://docs.oracle.com/javase/7/docs/api/index.html?java/util/regex/package-summary.html">java.util.regex package</a>. </p> </section> <section name="uri"> <p> This property represents a URI. The string representation is parsed using a custom routine to analyze what type of URI the string is. It can be a URL, regular file, or a resource path. It will try loading the path as a URL first, then as a file that must exist, and then finally as a resource on the classpath. </p> </section> <section name="lineSeparator"> <p> This property represents the policy for line returns. The following table describes the valid options: </p> <table summary="line separator options"> <tr> <td>Option</td> <td>Definition</td> </tr> <tr> <td><code>crlf</code></td> <td>Windows-style</td> </tr> <tr> <td><code>cr</code></td> <td>Mac-style</td> </tr> <tr> <td><code>lf</code></td> <td>Unix-style</td> </tr> <tr> <td><code>lf_cr_crlf</code></td> <td>lf, cr or crlf</td> </tr> <tr> <td><code>system</code></td> <td>system default</td> </tr> </table> </section> <section name="parenPad"> <p> This property represents the policy for padding with white space. The following table describes the valid options: </p> <table summary="padding options"> <tr> <td>Option</td> <td>Definition</td> </tr> <tr> <td><code>nospace</code></td> <td> Do not pad. For example, <code>method(a, b);</code> </td> </tr> <tr> <td><code>space</code></td> <td> Ensure padding. For example, <code>method( a, b );</code> </td> </tr> </table> </section> <section name="wrapOp"> <p> This property represents the policy for wrapping lines. The following table describes the valid options: </p> <table summary="wrap options"> <tr> <td>Option</td> <td>Definition</td> </tr> <tr> <td><code>nl</code></td> <td> The token must be on a new line. For example: <pre> someVariable = aBigVariableNameToMakeThings + "this may work" + lookVeryInteresting; </pre> </td> </tr> <tr> <td><code>eol</code></td> <td> The token must be at the end of the line. For example: <pre> someVariable = aBigVariableNameToMakeThings + "this may work" + lookVeryInteresting; </pre> </td> </tr> </table> </section> <section name="block"> <p> This property represents the policy for checking block statements. The following table describes the valid options: </p> <table summary="block options"> <tr> <td>Option</td> <td>Definition</td> </tr> <tr> <td><code>text</code></td> <td> Require that there is some text in the block. For example: <pre> catch (Exception ex) { // This is a bad coding practice } </pre> </td> </tr> <tr> <td><code>statement</code></td> <td> Require that there is a statement in the block. For example: <pre> finally { lock.release(); } </pre> </td> </tr> </table> </section> <section name="lcurly"> <p> This property represents the policy for checking the placement of a left curly brace (<code>'{'</code>). The following table describes the valid options: </p> <table summary="left curly options"> <tr> <td>Option</td> <td>Definition</td> </tr> <tr> <td><code>eol</code></td> <td> The brace must always be on the end of the line. For example: <pre> if (condition) { ... </pre> </td> </tr> <tr> <td><code>nl</code></td> <td> The brace must always be on a new line. For example: <pre> if (condition) { ... </pre> </td> </tr> <tr> <td><code>nlow</code></td> <td> If the statement/expression/declaration connected to the brace spans multiple lines, than apply <code>nl</code> rule. Otherwise apply the <code>eol</code> rule. <code>nlow</code> is a mnemonic for "new line on wrap". For the example above Checkstyle will enforce: <pre> if (condition) { ... </pre> But for a statement spanning multiple lines, Checkstyle will enforce: <pre> if (condition1 &amp;&amp; condition2 &amp;&amp; condition3 &amp;&amp; condition4) { ... </pre> </td> </tr> </table> </section> <section name="rcurly"> <p> This property represents the policy for checking the placement of a right curly brace (<code>'}'</code>). The following table describes the valid options: </p> <table summary="right curly options"> <tr> <td>Option</td> <td>Definition</td> </tr> <tr> <td><code>same</code></td> <td> The brace should be on the same line as the next part of a multi-block statement (one that directly contains multiple blocks: if/else-if/else or try/catch/finally). It also allows single-line format of multi-block statements. <p>Examples:</p> <pre> // try-catch-finally blocks try { ... <b>}</b> catch (Exception ex) { // this is OK ... <b>}</b> finally { // this is OK ... } try { ... <b>}</b> // this is NOT OK, not on the same line as the next part of a multi-block statement catch (Exception ex) { ... <b>}</b> // this is NOT OK, not on the same line as the next part of a multi-block statement finally { ... } // if-else blocks if (a &#62; 0) { ... <b>}</b> else { // this is OK ... } if (a &#62; 0) { ... <b>}</b> // this is NOT OK, not on the same line as the next part of a multi-block statement else { ... } if (a > 0) { ... <b>}</b> int i = 5; // this is NOT OK, next part of a multi-block statement is absent // Single line blocks will rise violations, because right curly // brace is not on the same line as the next part of a multi-block // statement, it just ends the line. public long getId() {return id;<b>}</b> // this is NOT OK Thread t = new Thread(new Runnable() { @Override public void run() { ... <b>}</b> // this is NOT OK, brace is not on the same line as the next part // of a multi-block statement <b>}</b>); // this is OK, allowed for better code readability if (a &#62; 0) { ... <b>}</b> // OK, single-line multi-block statement if (a &#62; 0) { ... } else { ... <b>}</b> // OK, single-line multi-block statement if (a &#62; 0) { ... } else { ... <b>}</b> // OK, single-line multi-block statement </pre> </td> </tr> <tr> <td><code>alone</code></td> <td> The brace must be alone on the line. For example: <pre> try { ... <b>}</b> finally { ... <b>}</b> </pre> </td> </tr> <tr> <td><code>alone_or_singleline</code></td> <td> The brace must be alone on the line, yet single-line format of block is allowed. For example: <pre> // Brace is alone on the line try { ... <b>}</b> finally { ... <b>}</b> // Single-line format of block public long getId() { return id; <b>}</b> </pre> </td> </tr> </table> </section> <section name="scope"> <p>This property represents a Java scope. The scope is treated inclusively (as javadoc does): 'package' means all 'package', 'protected' and 'public' methods/fields/classes. The valid options are:</p> <ul> <li><code>nothing</code></li> <li><code>public</code></li> <li><code>protected</code></li> <li><code>package</code></li> <li><code>private</code></li> <li><code>anoninner</code></li> </ul> </section> <section name="access_modifiers"> <p>This property represents Java access modifiers.</p> <ul> <li><code>public</code></li> <li><code>protected</code></li> <li><code>package</code></li> <li><code>private</code></li> </ul> </section> <section name="severity"> <p> This property represents the severity level of a check violation. The valid options are: </p> <ul> <li><code>ignore</code></li> <li><code>info</code></li> <li><code>warning</code></li> <li><code>error</code></li> </ul> </section> <section name="importOrder"> <p> This property represents the policy for checking imports order. The following table describes the valid options: </p> <table summary="import order options"> <tr> <td>Option</td> <td>Definition</td> </tr> <tr> <td><code>top</code></td> <td>All static imports are at the top. For example: <pre> import static a.b.C.*; import static x.y.Z.*; import a.b.D; import x.y.Z;</pre> </td> </tr> <tr> <td><code>above</code></td> <td>All static imports are above the local group. For example: <pre> import static a.b.C.*; import a.b.D; import static x.y.Z.*; import x.y.Z;</pre> </td> </tr> <tr> <td><code>inflow</code></td> <td>All static imports are processed like non static imports. For example: <pre> import static a.b.C.*; import a.b.D; import x.y.Z; import static x.y.Z.*;</pre> </td> </tr> <tr> <td><code>under</code></td> <td>All static imports are under the local group. For example: <pre> import a.b.D; import static a.b.C.*; import x.y.Z; import static x.y.Z.*;</pre> </td> </tr> <tr> <td><code>bottom</code></td> <td>All static imports are at the bottom. For example: <pre> import a.b.D; import x.y.Z; import static a.b.C.*; import static x.y.Z.*;</pre> </td> </tr> </table> </section> <section name="elementStyle"> <p> This property represents the policy for the styles for defining elements in an annotation. The following table describes the valid options: </p> <table summary="elementStyle options"> <tr> <td>Option</td> <td>Definition</td> </tr> <tr> <td><code>expanded</code></td> <td> The expanded version is sometimes referred to as "named parameters" in other languages. Example: <pre>@SuppressWarnings(value={"unchecked","unused",})</pre> </td> </tr> <tr> <td><code>compact</code></td> <td> This style can only be used when there is an element called 'value' which is either the sole element or all other elements have default values. Examples: <pre>@SuppressWarnings({"unchecked","unused",})</pre> and: <pre>@SuppressWarnings("unchecked")</pre> </td> </tr> <tr> <td><code>compact_no_array</code></td> <td> It is similar to the <code>compact</code> style but single value arrays are flagged. With annotations a single value array does not need to be placed in an array initializer. This style can only be used when there is an element called 'value' which is either the sole element or all other elements have default values. Example: <pre>@SuppressWarnings("unchecked")</pre> </td> </tr> <tr> <td><code>ignore</code></td> <td> Anything goes. </td> </tr> </table> </section> <section name="closingParens"> <p> This property represents the policy for the styles for the ending parenthesis. The following table describes the valid options: </p> <table summary="closingParens options"> <tr> <td>Option</td> <td>Definition</td> </tr> <tr> <td><code>always</code></td> <td> Example: <pre>@Deprecated()</pre> </td> </tr> <tr> <td><code>never</code></td> <td> Example: <pre>@Deprecated</pre> </td> </tr> <tr> <td><code>ignore</code></td> <td> Anything goes. </td> </tr> </table> </section> <section name="trailingArrayComma"> <p> This property represents the policy for the styles for the trailing array comma. The following table describes the valid options: </p> <table summary="trailingArrayComma options"> <tr> <td>Option</td> <td>Definition</td> </tr> <tr> <td><code>always</code></td> <td> Example: <pre>@SuppressWarnings(value={"unchecked","unused",})</pre> </td> </tr> <tr> <td><code>never</code></td> <td> Example: <pre>@SuppressWarnings(value={"unchecked","unused"})</pre> </td> </tr> <tr> <td><code>ignore</code></td> <td> Anything goes. </td> </tr> </table> </section> </body> </document>