From 41426065202302d49b03b6a22db9a704a5719a4c Mon Sep 17 00:00:00 2001 From: mohamedsamehsalah Date: Sat, 25 Nov 2023 22:21:16 +0100 Subject: [PATCH] TIL: Illegal static declaration in inner class --- .../bugpatterns/Slf4jLogDeclaration.java | 6 ++-- .../bugpatterns/Slf4jLogDeclarationTest.java | 28 +++++++++---------- 2 files changed, 17 insertions(+), 17 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 0c78359718..99052b6712 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 @@ -115,12 +115,12 @@ private static void fixLoggerVariableDeclaration( public @Nullable Void visitMethodInvocation( MethodInvocationTree methodTree, Name className) { if (GET_LOGGER_METHOD.matches(methodTree, state)) { - ExpressionTree arg1 = methodTree.getArguments().get(0); - String argumentName = SourceCode.treeToString(arg1, state); + ExpressionTree arg = methodTree.getArguments().get(0); + String argumentName = SourceCode.treeToString(arg, state); if (!className.contentEquals(argumentName)) { fixBuilder.merge( - SuggestedFix.replace(arg1, className + JavaFileObject.Kind.CLASS.extension)); + SuggestedFix.replace(arg, className + JavaFileObject.Kind.CLASS.extension)); } } return super.visitMethodInvocation(methodTree, className); 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 6f6355191c..2a07f01811 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 @@ -16,31 +16,31 @@ void replacement() { "class A {", " Logger NOT_PROPER_LOGGER_NAME = LoggerFactory.getLogger(A.class);", "", - " class B {", + " static class B {", " private Logger NOT_PROPER_LOGGER_NAME = LoggerFactory.getLogger(B.class);", " }", "", - " class C {", + " static class C {", " private static Logger NOT_PROPER_LOGGER_NAME = LoggerFactory.getLogger(C.class);", " }", "", - " class D {", + " static class D {", " static final Logger NOT_PROPER_LOGGER_NAME = LoggerFactory.getLogger(D.class);", " }", "", - " class E {", + " static class E {", " private final Logger NOT_PROPER_LOGGER_NAME = LoggerFactory.getLogger(E.class);", " }", "", - " class F {", + " static class F {", " private static final Logger NOT_PROPER_LOGGER_NAME = LoggerFactory.getLogger(F.class);", " }", "", - " class G {", + " static class G {", " private static final Logger NOT_PROPER_LOGGER_NAME = LoggerFactory.getLogger(G.class);", " }", "", - " class H {", + " static class H {", " private static final Logger LOGGER_WITH_WRONG_CLASS_AS_ARGUMENT =", " LoggerFactory.getLogger(J.class);", " }", @@ -59,31 +59,31 @@ void replacement() { "class A {", " private static final Logger LOG = LoggerFactory.getLogger(A.class);", "", - " class B {", + " static class B {", " private static final Logger LOG = LoggerFactory.getLogger(B.class);", " }", "", - " class C {", + " static class C {", " private static final Logger LOG = LoggerFactory.getLogger(C.class);", " }", "", - " class D {", + " static class D {", " private static final Logger LOG = LoggerFactory.getLogger(D.class);", " }", "", - " class E {", + " static class E {", " private static final Logger LOG = LoggerFactory.getLogger(E.class);", " }", "", - " class F {", + " static class F {", " private static final Logger LOG = LoggerFactory.getLogger(F.class);", " }", "", - " class G {", + " static class G {", " private static final Logger LOG = LoggerFactory.getLogger(G.class);", " }", "", - " class H {", + " static class H {", " private static final Logger LOG = LoggerFactory.getLogger(H.class);", " }", "",