EmptyBlock
+ Description
+
+ Checks for empty blocks.
+
+ Properties
+
+
+
+ | option |
+ policy on block contents |
+ block policy |
+ stmt |
+
+
+ | tokens |
+ blocks to check |
+ subset of tokens LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY,
+ LITERAL_IF, LITERAL_FOR, LITERAL_TRY, LITERAL_WHILE, STATIC_INIT |
+ all tokens |
+
+
-Missing Braces
+ Examples
+
+ To configure the check:
+
+
+<module name="EmptyBlock"/>
+
+
+ To configure the check for the text policy and only
+ catch blocks:
+
+
+<module name="EmptyBlock">
+ <property name="option" value="text"/>
+ <property name="tokens" value="LITERAL_CATCH"/>
+</module>
+
+ Package
+
+ com.puppycrawl.tools.checkstyle.checks
+
+ Parent Module
+
+ TreeWalker
+
+ LeftCurly Checks Description
+
+ There are three checks for the placement of left curly braces ('
+ {') for code blocks:
+
+
+ -
+ MethodLeftCurly checks for methods and constructors.
+ It's token set is METHOD_DEF and CTOR_DEF.
+
+ -
+ TypeLeftCurly checks for classes and interfaces. It's
+ token set is CLASS_DEF and INTERFACE_DEF.
+
+ -
+ OtherLeftCurly checks for blocks other than methods,
+ constructors, and types. It's token set is LITERAL_CATCH, LITERAL_DO,
+ LITERAL_ELSE, LITERAL_FINALLY, LITERAL_FOR, LITERAL_IF, LITERAL_SWITCH,
+ LITERAL_SYNCHRONIZED, LITERAL_TRY, and LITERAL_WHILE.
+
+
+
+ All left curly brace checks have a policy to verify that is specified using
+ property option. Policies eol and
+ nlow take into account property maxLineLength.
+
+ Properties other than tokens
+
+
+
+ | option |
+ policy on placement of a left curly brace ('{') |
+ left curly brace policy |
+ eol |
+
+
+ | maxLineLength |
+ maximum number of characters in a line |
+ integer |
+ 80 |
+
+
-The property checkstyle.ignore.braces controls
-whether to ignore checking for missing braces {}'s
-for the following constructs:
+ Examples
+
+ To configure the OtherLeftCurly check:
+
+
+<module name="OtherLeftCurly"/>
+
+
+ To configure the MethodLeftCurly check for the nl policy and maximum
+ line length 120:
+
+
+<module name="MethodLeftCurly">
+ <property name="option" value="nl"/>
+ <property name="maxLineLength" value="120"/>
+</module>
+
+ Package
+
+ com.puppycrawl.tools.checkstyle.checks
+
+ Parent Module
+
+ TreeWalker
+
+ NeedBraces Description
+
+ Checks for braces around code blocks.
+
+ Properties
+
+
+
+ | tokens |
+ blocks to check |
+ subset of tokens LITERAL_DO, LITERAL_ELSE, LITERAL_IF, LITERAL_FOR,
+ LITERAL_WHILE |
+ all tokens |
+
+
-
- - if/else
- - while
- - for
- - do/while
-
+ Examples
+
+ To configure the check:
+
+
+<module name="NeedBraces"/>
+
+
+ To configure the check for if and
+ else blocks:
+
+
+<module name="NeedBraces">
+ <property name="tokens" value="LITERAL_IF, LITERAL_ELSE"/>
+</module>
+
+ Package
+
+ com.puppycrawl.tools.checkstyle.checks
+
+ Parent Module
+
+ TreeWalker
+
+ RightCurly Description
+
+ Checks the placement of right curly braces ('}') for
+ else, try, and catch
+ tokens. The policy to verify is specified using property
+ option.
+
+ Properties
+
+
+
+ | option |
+ policy on placement of a right curly brace ('}') |
+ right curly brace policy |
+ same |
+
+
+ | tokens |
+ blocks to check |
+ subset of tokens LITERAL_CATCH, LITERAL_ELSE, LITERAL_TRY |
+ LITERAL_CATCH, LITERAL_ELSE, LITERAL_TRY |
+
+
- The property type is boolean and
-defaults to false.
+ Examples
+
+ To configure the check:
+
+
+<module name="RightCurly"/>
+
+
+ To configure the check with policy alone for
+ else tokens:
+
+
+<module name="RightCurly">
+ <property name="option" value="alone"/>
+ <property name="tokens" value="LITERAL_ELSE"/>
+</module>
+
+ Package
+
+ com.puppycrawl.tools.checkstyle.checks
+
+ Parent Module
+
+ TreeWalker
+
+ |
+