@@ -67,7 +67,7 @@ private String getJavaDoc(final Element element) {
67
67
68
68
/**
69
69
* {@return the tags inside a JavaDoc comment}
70
- *
70
+ *
71
71
* @param element the Java element to get its JavaDoc tags
72
72
*/
73
73
public List <? extends DocTree > getTags (final Element element ) {
@@ -87,8 +87,7 @@ public Root parseRootDoc() {
87
87
final Package packageNode = getPackage (rootNode , classDoc );
88
88
89
89
switch (classDoc .getKind ()) {
90
- case ANNOTATION_TYPE ->
91
- packageNode .getAnnotation ().add (parseAnnotationTypeDoc (classDoc ));
90
+ case ANNOTATION_TYPE -> packageNode .getAnnotation ().add (parseAnnotationTypeDoc (classDoc ));
92
91
case ENUM -> packageNode .getEnum ().add (parseEnum (classDoc ));
93
92
case INTERFACE -> packageNode .getInterface ().add (parseInterface (classDoc ));
94
93
default -> packageNode .getClazz ().add (parseClass (classDoc ));
@@ -100,7 +99,7 @@ public Root parseRootDoc() {
100
99
101
100
/**
102
101
* {@return the package node for the given class element}
103
- *
102
+ *
104
103
* @param rootNode
105
104
* @param classElement class to get its package
106
105
*/
@@ -140,7 +139,7 @@ protected Package parsePackage(final PackageElement packageDoc) {
140
139
protected Annotation parseAnnotationTypeDoc (final TypeElement annotationTypeDoc ) {
141
140
final Annotation annotationNode = objectFactory .createAnnotation ();
142
141
annotationNode .setName (annotationTypeDoc .getSimpleName ().toString ());
143
- annotationNode .setQualified (annotationTypeDoc . getQualifiedName (). toString ( ));
142
+ annotationNode .setQualified (getQualifiedName (annotationTypeDoc ));
144
143
final String comment = getJavaDoc (annotationTypeDoc );
145
144
if (!comment .isEmpty ()) {
146
145
annotationNode .setComment (comment );
@@ -199,22 +198,20 @@ protected AnnotationElement parseAnnotationTypeElementDoc(
199
198
*/
200
199
protected AnnotationInstance parseAnnotationDesc (final AnnotationMirror annotationDesc ,
201
200
final Name programElement ) {
202
- final AnnotationInstance annotationInstanceNode = objectFactory .createAnnotationInstance ();
201
+ final var annotationInstance = objectFactory .createAnnotationInstance ();
203
202
204
203
try {
205
204
final var annotTypeInfo = annotationDesc .getAnnotationType ();
206
- annotationInstanceNode .setName (annotTypeInfo .asElement ().getSimpleName ().toString ());
207
- annotationInstanceNode
208
- .setQualified (annotTypeInfo .asElement ().getSimpleName ().toString ());
205
+ annotationInstance .setName (annotTypeInfo .asElement ().getSimpleName ().toString ());
206
+ annotationInstance .setQualified (annotTypeInfo .asElement ().getSimpleName ().toString ());
209
207
} catch (ClassCastException castException ) {
210
208
LOGGER .severe (
211
209
"Unable to obtain type data about an annotation found on: " + programElement );
212
210
LOGGER .severe ("Add to the classpath the class/jar that defines this annotation." );
213
211
}
214
212
215
213
for (final var elementValuesPair : annotationDesc .getElementValues ().entrySet ()) {
216
- final AnnotationArgument annotationArgumentNode =
217
- objectFactory .createAnnotationArgument ();
214
+ final AnnotationArgument annotationArgumentNode = objectFactory .createAnnotationArgument ();
218
215
annotationArgumentNode .setName (elementValuesPair .getKey ().getSimpleName ().toString ());
219
216
220
217
final TypeMirror annotationArgumentType = elementValuesPair .getKey ().asType ();
@@ -227,33 +224,37 @@ protected AnnotationInstance parseAnnotationDesc(final AnnotationMirror annotati
227
224
case AnnotationValue [] annotationValues -> {
228
225
for (final AnnotationValue annotationValue : annotationValues ) {
229
226
if (annotationValue .getValue () instanceof AnnotationMirror annoDesc ) {
230
- annotationArgumentNode .getAnnotation ()
231
- .add (parseAnnotationDesc (annoDesc , programElement ));
227
+ annotationArgumentNode .getAnnotation ().add (parseAnnotationDesc (annoDesc , programElement ));
232
228
} else {
233
- annotationArgumentNode .getValue ()
234
- .add (annotationValue .getValue ().toString ());
229
+ annotationArgumentNode .getValue ().add (annotationValue .getValue ().toString ());
235
230
}
236
231
}
237
232
}
238
- case VariableElement fieldDoc ->
239
- annotationArgumentNode .getValue ().add (fieldDoc .getSimpleName ().toString ());
240
- case TypeElement classDoc ->
241
- annotationArgumentNode .getValue ().add (classDoc .getQualifiedName ().toString ());
233
+ case VariableElement fieldDoc -> annotationArgumentNode .getValue ().add (getSimpleName (fieldDoc ));
234
+ case TypeElement classDoc -> annotationArgumentNode .getValue ().add (getQualifiedName (classDoc ));
242
235
case null -> {
243
236
}
244
237
default -> annotationArgumentNode .getValue ().add (objValue .toString ());
245
238
}
246
239
247
- annotationInstanceNode .getArgument ().add (annotationArgumentNode );
240
+ annotationInstance .getArgument ().add (annotationArgumentNode );
248
241
}
249
242
250
- return annotationInstanceNode ;
243
+ return annotationInstance ;
244
+ }
245
+
246
+ private static String getQualifiedName (final TypeElement typeElement ) {
247
+ return typeElement .getQualifiedName ().toString ();
248
+ }
249
+
250
+ private static String getSimpleName (final VariableElement element ) {
251
+ return element .getSimpleName ().toString ();
251
252
}
252
253
253
254
protected Enum parseEnum (final TypeElement classDoc ) {
254
255
final Enum enumNode = objectFactory .createEnum ();
255
256
enumNode .setName (classDoc .getSimpleName ().toString ());
256
- enumNode .setQualified (classDoc . getQualifiedName (). toString ( ));
257
+ enumNode .setQualified (getQualifiedName (classDoc ));
257
258
final String comment = getJavaDoc (classDoc );
258
259
if (!comment .isEmpty ()) {
259
260
enumNode .setComment (comment );
@@ -278,8 +279,7 @@ protected Enum parseEnum(final TypeElement classDoc) {
278
279
}
279
280
280
281
for (final AnnotationMirror annotationDesc : classDoc .getAnnotationMirrors ()) {
281
- enumNode .getAnnotation ()
282
- .add (parseAnnotationDesc (annotationDesc , classDoc .getQualifiedName ()));
282
+ enumNode .getAnnotation ().add (parseAnnotationDesc (annotationDesc , classDoc .getQualifiedName ()));
283
283
}
284
284
285
285
for (final DocTree tag : getTags (classDoc )) {
@@ -297,15 +297,14 @@ protected Enum parseEnum(final TypeElement classDoc) {
297
297
*/
298
298
protected EnumConstant parseEnumConstant (final VariableElement fieldDoc ) {
299
299
final EnumConstant enumConstant = objectFactory .createEnumConstant ();
300
- enumConstant .setName (fieldDoc . getSimpleName (). toString ( ));
300
+ enumConstant .setName (getSimpleName (fieldDoc ));
301
301
final String comment = getJavaDoc (fieldDoc );
302
302
if (!comment .isEmpty ()) {
303
303
enumConstant .setComment (comment );
304
304
}
305
305
306
306
for (final AnnotationMirror annotationDesc : fieldDoc .getAnnotationMirrors ()) {
307
- enumConstant .getAnnotation ()
308
- .add (parseAnnotationDesc (annotationDesc , fieldDoc .getSimpleName ()));
307
+ enumConstant .getAnnotation ().add (parseAnnotationDesc (annotationDesc , fieldDoc .getSimpleName ()));
309
308
}
310
309
311
310
for (final DocTree tag : getTags (fieldDoc )) {
@@ -318,7 +317,7 @@ protected EnumConstant parseEnumConstant(final VariableElement fieldDoc) {
318
317
protected Interface parseInterface (final TypeElement classDoc ) {
319
318
final Interface interfaceNode = objectFactory .createInterface ();
320
319
interfaceNode .setName (classDoc .getSimpleName ().toString ());
321
- interfaceNode .setQualified (classDoc . getQualifiedName (). toString ( ));
320
+ interfaceNode .setQualified (getQualifiedName (classDoc ));
322
321
final String comment = getJavaDoc (classDoc );
323
322
if (!comment .isEmpty ()) {
324
323
interfaceNode .setComment (comment );
@@ -342,8 +341,7 @@ protected Interface parseInterface(final TypeElement classDoc) {
342
341
}
343
342
344
343
for (final AnnotationMirror annotationDesc : classDoc .getAnnotationMirrors ()) {
345
- interfaceNode .getAnnotation ()
346
- .add (parseAnnotationDesc (annotationDesc , classDoc .getQualifiedName ()));
344
+ interfaceNode .getAnnotation ().add (parseAnnotationDesc (annotationDesc , classDoc .getQualifiedName ()));
347
345
}
348
346
349
347
for (final DocTree tag : getTags (classDoc )) {
@@ -360,7 +358,7 @@ protected Interface parseInterface(final TypeElement classDoc) {
360
358
protected Class parseClass (final TypeElement classDoc ) {
361
359
final Class classNode = objectFactory .createClass ();
362
360
classNode .setName (classDoc .getSimpleName ().toString ());
363
- classNode .setQualified (classDoc . getQualifiedName (). toString ( ));
361
+ classNode .setQualified (getQualifiedName (classDoc ));
364
362
final String comment = getJavaDoc (classDoc );
365
363
if (!comment .isEmpty ()) {
366
364
classNode .setComment (comment );
@@ -394,8 +392,7 @@ protected Class parseClass(final TypeElement classDoc) {
394
392
}
395
393
396
394
for (final AnnotationMirror annotationDesc : classDoc .getAnnotationMirrors ()) {
397
- final var annotationInstance =
398
- parseAnnotationDesc (annotationDesc , classDoc .getQualifiedName ());
395
+ final var annotationInstance = parseAnnotationDesc (annotationDesc , classDoc .getQualifiedName ());
399
396
classNode .getAnnotation ().add (annotationInstance );
400
397
}
401
398
@@ -444,8 +441,7 @@ protected Constructor parseConstructor(final ExecutableElement constructorDoc) {
444
441
}
445
442
446
443
for (final AnnotationMirror annotationDesc : constructorDoc .getAnnotationMirrors ()) {
447
- final var annotationInstance =
448
- parseAnnotationDesc (annotationDesc , constructorDoc .getSimpleName ());
444
+ final var annotationInstance = parseAnnotationDesc (annotationDesc , constructorDoc .getSimpleName ());
449
445
constructorNode .getAnnotation ().add (annotationInstance );
450
446
}
451
447
@@ -488,8 +484,7 @@ protected Method parseMethod(final ExecutableElement methodDoc) {
488
484
}
489
485
490
486
for (final AnnotationMirror annotationDesc : methodDoc .getAnnotationMirrors ()) {
491
- final var annotationInstance =
492
- parseAnnotationDesc (annotationDesc , methodDoc .getSimpleName ());
487
+ final var annotationInstance = parseAnnotationDesc (annotationDesc , methodDoc .getSimpleName ());
493
488
methodNode .getAnnotation ().add (annotationInstance );
494
489
}
495
490
@@ -502,12 +497,11 @@ protected Method parseMethod(final ExecutableElement methodDoc) {
502
497
503
498
protected MethodParameter parseMethodParameter (final VariableElement parameter ) {
504
499
final MethodParameter parameterMethodNode = objectFactory .createMethodParameter ();
505
- parameterMethodNode .setName (parameter . getSimpleName (). toString ( ));
500
+ parameterMethodNode .setName (getSimpleName (parameter ));
506
501
parameterMethodNode .setType (parseTypeInfo (parameter .asType ()));
507
502
508
503
for (final AnnotationMirror annotationDesc : parameter .getAnnotationMirrors ()) {
509
- final var annotationInstance =
510
- parseAnnotationDesc (annotationDesc , parameter .getSimpleName ());
504
+ final var annotationInstance = parseAnnotationDesc (annotationDesc , parameter .getSimpleName ());
511
505
parameterMethodNode .getAnnotation ().add (annotationInstance );
512
506
}
513
507
@@ -517,8 +511,8 @@ protected MethodParameter parseMethodParameter(final VariableElement parameter)
517
511
protected Field parseField (final VariableElement fieldDoc ) {
518
512
final Field fieldNode = objectFactory .createField ();
519
513
fieldNode .setType (parseTypeInfo (fieldDoc .asType ()));
520
- fieldNode .setName (fieldDoc . getSimpleName (). toString ( ));
521
- fieldNode .setQualified (fieldDoc . getSimpleName (). toString ( ));
514
+ fieldNode .setName (getSimpleName (fieldDoc ));
515
+ fieldNode .setQualified (getSimpleName (fieldDoc ));
522
516
String comment = getJavaDoc (fieldDoc );
523
517
if (!comment .isEmpty ()) {
524
518
fieldNode .setComment (comment );
@@ -531,8 +525,7 @@ protected Field parseField(final VariableElement fieldDoc) {
531
525
fieldNode .setConstant (requireNonNullElse (fieldDoc .getConstantValue (), "" ).toString ());
532
526
533
527
for (final AnnotationMirror annotationDesc : fieldDoc .getAnnotationMirrors ()) {
534
- fieldNode .getAnnotation ()
535
- .add (parseAnnotationDesc (annotationDesc , fieldDoc .getSimpleName ()));
528
+ fieldNode .getAnnotation ().add (parseAnnotationDesc (annotationDesc , fieldDoc .getSimpleName ()));
536
529
}
537
530
538
531
for (final DocTree tag : getTags (fieldDoc )) {
@@ -608,15 +601,15 @@ protected TagInfo parseTag(final DocTree tagDoc) {
608
601
609
602
/**
610
603
* {@return string representation of the element scope}
611
- *
604
+ *
612
605
* @param doc the element to get its scope
613
606
*/
614
607
protected String parseScope (final Element doc ) {
615
- if (doc . getModifiers (). contains ( Modifier .PRIVATE )) {
608
+ if (hasModifier ( doc , Modifier .PRIVATE )) {
616
609
return "private" ;
617
- } else if (doc . getModifiers (). contains ( Modifier .PROTECTED )) {
610
+ } else if (hasModifier ( doc , Modifier .PROTECTED )) {
618
611
return "protected" ;
619
- } else if (doc . getModifiers (). contains ( Modifier .PUBLIC )) {
612
+ } else if (hasModifier ( doc , Modifier .PUBLIC )) {
620
613
return "public" ;
621
614
}
622
615
0 commit comments