Skip to content

Commit

Permalink
Issue checkstyle#7613: Update doc for MutableException
Browse files Browse the repository at this point in the history
  • Loading branch information
arinmodi committed Nov 6, 2022
1 parent b1c4475 commit 250582f
Show file tree
Hide file tree
Showing 2 changed files with 260 additions and 0 deletions.
Expand Up @@ -66,6 +66,132 @@
* <pre>
* &lt;module name=&quot;MutableException&quot;/&gt;
* </pre>
* <p>Example:</p>
* <pre>
* class FirstClass extends Exception {
* private int code; // OK, Class-Name doesn't match with default pattern
*
* public FirstClass() {
* code = 1;
* }
* }
*
* class MyException extends Exception {
* private int code; // violation, The field 'code' must be declared final
*
* public MyException() {
* code = 2;
* }
* }
*
* class MyThrowable extends Throwable {
* final int code;
* String message; // violation, The field 'message' must be declared final
*
* public MyThrowable(int code, String message) {
* this.code = code;
* this.message = message;
* }
* }
*
* class BadException extends java.lang.Exception {
* int code; // violation, The field 'code' must be declared final
*
* public BadException(int code) {
* this.code = code;
* }
* }
* </pre>
* <p>
* To configure the check so that it only checks for class names
* that match pattern:
* </p>
* <pre>
* &lt;module name=&quot;MutableException&quot;&gt;
* &lt;property name=&quot;format&quot; value=&quot;^.*Exception$&quot;/&gt;
* &lt;/module&gt;
* </pre>
* <p>Example:</p>
* <pre>
* class FirstClass extends Exception {
* private int code; // OK, Class-Name doesn't match with Given pattern
*
* public FirstClass() {
* code = 1;
* }
* }
*
* class MyException extends Exception {
* private int code; // violation, The field 'code' must be declared final
*
* public MyException() {
* code = 2;
* }
* }
*
* class MyThrowable extends Throwable {
* final int code; // OK
* String message; // OK
*
* public MyThrowable(int code, String message) {
* this.code = code;
* this.message = message;
* }
* }
*
* class BadException extends java.lang.Exception {
* int code; // violation, The field 'code' must be declared final
*
* public BadException(int code) {
* this.code = code;
* }
* }
* </pre>
* <p>
* To configure the check so that it only checks for type names used in 'extends'
* that match pattern:
* </p>
* <pre>
* &lt;module name=&quot;MutableException&quot;&gt;
* &lt;property name=&quot;extendedClassNameFormat&quot; value=&quot;^.*Throwable$&quot;/&gt;
* &lt;/module&gt;
* </pre>
* <p>Example:</p>
* <pre>
* class FirstClass extends Exception {
* private int code; // OK, Extended-Class-Name doesn't match with Given pattern
*
* public FirstClass() {
* code = 1;
* }
* }
*
* class MyException extends Exception {
* private int code; // OK, Extended-Class-Name doesn't match with Given pattern
*
* public MyException() {
* code = 2;
* }
* }
*
* class MyThrowable extends Throwable {
* final int code; // OK
* String message; // violation, The field 'message' must be declared final
*
* public MyThrowable(int code, String message) {
* this.code = code;
* this.message = message;
* }
* }
*
* class BadException extends java.lang.Exception {
* int code; // OK, Extended-Class-Name doesn't match with Given pattern
*
* public BadException(int code) {
* this.code = code;
* }
* }
* </pre>
* <p>
* Parent is {@code com.puppycrawl.tools.checkstyle.TreeWalker}
* </p>
Expand Down
134 changes: 134 additions & 0 deletions src/xdocs/config_design.xml
Expand Up @@ -789,6 +789,140 @@ public interface Test2 { // violation
<source>
&lt;module name=&quot;MutableException&quot;/&gt;
</source>
<p>Example:</p>
<div class="wrapper">
<source>
class FirstClass extends Exception {
private int code; // OK, Class-Name doesn't match with default pattern

public FirstClass() {
code = 1;
}
}

class MyException extends Exception {
private int code; // violation, The field 'code' must be declared final

public MyException() {
code = 2;
}
}

class MyThrowable extends Throwable {
final int code;
String message; // violation, The field 'message' must be declared final

public MyThrowable(int code, String message) {
this.code = code;
this.message = message;
}
}

class BadException extends java.lang.Exception {
int code; // violation, The field 'code' must be declared final

public BadException(int code) {
this.code = code;
}
}
</source>
</div>

<p>
To configure the check so that it only checks for class names
that match pattern:
</p>
<source>
&lt;module name=&quot;MutableException&quot;&gt;
&lt;property name=&quot;format&quot; value=&quot;^.*Exception$&quot;/&gt;
&lt;/module&gt;
</source>
<p>Example:</p>
<div class="wrapper">
<source>
class FirstClass extends Exception {
private int code; // OK, Class-Name doesn't match with Given pattern

public FirstClass() {
code = 1;
}
}

class MyException extends Exception {
private int code; // violation, The field 'code' must be declared final

public MyException() {
code = 2;
}
}

class MyThrowable extends Throwable {
final int code; // OK
String message; // OK

public MyThrowable(int code, String message) {
this.code = code;
this.message = message;
}
}

class BadException extends java.lang.Exception {
int code; // violation, The field 'code' must be declared final

public BadException(int code) {
this.code = code;
}
}
</source>
</div>

<p>
To configure the check so that it only checks for type names used in 'extends'
that match pattern:
</p>
<source>
&lt;module name=&quot;MutableException&quot;&gt;
&lt;property name=&quot;extendedClassNameFormat&quot; value=&quot;^.*Throwable$&quot;/&gt;
&lt;/module&gt;
</source>
<p>Example:</p>
<div class="wrapper">
<source>
class FirstClass extends Exception {
private int code; // OK, Extended-Class-Name doesn't match with Given pattern

public FirstClass() {
code = 1;
}
}

class MyException extends Exception {
private int code; // OK, Extended-Class-Name doesn't match with Given pattern

public MyException() {
code = 2;
}
}

class MyThrowable extends Throwable {
final int code; // OK
String message; // violation, The field 'message' must be declared final

public MyThrowable(int code, String message) {
this.code = code;
this.message = message;
}
}

class BadException extends java.lang.Exception {
int code; // OK, Extended-Class-Name doesn't match with Given pattern

public BadException(int code) {
this.code = code;
}
}
</source>
</div>
</subsection>

<subsection name="Example of Usage" id="MutableException_Example_of_Usage">
Expand Down

0 comments on commit 250582f

Please sign in to comment.