Added allowInSwitchCase property to AvoidNestedBlocksCheck
to allow limiting the scope of variables to one case of a switch statement.
This commit is contained in:
parent
59de966a7e
commit
97d669aad4
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue