From 61626b7c5c0c00f22b0ef3972fc8a1ca6ca68a06 Mon Sep 17 00:00:00 2001 From: mohamedsamehsalah Date: Sat, 25 Nov 2023 21:19:44 +0100 Subject: [PATCH] Fix checkstyles --- .../errorprone/bugpatterns/Slf4jLogDeclaration.java | 13 ++++++++----- .../bugpatterns/Slf4jLogDeclarationTest.java | 4 ++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/Slf4jLogDeclaration.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/Slf4jLogDeclaration.java index fc8dcac3e6..0c78359718 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/Slf4jLogDeclaration.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/Slf4jLogDeclaration.java @@ -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; @@ -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()); } - 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)) { 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) { new TreeScanner<@Nullable Void, Name>() { @@ -109,6 +111,7 @@ private static void fixLoggerVariableDeclaration(VisitorState state, Builder fix return super.visitClass(classTree, classTree.getSimpleName()); } + @Override public @Nullable Void visitMethodInvocation( MethodInvocationTree methodTree, Name className) { if (GET_LOGGER_METHOD.matches(methodTree, state)) { diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/Slf4jLogDeclarationTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/Slf4jLogDeclarationTest.java index 42ab513ad1..6f6355191c 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/Slf4jLogDeclarationTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/Slf4jLogDeclarationTest.java @@ -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 {}", @@ -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 {",