Skip to content

Commit

Permalink
Issue #12282: Resolve Pitest suppression for ParenPad
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin222004 committed Oct 22, 2022
1 parent 423c0a7 commit bb71b4b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 10 deletions.
9 changes: 0 additions & 9 deletions .ci/pitest-suppressions/pitest-whitespace-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,6 @@
<lineContent>processLeft(ast.findFirstToken(TokenTypes.LPAREN));</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>ParenPadCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.whitespace.ParenPadCheck</mutatedClass>
<mutatedMethod>visitToken</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.experimental.RemoveSwitchMutator_3</mutator>
<description>RemoveSwitch 3 mutation</description>
<lineContent>switch (ast.getType()) {</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>ParenPadCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.whitespace.ParenPadCheck</mutatedClass>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,13 @@ public void visitToken(DetailAST ast) {
case TokenTypes.ANNOTATION:
case TokenTypes.ENUM_CONSTANT_DEF:
case TokenTypes.LITERAL_NEW:
case TokenTypes.LITERAL_SYNCHRONIZED:
case TokenTypes.LAMBDA:
visitTokenWithOptionalParentheses(ast);
break;
case TokenTypes.RESOURCE_SPECIFICATION:
visitResourceSpecification(ast);
break;
case TokenTypes.LITERAL_SYNCHRONIZED:
default:
processLeft(ast.findFirstToken(TokenTypes.LPAREN));
processRight(ast.findFirstToken(TokenTypes.RPAREN));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import static com.puppycrawl.tools.checkstyle.checks.whitespace.AbstractParenPadCheck.MSG_WS_NOT_PRECEDED;
import static com.puppycrawl.tools.checkstyle.checks.whitespace.AbstractParenPadCheck.MSG_WS_PRECEDED;

import com.puppycrawl.tools.checkstyle.api.Configuration;
import com.puppycrawl.tools.checkstyle.checks.modifier.ModifierOrderCheck;
import org.junit.jupiter.api.Test;

import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
Expand Down Expand Up @@ -513,6 +515,13 @@ public void testParenPadCheckEmoji() throws Exception {
getPath("InputParenPadCheckEmoji.java"), expected);
}

@Test
public void InputParenPadForSynchronized() throws Exception {
final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
verifyWithInlineConfigParser(
getPath("InputParenPadForSynchronized.java"), expected);
}

/**
* Pitest requires us to specify more concrete lower bound for condition for
* ParenPadCheck#isAcceptableToken as nodes of first several types like CTOR_DEF,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
ParenPad
option = (default)nospace
tokens = LITERAL_SYNCHRONIZED, CTOR_DEF, CTOR_CALL, LITERAL_IF
*/

package com.puppycrawl.tools.checkstyle.checks.whitespace.parenpad;

/**
*
* Thread-safe Singleton class.
* The instance is lazily initialized and thus needs synchronization
* mechanism.
*
*/
class InputParenPadForSynchronized {

private static InputParenPadForSynchronized instance = null;
private InputParenPadForSynchronized() {
}

public synchronized static InputParenPadForSynchronized getInstance() {
/*
* The instance gets created only when it is called for first time.
* Lazy -loading
*/
if(instance == null) {
instance = new InputParenPadForSynchronized();
}
return instance;
}
}

0 comments on commit bb71b4b

Please sign in to comment.