Skip to content
This repository was archived by the owner on Dec 19, 2023. It is now read-only.

Commit 297d93a

Browse files
authored
Fix handling of invalid tags and migrate deprecated method (#374)
* Fix handling of invalid tags and migrate deprecated method * Fix handling of invalid tags and migrate deprecated method * Fix handling of invalid tags for fields
1 parent b9f133c commit 297d93a

File tree

5 files changed

+26
-11
lines changed

5 files changed

+26
-11
lines changed

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,11 @@
338338
<artifactId>commons-lang3</artifactId>
339339
<version>3.9</version>
340340
</dependency>
341+
<dependency>
342+
<groupId>org.apache.commons</groupId>
343+
<artifactId>commons-text</artifactId>
344+
<version>1.8</version>
345+
</dependency>
341346
<dependency>
342347
<groupId>commons-io</groupId>
343348
<artifactId>commons-io</artifactId>

spring-auto-restdocs-json-doclet-jdk9/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
</dependency>
2727
<dependency>
2828
<groupId>org.apache.commons</groupId>
29-
<artifactId>commons-lang3</artifactId>
29+
<artifactId>commons-text</artifactId>
3030
</dependency>
3131
<dependency>
3232
<groupId>junit</groupId>

spring-auto-restdocs-json-doclet-jdk9/src/main/java/capital/scalable/restdocs/jsondoclet/FieldDocumentation.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* #%L
33
* Spring Auto REST Docs Json Doclet for JDK9+
44
* %%
5-
* Copyright (C) 2015 - 2019 Scalable Capital GmbH
5+
* Copyright (C) 2015 - 2020 Scalable Capital GmbH
66
* %%
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
@@ -29,26 +29,31 @@
2929
import java.util.Optional;
3030

3131
import com.sun.source.doctree.BlockTagTree;
32+
import com.sun.source.doctree.DocTree;
3233
import jdk.javadoc.doclet.DocletEnvironment;
3334

3435
public class FieldDocumentation {
3536

3637
private String comment;
3738
private final Map<String, String> tags = new HashMap<>();
3839

40+
private void addTag(DocTree tag) {
41+
if (tag instanceof BlockTagTree) {
42+
tags.put(
43+
cleanupTagName(((BlockTagTree) tag).getTagName()),
44+
cleanupTagValue(tag.toString()));
45+
}
46+
}
47+
3948
public static FieldDocumentation fromFieldDoc(DocletEnvironment docEnv,
4049
Element fieldElement) {
4150
FieldDocumentation fd = new FieldDocumentation();
4251
fd.comment = cleanupDocComment(docEnv.getElementUtils().getDocComment(fieldElement));
4352

44-
4553
Optional.ofNullable(docEnv.getDocTrees().getDocCommentTree(fieldElement))
4654
.ifPresent(docCommentTree -> docCommentTree.getBlockTags()
47-
.forEach(tag -> fd.tags.put(
48-
cleanupTagName(((BlockTagTree) tag).getTagName()),
49-
cleanupTagValue(tag.toString()))));
55+
.forEach(tag -> fd.addTag(tag)));
5056

5157
return fd;
5258
}
53-
5459
}

spring-auto-restdocs-json-doclet-jdk9/src/main/java/capital/scalable/restdocs/jsondoclet/MethodDocumentation.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* #%L
33
* Spring Auto REST Docs Json Doclet for JDK9+
44
* %%
5-
* Copyright (C) 2015 - 2019 Scalable Capital GmbH
5+
* Copyright (C) 2015 - 2020 Scalable Capital GmbH
66
* %%
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
@@ -22,7 +22,7 @@
2222
import static capital.scalable.restdocs.jsondoclet.DocletUtils.cleanupDocComment;
2323
import static capital.scalable.restdocs.jsondoclet.DocletUtils.cleanupTagName;
2424
import static capital.scalable.restdocs.jsondoclet.DocletUtils.cleanupTagValue;
25-
import static org.apache.commons.lang3.StringEscapeUtils.unescapeJava;
25+
import static org.apache.commons.text.StringEscapeUtils.unescapeJava;
2626

2727
import javax.lang.model.element.Element;
2828
import java.util.HashMap;
@@ -54,7 +54,7 @@ public static MethodDocumentation fromMethodDoc(DocletEnvironment docEnv,
5454
ParamTree paramTag = (ParamTree) tag;
5555
md.parameters.put(paramTag.getName().toString(),
5656
unescapeJava(paramTag.getDescription().toString()));
57-
} else {
57+
} else if (tag instanceof BlockTagTree) {
5858
md.tags.put(
5959
cleanupTagName(((BlockTagTree) tag).getTagName()),
6060
unescapeJava(cleanupTagValue(tag.toString())));

spring-auto-restdocs-json-doclet-jdk9/src/test/java/capital/scalable/restdocs/jsondoclet/DocumentedClass.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* #%L
33
* Spring Auto REST Docs Json Doclet for JDK9+
44
* %%
5-
* Copyright (C) 2015 - 2019 Scalable Capital GmbH
5+
* Copyright (C) 2015 - 2020 Scalable Capital GmbH
66
* %%
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
@@ -23,6 +23,8 @@
2323

2424
/**
2525
* This is a test class. UTF 8 test: 我能吞下玻璃而不伤身体。Árvíztűrő tükörfúrógép
26+
*
27+
* @ Don't fail on invalid tags
2628
*/
2729
class DocumentedClass {
2830
/**
@@ -34,6 +36,8 @@ class DocumentedClass {
3436

3537
/**
3638
* Path within location
39+
*
40+
* @ Don't fail on invalid tags
3741
*/
3842
private BigDecimal path;
3943

@@ -54,6 +58,7 @@ public void execute() {
5458
* @param force true if force (テスト)
5559
* @title Do initiate (テスト)
5660
* @deprecated use other method (テスト)
61+
* @ Don't fail on invalid tags
5762
*/
5863
private void initiate(String when, boolean force, int notDocumented) {
5964
}

0 commit comments

Comments
 (0)