vy commented on code in PR #102:
URL: 
https://github.com/apache/logging-log4j-tools/pull/102#discussion_r1482996754


##########
log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/DocGenProcessor.java:
##########
@@ -0,0 +1,692 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.logging.log4j.docgen.processor;
+
+import static org.apache.commons.lang3.StringUtils.defaultIfEmpty;
+import static org.apache.commons.lang3.StringUtils.defaultString;
+
+import aQute.bnd.annotation.Resolution;
+import aQute.bnd.annotation.spi.ServiceProvider;
+import com.sun.source.doctree.DocCommentTree;
+import com.sun.source.doctree.DocTree;
+import com.sun.source.doctree.ParamTree;
+import com.sun.source.util.DocTrees;
+import com.sun.source.util.SimpleDocTreeVisitor;
+import java.io.IOException;
+import java.io.Writer;
+import java.lang.annotation.Annotation;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import javax.annotation.processing.AbstractProcessor;
+import javax.annotation.processing.Messager;
+import javax.annotation.processing.ProcessingEnvironment;
+import javax.annotation.processing.Processor;
+import javax.annotation.processing.RoundEnvironment;
+import javax.annotation.processing.SupportedAnnotationTypes;
+import javax.annotation.processing.SupportedSourceVersion;
+import javax.lang.model.SourceVersion;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.ExecutableElement;
+import javax.lang.model.element.Modifier;
+import javax.lang.model.element.Name;
+import javax.lang.model.element.QualifiedNameable;
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.element.VariableElement;
+import javax.lang.model.type.ArrayType;
+import javax.lang.model.type.DeclaredType;
+import javax.lang.model.type.NoType;
+import javax.lang.model.type.PrimitiveType;
+import javax.lang.model.type.TypeMirror;
+import javax.lang.model.type.TypeVariable;
+import javax.lang.model.util.Elements;
+import javax.lang.model.util.SimpleElementVisitor8;
+import javax.lang.model.util.SimpleTypeVisitor8;
+import javax.lang.model.util.Types;
+import javax.tools.Diagnostic;
+import javax.tools.FileObject;
+import javax.tools.StandardLocation;
+import javax.xml.stream.XMLStreamException;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.logging.log4j.docgen.AbstractType;
+import org.apache.logging.log4j.docgen.Description;
+import org.apache.logging.log4j.docgen.PluginAttribute;
+import org.apache.logging.log4j.docgen.PluginElement;
+import org.apache.logging.log4j.docgen.PluginSet;
+import org.apache.logging.log4j.docgen.PluginType;
+import org.apache.logging.log4j.docgen.ScalarType;
+import org.apache.logging.log4j.docgen.ScalarValue;
+import org.apache.logging.log4j.docgen.Type;
+import org.apache.logging.log4j.docgen.io.stax.PluginBundleStaxWriter;
+import org.apache.logging.log4j.plugins.Factory;
+import org.apache.logging.log4j.plugins.Namespace;
+import org.apache.logging.log4j.plugins.Plugin;
+import org.apache.logging.log4j.plugins.PluginBuilderAttribute;
+import org.apache.logging.log4j.plugins.PluginFactory;
+import org.apache.logging.log4j.plugins.validation.constraints.Required;
+import org.jspecify.annotations.NullMarked;
+import org.jspecify.annotations.Nullable;
+
+@ServiceProvider(value = Processor.class, resolution = Resolution.OPTIONAL)
+@SupportedAnnotationTypes("org.apache.logging.log4j.plugins.*")
+@SupportedSourceVersion(SourceVersion.RELEASE_17)
+@NullMarked
+public class DocGenProcessor extends AbstractProcessor {
+
+    private static final String MULTIPLICITY_UNBOUNDED = "*";
+    private static final CharSequence[] GETTER_SETTER_PREFIXES = {"get", "is", 
"set"};
+    private static final List<Class<? extends Annotation>> 
PROPERTY_ANNOTATION_TYPES = List.of(
+            PluginBuilderAttribute.class,
+            org.apache.logging.log4j.plugins.PluginAttribute.class,
+            org.apache.logging.log4j.plugins.PluginElement.class);
+    private static final List<Class<? extends Annotation>> 
FACTORY_ANNOTATION_TYPES =
+            List.of(Factory.class, PluginFactory.class);
+    /**
+     * Reference types from the {@code java.*} namespace that are described
+     * in {@code org/apache/logging/log4j/docgen/internal/configuration.xml}
+     */
+    private static final Set<String> KNOWN_SCALAR_TYPES = Set.of(
+            "java.lang.Boolean",
+            "java.lang.Character",
+            "java.lang.Byte",
+            "java.lang.Short",
+            "java.lang.Integer",
+            "java.lang.Long",
+            "java.lang.Float",
+            "java.lang.Double",
+            "java.lang.String");
+
+    // Plugins
+    private final Map<String, PluginType> pluginTypes = new TreeMap<>();
+    // Other interfaces
+    private final Map<String, TypeElement> abstractTypes = new TreeMap<>();
+    // Scalar types
+    private final Map<String, TypeElement> scalarTypes = new TreeMap<>();
+
+    private AsciidocConverter converter;
+    private DocTrees docTrees;
+    private Elements elements;
+    private Types types;
+    private Messager messager;
+    // Type corresponding to java.util.Collection
+    private DeclaredType collectionType;
+    // Type corresponding to java.lang.Enum
+    private DeclaredType enumType;
+
+    @SuppressWarnings({"DataFlowIssue", "unused"})
+    public DocGenProcessor() {
+        converter = null;
+        docTrees = null;
+        elements = null;
+        types = null;
+        messager = null;
+        collectionType = null;
+        enumType = null;
+    }
+
+    // For testing and silencing nullability warnings
+    @SuppressWarnings("unused")
+    DocGenProcessor(final ProcessingEnvironment processingEnv) {
+        docTrees = DocTrees.instance(processingEnv);
+        converter = new AsciidocConverter(docTrees);
+        elements = processingEnv.getElementUtils();
+        types = processingEnv.getTypeUtils();
+        messager = processingEnv.getMessager();
+        collectionType = (DeclaredType)
+                
types.erasure(elements.getTypeElement("java.util.Collection").asType());
+        enumType = (DeclaredType)
+                
types.erasure(elements.getTypeElement("java.lang.Enum").asType());

Review Comment:
   Why not simply replacing this with `init(processingEnv)`?



##########
log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/DocGenProcessorTest.java:
##########


Review Comment:
   Nit: Could you use `src/test/resources/example-java-files` instead of 
`src/test/it/example`, please?



##########
log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/DocGenProcessor.java:
##########
@@ -0,0 +1,692 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.logging.log4j.docgen.processor;
+
+import static org.apache.commons.lang3.StringUtils.defaultIfEmpty;
+import static org.apache.commons.lang3.StringUtils.defaultString;
+
+import aQute.bnd.annotation.Resolution;
+import aQute.bnd.annotation.spi.ServiceProvider;
+import com.sun.source.doctree.DocCommentTree;
+import com.sun.source.doctree.DocTree;
+import com.sun.source.doctree.ParamTree;
+import com.sun.source.util.DocTrees;
+import com.sun.source.util.SimpleDocTreeVisitor;
+import java.io.IOException;
+import java.io.Writer;
+import java.lang.annotation.Annotation;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import javax.annotation.processing.AbstractProcessor;
+import javax.annotation.processing.Messager;
+import javax.annotation.processing.ProcessingEnvironment;
+import javax.annotation.processing.Processor;
+import javax.annotation.processing.RoundEnvironment;
+import javax.annotation.processing.SupportedAnnotationTypes;
+import javax.annotation.processing.SupportedSourceVersion;
+import javax.lang.model.SourceVersion;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.ExecutableElement;
+import javax.lang.model.element.Modifier;
+import javax.lang.model.element.Name;
+import javax.lang.model.element.QualifiedNameable;
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.element.VariableElement;
+import javax.lang.model.type.ArrayType;
+import javax.lang.model.type.DeclaredType;
+import javax.lang.model.type.NoType;
+import javax.lang.model.type.PrimitiveType;
+import javax.lang.model.type.TypeMirror;
+import javax.lang.model.type.TypeVariable;
+import javax.lang.model.util.Elements;
+import javax.lang.model.util.SimpleElementVisitor8;
+import javax.lang.model.util.SimpleTypeVisitor8;
+import javax.lang.model.util.Types;
+import javax.tools.Diagnostic;
+import javax.tools.FileObject;
+import javax.tools.StandardLocation;
+import javax.xml.stream.XMLStreamException;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.logging.log4j.docgen.AbstractType;
+import org.apache.logging.log4j.docgen.Description;
+import org.apache.logging.log4j.docgen.PluginAttribute;
+import org.apache.logging.log4j.docgen.PluginElement;
+import org.apache.logging.log4j.docgen.PluginSet;
+import org.apache.logging.log4j.docgen.PluginType;
+import org.apache.logging.log4j.docgen.ScalarType;
+import org.apache.logging.log4j.docgen.ScalarValue;
+import org.apache.logging.log4j.docgen.Type;
+import org.apache.logging.log4j.docgen.io.stax.PluginBundleStaxWriter;
+import org.apache.logging.log4j.plugins.Factory;
+import org.apache.logging.log4j.plugins.Namespace;
+import org.apache.logging.log4j.plugins.Plugin;
+import org.apache.logging.log4j.plugins.PluginBuilderAttribute;
+import org.apache.logging.log4j.plugins.PluginFactory;
+import org.apache.logging.log4j.plugins.validation.constraints.Required;
+import org.jspecify.annotations.NullMarked;
+import org.jspecify.annotations.Nullable;
+
+@ServiceProvider(value = Processor.class, resolution = Resolution.OPTIONAL)
+@SupportedAnnotationTypes("org.apache.logging.log4j.plugins.*")
+@SupportedSourceVersion(SourceVersion.RELEASE_17)
+@NullMarked
+public class DocGenProcessor extends AbstractProcessor {
+
+    private static final String MULTIPLICITY_UNBOUNDED = "*";
+    private static final CharSequence[] GETTER_SETTER_PREFIXES = {"get", "is", 
"set"};
+    private static final List<Class<? extends Annotation>> 
PROPERTY_ANNOTATION_TYPES = List.of(
+            PluginBuilderAttribute.class,
+            org.apache.logging.log4j.plugins.PluginAttribute.class,
+            org.apache.logging.log4j.plugins.PluginElement.class);
+    private static final List<Class<? extends Annotation>> 
FACTORY_ANNOTATION_TYPES =
+            List.of(Factory.class, PluginFactory.class);
+    /**
+     * Reference types from the {@code java.*} namespace that are described
+     * in {@code org/apache/logging/log4j/docgen/internal/configuration.xml}
+     */
+    private static final Set<String> KNOWN_SCALAR_TYPES = Set.of(
+            "java.lang.Boolean",
+            "java.lang.Character",
+            "java.lang.Byte",
+            "java.lang.Short",
+            "java.lang.Integer",
+            "java.lang.Long",
+            "java.lang.Float",
+            "java.lang.Double",
+            "java.lang.String");
+
+    // Plugins
+    private final Map<String, PluginType> pluginTypes = new TreeMap<>();
+    // Other interfaces
+    private final Map<String, TypeElement> abstractTypes = new TreeMap<>();
+    // Scalar types
+    private final Map<String, TypeElement> scalarTypes = new TreeMap<>();
+
+    private AsciidocConverter converter;
+    private DocTrees docTrees;
+    private Elements elements;
+    private Types types;
+    private Messager messager;
+    // Type corresponding to java.util.Collection
+    private DeclaredType collectionType;
+    // Type corresponding to java.lang.Enum
+    private DeclaredType enumType;
+
+    @SuppressWarnings({"DataFlowIssue", "unused"})
+    public DocGenProcessor() {
+        converter = null;
+        docTrees = null;
+        elements = null;
+        types = null;
+        messager = null;
+        collectionType = null;
+        enumType = null;
+    }
+
+    // For testing and silencing nullability warnings
+    @SuppressWarnings("unused")
+    DocGenProcessor(final ProcessingEnvironment processingEnv) {
+        docTrees = DocTrees.instance(processingEnv);
+        converter = new AsciidocConverter(docTrees);
+        elements = processingEnv.getElementUtils();
+        types = processingEnv.getTypeUtils();
+        messager = processingEnv.getMessager();
+        collectionType = (DeclaredType)
+                
types.erasure(elements.getTypeElement("java.util.Collection").asType());
+        enumType = (DeclaredType)
+                
types.erasure(elements.getTypeElement("java.lang.Enum").asType());
+    }
+
+    @Override
+    public synchronized void init(final ProcessingEnvironment processingEnv) {
+        super.init(processingEnv);
+        docTrees = DocTrees.instance(processingEnv);
+        converter = new AsciidocConverter(docTrees);
+        elements = processingEnv.getElementUtils();
+        types = processingEnv.getTypeUtils();
+        messager = processingEnv.getMessager();
+        collectionType = (DeclaredType)
+                
types.erasure(elements.getTypeElement("java.util.Collection").asType());
+        enumType = (DeclaredType)
+                
types.erasure(elements.getTypeElement("java.lang.Enum").asType());
+    }
+
+    @Override
+    public boolean process(final Set<? extends TypeElement> annotations, final 
RoundEnvironment roundEnv) {

Review Comment:
   Shall we split this method a bit? `processPlugins()`, 
`processAbstractTypes()`, `processScalarTypes()`, `writePluginSet()`, etc.
   
   For the record, I very much prefer self-descriptive method names that avoid 
using generic terms like `process`, `manage`, `do`, `test`, etc. (IIRC, this 
was advised in Clean Code too.) For instance, `populatePluginDescriptions()`. 
In particular, in our context, the notion of _plugin_ is extremely overloaded.



##########
log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/DocGenProcessor.java:
##########
@@ -0,0 +1,692 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.logging.log4j.docgen.processor;
+
+import static org.apache.commons.lang3.StringUtils.defaultIfEmpty;
+import static org.apache.commons.lang3.StringUtils.defaultString;
+
+import aQute.bnd.annotation.Resolution;
+import aQute.bnd.annotation.spi.ServiceProvider;
+import com.sun.source.doctree.DocCommentTree;
+import com.sun.source.doctree.DocTree;
+import com.sun.source.doctree.ParamTree;
+import com.sun.source.util.DocTrees;
+import com.sun.source.util.SimpleDocTreeVisitor;
+import java.io.IOException;
+import java.io.Writer;
+import java.lang.annotation.Annotation;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import javax.annotation.processing.AbstractProcessor;
+import javax.annotation.processing.Messager;
+import javax.annotation.processing.ProcessingEnvironment;
+import javax.annotation.processing.Processor;
+import javax.annotation.processing.RoundEnvironment;
+import javax.annotation.processing.SupportedAnnotationTypes;
+import javax.annotation.processing.SupportedSourceVersion;
+import javax.lang.model.SourceVersion;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.ExecutableElement;
+import javax.lang.model.element.Modifier;
+import javax.lang.model.element.Name;
+import javax.lang.model.element.QualifiedNameable;
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.element.VariableElement;
+import javax.lang.model.type.ArrayType;
+import javax.lang.model.type.DeclaredType;
+import javax.lang.model.type.NoType;
+import javax.lang.model.type.PrimitiveType;
+import javax.lang.model.type.TypeMirror;
+import javax.lang.model.type.TypeVariable;
+import javax.lang.model.util.Elements;
+import javax.lang.model.util.SimpleElementVisitor8;
+import javax.lang.model.util.SimpleTypeVisitor8;
+import javax.lang.model.util.Types;
+import javax.tools.Diagnostic;
+import javax.tools.FileObject;
+import javax.tools.StandardLocation;
+import javax.xml.stream.XMLStreamException;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.logging.log4j.docgen.AbstractType;
+import org.apache.logging.log4j.docgen.Description;
+import org.apache.logging.log4j.docgen.PluginAttribute;
+import org.apache.logging.log4j.docgen.PluginElement;
+import org.apache.logging.log4j.docgen.PluginSet;
+import org.apache.logging.log4j.docgen.PluginType;
+import org.apache.logging.log4j.docgen.ScalarType;
+import org.apache.logging.log4j.docgen.ScalarValue;
+import org.apache.logging.log4j.docgen.Type;
+import org.apache.logging.log4j.docgen.io.stax.PluginBundleStaxWriter;
+import org.apache.logging.log4j.plugins.Factory;
+import org.apache.logging.log4j.plugins.Namespace;
+import org.apache.logging.log4j.plugins.Plugin;
+import org.apache.logging.log4j.plugins.PluginBuilderAttribute;
+import org.apache.logging.log4j.plugins.PluginFactory;
+import org.apache.logging.log4j.plugins.validation.constraints.Required;
+import org.jspecify.annotations.NullMarked;
+import org.jspecify.annotations.Nullable;
+
+@ServiceProvider(value = Processor.class, resolution = Resolution.OPTIONAL)
+@SupportedAnnotationTypes("org.apache.logging.log4j.plugins.*")
+@SupportedSourceVersion(SourceVersion.RELEASE_17)
+@NullMarked
+public class DocGenProcessor extends AbstractProcessor {
+
+    private static final String MULTIPLICITY_UNBOUNDED = "*";
+    private static final CharSequence[] GETTER_SETTER_PREFIXES = {"get", "is", 
"set"};
+    private static final List<Class<? extends Annotation>> 
PROPERTY_ANNOTATION_TYPES = List.of(
+            PluginBuilderAttribute.class,
+            org.apache.logging.log4j.plugins.PluginAttribute.class,
+            org.apache.logging.log4j.plugins.PluginElement.class);
+    private static final List<Class<? extends Annotation>> 
FACTORY_ANNOTATION_TYPES =
+            List.of(Factory.class, PluginFactory.class);
+    /**
+     * Reference types from the {@code java.*} namespace that are described
+     * in {@code org/apache/logging/log4j/docgen/internal/configuration.xml}
+     */
+    private static final Set<String> KNOWN_SCALAR_TYPES = Set.of(
+            "java.lang.Boolean",
+            "java.lang.Character",
+            "java.lang.Byte",
+            "java.lang.Short",
+            "java.lang.Integer",
+            "java.lang.Long",
+            "java.lang.Float",
+            "java.lang.Double",
+            "java.lang.String");
+
+    // Plugins
+    private final Map<String, PluginType> pluginTypes = new TreeMap<>();
+    // Other interfaces
+    private final Map<String, TypeElement> abstractTypes = new TreeMap<>();
+    // Scalar types
+    private final Map<String, TypeElement> scalarTypes = new TreeMap<>();
+
+    private AsciidocConverter converter;
+    private DocTrees docTrees;
+    private Elements elements;
+    private Types types;
+    private Messager messager;
+    // Type corresponding to java.util.Collection
+    private DeclaredType collectionType;
+    // Type corresponding to java.lang.Enum
+    private DeclaredType enumType;
+
+    @SuppressWarnings({"DataFlowIssue", "unused"})
+    public DocGenProcessor() {
+        converter = null;
+        docTrees = null;
+        elements = null;
+        types = null;
+        messager = null;
+        collectionType = null;
+        enumType = null;
+    }
+
+    // For testing and silencing nullability warnings
+    @SuppressWarnings("unused")
+    DocGenProcessor(final ProcessingEnvironment processingEnv) {
+        docTrees = DocTrees.instance(processingEnv);
+        converter = new AsciidocConverter(docTrees);
+        elements = processingEnv.getElementUtils();
+        types = processingEnv.getTypeUtils();
+        messager = processingEnv.getMessager();
+        collectionType = (DeclaredType)
+                
types.erasure(elements.getTypeElement("java.util.Collection").asType());
+        enumType = (DeclaredType)
+                
types.erasure(elements.getTypeElement("java.lang.Enum").asType());
+    }
+
+    @Override
+    public synchronized void init(final ProcessingEnvironment processingEnv) {
+        super.init(processingEnv);
+        docTrees = DocTrees.instance(processingEnv);
+        converter = new AsciidocConverter(docTrees);
+        elements = processingEnv.getElementUtils();
+        types = processingEnv.getTypeUtils();
+        messager = processingEnv.getMessager();
+        collectionType = (DeclaredType)
+                
types.erasure(elements.getTypeElement("java.util.Collection").asType());
+        enumType = (DeclaredType)
+                
types.erasure(elements.getTypeElement("java.lang.Enum").asType());
+    }
+
+    @Override
+    public boolean process(final Set<? extends TypeElement> annotations, final 
RoundEnvironment roundEnv) {
+        final PluginSet set = new PluginSet();
+        // First step: document plugins
+        roundEnv.getElementsAnnotatedWith(Plugin.class).forEach(element -> {
+            if (element instanceof final TypeElement typeElement) {
+                final PluginType pluginType = new PluginType();
+                final Plugin pluginAnnotation = 
element.getAnnotation(Plugin.class);
+                processPlugin(typeElement, pluginAnnotation, pluginType);
+                pluginTypes.put(pluginType.getClassName(), pluginType);
+            }
+        });
+        pluginTypes.values().forEach(set::addPlugin);
+        // Second step: document abstract types
+        abstractTypes.values().forEach(type -> {
+            final AbstractType abstractType = new AbstractType();
+            processAbstractType(type, abstractType);
+            if (!abstractType.getDescription().getText().isEmpty()) {
+                set.addAbstractType(abstractType);
+            }
+        });
+        // Second step: document scalars
+        scalarTypes.values().forEach(type -> {
+            final ScalarType scalarType = new ScalarType();
+            processScalarType(type, scalarType);
+            set.addScalar(scalarType);
+        });
+        // Write the result file
+        if (roundEnv.processingOver()) {
+            try {
+                final FileObject output = processingEnv
+                        .getFiler()
+                        .createResource(StandardLocation.CLASS_OUTPUT, "", 
"META-INF/log4j/plugins.xml");
+
+                try (final Writer writer = output.openWriter()) {
+                    new PluginBundleStaxWriter().write(writer, set);
+                }
+            } catch (final IOException | XMLStreamException e) {
+                messager.printMessage(
+                        Diagnostic.Kind.ERROR,
+                        "An error occurred while writing to 
`META-INF/log4j/plugins.xml`: " + e.getMessage());
+            }
+        }
+        return false;
+    }
+
+    private void processType(final QualifiedNameable element, final Type 
docgenType) {
+        // Class name
+        docgenType.setClassName(element.getQualifiedName().toString());
+        // Description
+        docgenType.setDescription(createDescription(element, null));
+    }
+
+    private void processAbstractType(final QualifiedNameable element, final 
AbstractType abstractType) {
+        processType(element, abstractType);
+    }
+
+    private void processScalarType(final TypeElement element, final ScalarType 
scalarType) {
+        processType(element, scalarType);
+        if (types.isSubtype(element.asType(), enumType)) {
+            for (final Element member : element.getEnclosedElements()) {
+                if (member instanceof final VariableElement field
+                        && field.getModifiers().contains(Modifier.STATIC)
+                        && types.isSameType(field.asType(), element.asType())) 
{
+                    final ScalarValue value = new ScalarValue();

Review Comment:
   @ppkarwasz, around this method I started losing my marbles. I navigated the 
branch locally in my IDE too, it did not help either. Hence, there is nothing 
much I can do than assuming _"it works"_.



##########
log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/DocGenProcessorTest.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.logging.log4j.docgen.processor;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+
+import java.io.IOException;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Locale;
+import java.util.Set;
+import java.util.stream.Stream;
+import javax.tools.Diagnostic;
+import javax.tools.DiagnosticCollector;
+import javax.tools.JavaCompiler;
+import javax.tools.JavaCompiler.CompilationTask;
+import javax.tools.JavaFileObject;
+import javax.tools.StandardJavaFileManager;
+import javax.tools.StandardLocation;
+import javax.tools.ToolProvider;
+import org.apache.logging.log4j.docgen.xsd.SchemaGenerator;
+import org.junit.jupiter.api.Test;
+import org.xmlunit.assertj3.XmlAssert;
+
+public class DocGenProcessorTest {
+
+    @Test
+    void descriptorGenerationSucceeds() {
+        final Path basePath = Paths.get(System.getProperty("basedir", "."));
+        final Path schema = 
basePath.resolve("target/generated-site/resources/xsd/plugins-0.1.0.xsd");
+        final URL expected = 
SchemaGenerator.class.getResource("/expected/processor/META-INF/log4j/plugins.xml");
+        final Path actual = 
assertDoesNotThrow(DocGenProcessorTest::generateDescriptor);
+        XmlAssert.assertThat(actual)
+                .isValidAgainst(schema)
+                .and(expected)
+                .ignoreComments()
+                .ignoreWhitespace()
+                .areIdentical();
+    }
+
+    private static Path generateDescriptor() throws IOException {
+        final JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+        final DiagnosticCollector<JavaFileObject> ds = new 
DiagnosticCollector<>();
+        final StandardJavaFileManager fileManager =
+                compiler.getStandardFileManager(null, Locale.ROOT, 
StandardCharsets.UTF_8);

Review Comment:
   I was totally unaware of this convenience! :exploding_head: :star_struck: We 
can replace code like the following in several Log4j projects:
   ```
           final String javaHome = getProperty("java.home");
           final String javaBin = javaHome + File.separator + "bin" + 
File.separator + "java";
   ```



##########
log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/DocGenProcessor.java:
##########
@@ -0,0 +1,692 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.logging.log4j.docgen.processor;
+
+import static org.apache.commons.lang3.StringUtils.defaultIfEmpty;
+import static org.apache.commons.lang3.StringUtils.defaultString;
+
+import aQute.bnd.annotation.Resolution;
+import aQute.bnd.annotation.spi.ServiceProvider;
+import com.sun.source.doctree.DocCommentTree;
+import com.sun.source.doctree.DocTree;
+import com.sun.source.doctree.ParamTree;
+import com.sun.source.util.DocTrees;
+import com.sun.source.util.SimpleDocTreeVisitor;
+import java.io.IOException;
+import java.io.Writer;
+import java.lang.annotation.Annotation;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import javax.annotation.processing.AbstractProcessor;
+import javax.annotation.processing.Messager;
+import javax.annotation.processing.ProcessingEnvironment;
+import javax.annotation.processing.Processor;
+import javax.annotation.processing.RoundEnvironment;
+import javax.annotation.processing.SupportedAnnotationTypes;
+import javax.annotation.processing.SupportedSourceVersion;
+import javax.lang.model.SourceVersion;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.ExecutableElement;
+import javax.lang.model.element.Modifier;
+import javax.lang.model.element.Name;
+import javax.lang.model.element.QualifiedNameable;
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.element.VariableElement;
+import javax.lang.model.type.ArrayType;
+import javax.lang.model.type.DeclaredType;
+import javax.lang.model.type.NoType;
+import javax.lang.model.type.PrimitiveType;
+import javax.lang.model.type.TypeMirror;
+import javax.lang.model.type.TypeVariable;
+import javax.lang.model.util.Elements;
+import javax.lang.model.util.SimpleElementVisitor8;
+import javax.lang.model.util.SimpleTypeVisitor8;
+import javax.lang.model.util.Types;
+import javax.tools.Diagnostic;
+import javax.tools.FileObject;
+import javax.tools.StandardLocation;
+import javax.xml.stream.XMLStreamException;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.logging.log4j.docgen.AbstractType;
+import org.apache.logging.log4j.docgen.Description;
+import org.apache.logging.log4j.docgen.PluginAttribute;
+import org.apache.logging.log4j.docgen.PluginElement;
+import org.apache.logging.log4j.docgen.PluginSet;
+import org.apache.logging.log4j.docgen.PluginType;
+import org.apache.logging.log4j.docgen.ScalarType;
+import org.apache.logging.log4j.docgen.ScalarValue;
+import org.apache.logging.log4j.docgen.Type;
+import org.apache.logging.log4j.docgen.io.stax.PluginBundleStaxWriter;
+import org.apache.logging.log4j.plugins.Factory;
+import org.apache.logging.log4j.plugins.Namespace;
+import org.apache.logging.log4j.plugins.Plugin;
+import org.apache.logging.log4j.plugins.PluginBuilderAttribute;
+import org.apache.logging.log4j.plugins.PluginFactory;
+import org.apache.logging.log4j.plugins.validation.constraints.Required;
+import org.jspecify.annotations.NullMarked;
+import org.jspecify.annotations.Nullable;
+
+@ServiceProvider(value = Processor.class, resolution = Resolution.OPTIONAL)
+@SupportedAnnotationTypes("org.apache.logging.log4j.plugins.*")
+@SupportedSourceVersion(SourceVersion.RELEASE_17)
+@NullMarked
+public class DocGenProcessor extends AbstractProcessor {
+
+    private static final String MULTIPLICITY_UNBOUNDED = "*";
+    private static final CharSequence[] GETTER_SETTER_PREFIXES = {"get", "is", 
"set"};
+    private static final List<Class<? extends Annotation>> 
PROPERTY_ANNOTATION_TYPES = List.of(
+            PluginBuilderAttribute.class,
+            org.apache.logging.log4j.plugins.PluginAttribute.class,
+            org.apache.logging.log4j.plugins.PluginElement.class);
+    private static final List<Class<? extends Annotation>> 
FACTORY_ANNOTATION_TYPES =
+            List.of(Factory.class, PluginFactory.class);
+    /**
+     * Reference types from the {@code java.*} namespace that are described
+     * in {@code org/apache/logging/log4j/docgen/internal/configuration.xml}
+     */
+    private static final Set<String> KNOWN_SCALAR_TYPES = Set.of(
+            "java.lang.Boolean",
+            "java.lang.Character",
+            "java.lang.Byte",
+            "java.lang.Short",
+            "java.lang.Integer",
+            "java.lang.Long",
+            "java.lang.Float",
+            "java.lang.Double",
+            "java.lang.String");
+
+    // Plugins
+    private final Map<String, PluginType> pluginTypes = new TreeMap<>();

Review Comment:
   Can't this be a local variable in `process()`?



##########
log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/DocGenProcessor.java:
##########
@@ -0,0 +1,692 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.logging.log4j.docgen.processor;
+
+import static org.apache.commons.lang3.StringUtils.defaultIfEmpty;
+import static org.apache.commons.lang3.StringUtils.defaultString;
+
+import aQute.bnd.annotation.Resolution;
+import aQute.bnd.annotation.spi.ServiceProvider;
+import com.sun.source.doctree.DocCommentTree;
+import com.sun.source.doctree.DocTree;
+import com.sun.source.doctree.ParamTree;
+import com.sun.source.util.DocTrees;
+import com.sun.source.util.SimpleDocTreeVisitor;
+import java.io.IOException;
+import java.io.Writer;
+import java.lang.annotation.Annotation;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import javax.annotation.processing.AbstractProcessor;
+import javax.annotation.processing.Messager;
+import javax.annotation.processing.ProcessingEnvironment;
+import javax.annotation.processing.Processor;
+import javax.annotation.processing.RoundEnvironment;
+import javax.annotation.processing.SupportedAnnotationTypes;
+import javax.annotation.processing.SupportedSourceVersion;
+import javax.lang.model.SourceVersion;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.ExecutableElement;
+import javax.lang.model.element.Modifier;
+import javax.lang.model.element.Name;
+import javax.lang.model.element.QualifiedNameable;
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.element.VariableElement;
+import javax.lang.model.type.ArrayType;
+import javax.lang.model.type.DeclaredType;
+import javax.lang.model.type.NoType;
+import javax.lang.model.type.PrimitiveType;
+import javax.lang.model.type.TypeMirror;
+import javax.lang.model.type.TypeVariable;
+import javax.lang.model.util.Elements;
+import javax.lang.model.util.SimpleElementVisitor8;
+import javax.lang.model.util.SimpleTypeVisitor8;
+import javax.lang.model.util.Types;
+import javax.tools.Diagnostic;
+import javax.tools.FileObject;
+import javax.tools.StandardLocation;
+import javax.xml.stream.XMLStreamException;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.logging.log4j.docgen.AbstractType;
+import org.apache.logging.log4j.docgen.Description;
+import org.apache.logging.log4j.docgen.PluginAttribute;
+import org.apache.logging.log4j.docgen.PluginElement;
+import org.apache.logging.log4j.docgen.PluginSet;
+import org.apache.logging.log4j.docgen.PluginType;
+import org.apache.logging.log4j.docgen.ScalarType;
+import org.apache.logging.log4j.docgen.ScalarValue;
+import org.apache.logging.log4j.docgen.Type;
+import org.apache.logging.log4j.docgen.io.stax.PluginBundleStaxWriter;
+import org.apache.logging.log4j.plugins.Factory;
+import org.apache.logging.log4j.plugins.Namespace;
+import org.apache.logging.log4j.plugins.Plugin;
+import org.apache.logging.log4j.plugins.PluginBuilderAttribute;
+import org.apache.logging.log4j.plugins.PluginFactory;
+import org.apache.logging.log4j.plugins.validation.constraints.Required;
+import org.jspecify.annotations.NullMarked;
+import org.jspecify.annotations.Nullable;
+
+@ServiceProvider(value = Processor.class, resolution = Resolution.OPTIONAL)
+@SupportedAnnotationTypes("org.apache.logging.log4j.plugins.*")
+@SupportedSourceVersion(SourceVersion.RELEASE_17)
+@NullMarked
+public class DocGenProcessor extends AbstractProcessor {
+
+    private static final String MULTIPLICITY_UNBOUNDED = "*";
+    private static final CharSequence[] GETTER_SETTER_PREFIXES = {"get", "is", 
"set"};
+    private static final List<Class<? extends Annotation>> 
PROPERTY_ANNOTATION_TYPES = List.of(
+            PluginBuilderAttribute.class,
+            org.apache.logging.log4j.plugins.PluginAttribute.class,
+            org.apache.logging.log4j.plugins.PluginElement.class);
+    private static final List<Class<? extends Annotation>> 
FACTORY_ANNOTATION_TYPES =
+            List.of(Factory.class, PluginFactory.class);
+    /**
+     * Reference types from the {@code java.*} namespace that are described
+     * in {@code org/apache/logging/log4j/docgen/internal/configuration.xml}
+     */
+    private static final Set<String> KNOWN_SCALAR_TYPES = Set.of(
+            "java.lang.Boolean",
+            "java.lang.Character",
+            "java.lang.Byte",
+            "java.lang.Short",
+            "java.lang.Integer",
+            "java.lang.Long",
+            "java.lang.Float",
+            "java.lang.Double",
+            "java.lang.String");
+
+    // Plugins
+    private final Map<String, PluginType> pluginTypes = new TreeMap<>();
+    // Other interfaces
+    private final Map<String, TypeElement> abstractTypes = new TreeMap<>();
+    // Scalar types
+    private final Map<String, TypeElement> scalarTypes = new TreeMap<>();
+
+    private AsciidocConverter converter;
+    private DocTrees docTrees;
+    private Elements elements;
+    private Types types;
+    private Messager messager;
+    // Type corresponding to java.util.Collection
+    private DeclaredType collectionType;
+    // Type corresponding to java.lang.Enum
+    private DeclaredType enumType;
+
+    @SuppressWarnings({"DataFlowIssue", "unused"})

Review Comment:
   `DataFlowIssue` is a redundant suppression, IDEA says.



-- 
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: notifications-unsubscr...@logging.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to