1818
1919import com .puppycrawl .tools .checkstyle .api .DetailNode ;
2020import com .puppycrawl .tools .checkstyle .api .JavadocCommentsTokenTypes ;
21- import com .puppycrawl .tools .checkstyle .api .JavadocTokenTypes ;
2221import io .jooby .SneakyThrows .Consumer2 ;
2322import io .jooby .SneakyThrows .Consumer3 ;
2423import io .jooby .StatusCode ;
3231public class JavaDocTag {
3332 private static final Predicate <DetailNode > CUSTOM_TAG =
3433 javadocToken (JavadocCommentsTokenTypes .CUSTOM_BLOCK_TAG );
35- private static final Predicate <DetailNode > TAG_SHORT =
36- CUSTOM_TAG .and (it -> it .getText ().equals ("@tag" ));
37- private static final Predicate <DetailNode > TAG =
38- CUSTOM_TAG .and (it -> it .getText ().startsWith ("@tag." ));
39- private static final Predicate <DetailNode > SERVER =
40- CUSTOM_TAG .and (it -> it .getText ().startsWith ("@server." ));
34+ private static final Predicate <DetailNode > TAG_SHORT = it -> it .getText ().equals ("tag" );
35+ private static final Predicate <DetailNode > TAG = it -> it .getText ().startsWith ("tag." );
36+ private static final Predicate <DetailNode > SERVER = it -> it .getText ().startsWith ("server." );
4137 private static final Predicate <DetailNode > SECURITY =
42- CUSTOM_TAG .and (
43- it -> it .getText ().equals ("@security" ) || it .getText ().equals ("@securityRequirement" ));
44- private static final Predicate <DetailNode > SECURITY_REQUIREMENT =
45- CUSTOM_TAG .and (it -> it .getText ().equals ("@securityRequirement" ));
38+ it -> it .getText ().equals ("security" ) || it .getText ().equals ("securityRequirement" );
4639 private static final Predicate <DetailNode > SECURITY_SCHEME =
47- CUSTOM_TAG .and (it -> it .getText ().startsWith ("@securityScheme." ));
48- private static final Predicate <DetailNode > CONTACT =
49- CUSTOM_TAG .and (it -> it .getText ().startsWith ("@contact." ));
50- private static final Predicate <DetailNode > LICENSE =
51- CUSTOM_TAG .and (it -> it .getText ().startsWith ("@license." ));
40+ it -> it .getText ().startsWith ("securityScheme." );
41+ private static final Predicate <DetailNode > CONTACT = it -> it .getText ().startsWith ("contact." );
42+ private static final Predicate <DetailNode > LICENSE = it -> it .getText ().startsWith ("license." );
5243 private static final Predicate <DetailNode > OPERATION_ID =
53- CUSTOM_TAG .and (it -> it .getText ().equals ("@operationId" ));
54- private static final Predicate <DetailNode > EXTENSION =
55- CUSTOM_TAG .and (it -> it .getText ().startsWith ("@x-" ));
44+ it -> it .getText ().equals ("operationId" );
45+ private static final Predicate <DetailNode > EXTENSION = it -> it .getText ().startsWith ("x-" );
5646 private static final Predicate <DetailNode > THROWS =
57- it -> tree (it ).anyMatch (javadocToken (JavadocTokenTypes . THROWS_LITERAL ));
47+ it -> tree (it ).anyMatch (javadocToken (JavadocCommentsTokenTypes . THROWS_BLOCK_TAG ));
5848 private static final Predicate <DetailNode > PARAM =
59- it -> tree (it ).anyMatch (javadocToken (JavadocTokenTypes . PARAM_LITERAL ));
49+ it -> tree (it ).anyMatch (javadocToken (JavadocCommentsTokenTypes . PARAM_BLOCK_TAG ));
6050
6151 public static Map <String , String > getParametersDoc (DetailNode node ) {
6252 var parameters = new LinkedHashMap <String , String >();
6353 javaDocTag (
6454 node ,
6555 PARAM ,
6656 (tag , value ) -> {
67- children (tag )
68- .filter (javadocToken (JavadocTokenTypes .PARAMETER_NAME ))
57+ tree (tag )
58+ .filter (javadocToken (JavadocCommentsTokenTypes .PARAMETER_NAME ))
6959 .findFirst ()
7060 .map (DetailNode ::getText )
7161 .ifPresent (
72- name -> {
73- children (tag )
74- .filter (javadocToken (JavadocTokenTypes .DESCRIPTION ))
75- .findFirst ()
76- .map (description -> JavaDocNode .getText (tree (description ).toList (), true ))
77- .ifPresent (text -> parameters .put (name , text ));
78- });
62+ name ->
63+ tree (tag )
64+ .filter (javadocToken (JavadocCommentsTokenTypes .DESCRIPTION ))
65+ .findFirst ()
66+ .map (description -> JavaDocNode .getText (tree (description ).toList (), true ))
67+ .ifPresent (text -> parameters .put (name , text )));
7968 });
8069 return parameters ;
8170 }
@@ -84,10 +73,10 @@ public static String getReturnDoc(DetailNode node) {
8473 var text = new StringBuilder ();
8574 javaDocTag (
8675 node ,
87- javadocToken (JavadocTokenTypes . RETURN_LITERAL ),
76+ javadocToken (JavadocCommentsTokenTypes . RETURN_BLOCK_TAG ),
8877 (tag , value ) -> {
89- children (tag .getParent ())
90- .filter (javadocToken (JavadocTokenTypes .DESCRIPTION ))
78+ tree (tag .getParent ())
79+ .filter (javadocToken (JavadocCommentsTokenTypes .DESCRIPTION ))
9180 .findFirst ()
9281 .map (description -> JavaDocNode .getText (tree (description ).toList (), true ))
9382 .ifPresent (text ::append );
@@ -246,7 +235,7 @@ private static List<Map<String, Object>> parse(
246235 node ,
247236 filter ,
248237 (tag , value ) -> {
249- values .add (tag .getText ().substring (1 ));
238+ values .add (tag .getText ()); // .substring(1));
250239 values .add (value );
251240 });
252241 return JavaDocObjectParser .parse (values ).stream ()
@@ -267,14 +256,14 @@ public static Map<StatusCode, ResponseExt> throwList(DetailNode node) {
267256 .flatMap (
268257 it ->
269258 tree (it )
270- .filter (javadocToken (JavadocCommentsTokenTypes .HTML_TAG_START ))
271259 .filter (tagName -> tagName .getText ().equals ("code" ))
260+ .map (DetailNode ::getParent )
261+ .map (DetailNode ::getParent )
272262 .flatMap (
273- tagName ->
274- backward (tagName )
275- .filter (javadocToken (JavadocCommentsTokenTypes .TAG_NAME ))
276- .findFirst ()
277- .stream ())
263+ start ->
264+ children (start )
265+ .filter (
266+ javadocToken (JavadocCommentsTokenTypes .HTML_CONTENT )))
278267 .flatMap (
279268 htmlTag ->
280269 children (htmlTag )
@@ -365,7 +354,7 @@ public static void javaDocTag(
365354 .filter (javadocToken (JavadocCommentsTokenTypes .DESCRIPTION ))
366355 .findFirst ()
367356 .orElse (null );
368- var tagText = tagValue == null ? null : getText (List . of (), true );
357+ var tagText = tagValue == null ? null : getText (children ( tagValue ). toList (), true );
369358 consumer .accept (tagName , tagValue , tagText );
370359 }
371360 }
0 commit comments