Skip to content

Commit

Permalink
SONARJAVA-4448 S2437: Rephrase issue message to not use "silly" (#4535)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaufco authored Nov 15, 2023
1 parent 71f5cb1 commit 15b708d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ public final class CheckList {
ServletInstanceFieldCheck.class,
ServletMethodsExceptionsThrownCheck.class,
ShiftOnIntOrLongCheck.class,
SillyBitOperationCheck.class,
UnnecessaryBitOperationCheck.class,
SillyEqualsCheck.class,
SillyStringOperationsCheck.class,
SimpleClassNameCheck.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import java.util.List;

@Rule(key = "S2437")
public class SillyBitOperationCheck extends IssuableSubscriptionVisitor {
public class UnnecessaryBitOperationCheck extends IssuableSubscriptionVisitor {

@Override
public List<Kind> nodesToVisit() {
Expand Down Expand Up @@ -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.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

0 comments on commit 15b708d

Please sign in to comment.