Skip to content

Commit

Permalink
Issue checkstyle#11720: Kill surviving mutation in RequireThisCheck r…
Browse files Browse the repository at this point in the history
…elated to static blocks
  • Loading branch information
Vyom-Yadav committed Jun 29, 2022
1 parent c8c2d8c commit becba42
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 34 deletions.
@@ -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_ELSE</mutator>
<description>removed conditional - replaced equality check with false</description>
<lineContent>if (definitionToken.getType() == TokenTypes.STATIC_INIT) {</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
Expand Up @@ -202,7 +202,6 @@ pitest-coding-require-this-check)
"RequireThisCheck.java.html:<td class='covered'><pre><span class='survived'> if (isAnonymousClassDef(ast)) {</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 (definitionToken.getType() == TokenTypes.STATIC_INIT) {</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'> if (sibling != null &#38;&#38; isAssignToken(parent.getType())) {</span></pre></td></tr>"
Expand Down
Expand Up @@ -850,37 +850,26 @@ private static boolean isAstInside(DetailAST tree, DetailAST ast) {
*/
private boolean canBeReferencedFromStaticContext(DetailAST ident) {
AbstractFrame variableDeclarationFrame = findFrame(ident, false);
boolean staticInitializationBlock = false;
while (variableDeclarationFrame.getType() == FrameType.BLOCK_FRAME
|| variableDeclarationFrame.getType() == FrameType.FOR_FRAME) {
final DetailAST blockFrameNameIdent = variableDeclarationFrame.getFrameNameIdent();
final DetailAST definitionToken = blockFrameNameIdent.getParent();
if (definitionToken.getType() == TokenTypes.STATIC_INIT) {
staticInitializationBlock = true;
break;
}
|| variableDeclarationFrame.getType() == FrameType.FOR_FRAME) {
variableDeclarationFrame = variableDeclarationFrame.getParent();
}

boolean staticContext = false;
if (staticInitializationBlock) {
staticContext = true;

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 {
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 frameNameIdent = variableDeclarationFrame.getFrameNameIdent();
final DetailAST definitionToken = frameNameIdent.getParent();
staticContext = definitionToken.findFirstToken(TokenTypes.MODIFIERS)
.findFirstToken(TokenTypes.LITERAL_STATIC) != null;
}
return !staticContext;
}
Expand Down

0 comments on commit becba42

Please sign in to comment.