From 15b708d95a5dfdfad21c5dc05b5efab9b7a62228 Mon Sep 17 00:00:00 2001 From: Marco Kaufmann <83189575+kaufco@users.noreply.github.com> Date: Wed, 15 Nov 2023 15:57:03 +0100 Subject: [PATCH] SONARJAVA-4448 S2437: Rephrase issue message to not use "silly" (#4535) --- ...ck.java => UnnecessaryBitOperationCheck.java} | 16 ++++++++-------- .../java/org/sonar/java/checks/CheckList.java | 2 +- ...ck.java => UnnecessaryBitOperationCheck.java} | 4 ++-- ...ava => UnnecessaryBitOperationCheckTest.java} | 6 +++--- 4 files changed, 14 insertions(+), 14 deletions(-) rename java-checks-test-sources/src/main/java/checks/{SillyBitOperationCheck.java => UnnecessaryBitOperationCheck.java} (69%) rename java-checks/src/main/java/org/sonar/java/checks/{SillyBitOperationCheck.java => UnnecessaryBitOperationCheck.java} (94%) rename java-checks/src/test/java/org/sonar/java/checks/{SillyBitOperationCheckTest.java => UnnecessaryBitOperationCheckTest.java} (86%) diff --git a/java-checks-test-sources/src/main/java/checks/SillyBitOperationCheck.java b/java-checks-test-sources/src/main/java/checks/UnnecessaryBitOperationCheck.java similarity index 69% rename from java-checks-test-sources/src/main/java/checks/SillyBitOperationCheck.java rename to java-checks-test-sources/src/main/java/checks/UnnecessaryBitOperationCheck.java index 98327e24d3d..17d9b524f72 100644 --- a/java-checks-test-sources/src/main/java/checks/SillyBitOperationCheck.java +++ b/java-checks-test-sources/src/main/java/checks/UnnecessaryBitOperationCheck.java @@ -1,16 +1,16 @@ package checks; -class SillyBitOperationCheck { +class UnnecessaryBitOperationCheck { private void foo() { int result; int bitMask = 0x000F; - result = bitMask & -1; // Noncompliant {{Remove this silly bit operation.}} - result = bitMask | 0; // Noncompliant [[sc=22;ec=23]] {{Remove this silly bit operation.}} - result = bitMask ^ 0; // Noncompliant {{Remove this silly bit operation.}} - result &= -1; // Noncompliant [[sc=12;ec=14]] {{Remove this silly bit operation.}} - result |= 0; // Noncompliant {{Remove this silly bit operation.}} - result ^= 0; // Noncompliant {{Remove this silly bit operation.}} + result = bitMask & -1; // Noncompliant {{Remove this unnecessary bit operation.}} + result = bitMask | 0; // Noncompliant [[sc=22;ec=23]] {{Remove this unnecessary bit operation.}} + result = bitMask ^ 0; // Noncompliant {{Remove this unnecessary bit operation.}} + result &= -1; // Noncompliant [[sc=12;ec=14]] {{Remove this unnecessary bit operation.}} + result |= 0; // Noncompliant {{Remove this unnecessary bit operation.}} + result ^= 0; // Noncompliant {{Remove this unnecessary bit operation.}} result = bitMask & 1; // Compliant result = bitMask | 1; // compliant @@ -21,7 +21,7 @@ private void foo() { long bitMaskLong = 0x000F; long resultLong; - resultLong = bitMaskLong & -1l; // Noncompliant {{Remove this silly bit operation.}} + resultLong = bitMaskLong & -1l; // Noncompliant {{Remove this unnecessary bit operation.}} resultLong = bitMaskLong & 0L; // Compliant resultLong = bitMaskLong & returnLong(); // Compliant resultLong = bitMaskLong & 0x0F; // Compliant diff --git a/java-checks/src/main/java/org/sonar/java/checks/CheckList.java b/java-checks/src/main/java/org/sonar/java/checks/CheckList.java index 3ea1fade161..a26e43d82c6 100644 --- a/java-checks/src/main/java/org/sonar/java/checks/CheckList.java +++ b/java-checks/src/main/java/org/sonar/java/checks/CheckList.java @@ -612,7 +612,7 @@ public final class CheckList { ServletInstanceFieldCheck.class, ServletMethodsExceptionsThrownCheck.class, ShiftOnIntOrLongCheck.class, - SillyBitOperationCheck.class, + UnnecessaryBitOperationCheck.class, SillyEqualsCheck.class, SillyStringOperationsCheck.class, SimpleClassNameCheck.class, diff --git a/java-checks/src/main/java/org/sonar/java/checks/SillyBitOperationCheck.java b/java-checks/src/main/java/org/sonar/java/checks/UnnecessaryBitOperationCheck.java similarity index 94% rename from java-checks/src/main/java/org/sonar/java/checks/SillyBitOperationCheck.java rename to java-checks/src/main/java/org/sonar/java/checks/UnnecessaryBitOperationCheck.java index 6ad86e33978..e36b1f29a7d 100644 --- a/java-checks/src/main/java/org/sonar/java/checks/SillyBitOperationCheck.java +++ b/java-checks/src/main/java/org/sonar/java/checks/UnnecessaryBitOperationCheck.java @@ -33,7 +33,7 @@ import java.util.List; @Rule(key = "S2437") -public class SillyBitOperationCheck extends IssuableSubscriptionVisitor { +public class UnnecessaryBitOperationCheck extends IssuableSubscriptionVisitor { @Override public List nodesToVisit() { @@ -61,7 +61,7 @@ public void visitNode(Tree tree) { } Long evaluatedExpression = LiteralUtils.longLiteralValue(expression); if (evaluatedExpression != null && getBitwiseOperationIdentityElement(tree).equals(evaluatedExpression)) { - reportIssue(operatorToken, "Remove this silly bit operation."); + reportIssue(operatorToken, "Remove this unnecessary bit operation."); } } diff --git a/java-checks/src/test/java/org/sonar/java/checks/SillyBitOperationCheckTest.java b/java-checks/src/test/java/org/sonar/java/checks/UnnecessaryBitOperationCheckTest.java similarity index 86% rename from java-checks/src/test/java/org/sonar/java/checks/SillyBitOperationCheckTest.java rename to java-checks/src/test/java/org/sonar/java/checks/UnnecessaryBitOperationCheckTest.java index 7e73012c156..3818a5f041f 100644 --- a/java-checks/src/test/java/org/sonar/java/checks/SillyBitOperationCheckTest.java +++ b/java-checks/src/test/java/org/sonar/java/checks/UnnecessaryBitOperationCheckTest.java @@ -24,13 +24,13 @@ import static org.sonar.java.checks.verifier.TestUtils.mainCodeSourcesPath; -class SillyBitOperationCheckTest { +class UnnecessaryBitOperationCheckTest { @Test void test() { CheckVerifier.newVerifier() - .onFile(mainCodeSourcesPath("checks/SillyBitOperationCheck.java")) - .withCheck(new SillyBitOperationCheck()) + .onFile(mainCodeSourcesPath("checks/UnnecessaryBitOperationCheck.java")) + .withCheck(new UnnecessaryBitOperationCheck()) .verifyIssues(); } }