From f9a7aee2259b25e74fb21e18b99cdf3d47a25f9c Mon Sep 17 00:00:00 2001 From: Vyom-Yadav Date: Tue, 26 Jul 2022 17:39:21 +0530 Subject: [PATCH] Issue #11720: Kill surviving mutation in UnnecessaryParenthesesCheck related to lambdas --- .../pitest-coding-1-suppressions.xml | 9 --------- .../checks/coding/UnnecessaryParenthesesCheck.java | 11 +++++------ 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/.ci/pitest-suppressions/pitest-coding-1-suppressions.xml b/.ci/pitest-suppressions/pitest-coding-1-suppressions.xml index 1190ceeae81..ae3bea5dff7 100644 --- a/.ci/pitest-suppressions/pitest-coding-1-suppressions.xml +++ b/.ci/pitest-suppressions/pitest-coding-1-suppressions.xml @@ -1,14 +1,5 @@ - - UnnecessaryParenthesesCheck.java - com.puppycrawl.tools.checkstyle.checks.coding.UnnecessaryParenthesesCheck - visitToken - org.pitest.mutationtest.engine.gregor.mutators.RemoveConditionalMutator_EQUAL_IF - removed conditional - replaced equality check with true - if (type == TokenTypes.LAMBDA && isLambdaSingleParameterSurrounded(ast)) { - - VariableDeclarationUsageDistanceCheck.java com.puppycrawl.tools.checkstyle.checks.coding.VariableDeclarationUsageDistanceCheck diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/UnnecessaryParenthesesCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/UnnecessaryParenthesesCheck.java index ab3e2e6e65a..09bbbb45e63 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/UnnecessaryParenthesesCheck.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/UnnecessaryParenthesesCheck.java @@ -476,13 +476,13 @@ public int[] getRequiredTokens() { // -@cs[CyclomaticComplexity] All logs should be in visit token. @Override public void visitToken(DetailAST ast) { - final int type = ast.getType(); final DetailAST parent = ast.getParent(); - if (type == TokenTypes.LAMBDA && isLambdaSingleParameterSurrounded(ast)) { + if (isLambdaSingleParameterSurrounded(ast)) { log(ast, MSG_LAMBDA, ast.getText()); } else if (parent.getType() != TokenTypes.ANNOTATION_MEMBER_VALUE_PAIR) { + final int type = ast.getType(); final boolean surrounded = isSurrounded(ast); // An identifier surrounded by parentheses. if (surrounded && type == TokenTypes.IDENT) { @@ -623,11 +623,10 @@ private static boolean unnecessaryParenAroundOperators(DetailAST ast) { } /** - * Tests if the given lambda node has a single parameter, no defined type, and is surrounded - * by parentheses. + * Tests if the given node has a single parameter, no defined type, and is surrounded + * by parentheses. This condition can only be true for lambdas. * - * @param ast a {@code DetailAST} whose type is - * {@code TokenTypes.LAMBDA}. + * @param ast a {@code DetailAST} node * @return {@code true} if the lambda has a single parameter, no defined type, and is * surrounded by parentheses. */