From 1c556365b25f1127e456aa314c424863c12b52ec Mon Sep 17 00:00:00 2001 From: mohamedsamehsalah Date: Mon, 2 Oct 2023 08:43:12 +0200 Subject: [PATCH] Address comments: Fix mutation tests --- .../CanonicalConstantFieldName.java | 20 ++++++++----------- .../CanonicalConstantFieldNameTest.java | 2 +- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/CanonicalConstantFieldName.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/CanonicalConstantFieldName.java index 80a5614feca..17c181d33e4 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/CanonicalConstantFieldName.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/CanonicalConstantFieldName.java @@ -128,20 +128,16 @@ public Description matchCompilationUnit(CompilationUnitTree tree, VisitorState s if (IS_CONSTANT.matches(variableTree, state) && isFieldAccessModifierApplicable(variableTree, state)) { VarSymbol variableSymbol = ASTHelpers.getSymbol(variableTree); + String variableName = variableSymbol.getSimpleName().toString(); - if (variableSymbol != null) { - String variableName = variableSymbol.getSimpleName().toString(); + if (!isVariableUpperSnakeCase(variableName) && !isVariableNameExcluded(variableName)) { + String replacement = toUpperSnakeCase(variableName); - if (!isVariableUpperSnakeCase(variableName) - && !isVariableNameExcluded(variableName)) { - String replacement = toUpperSnakeCase(variableName); - - if (variableSymbols.stream() - .noneMatch(s -> s.getSimpleName().toString().equals(replacement))) { - fixBuilder.merge(SuggestedFixes.renameVariable(variableTree, replacement, state)); - } else { - reportConstantRenameBlocker(variableTree, replacement, state); - } + if (variableSymbols.stream() + .noneMatch(s -> s.getSimpleName().toString().equals(replacement))) { + fixBuilder.merge(SuggestedFixes.renameVariable(variableTree, replacement, state)); + } else { + reportConstantRenameBlocker(variableTree, replacement, state); } } } diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/CanonicalConstantFieldNameTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/CanonicalConstantFieldNameTest.java index 09415f681c1..4379b3de374 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/CanonicalConstantFieldNameTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/CanonicalConstantFieldNameTest.java @@ -125,7 +125,7 @@ void excludeFlaggedConstants() { } @Test - void IncludePublicConstants() { + void includePublicConstants() { BugCheckerRefactoringTestHelper.newInstance(CanonicalConstantFieldName.class, getClass()) .setArgs("-XepOpt:CanonicalConstantFieldName:IncludePublicConstantFields=true") .addInputLines(