Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #11720: Kill surviving mutation in VariableDeclarationUsageDist…
…anceCheck in getFirstNodeInsideIfBlock
- Loading branch information
1 parent
60c6b19
commit a97c3e8
Showing
4 changed files
with
106 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...g/variabledeclarationusagedistance/InputVariableDeclarationUsageDistanceIfStatements.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
VariableDeclarationUsageDistance | ||
allowedDistance = 1 | ||
ignoreVariablePattern = (default) | ||
validateBetweenScopes = true | ||
ignoreFinal = false | ||
*/ | ||
|
||
package com.puppycrawl.tools.checkstyle.checks.coding.variabledeclarationusagedistance; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
public class InputVariableDeclarationUsageDistanceIfStatements { | ||
void method2() { | ||
int a = 12; // violation | ||
if (true) { | ||
method2(); | ||
checkIfStatementWithoutParen(); | ||
method2(); | ||
a++; | ||
} | ||
} | ||
|
||
void checkIfStatementWithoutParen() { | ||
int a = 12; // violation | ||
method2(); | ||
if (true) | ||
a++; | ||
int b = 12; // violation | ||
method2(); | ||
if (false) | ||
method2(); | ||
else if(true) | ||
b++; | ||
int c = 12; // violation | ||
method2(); | ||
checkIfStatementWithoutParen(); | ||
if (true) | ||
c++; | ||
else | ||
method2(); | ||
} | ||
|
||
void testConsecutiveIfStatements() { | ||
int a = 12; // ok | ||
int b = 13; // violation | ||
int c = 14; // violation | ||
int d = 15; // violation | ||
if (true) | ||
a++; | ||
if (true) | ||
b++; | ||
if (false) | ||
c++; | ||
if (true) | ||
d++; | ||
} | ||
|
||
int testReturnStatement() { | ||
int a = 1; // violation | ||
testConsecutiveIfStatements(); | ||
testConsecutiveIfStatements(); | ||
testConsecutiveIfStatements(); | ||
if (true) | ||
return a; | ||
|
||
return 0; | ||
} | ||
} |