Skip to content

Commit 8abc774

Browse files
committed
Downgrade Java version to 11.
1 parent 1cd484a commit 8abc774

File tree

10 files changed

+92
-71
lines changed

10 files changed

+92
-71
lines changed

log4j-docgen/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<artifactId>log4j-docgen</artifactId>
2828

2929
<properties>
30-
<maven.compiler.release>17</maven.compiler.release>
30+
<maven.compiler.release>11</maven.compiler.release>
3131
<bnd.baseline.fail.on.missing>false</bnd.baseline.fail.on.missing>
3232

3333
<!-- Dependency versions -->

log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/AbstractAsciidocTreeVisitor.java

+22-12
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
package org.apache.logging.log4j.docgen.processor;
1818

19+
import static org.apache.commons.lang3.StringUtils.isEmpty;
1920
import static org.apache.commons.lang3.StringUtils.substringBefore;
2021

2122
import com.sun.source.doctree.DocTree;
@@ -25,7 +26,6 @@
2526
import com.sun.source.doctree.LiteralTree;
2627
import com.sun.source.doctree.StartElementTree;
2728
import com.sun.source.doctree.TextTree;
28-
import com.sun.source.util.DocTrees;
2929
import com.sun.source.util.SimpleDocTreeVisitor;
3030
import java.util.ArrayList;
3131
import java.util.regex.Pattern;
@@ -59,15 +59,6 @@ abstract class AbstractAsciidocTreeVisitor extends SimpleDocTreeVisitor<Void, As
5959
// Simple pattern to match (most) XML opening tags
6060
private static final Pattern XML_TAG = Pattern.compile("<\\w+\\s*(\\w+=[\"'][^\"']*[\"']\\s*)*/?>");
6161

