Added allowInSwitchCase property to AvoidNestedBlocksCheck

to allow limiting the scope of variables to one case of a switch statement.
This commit is contained in:
Lars Kühne 2003-07-05 11:12:17 +00:00
parent 59de966a7e
commit 97d669aad4
1 changed files with 22 additions and 3 deletions

View File

@ -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;
}
}