44
44
import javax .annotation .processing .Processor ;
45
45
import javax .annotation .processing .RoundEnvironment ;
46
46
import javax .annotation .processing .SupportedAnnotationTypes ;
47
- import javax .annotation .processing .SupportedSourceVersion ;
48
47
import javax .lang .model .SourceVersion ;
49
48
import javax .lang .model .element .AnnotationMirror ;
50
49
import javax .lang .model .element .Element ;
84
83
85
84
@ ServiceProvider (value = Processor .class , resolution = Resolution .OPTIONAL )
86
85
@ SupportedAnnotationTypes ("org.apache.logging.log4j.plugins.*" )
87
- @ SupportedSourceVersion (SourceVersion .RELEASE_17 )
88
86
@ NullMarked
89
87
public class DocGenProcessor extends AbstractProcessor {
90
88
@@ -159,6 +157,11 @@ public synchronized void init(final ProcessingEnvironment processingEnv) {
159
157
types .erasure (elements .getTypeElement ("java.lang.Enum" ).asType ());
160
158
}
161
159
160
+ @ Override
161
+ public SourceVersion getSupportedSourceVersion () {
162
+ return SourceVersion .latestSupported ();
163
+ }
164
+
162
165
@ Override
163
166
public boolean process (final Set <? extends TypeElement > unused , final RoundEnvironment roundEnv ) {
164
167
// First step: document plugins
@@ -175,13 +178,13 @@ public boolean process(final Set<? extends TypeElement> unused, final RoundEnvir
175
178
}
176
179
177
180
private void addPluginDocumentation (final Element element ) {
178
- if (element instanceof final TypeElement typeElement ) {
181
+ if (element instanceof TypeElement ) {
179
182
final PluginType pluginType = new PluginType ();
180
183
pluginType .setName (annotations .getPluginSpecifiedName (element ).orElseGet (() -> element .getSimpleName ()
181
184
.toString ()));
182
185
pluginType .setNamespace (
183
186
annotations .getPluginSpecifiedNamespace (element ).orElse ("Core" ));
184
- populatePlugin (typeElement , pluginType );
187
+ populatePlugin (( TypeElement ) element , pluginType );
185
188
pluginSet .addPlugin (pluginType );
186
189
} else {
187
190
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
233
236
populateType (element , scalarType );
234
237
if (types .isSubtype (element .asType (), enumType )) {
235
238
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 ;
239
243
final ScalarValue value = new ScalarValue ();
240
244
value .setDescription (createDescription (field , null ));
241
245
value .setName (field .getSimpleName ().toString ());
@@ -277,7 +281,8 @@ private void populatePlugin(final TypeElement element, final PluginType pluginTy
277
281
registerSupertypes (element ).forEach (pluginType ::addSupertype );
278
282
// Plugin factory
279
283
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 ;
281
286
final Map <String , String > descriptions = getParameterDescriptions (executable );
282
287
final List <? extends VariableElement > parameters = executable .getParameters ();
283
288
if (parameters .isEmpty ()) {
@@ -354,18 +359,17 @@ private PluginAttribute createPluginAttribute(
354
359
final TypeMirror type = getMemberType (element );
355
360
final String className = getClassName (type );
356
361
// 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 ));
361
364
}
362
365
attribute .setType (className );
363
366
// Description
364
367
attribute .setDescription (createDescription (element , description ));
365
368
// Required
366
369
attribute .setRequired (annotations .hasRequiredConstraint (element ));
367
370
// 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 ;
369
373
if (defaultValue != null ) {
370
374
attribute .setDefaultValue (elements .getConstantExpression (defaultValue ));
371
375
}
@@ -407,8 +411,8 @@ public Void visitType(final TypeElement element, final Set<String> supertypes) {
407
411
}
408
412
409
413
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 );
412
416
final String className = element .getQualifiedName ().toString ();
413
417
abstractTypesToDocument .add (element );
414
418
if (supertypes .add (className )) {
@@ -443,14 +447,17 @@ public TypeMirror visitVariable(final VariableElement element, final Void unused
443
447
public @ Nullable TypeMirror visitExecutable (final ExecutableElement element , final Void unused ) {
444
448
final TypeMirror returnType = element .getReturnType ();
445
449
final List <? extends VariableElement > parameters = element .getParameters ();
446
- return switch (parameters .size ()) {
450
+ switch (parameters .size ()) {
447
451
// A getter
448
- case 0 -> returnType ;
452
+ case 0 :
453
+ return returnType ;
449
454
// A setter
450
- case 1 -> parameters .get (0 ).asType ();
455
+ case 1 :
456
+ return parameters .get (0 ).asType ();
451
457
// Invalid property
452
- default -> super .visitExecutable (element , unused );
453
- };
458
+ default :
459
+ return super .visitExecutable (element , unused );
460
+ }
454
461
}
455
462
},
456
463
null );
@@ -522,7 +529,7 @@ private Collection<? extends Element> getAllMembers(final TypeElement element) {
522
529
523
530
private @ Nullable TypeElement getSuperclass (final TypeElement element ) {
524
531
final TypeMirror superclass = element .getSuperclass ();
525
- return superclass instanceof final DeclaredType declaredType ? asTypeElement (declaredType ) : null ;
532
+ return superclass instanceof DeclaredType ? asTypeElement (( DeclaredType ) superclass ) : null ;
526
533
}
527
534
528
535
// 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) {
551
558
552
559
@ Override
553
560
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
+ }
565
581
}
566
582
567
583
@ Override
0 commit comments