62-
/**
63-
* Used to convert entities into strings.
64-
*/
65-
private final DocTrees docTrees;
66-
67-
AbstractAsciidocTreeVisitor(final DocTrees docTrees) {
68-
this.docTrees = docTrees;
69-
}
70-
7162
@Override
7263
public Void visitStartElement(final StartElementTree node, final AsciidocData data) {
7364
final String elementName = node.getName().toString();
@@ -165,7 +156,7 @@ public Void visitEndElement(final EndElementTree node, final AsciidocData data)
165156
case "h5":
166157
case "h6":
167158
// Only flush the current line
168-
if (!data.getCurrentLine().isEmpty()) {
159+
if (!isEmpty(data.getCurrentLine())) {
169160
data.newLine();
170161
}
171162
// The current paragraph contains the title
@@ -258,7 +249,26 @@ public Void visitLiteral(final LiteralTree node, final AsciidocData data) {
258249

259250
@Override
260251
public Void visitEntity(final EntityTree node, final AsciidocData asciidocData) {
261-
final String text = docTrees.getCharacters(node);
252+
final String text;
253+
switch (node.getName().toString()) {
254+
case "amp":
255+
text = "&";
256+
break;
257+
case "apos":
258+
text = "'";
259+
break;
260+
case "gt":
261+
text = ">";
262+
break;
263+
case "lt":
264+
text = "<";
265+
break;
266+
case "quot":
267+
text = "\"";
268+
break;
269+
default:
270+
text = null;
271+
}
262272
if (text != null) {
263273
asciidocData.append(text);
264274
}

log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/AsciidocConverter.java

+2-10
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ final class AsciidocConverter {
3434

3535
AsciidocConverter(final DocTrees docTrees) {
3636
this.docTrees = docTrees;
37-
this.docCommentTreeVisitor = new DocCommentTreeVisitor(docTrees);
38-
this.paramTreeVisitor = new ParamTreeVisitor(docTrees);
37+
this.docCommentTreeVisitor = new DocCommentTreeVisitor();
38+
this.paramTreeVisitor = new ParamTreeVisitor();
3939
}
4040

4141
public String toAsciiDoc(final Element element) {
@@ -56,10 +56,6 @@ public String toAsciiDoc(final ParamTree tree) {
5656
}
5757

5858
private static final class DocCommentTreeVisitor extends AbstractAsciidocTreeVisitor {
59-
public DocCommentTreeVisitor(final DocTrees docTrees) {
60-
super(docTrees);
61-
}
62-
6359
@Override
6460
public Void visitDocComment(final DocCommentTree node, final AsciidocData data) {
6561
// Summary block wrapped in a new paragraph.
@@ -78,10 +74,6 @@ public Void visitDocComment(final DocCommentTree node, final AsciidocData data)
7874
}
7975

8076
private static final class ParamTreeVisitor extends AbstractAsciidocTreeVisitor {
81-
public ParamTreeVisitor(final DocTrees docTrees) {
82-
super(docTrees);
83-
}
84-
8577
@Override
8678
public Void visitParam(final ParamTree node, final AsciidocData data) {
8779
for (final DocTree docTree : node.getDescription()) {

log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/AsciidocData.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
*/
1717
package org.apache.logging.log4j.docgen.processor;
1818

19+
import static org.apache.commons.lang3.StringUtils.isEmpty;
20+
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
21+
1922
import java.util.ArrayDeque;
2023
import java.util.Deque;
2124
import java.util.EmptyStackException;
@@ -75,7 +78,7 @@ public AsciidocData appendAdjustingSpace(final CharSequence text) {
7578
if (!normalized.isEmpty()) {
7679
final StringBuilder currentLine = getCurrentLine();
7780
// Last char of current line or space
78-
final char lineLastChar = currentLine.isEmpty() ? SPACE_CHAR : currentLine.charAt(currentLine.length() - 1);
81+
final char lineLastChar = isEmpty(currentLine) ? SPACE_CHAR : currentLine.charAt(currentLine.length() - 1);
7982
// First char of test
8083
final char textFirstChar = normalized.charAt(0);
8184
if (lineLastChar == SPACE_CHAR && textFirstChar == SPACE_CHAR) {
@@ -98,7 +101,7 @@ public void newTextSpan() {
98101
public String popTextSpan() {
99102
// Flush the paragraph
100103
final StringBuilder line = lines.peek();
101-
if (line != null && !line.isEmpty()) {
104+
if (isNotEmpty(line)) {
102105
newLine();
103106
}
104107
lines.pop();

log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/DocGenProcessor.java

+48-32
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import javax.annotation.processing.Processor;
4545
import javax.annotation.processing.RoundEnvironment;
4646
import javax.annotation.processing.SupportedAnnotationTypes;
47-
import javax.annotation.processing.SupportedSourceVersion;
4847
import javax.lang.model.SourceVersion;
4948
import javax.lang.model.element.AnnotationMirror;
5049
import javax.lang.model.element.Element;
@@ -84,7 +83,6 @@
8483

8584
@ServiceProvider(value = Processor.class, resolution = Resolution.OPTIONAL)
8685
@SupportedAnnotationTypes("org.apache.logging.log4j.plugins.*")
87-
@SupportedSourceVersion(SourceVersion.RELEASE_17)
8886
@NullMarked
8987
public class DocGenProcessor extends AbstractProcessor {
9088

@@ -159,6 +157,11 @@ public synchronized void init(final ProcessingEnvironment processingEnv) {
159157
types.erasure(elements.getTypeElement("java.lang.Enum").asType());
160158
}
161159

160+
@Override
161+
public SourceVersion getSupportedSourceVersion() {
162+
return SourceVersion.latestSupported();
163+
}
164+
162165
@Override
163166
public boolean process(final Set<? extends TypeElement> unused, final RoundEnvironment roundEnv) {
164167
// First step: document plugins
@@ -175,13 +178,13 @@ public boolean process(final Set<? extends TypeElement> unused, final RoundEnvir
175178
}
176179

177180
private void addPluginDocumentation(final Element element) {
178-
if (element instanceof final TypeElement typeElement) {
181+
if (element instanceof TypeElement) {
179182
final PluginType pluginType = new PluginType();
180183
pluginType.setName(annotations.getPluginSpecifiedName(element).orElseGet(() -> element.getSimpleName()
181184
.toString()));
182185
pluginType.setNamespace(
183186
annotations.getPluginSpecifiedNamespace(element).orElse("Core"));
184-
populatePlugin(typeElement, pluginType);
187+
populatePlugin((TypeElement) element, pluginType);
185188
pluginSet.addPlugin(pluginType);
186189
} else {
187190
messager.printMessage(Diagnostic.Kind.WARNING, "Found @Plugin annotation on unexpected element.", element);
@@ -233,9 +236,10 @@ private void populateScalarType(final TypeElement element, final ScalarType scal
233236
populateType(element, scalarType);
234237
if (types.isSubtype(element.asType(), enumType)) {
235238
for (final Element member : element.getEnclosedElements()) {
236-
if (member instanceof final VariableElement field
237-
&& field.getModifiers().contains(Modifier.STATIC)
238-
&& types.isSameType(field.asType(), element.asType())) {
239+
if (member instanceof VariableElement
240+
&& member.getModifiers().contains(Modifier.STATIC)
241+
&& types.isSameType(member.asType(), element.asType())) {
242+
final VariableElement field = (VariableElement) member;
239243
final ScalarValue value = new ScalarValue();
240244
value.setDescription(createDescription(field, null));
241245
value.setName(field.getSimpleName().toString());
@@ -277,7 +281,8 @@ private void populatePlugin(final TypeElement element, final PluginType pluginTy
277281
registerSupertypes(element).forEach(pluginType::addSupertype);
278282
// Plugin factory
279283
for (final Element member : element.getEnclosedElements()) {
280-
if (annotations.hasFactoryAnnotation(member) && member instanceof final ExecutableElement executable) {
284+
if (annotations.hasFactoryAnnotation(member) && member instanceof ExecutableElement) {
285+
final ExecutableElement executable = (ExecutableElement) member;
281286
final Map<String, String> descriptions = getParameterDescriptions(executable);
282287
final List<? extends VariableElement> parameters = executable.getParameters();
283288
if (parameters.isEmpty()) {
@@ -354,18 +359,17 @@ private PluginAttribute createPluginAttribute(
354359
final TypeMirror type = getMemberType(element);
355360
final String className = getClassName(type);
356361
// If type is not a well-known declared type, add it to the scanning queue.
357-
if (className != null
358-
&& !KNOWN_SCALAR_TYPES.contains(className)
359-
&& type instanceof final DeclaredType declaredType) {
360-
scalarTypesToDocument.add(asTypeElement(declaredType));
362+
if (className != null && !KNOWN_SCALAR_TYPES.contains(className) && type instanceof DeclaredType) {
363+
scalarTypesToDocument.add(asTypeElement((DeclaredType) type));
361364
}
362365
attribute.setType(className);
363366
// Description
364367
attribute.setDescription(createDescription(element, description));
365368
// Required
366369
attribute.setRequired(annotations.hasRequiredConstraint(element));
367370
// Default value
368-
final Object defaultValue = element instanceof final VariableElement field ? field.getConstantValue() : null;
371+
final Object defaultValue =
372+
element instanceof VariableElement ? ((VariableElement) element).getConstantValue() : null;
369373
if (defaultValue != null) {
370374
attribute.setDefaultValue(elements.getConstantExpression(defaultValue));
371375
}
@@ -407,8 +411,8 @@ public Void visitType(final TypeElement element, final Set<String> supertypes) {
407411
}
408412

409413
private void registerAndVisit(final TypeMirror type, final Set<String> supertypes) {
410-
if (type instanceof final DeclaredType declaredType) {
411-
final TypeElement element = asTypeElement(declaredType);
414+
if (type instanceof DeclaredType) {
415+
final TypeElement element = asTypeElement((DeclaredType) type);
412416
final String className = element.getQualifiedName().toString();
413417
abstractTypesToDocument.add(element);
414418
if (supertypes.add(className)) {
@@ -443,14 +447,17 @@ public TypeMirror visitVariable(final VariableElement element, final Void unused
443447
public @Nullable TypeMirror visitExecutable(final ExecutableElement element, final Void unused) {
444448
final TypeMirror returnType = element.getReturnType();
445449
final List<? extends VariableElement> parameters = element.getParameters();
446-
return switch (parameters.size()) {
450+
switch (parameters.size()) {
447451
// A getter
448-
case 0 -> returnType;
452+
case 0:
453+
return returnType;
449454
// A setter
450-
case 1 -> parameters.get(0).asType();
455+
case 1:
456+
return parameters.get(0).asType();
451457
// Invalid property
452-
default -> super.visitExecutable(element, unused);
453-
};
458+
default:
459+
return super.visitExecutable(element, unused);
460+
}
454461
}
455462
},
456463
null);
@@ -522,7 +529,7 @@ private Collection<? extends Element> getAllMembers(final TypeElement element) {
522529

523530
private @Nullable TypeElement getSuperclass(final TypeElement element) {
524531
final TypeMirror superclass = element.getSuperclass();
525-
return superclass instanceof final DeclaredType declaredType ? asTypeElement(declaredType) : null;
532+
return superclass instanceof DeclaredType ? asTypeElement((DeclaredType) superclass) : null;
526533
}
527534

528535
// TODO: Can the element associated to a declared type be anything else than a type element?
@@ -551,17 +558,26 @@ public String visitDeclared(final DeclaredType t, final Void unused) {
551558

552559
@Override
553560
public String visitPrimitive(final PrimitiveType t, final Void unused) {
554-
return switch (t.getKind()) {
555-
case BOOLEAN -> "boolean";
556-
case BYTE -> "byte";
557-
case SHORT -> "short";
558-
case INT -> "int";
559-
case LONG -> "long";
560-
case CHAR -> "char";
561-
case FLOAT -> "float";
562-
case DOUBLE -> "double";
563-
default -> throw new IllegalArgumentException();
564-
};
561+
switch (t.getKind()) {
562+
case BOOLEAN:
563+
return "boolean";
564+
case BYTE:
565+
return "byte";
566+
case SHORT:
567+
return "short";
568+
case INT:
569+
return "int";
570+
case LONG:
571+
return "long";
572+
case CHAR:
573+
return "char";
574+
case FLOAT:
575+
return "float";
576+
case DOUBLE:
577+
return "double";
578+
default:
579+
throw new IllegalArgumentException();
580+
}
565581
}
566582

567583
@Override

log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/internal/SectionImpl.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ public SectionImpl(final ContentNode parent) {
3131
public void formatTo(final StringBuilder buffer) {
3232
final String title = getTitle();
3333
if (title != null) {
34-
buffer.append("=".repeat(computeSectionLevel(this)))
35-
.append(' ')
36-
.append(title)
37-
.append("\n\n");
34+
for (int i = 0; i < computeSectionLevel(this); i++) {
35+
buffer.append('=');
36+
}
37+
buffer.append(' ').append(title).append("\n\n");
3838
}
3939
formatNodeCollection(getBlocks(), "\n", buffer);
4040
}

log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/internal/StructuralNodeImpl.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ public final String convert() {
7575
protected abstract void formatTo(final StringBuilder buffer);
7676

7777
protected static void formatNode(final StructuralNode node, final StringBuilder buffer) {
78-
if (node instanceof final StructuralNodeImpl impl) {
79-
impl.formatTo(buffer);
78+
if (node instanceof StructuralNodeImpl) {
79+
((StructuralNodeImpl) node).formatTo(buffer);
8080
} else {
8181
buffer.append(node.convert());
8282
}

log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/util/TypeLookup.java

-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717
package org.apache.logging.log4j.docgen.util;
1818

19-
import java.io.Serial;
2019
import java.util.HashSet;
2120
import java.util.Set;
2221
import java.util.TreeMap;
@@ -28,7 +27,6 @@
2827

2928
public final class TypeLookup extends TreeMap<String, Type> {
3029

31-
@Serial
3230
private static final long serialVersionUID = 1L;
3331

3432
public static TypeLookup of(final Iterable<? extends PluginSet> sets) {

log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/AsciidocConverterTest.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.List;
2929
import java.util.Locale;
3030
import java.util.Set;
31+
import java.util.stream.Collectors;
3132
import javax.lang.model.SourceVersion;
3233
import javax.lang.model.element.Element;
3334
import javax.tools.Diagnostic;
@@ -67,7 +68,7 @@ void convertToAsciidoc() throws Exception {
6768

6869
final Path basePath = Paths.get(System.getProperty("basedir", "."));
6970
final Path sourcePath = basePath.resolve("src/test/it/example/JavadocExample.java");
70-
final Iterable<? extends JavaFileObject> sources = fileManager.getJavaFileObjectsFromPaths(List.of(sourcePath));
71+
final Iterable<? extends JavaFileObject> sources = fileManager.getJavaFileObjects(sourcePath);
7172

7273
final Path destPath = basePath.resolve("target/test-site");
7374
Files.createDirectories(destPath);
@@ -79,7 +80,7 @@ void convertToAsciidoc() throws Exception {
7980
final List<String> warnings = ds.getDiagnostics().stream()
8081
.filter(d -> d.getKind() != Diagnostic.Kind.NOTE)
8182
.map(d -> d.getMessage(Locale.ROOT))
82-
.toList();
83+
.collect(Collectors.toList());
8384
assertThat(warnings).isEmpty();
8485
final Path expectedPath = Paths.get(AsciidocConverterTest.class
8586
.getResource("/expected/processor/JavadocExample.adoc")
@@ -104,7 +105,7 @@ public Set<? extends Option> getSupportedOptions() {
104105

105106
@Override
106107
public SourceVersion getSupportedSourceVersion() {
107-
return SourceVersion.RELEASE_17;
108+
return SourceVersion.latestSupported();
108109
}
109110

110111
@Override

0 commit comments

Comments
 (0)