Skip to content

Commit

Permalink
Issue #11720: Kill surviving mutation in RequireThisCheck related to …
Browse files Browse the repository at this point in the history
…checking static context
  • Loading branch information
Vyom-Yadav committed Jul 2, 2022
1 parent 685a1ac commit dfdcc07
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<suppressedMutations>
<mutation unstable="false">
<sourceFile>RequireThisCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.coding.RequireThisCheck</mutatedClass>
<mutatedMethod>canBeReferencedFromStaticContext</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.RemoveConditionalMutator_EQUAL_IF</mutator>
<description>removed conditional - replaced equality check with true</description>
<lineContent>if (variableDeclarationFrame.getType() == FrameType.CLASS_FRAME) {</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>RequireThisCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.coding.RequireThisCheck</mutatedClass>
Expand Down
1 change: 0 additions & 1 deletion .ci/pitest-survival-check-html.sh
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ pitest-coding-require-this-check)
"RequireThisCheck.java.html:<td class='covered'><pre><span class='survived'> &#38;&#38; ast.getParent().getType() != TokenTypes.LITERAL_CATCH) {</span></pre></td></tr>"
"RequireThisCheck.java.html:<td class='covered'><pre><span class='survived'> &#38;&#38; parent.getType() != TokenTypes.CTOR_DEF</span></pre></td></tr>"
"RequireThisCheck.java.html:<td class='covered'><pre><span class='survived'> &#38;&#38; lastChild.getType() == TokenTypes.OBJBLOCK;</span></pre></td></tr>"
"RequireThisCheck.java.html:<td class='covered'><pre><span class='survived'> if (variableDeclarationFrame.getType() == FrameType.CLASS_FRAME) {</span></pre></td></tr>"
"RequireThisCheck.java.html:<td class='covered'><pre><span class='survived'> if (fieldUsageFrame.getType() == FrameType.BLOCK_FRAME) {</span></pre></td></tr>"
"RequireThisCheck.java.html:<td class='covered'><pre><span class='survived'> return left.getType() == right.getType() &#38;&#38; left.getText().equals(right.getText());</span></pre></td></tr>"
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -848,28 +848,13 @@ private static boolean isAstInside(DetailAST tree, DetailAST ast) {
* @param ident ident token.
* @return true if field can be referenced from a static context.
*/
private boolean canBeReferencedFromStaticContext(DetailAST ident) {
AbstractFrame variableDeclarationFrame = findFrame(ident, false);
while (variableDeclarationFrame.getType() == FrameType.BLOCK_FRAME
|| variableDeclarationFrame.getType() == FrameType.FOR_FRAME) {
variableDeclarationFrame = variableDeclarationFrame.getParent();
}

private static boolean canBeReferencedFromStaticContext(DetailAST ident) {
boolean staticContext = false;

if (variableDeclarationFrame.getType() == FrameType.CLASS_FRAME) {
final DetailAST codeBlockDefinition = getCodeBlockDefinitionToken(ident);
if (codeBlockDefinition != null) {
final DetailAST modifiers = codeBlockDefinition.getFirstChild();
staticContext = codeBlockDefinition.getType() == TokenTypes.STATIC_INIT
|| modifiers.findFirstToken(TokenTypes.LITERAL_STATIC) != null;
}
}
else {
final DetailAST frameNameIdent = variableDeclarationFrame.getFrameNameIdent();
final DetailAST definitionToken = frameNameIdent.getParent();
staticContext = definitionToken.findFirstToken(TokenTypes.MODIFIERS)
.findFirstToken(TokenTypes.LITERAL_STATIC) != null;
final DetailAST codeBlockDefinition = getCodeBlockDefinitionToken(ident);
if (codeBlockDefinition != null) {
final DetailAST modifiers = codeBlockDefinition.getFirstChild();
staticContext = codeBlockDefinition.getType() == TokenTypes.STATIC_INIT
|| modifiers.findFirstToken(TokenTypes.LITERAL_STATIC) != null;
}
return !staticContext;
}
Expand Down

0 comments on commit dfdcc07

Please sign in to comment.