jaykataria1111 commented on code in PR #3195:
URL: https://github.com/apache/logging-log4j2/pull/3195#discussion_r1855086900


##########
log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/processor/PluginProcessor.java:
##########
@@ -107,6 +120,93 @@ public boolean process(final Set<? extends TypeElement> 
annotations, final Round
         return false;
     }
 
+    private void processBuilderAttributes(final Iterable<? extends Element> 
elements) {
+        for (final Element element : elements) {
+            if (element instanceof VariableElement) {
+                processBuilderAttributes((VariableElement) element);
+            }
+        }
+    }
+
+    private void processBuilderAttributes(final VariableElement element) {
+        final String fieldName = element.getSimpleName().toString(); // 
Getting the name of the field
+        SuppressWarnings suppress = 
element.getAnnotation(SuppressWarnings.class);
+        if (suppress != null && 
Arrays.asList(suppress.value()).contains("log4j.public.setter")) {
+            // Suppress the warning due to annotation
+            return;
+        }
+        final Element enclosingElement = element.getEnclosingElement();
+        // `element is a field
+        if (enclosingElement instanceof TypeElement) {
+            final TypeElement typeElement = (TypeElement) enclosingElement;
+            // Check the siblings of the field
+            for (final Element enclosedElement : 
typeElement.getEnclosedElements()) {
+                // `enclosedElement is a method or constructor
+                if (enclosedElement instanceof ExecutableElement) {
+                    final ExecutableElement methodElement = 
(ExecutableElement) enclosedElement;
+                    final String methodName = 
methodElement.getSimpleName().toString();
+
+                    if ((methodName.toLowerCase(Locale.ROOT).startsWith("set") 
// Typical pattern for setters
+                                    || methodName
+                                            .toLowerCase(Locale.ROOT)
+                                            .startsWith("with")) // Typical 
pattern for setters
+                            && methodElement.getParameters().size()
+                                    == 1 // It is a weird pattern to not have 
public setter
+                    ) {
+
+                        Types typeUtils = processingEnv.getTypeUtils();
+
+                        boolean followsNamePattern = methodName
+                                        .toLowerCase(Locale.ROOT)
+                                        .equals(String.format("set%s", 
fieldName.toLowerCase(Locale.ROOT)))
+                                || methodName
+                                        .toLowerCase(Locale.ROOT)
+                                        .equals(String.format("with%s", 
fieldName.toLowerCase(Locale.ROOT)));
+
+                        if 
(fieldName.toLowerCase(Locale.ROOT).startsWith("is")) {
+                            followsNamePattern = methodName
+                                            .toLowerCase(Locale.ROOT)
+                                            .equals(String.format(
+                                                    "set%s",
+                                                    fieldName
+                                                            
.toLowerCase(Locale.ROOT)
+                                                            .substring(2)))
+                                    || methodName
+                                            .toLowerCase(Locale.ROOT)
+                                            .equals(String.format(
+                                                    "with%s",
+                                                    fieldName
+                                                            
.toLowerCase(Locale.ROOT)
+                                                            .substring(2)));
+                        }

Review Comment:
   Great Idea, I concur. 
   
   Gotcha, we are going to get some more errors here, I am going to add more 
suppress warnings in them.
   
   We should deprecate the old methods, and create new methods for setters, 
which have improper naming right now, what do you think, can I make an issue 
for this? 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to