Skip to content

Commit

Permalink
Fix checkstyles
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamedsamehsalah committed Nov 25, 2023
1 parent cd2ac85 commit 61626b7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import com.google.errorprone.bugpatterns.BugChecker;
import com.google.errorprone.bugpatterns.BugChecker.ClassTreeMatcher;
import com.google.errorprone.fixes.SuggestedFix;
import com.google.errorprone.fixes.SuggestedFix.Builder;
import com.google.errorprone.fixes.SuggestedFixes;
import com.google.errorprone.matchers.Description;
import com.google.errorprone.matchers.Matcher;
Expand Down Expand Up @@ -85,22 +84,25 @@ public Description matchClass(ClassTree tree, VisitorState state) {
}
fixLoggerVariableDeclaration(state, fixBuilder);

return describeMatch(tree, fixBuilder.build());
return fixBuilder.isEmpty() ? Description.NO_MATCH : describeMatch(tree, fixBuilder.build());

Check warning on line 87 in error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/Slf4jLogDeclaration.java

View workflow job for this annotation

GitHub Actions / pitest

A change can be made to line 87 without causing a test to fail

removed conditional - replaced equality check with false (covered by 1 tests RemoveConditionalMutator_EQUAL_ELSE)
}

private void fixLoggerVariableModifiers(Tree member, VisitorState state, Builder fixBuilder) {
private static void fixLoggerVariableModifiers(
Tree member, VisitorState state, SuggestedFix.Builder fixBuilder) {
SuggestedFixes.addModifiers(member, state, Modifier.PRIVATE, Modifier.STATIC, Modifier.FINAL)
.ifPresent(fixBuilder::merge);
}

private void canonicalizeLoggerVariable(Tree member, VisitorState state, Builder fixBuilder) {
private void canonicalizeLoggerVariable(
Tree member, VisitorState state, SuggestedFix.Builder fixBuilder) {
VariableTree variable = (VariableTree) member;
if (!variable.getName().toString().equals(canonicalizedLoggerName)) {

Check warning on line 99 in error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/Slf4jLogDeclaration.java

View workflow job for this annotation

GitHub Actions / pitest

A change can be made to line 99 without causing a test to fail

removed conditional - replaced equality check with true (covered by 1 tests RemoveConditionalMutator_EQUAL_IF)
fixBuilder.merge(SuggestedFixes.renameVariable(variable, canonicalizedLoggerName, state));
}
}

private static void fixLoggerVariableDeclaration(VisitorState state, Builder fixBuilder) {
private static void fixLoggerVariableDeclaration(
VisitorState state, SuggestedFix.Builder fixBuilder) {
for (Tree typeDeclaration : state.getPath().getCompilationUnit().getTypeDecls()) {
if (typeDeclaration instanceof ClassTree) {

Check warning on line 107 in error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/Slf4jLogDeclaration.java

View workflow job for this annotation

GitHub Actions / pitest

A change can be made to line 107 without causing a test to fail

removed conditional - replaced equality check with true (covered by 1 tests RemoveConditionalMutator_EQUAL_IF)
new TreeScanner<@Nullable Void, Name>() {
Expand All @@ -109,6 +111,7 @@ private static void fixLoggerVariableDeclaration(VisitorState state, Builder fix
return super.visitClass(classTree, classTree.getSimpleName());

Check warning on line 111 in error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/Slf4jLogDeclaration.java

View workflow job for this annotation

GitHub Actions / pitest

A change can be made to line 111 without causing a test to fail

replaced return value with null for visitClass (covered by 1 tests NullReturnValsMutator)
}

@Override
public @Nullable Void visitMethodInvocation(
MethodInvocationTree methodTree, Name className) {
if (GET_LOGGER_METHOD.matches(methodTree, state)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void replacement() {
"",
" class H {",
" private static final Logger LOGGER_WITH_WRONG_CLASS_AS_ARGUMENT =",
" LoggerFactory.getLogger(J.class);",
" LoggerFactory.getLogger(J.class);",
" }",
"",
" class J {}",
Expand All @@ -60,7 +60,7 @@ void replacement() {
" private static final Logger LOG = LoggerFactory.getLogger(A.class);",
"",
" class B {",
" private static final Logger LOG = LoggerFactory.getLogger(B.class);",
" private static final Logger LOG = LoggerFactory.getLogger(B.class);",
" }",
"",
" class C {",
Expand Down

0 comments on commit 61626b7

Please sign in to comment.