Checks for blocks |
![]() |
EmptyBlockDescriptionChecks for empty blocks. Properties
ExamplesTo 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> Packagecom.puppycrawl.tools.checkstyle.checks.blocks Parent ModuleLeftCurlyDescriptionChecks for the placement of left curly braces ('{') for code blocks. The policy to verify is specified using property option. Policies eol and nlow take into account property maxLineLength. Properties
ExamplesTo configure the check: <module name="LeftCurly"/> To configure the check to apply the nl policy to type blocks: <module name="LeftCurly"> <property name="option" value="nl"/> <property name="tokens" value="CLASS_DEF,INTERFACE_DEF"/> </module> Packagecom.puppycrawl.tools.checkstyle.checks.blocks Parent ModuleNeedBracesDescriptionChecks for braces around code blocks. Properties
ExamplesTo 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> Packagecom.puppycrawl.tools.checkstyle.checks.blocks Parent ModuleRightCurlyDescriptionChecks the placement of right curly braces ('}') for else, try, and catch tokens. The policy to verify is specified using property option. Properties
ExamplesTo 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> Packagecom.puppycrawl.tools.checkstyle.checks.blocks Parent ModuleAvoidNestedBlocksDescriptionFinds nested blocks, i.e. blocks that are used freely in the code. Rationale: Nested blocks are often leftovers from the debugging process, they confuse the reader. For example this Check finds the obsolete braces in public void guessTheOutput() { int whichIsWich = 0; { int whichIsWhich = 2; } System.out.println("value = " + whichIsWhich); } and debugging / refactoring leftovers such as // if (conditionThatIsNotUsedAnyLonger) { System.out.println("unconditional"); } 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. 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; } } Properties
ExamplesTo configure the check: <module name="AvoidNestedBlocks"/> Packagecom.puppycrawl.tools.checkstyle.checks.blocks Parent Module |
Copyright © 2002-2003 Oliver Burn. All rights Reserved.