Since Checkstyle 3.2
Checks for illegal tokens. By default, labels are prohibited.
Rationale: Certain language features can harm readability, lead to confusion or are not obvious to novice developers. Other features may be discouraged in certain frameworks, such as not having native methods in Enterprise JavaBeans components.
name | description | type | default value | since |
---|---|---|---|---|
tokens | tokens to check | set of any supported tokens | LABELED_STAT . | 3.2 |
To configure the check:
<module name="Checker"> <module name="TreeWalker"> <module name="IllegalToken"/> </module> </module>
Example:
public void myTest() { outer: // violation for (int i = 0; i < 5; i++) { if (i == 1) { break outer; } } }
To configure the check to report violation on token LITERAL_NATIVE:
<module name="Checker"> <module name="TreeWalker"> <module name="IllegalToken"> <property name="tokens" value="LITERAL_NATIVE"/> </module> </module> </module>
Example:
public native void myTest(); // violation
All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.
com.puppycrawl.tools.checkstyle.checks.coding