From 97d669aad430216e2cf48fca85dd44676f9728cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20K=C3=BChne?= Date: Sat, 5 Jul 2003 11:12:17 +0000 Subject: [PATCH] Added allowInSwitchCase property to AvoidNestedBlocksCheck to allow limiting the scope of variables to one case of a switch statement. --- .../tools/checkstyle/InputNestedBlocks.java | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/testinputs/com/puppycrawl/tools/checkstyle/InputNestedBlocks.java b/src/testinputs/com/puppycrawl/tools/checkstyle/InputNestedBlocks.java index 38da1b342..2fc6c03bd 100644 --- a/src/testinputs/com/puppycrawl/tools/checkstyle/InputNestedBlocks.java +++ b/src/testinputs/com/puppycrawl/tools/checkstyle/InputNestedBlocks.java @@ -29,14 +29,33 @@ class InputNestedBlocks x = 2; } + // case statements are a bit complicated, + // they do not have its own variable scope by default. + // Hence it may be OK in some development teams to allow + // nested blocks if they are the complete case body. switch (x) { case 0: - x = 3; // OK + // OK + x = 3; break; + case 1: + // Not OK, SLIST is not complete case body + { + x = 1; + } + break; + case 2: + // OK if allowInSwitchCase is true, SLIST is complete case body + { + x = 1; + break; + } + case 3: // test fallthrough default: - { // should be marked, even if a switch - // case does not have its own scope + // Not OK, SLIST is not complete case body + System.out.println("Hello"); + { x = 2; } }