Skip to content

Commit

Permalink
Issue checkstyle#11720: Kill surviving mutation in VariableDeclaratio…
Browse files Browse the repository at this point in the history
…nUsageDistanceCheck in getFirstNodeInsideIfBlock
  • Loading branch information
Vyom-Yadav committed Jul 27, 2022
1 parent 9641a07 commit 4149d9d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 32 deletions.
18 changes: 0 additions & 18 deletions .ci/pitest-suppressions/pitest-coding-1-suppressions.xml
Expand Up @@ -153,15 +153,6 @@
<lineContent>else if (isChild(currentNode, variable)) {</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>VariableDeclarationUsageDistanceCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.coding.VariableDeclarationUsageDistanceCheck</mutatedClass>
<mutatedMethod>getFirstNodeInsideIfBlock</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.RemoveConditionalMutator_EQUAL_ELSE</mutator>
<description>removed conditional - replaced equality check with false</description>
<lineContent>else if (isChild(currentNode, variable)) {</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>VariableDeclarationUsageDistanceCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.coding.VariableDeclarationUsageDistanceCheck</mutatedClass>
Expand All @@ -171,15 +162,6 @@
<lineContent>if (currentNode.getType() == TokenTypes.LITERAL_IF) {</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>VariableDeclarationUsageDistanceCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.coding.VariableDeclarationUsageDistanceCheck</mutatedClass>
<mutatedMethod>getFirstNodeInsideIfBlock</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.RemoveConditionalMutator_EQUAL_ELSE</mutator>
<description>removed conditional - replaced equality check with false</description>
<lineContent>if (currentNode.getType() == TokenTypes.LITERAL_IF) {</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>VariableDeclarationUsageDistanceCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.coding.VariableDeclarationUsageDistanceCheck</mutatedClass>
Expand Down
Expand Up @@ -766,11 +766,9 @@ private static DetailAST getFirstNodeInsideIfBlock(

if (!isVariableInOperatorExpr(block, variable)) {
DetailAST currentNode = block.getLastChild();
final List<DetailAST> variableUsageExpressions =
new ArrayList<>();
final List<DetailAST> variableUsageExpressions = new ArrayList<>();

while (currentNode != null
&& currentNode.getType() == TokenTypes.LITERAL_ELSE) {
if (currentNode.getType() == TokenTypes.LITERAL_ELSE) {
final DetailAST previousNode =
currentNode.getPreviousSibling();

Expand All @@ -781,20 +779,14 @@ private static DetailAST getFirstNodeInsideIfBlock(

// Looking into ELSE block, get its first child and analyze it.
currentNode = currentNode.getFirstChild();

if (currentNode.getType() == TokenTypes.LITERAL_IF) {
currentNode = currentNode.getLastChild();
}
else if (isChild(currentNode, variable)) {
variableUsageExpressions.add(currentNode);
currentNode = null;
}
}

// If IF block doesn't include ELSE then analyze variable usage
// only inside IF block.
if (currentNode != null
&& isChild(currentNode, variable)) {
// OR
// The IF block contained ELSE and currentNode is equal to the first child in
// ELSE block, then also analyze the first child.
if (isChild(currentNode, variable)) {
variableUsageExpressions.add(currentNode);
}

Expand Down
Expand Up @@ -86,6 +86,7 @@ public void testGeneralLogic2() throws Exception {
"17:9: " + getCheckMessage(MSG_KEY, "first", 5, 1),
"29:9: " + getCheckMessage(MSG_KEY, "allInvariants", 2, 1),
"59:9: " + getCheckMessage(MSG_KEY, "a", 2, 1),
"68:9: " + getCheckMessage(MSG_KEY, "a", 4, 1),
};
verifyWithInlineConfigParser(
getPath("InputVariableDeclarationUsageDistanceGeneral2.java"), expected);
Expand Down
Expand Up @@ -63,4 +63,14 @@ void method() throws Exception {
a.equals("");
}
}

void method2() {
int a = 12; // violation
if (true) {
method2();
p();
method2();
a++;
}
}
}

0 comments on commit 4149d9d

Please sign in to comment.