├── .gitignore
├── LICENSE
├── README.md
├── pom.xml
├── super-java-doc-core
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── uifuture
│ │ └── supercore
│ │ ├── SuperJavaDoc.java
│ │ ├── format
│ │ └── Format.java
│ │ ├── framework
│ │ └── AbstractFramework.java
│ │ ├── model
│ │ ├── ApiAction.java
│ │ ├── ApiDoc.java
│ │ ├── ApiModule.java
│ │ ├── DocTags.java
│ │ ├── FieldInfo.java
│ │ └── ObjectInfo.java
│ │ ├── resolver
│ │ ├── DocTagResolver.java
│ │ ├── IgnoreApi.java
│ │ └── parser
│ │ │ ├── JavaParserDocTagResolver.java
│ │ │ └── converter
│ │ │ ├── JavaParserTagConverter.java
│ │ │ ├── JavaParserTagConverterManager.java
│ │ │ ├── ParamTagConverter.java
│ │ │ ├── RespTagConverter.java
│ │ │ ├── SeeTagConverter.java
│ │ │ └── impl
│ │ │ └── DefaultJavaParserTagConverterImpl.java
│ │ ├── tag
│ │ ├── AbstractDocTag.java
│ │ └── impl
│ │ │ ├── DocTagImpl.java
│ │ │ ├── ParamTagImpl.java
│ │ │ ├── RespTagImpl.java
│ │ │ └── SeeTagImpl.java
│ │ └── utils
│ │ ├── ClassMapperUtils.java
│ │ ├── ClassUtils.java
│ │ ├── CommentUtils.java
│ │ ├── Constant.java
│ │ ├── FileUtils.java
│ │ ├── JsonFormatUtils.java
│ │ └── JsonUtils.java
│ └── resources
│ └── logback.xml
├── super-java-doc-spring
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── uifuture
│ │ └── superspring
│ │ ├── format
│ │ ├── HtmlForamt.java
│ │ ├── MarkdownFormat.java
│ │ ├── VelocityTemplater.java
│ │ ├── api.vm
│ │ └── html.vm
│ │ └── framework
│ │ ├── ParamInfo.java
│ │ ├── SpringApiAction.java
│ │ ├── SpringApiModule.java
│ │ └── SpringWebFramework.java
│ └── resources
│ └── logback.xml
├── super-java-doc-starter
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── uifuture
│ │ └── superstarter
│ │ └── boot
│ │ ├── DocConfiguration.java
│ │ ├── DocController.java
│ │ ├── DocProperties.java
│ │ └── EnableDoc.java
│ └── resources
│ └── static
│ └── superJavaDoc
│ ├── element-ui.css
│ ├── element-ui.js
│ ├── fonts
│ └── element-icons.woff
│ ├── index.html
│ └── vue.min.js
└── super-java-doc-test
├── pom.xml
└── src
├── main
├── java
│ └── com
│ │ └── uifuture
│ │ └── test
│ │ ├── TestApplication.java
│ │ ├── controller
│ │ ├── AccountController.java
│ │ ├── CommController.java
│ │ └── UserController.java
│ │ └── vo
│ │ ├── Account.java
│ │ ├── AccountEx.java
│ │ └── User.java
└── resources
│ ├── application.yml
│ └── logback.xml
└── test
└── java
└── com
└── uifuture
└── test
└── SuperJavaDocTest.java
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled class file
2 | *.class
3 |
4 | # Log file
5 | *.log
6 |
7 | # BlueJ files
8 | *.ctxt
9 |
10 | # Mobile Tools for Java (J2ME)
11 | .mtj.tmp/
12 |
13 | # Package Files #
14 | *.jar
15 | *.war
16 | *.nar
17 | *.ear
18 | *.zip
19 | *.tar.gz
20 | *.rar
21 |
22 | ### IntelliJ IDEA ###
23 | .idea
24 | *.iws
25 | *.iml
26 | *.ipr
27 | */target
28 |
29 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
30 | hs_err_pid*
31 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | # superJavaDoc 快速文档构建框架
3 |
4 | - **基于Java注释生成接口文档**
5 | - **注释支持扩展**
6 | - **接口框架支持扩展**
7 | - **默认支持markdown和离线/在线html等格式的文档**
8 | - **默认支持spring mvc规范**
9 | - **默认支持spring-boot直接内嵌启动**
10 |
11 | ## 基于SpringBoot在线直接使用
12 |
13 | ### 1.引入Maven依赖
14 | ```xml
15 |
16 |
17 | com.uifuture
18 | super-java-doc-starter
19 | 1.0.0
20 |
21 | ```
22 |
23 | ### 2.增加EnableDoc注解
24 | 在Application类上加上EnableDoc注解
25 | ```java
26 | @EnableDoc //<--- 加上此注解以便启用XDOC在线HTML文档
27 | @SpringBootApplication
28 | public class TestApplication {
29 |
30 | public static void main(String[] args) {
31 | SpringApplication.run(TestApplication.class, args);
32 | }
33 | }
34 | ```
35 |
36 | ### 3.1 properties配置文件
37 | ```
38 | #在application.properties配置项目源码的位置,直接在项目里启动时,如果是单模块的maven项目,默认可以不配置
39 | #是否启动XDoc,默认是true,因为可以不填
40 | doc.enable=true
41 | #源码路径,多个时用英文逗号隔开,super-java-doc-test为项目模块名称。单模块项目可以将super-java-doc-test/去掉,直接使用src/main/java
42 | doc.sourcePath=super-java-doc-test/src/main/java
43 | #用于配置文档页面标题
44 | doc.title=在线接口文档
45 | #标识接口文档的版本号
46 | doc.version=1.0
47 | ```
48 | ### 3.2 yml配置文件
49 | ```yml
50 | doc:
51 | enable: true #是否启动superJavaDoc,默认是true,因为可以不填
52 | title: 在线接口文档 #用于配置文档页面标题
53 | sourcePath: super-java-doc-test/src/main/java #源码路径,多个时用英文逗号隔开
54 | version: 1.0 #标识接口文档的版本号
55 | ```
56 |
57 | ### 4 使用
58 | **以上配置就都写好了**
59 |
60 | **跟着随便写几个Controller作为Demo接口,便于直接浏览生成效果:**
61 | ```java
62 |
63 | /**
64 | * BlogsController
65 | *
66 | * @author chenhaoxiang
67 | * @date 2018-09-12 18:23:40
68 | */
69 | @Controller
70 | @RequestMapping("admin/blogs")
71 | public class BlogsController {
72 | @Resource
73 | private BlogsService blogsService;
74 |
75 | /**
76 | * 添加Blogs
77 | *
78 | * @param blogs 对象
79 | * @return ResultModel统一响应结果
80 | */
81 | @PostMapping("add")
82 | @ResponseBody
83 | public ResultModel add(Blogs blogs) {
84 | blogsService.insert(blogs);
85 | return ResultModel.success();
86 | }
87 |
88 | /**
89 | * 根据ID进行删除
90 | *
91 | * @param id 主键
92 | * @return ResultModel统一响应结果
93 | */
94 | @PostMapping("delete")
95 | @ResponseBody
96 | public ResultModel delete(@RequestParam Integer id) {
97 | blogsService.deleteById(id);
98 | return ResultModel.success();
99 | }
100 |
101 | /**
102 | * 根据ID进行修改Blogs对象
103 | *
104 | * @param blogs 对象中必须有ID主键
105 | * @return ResultModel统一响应结果
106 | */
107 | @PostMapping("update")
108 | @ResponseBody
109 | public ResultModel update(Blogs blogs) {
110 | blogsService.updateById(blogs);
111 | return ResultModel.success();
112 | }
113 |
114 | /**
115 | * 查询详情
116 | *
117 | * @param id 主键
118 | * @return ResultModel统一响应结果
119 | */
120 | @PostMapping("detail")
121 | @ResponseBody
122 | public ResultModel detail(@RequestParam Integer id) {
123 | Blogs blogs = blogsService.selectById(id);
124 | return ResultModel.success(blogs);
125 | }
126 |
127 | /**
128 | * 分页查询
129 | *
130 | * @param page 当前页 默认0 不分页
131 | * @param size 每页的条数 默认为0 查询所有
132 | * @return ResultModel统一响应结果
133 | */
134 | @PostMapping("list")
135 | @ResponseBody
136 | public ResultModel list(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer size) {
137 | PageHelper.startPage(page, size);
138 | List list = blogsService.selectAll();
139 | PageInfo pageInfo = new PageInfo(list);
140 | return ResultModel.success(pageInfo);
141 | }
142 |
143 | }
144 |
145 | ```
146 |
147 | **直接启动项目, 敲入地址: http://localhost:8080/superJavaDoc/index.html**
148 |
149 | 如下两个图,为部分展示内容。
150 | 
151 |
152 | 
153 |
154 | ### 2.生成离线文档
155 | **支持html:**
156 | ```java
157 | @Test
158 | public void buildMarkdown() {
159 | //生成离线的Markdown格式的接口文档
160 | ByteArrayOutputStream out = new ByteArrayOutputStream();
161 | String rootDir = System.getProperty("user.dir");
162 | SuperJavaDoc xDoc = new SuperJavaDoc(rootDir + "/src/main/java/com/uifuture", new SpringWebFramework());
163 | xDoc.build(out, new MarkdownFormat());
164 |
165 | System.out.println(out.toString());
166 | }
167 | ```
168 |
169 | **支持markdown:**
170 | ```java
171 | @Test
172 | public void buildHtml() throws Exception {
173 | //生成离线的HTML格式的接口文档
174 | String userDir = System.getProperty("user.dir");
175 | FileOutputStream out = new FileOutputStream(new File(userDir, "api.html"));
176 | SuperJavaDoc xDoc = new SuperJavaDoc(userDir + "/src/main/java/com/uifuture", new SpringWebFramework());
177 | xDoc.build(out, new HtmlForamt());
178 | }
179 | ```
180 |
181 | **注意:生产环境不推荐开启此文,可能会消耗性能,所以在生成环境下,配置文件中配置如下即可:**
182 | ```txt
183 | doc.enable=false
184 | ```
185 |
186 |
187 | 欢迎有志之士一起开发。提Issues。
188 |
189 |
190 | 参考项目:https://gitee.com/treeleaf/xDoc
191 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.uifuture
8 | super-java-doc
9 | pom
10 | 1.0.0
11 |
12 | super-java-doc-core
13 | super-java-doc-spring
14 | super-java-doc-starter
15 |
16 | super-java-doc
17 | https://github.com/chenhaoxiang/super-java-doc
18 | super-java-doc,基于Java doc注释,自动构建文档,项目地址:https://github.com/chenhaoxiang/super-java-doc
19 |
20 |
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-dependencies
25 | 2.0.3.RELEASE
26 | pom
27 | import
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 | org.slf4j
37 | slf4j-api
38 | 1.7.25
39 |
40 |
41 |
42 |
43 | com.fasterxml.jackson.core
44 | jackson-databind
45 |
46 |
47 |
48 | commons-beanutils
49 | commons-beanutils
50 | 1.9.3
51 |
52 |
53 |
54 | commons-io
55 | commons-io
56 | 2.5
57 |
58 |
59 |
60 | junit
61 | junit
62 | test
63 |
64 |
65 |
66 |
67 | org.apache.commons
68 | commons-lang3
69 | 3.4
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 | org.sonatype.oss
78 | oss-parent
79 | 7
80 |
81 |
82 |
83 |
84 | The Apache License, Version 2.0
85 | http://www.apache.org/licenses/LICENSE-2.0.txt
86 |
87 |
88 |
89 |
90 | master
91 | git@github.com:chenhaoxiang/super-java-doc.git
92 | scm:git:git@github.com:chenhaoxiang/super-java-doc.git
93 | scm:git:git@github.com:chenhaoxiang/super-java-doc.git
94 |
95 |
96 |
97 |
98 | chenhaoxiang
99 | uifuture@uifuture.com
100 | uifuture
101 | http://chenhaoxiang.cn
102 |
103 |
104 |
105 |
106 |
107 | sonatype-oss-release
108 |
109 |
110 |
111 | org.apache.maven.plugins
112 | maven-gpg-plugin
113 |
114 | 1.5
115 |
116 |
117 | sign-artifacts
118 | verify
119 |
120 | sign
121 |
122 |
123 |
124 |
125 |
126 |
127 | org.apache.maven.plugins
128 | maven-javadoc-plugin
129 | 2.7
130 |
131 |
132 | attach-javadocs
133 |
134 | jar
135 |
136 |
137 | -Xdoclint:none
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 | src/main/java
151 |
152 | **/*.vm
153 |
154 | false
155 |
156 |
157 | src/main/resources
158 |
159 | **/*.*
160 |
161 | false
162 |
163 |
164 |
165 |
166 |
167 | org.apache.maven.plugins
168 | maven-compiler-plugin
169 | 3.7.0
170 |
171 | 8
172 | 8
173 | UTF-8
174 |
175 |
176 |
177 |
178 | org.apache.maven.plugins
179 | maven-source-plugin
180 | 3.0.1
181 |
182 |
183 | attach-sources
184 |
185 | jar-no-fork
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
--------------------------------------------------------------------------------
/super-java-doc-core/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | super-java-doc
7 | com.uifuture
8 | 1.0.0
9 |
10 | 4.0.0
11 |
12 | super-java-doc-core
13 |
14 |
15 |
16 |
17 |
18 | com.github.javaparser
19 | javaparser-core
20 | 3.6.10
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/super-java-doc-core/src/main/java/com/uifuture/supercore/SuperJavaDoc.java:
--------------------------------------------------------------------------------
1 | /**
2 | * uifuture.com
3 | * Copyright (C) 2013-2018 All Rights Reserved.
4 | */
5 | package com.uifuture.supercore;
6 |
7 | import com.uifuture.supercore.format.Format;
8 | import com.uifuture.supercore.framework.AbstractFramework;
9 | import com.uifuture.supercore.model.ApiDoc;
10 | import com.uifuture.supercore.model.ApiModule;
11 | import com.uifuture.supercore.resolver.DocTagResolver;
12 | import com.uifuture.supercore.resolver.parser.JavaParserDocTagResolver;
13 | import com.uifuture.supercore.utils.FileUtils;
14 | import org.apache.commons.io.IOUtils;
15 | import org.slf4j.Logger;
16 | import org.slf4j.LoggerFactory;
17 |
18 | import java.io.File;
19 | import java.io.IOException;
20 | import java.io.OutputStream;
21 | import java.util.ArrayList;
22 | import java.util.Arrays;
23 | import java.util.List;
24 | import java.util.Map;
25 |
26 | /**
27 | * 主入口,核心处理从这里开始
28 | *
29 | * @author chenhx
30 | * @version SuperMain.java, v 0.1 2018-09-26 下午 5:27
31 | */
32 | public class SuperJavaDoc {
33 |
34 | private static final String CHARSET = "utf-8";
35 |
36 | private Logger log = LoggerFactory.getLogger(getClass());
37 |
38 | /**
39 | * 源码路径
40 | */
41 | private List srcPaths;
42 |
43 | /**
44 | * api框架类型
45 | */
46 | private AbstractFramework abstractFramework;
47 |
48 | /**
49 | * 默认的java注释解析器实现
50 | *
51 | * 备注:基于sun doc的解析方式已经废弃,若需要请参考v1.0之前的版本
52 | *
53 | * @see JavaParserDocTagResolver
54 | */
55 | private DocTagResolver docTagResolver = new JavaParserDocTagResolver();
56 |
57 | /**
58 | * 构建doc对象
59 | * @param srcPath 源码路径
60 | * @param abstractFramework
61 | */
62 | public SuperJavaDoc(String srcPath, AbstractFramework abstractFramework) {
63 | this(Arrays.asList(srcPath), abstractFramework);
64 | }
65 |
66 | /**
67 | * 构建SuperJavaDoc对象
68 | * @param srcPaths 源码路径,支持多个
69 | * @param abstractFramework
70 | */
71 | public SuperJavaDoc(List srcPaths, AbstractFramework abstractFramework) {
72 | this.srcPaths = srcPaths;
73 | this.abstractFramework = abstractFramework;
74 | }
75 |
76 | /**
77 | * 解析源码并返回对应的接口数据
78 | *
79 | * @return API接口数据
80 | */
81 | public ApiDoc resolve() {
82 | List files = new ArrayList<>();
83 | for (String srcPath : this.srcPaths) {
84 | files.addAll(FileUtils.getAllJavaFiles(new File(srcPath)));
85 | }
86 |
87 | List apiModules = this.docTagResolver.resolve(files, abstractFramework);
88 |
89 | if (abstractFramework != null) {
90 | apiModules = abstractFramework.extend(apiModules);
91 | }
92 | return new ApiDoc(apiModules);
93 | }
94 |
95 | /**
96 | * 构建接口文档
97 | *
98 | * @param out 输出位置
99 | * @param format 文档格式
100 | */
101 | public void build(OutputStream out, Format format) {
102 | this.build(out, format, null);
103 | }
104 |
105 | /**
106 | * 构建接口文档
107 | *
108 | * @param out 输出位置
109 | * @param format 文档格式
110 | * @param properties 文档属性
111 | */
112 | public void build(OutputStream out, Format format, Map properties) {
113 | ApiDoc apiDoc = this.resolve();
114 | if (properties != null) {
115 | apiDoc.getProperties().putAll(properties);
116 | }
117 |
118 | if (apiDoc.getApiModules() != null && out != null && format != null) {
119 | String s = format.format(apiDoc);
120 | try {
121 | IOUtils.write(s, out, CHARSET);
122 | } catch (IOException e) {
123 | log.error("接口文档写入文件失败", e);
124 | } finally {
125 | IOUtils.closeQuietly(out);
126 | }
127 | }
128 | }
129 |
130 | /**
131 | * Setter method for property srcPaths.
132 | *
133 | * @param srcPaths value to be assigned to property srcPaths
134 | */
135 | public void setSrcPaths(List srcPaths) {
136 | this.srcPaths = srcPaths;
137 | }
138 |
139 | /**
140 | * Setter method for property framework.
141 | *
142 | * @param abstractFramework value to be assigned to property framework
143 | */
144 | public void setAbstractFramework(AbstractFramework abstractFramework) {
145 | this.abstractFramework = abstractFramework;
146 | }
147 |
148 | /**
149 | * Setter method for property docTagResolver.
150 | *
151 | * @param docTagResolver value to be assigned to property docTagResolver
152 | */
153 | public void setDocTagResolver(DocTagResolver docTagResolver) {
154 | this.docTagResolver = docTagResolver;
155 | }
156 | }
--------------------------------------------------------------------------------
/super-java-doc-core/src/main/java/com/uifuture/supercore/format/Format.java:
--------------------------------------------------------------------------------
1 | /**
2 | * uifuture.com
3 | * Copyright (C) 2013-2018 All Rights Reserved.
4 | */
5 | package com.uifuture.supercore.format;
6 |
7 | import com.uifuture.supercore.model.ApiDoc;
8 |
9 | /**
10 | * 文档输出格式
11 | *
12 | * @author chenhx
13 | * @version Format.java, v 0.1 2018-09-26 下午 4:31
14 | */
15 | public interface Format {
16 | String format(ApiDoc apiDoc);
17 | }
--------------------------------------------------------------------------------
/super-java-doc-core/src/main/java/com/uifuture/supercore/framework/AbstractFramework.java:
--------------------------------------------------------------------------------
1 | /**
2 | * uifuture.com
3 | * Copyright (C) 2013-2018 All Rights Reserved.
4 | */
5 | package com.uifuture.supercore.framework;
6 |
7 | import com.uifuture.supercore.model.ApiModule;
8 |
9 | import java.util.List;
10 |
11 | /**
12 | * 抽象各种API框架的特性,用于在基于SuperJavaDoc-core渲染出来的ApiModule基础中,进行再度包装
13 | *
14 | * @author chenhx
15 | * @version Framework.java, v 0.1 2018-09-26 下午 4:45
16 | */
17 | public abstract class AbstractFramework {
18 |
19 | /**
20 | * 扩展API数据
21 | *
22 | * @param apiModules 原始基本的Api数据
23 | * @return 扩展后的api数据
24 | */
25 | public abstract List extend(List apiModules);
26 |
27 | /**
28 | * 判断该类是否适合该框架
29 | *
30 | * @param classz 扫描到的类
31 | * @return 是支持
32 | */
33 | public abstract boolean support(Class> classz);
34 | }
--------------------------------------------------------------------------------
/super-java-doc-core/src/main/java/com/uifuture/supercore/model/ApiAction.java:
--------------------------------------------------------------------------------
1 | /**
2 | * uifuture.com
3 | * Copyright (C) 2013-2018 All Rights Reserved.
4 | */
5 | package com.uifuture.supercore.model;
6 |
7 | import com.fasterxml.jackson.annotation.JsonIgnore;
8 |
9 | import java.lang.reflect.Method;
10 |
11 | /**
12 | * 接口信息,一个接口类里面会有多个接口,每个接口都抽象成ApiAction
13 | *
14 | * @author chenhx
15 | * @version ApiAction.java, v 0.1 2018-09-26 下午 4:32
16 | */
17 | public class ApiAction {
18 | /**
19 | * 展示用的标题
20 | */
21 | private String title;
22 |
23 | /**
24 | * 接口方法名称
25 | */
26 | private String name;
27 |
28 | /**
29 | * 接口方法
30 | */
31 | @JsonIgnore
32 | private transient Method method;
33 |
34 | /**
35 | * 接口的描述
36 | */
37 | private String comment;
38 |
39 | /**
40 | * 方法上标注的注解
41 | */
42 | private com.uifuture.supercore.model.DocTags docTags;
43 |
44 | /**
45 | * Getter method for property title.
46 | *
47 | * @return property value of title
48 | */
49 | public String getTitle() {
50 | return title;
51 | }
52 |
53 | /**
54 | * Setter method for property title.
55 | *
56 | * @param title value to be assigned to property title
57 | */
58 | public void setTitle(String title) {
59 | this.title = title;
60 | }
61 |
62 | /**
63 | * Getter method for property name.
64 | *
65 | * @return property value of name
66 | */
67 | public String getName() {
68 | return name;
69 | }
70 |
71 | /**
72 | * Setter method for property name.
73 | *
74 | * @param name value to be assigned to property name
75 | */
76 | public void setName(String name) {
77 | this.name = name;
78 | }
79 |
80 | /**
81 | * Getter method for property method.
82 | *
83 | * @return property value of method
84 | */
85 | public Method getMethod() {
86 | return method;
87 | }
88 |
89 | /**
90 | * Setter method for property method.
91 | *
92 | * @param method value to be assigned to property method
93 | */
94 | public void setMethod(Method method) {
95 | this.method = method;
96 | }
97 |
98 | /**
99 | * Getter method for property comment.
100 | *
101 | * @return property value of comment
102 | */
103 | public String getComment() {
104 | return comment;
105 | }
106 |
107 | /**
108 | * Setter method for property comment.
109 | *
110 | * @param comment value to be assigned to property comment
111 | */
112 | public void setComment(String comment) {
113 | this.comment = comment;
114 | }
115 |
116 | /**
117 | * Getter method for property docTags.
118 | *
119 | * @return property value of docTags
120 | */
121 | public com.uifuture.supercore.model.DocTags getDocTags() {
122 | return docTags;
123 | }
124 |
125 | /**
126 | * Setter method for property docTags.
127 | *
128 | * @param docTags value to be assigned to property docTags
129 | */
130 | public void setDocTags(com.uifuture.supercore.model.DocTags docTags) {
131 | this.docTags = docTags;
132 | }
133 | }
--------------------------------------------------------------------------------
/super-java-doc-core/src/main/java/com/uifuture/supercore/model/ApiDoc.java:
--------------------------------------------------------------------------------
1 | /**
2 | * uifuture.com
3 | * Copyright (C) 2013-2018 All Rights Reserved.
4 | */
5 | package com.uifuture.supercore.model;
6 |
7 | import java.util.HashMap;
8 | import java.util.List;
9 | import java.util.Map;
10 |
11 | /**
12 | * @author chenhx
13 | * @version ApiDoc.java, v 0.1 2018-09-26 下午 4:31
14 | */
15 | public class ApiDoc {
16 |
17 | /**
18 | * 附带的属性
19 | */
20 | private Map properties = new HashMap<>();
21 |
22 | /**
23 | * 所有API模块
24 | */
25 | private List apiModules;
26 |
27 | public ApiDoc(List apiModules) {
28 | this.apiModules = apiModules;
29 | }
30 |
31 | public ApiDoc(Map properties, List apiModules) {
32 | this.properties = properties;
33 | this.apiModules = apiModules;
34 | }
35 |
36 | /**
37 | * Getter method for property properties.
38 | *
39 | * @return property value of properties
40 | */
41 | public Map getProperties() {
42 | return properties;
43 | }
44 |
45 | /**
46 | * Setter method for property properties.
47 | *
48 | * @param properties value to be assigned to property properties
49 | */
50 | public void setProperties(Map properties) {
51 | this.properties = properties;
52 | }
53 |
54 | /**
55 | * Getter method for property apiModules.
56 | *
57 | * @return property value of apiModules
58 | */
59 | public List getApiModules() {
60 | return apiModules;
61 | }
62 |
63 | /**
64 | * Setter method for property apiModules.
65 | *
66 | * @param apiModules value to be assigned to property apiModules
67 | */
68 | public void setApiModules(List apiModules) {
69 | this.apiModules = apiModules;
70 | }
71 | }
--------------------------------------------------------------------------------
/super-java-doc-core/src/main/java/com/uifuture/supercore/model/ApiModule.java:
--------------------------------------------------------------------------------
1 | /**
2 | * uifuture.com
3 | * Copyright (C) 2013-2018 All Rights Reserved.
4 | */
5 | package com.uifuture.supercore.model;
6 |
7 | import com.fasterxml.jackson.annotation.JsonIgnore;
8 |
9 | import java.util.LinkedList;
10 | import java.util.List;
11 |
12 | /**
13 | * 接口业务模块,一个接口类为一个模块
14 | *
15 | * @author chenhx
16 | * @version ApiModule.java, v 0.1 2018-09-26 下午 4:32
17 | */
18 | public class ApiModule {
19 | /**
20 | * 源码在哪个类
21 | */
22 | @JsonIgnore
23 | private transient Class> type;
24 |
25 | /**
26 | * 业务模块的描述
27 | */
28 | private String comment;
29 |
30 | /**
31 | * 此业务模块下有哪些接口
32 | */
33 | private List apiActions = new LinkedList<>();
34 |
35 | /**
36 | * Getter method for property type.
37 | *
38 | * @return property value of type
39 | */
40 | public Class> getType() {
41 | return type;
42 | }
43 |
44 | /**
45 | * Setter method for property type.
46 | *
47 | * @param type value to be assigned to property type
48 | */
49 | public void setType(Class> type) {
50 | this.type = type;
51 | }
52 |
53 | /**
54 | * Getter method for property comment.
55 | *
56 | * @return property value of comment
57 | */
58 | public String getComment() {
59 | return comment;
60 | }
61 |
62 | /**
63 | * Setter method for property comment.
64 | *
65 | * @param comment value to be assigned to property comment
66 | */
67 | public void setComment(String comment) {
68 | this.comment = comment;
69 | }
70 |
71 | /**
72 | * Getter method for property apiActions.
73 | *
74 | * @return property value of apiActions
75 | */
76 | public List getApiActions() {
77 | return apiActions;
78 | }
79 |
80 | /**
81 | * Setter method for property apiActions.
82 | *
83 | * @param apiActions value to be assigned to property apiActions
84 | */
85 | public void setApiActions(List apiActions) {
86 | this.apiActions = apiActions;
87 | }
88 | }
--------------------------------------------------------------------------------
/super-java-doc-core/src/main/java/com/uifuture/supercore/model/DocTags.java:
--------------------------------------------------------------------------------
1 | /**
2 | * uifuture.com
3 | * Copyright (C) 2013-2018 All Rights Reserved.
4 | */
5 | package com.uifuture.supercore.model;
6 |
7 | import com.uifuture.supercore.tag.AbstractDocTag;
8 |
9 | import java.util.ArrayList;
10 | import java.util.List;
11 |
12 | /**
13 | * @author chenhx
14 | * @version DocTags.java, v 0.1 2018-09-26 下午 4:37
15 | */
16 | public class DocTags {
17 |
18 | private List list;
19 |
20 | public DocTags() {
21 | }
22 |
23 | public DocTags(List list) {
24 | this.list = list;
25 | }
26 |
27 | public AbstractDocTag getTag(String name) {
28 | for (int i = 0; i < list.size(); i++) {
29 | AbstractDocTag abstractDocTag = list.get(i);
30 | if (abstractDocTag.getTagName().equals(name)) {
31 | return abstractDocTag;
32 | }
33 | }
34 | return null;
35 | }
36 |
37 | public List getTags(String name) {
38 | List abstractDocTags = new ArrayList();
39 | for (int i = 0; i < list.size(); i++) {
40 | AbstractDocTag abstractDocTag = list.get(i);
41 | if (abstractDocTag.getTagName().equals(name)) {
42 | abstractDocTags.add(abstractDocTag);
43 | }
44 | }
45 | return abstractDocTags;
46 | }
47 |
48 | /**
49 | * Getter method for property list.
50 | *
51 | * @return property value of list
52 | */
53 | public List getList() {
54 | return list;
55 | }
56 |
57 | /**
58 | * Setter method for property list.
59 | *
60 | * @param list value to be assigned to property list
61 | */
62 | public void setList(List list) {
63 | this.list = list;
64 | }
65 | }
--------------------------------------------------------------------------------
/super-java-doc-core/src/main/java/com/uifuture/supercore/model/FieldInfo.java:
--------------------------------------------------------------------------------
1 | /**
2 | * uifuture.com
3 | * Copyright (C) 2013-2018 All Rights Reserved.
4 | */
5 | package com.uifuture.supercore.model;
6 |
7 | import java.util.List;
8 |
9 | /**
10 | * @author chenhx
11 | * @version FieldInfo.java, v 0.1 2018-09-26 下午 4:37
12 | */
13 | public class FieldInfo {
14 |
15 | private String name;
16 |
17 | private Class> type;
18 |
19 | private String simpleTypeName;
20 |
21 | private String comment;
22 |
23 | /**
24 | * 是否必填,默认false
25 | */
26 | private boolean require;
27 |
28 | private List fieldInfos;
29 |
30 | /**
31 | * Getter method for property name.
32 | *
33 | * @return property value of name
34 | */
35 | public String getName() {
36 | return name;
37 | }
38 |
39 | /**
40 | * Setter method for property name.
41 | *
42 | * @param name value to be assigned to property name
43 | */
44 | public void setName(String name) {
45 | this.name = name;
46 | }
47 |
48 | /**
49 | * Getter method for property type.
50 | *
51 | * @return property value of type
52 | */
53 | public Class> getType() {
54 | return type;
55 | }
56 |
57 | /**
58 | * Setter method for property type.
59 | *
60 | * @param type value to be assigned to property type
61 | */
62 | public void setType(Class> type) {
63 | this.type = type;
64 | }
65 |
66 | /**
67 | * Getter method for property simpleTypeName.
68 | *
69 | * @return property value of simpleTypeName
70 | */
71 | public String getSimpleTypeName() {
72 | return simpleTypeName;
73 | }
74 |
75 | /**
76 | * Setter method for property simpleTypeName.
77 | *
78 | * @param simpleTypeName value to be assigned to property simpleTypeName
79 | */
80 | public void setSimpleTypeName(String simpleTypeName) {
81 | this.simpleTypeName = simpleTypeName;
82 | }
83 |
84 | /**
85 | * Getter method for property comment.
86 | *
87 | * @return property value of comment
88 | */
89 | public String getComment() {
90 | return comment;
91 | }
92 |
93 | /**
94 | * Setter method for property comment.
95 | *
96 | * @param comment value to be assigned to property comment
97 | */
98 | public void setComment(String comment) {
99 | this.comment = comment;
100 | }
101 |
102 | /**
103 | * Getter method for property require.
104 | *
105 | * @return property value of require
106 | */
107 | public boolean isRequire() {
108 | return require;
109 | }
110 |
111 | /**
112 | * Setter method for property require.
113 | *
114 | * @param require value to be assigned to property require
115 | */
116 | public void setRequire(boolean require) {
117 | this.require = require;
118 | }
119 |
120 | /**
121 | * Getter method for property fieldInfos.
122 | *
123 | * @return property value of fieldInfos
124 | */
125 | public List getFieldInfos() {
126 | return fieldInfos;
127 | }
128 |
129 | /**
130 | * Setter method for property fieldInfos.
131 | *
132 | * @param fieldInfos value to be assigned to property fieldInfos
133 | */
134 | public void setFieldInfos(List fieldInfos) {
135 | this.fieldInfos = fieldInfos;
136 | }
137 | }
--------------------------------------------------------------------------------
/super-java-doc-core/src/main/java/com/uifuture/supercore/model/ObjectInfo.java:
--------------------------------------------------------------------------------
1 | /**
2 | * uifuture.com
3 | * Copyright (C) 2013-2018 All Rights Reserved.
4 | */
5 | package com.uifuture.supercore.model;
6 |
7 | import java.util.ArrayList;
8 | import java.util.List;
9 |
10 | /**
11 | * @author chenhx
12 | * @version ObjectInfo.java, v 0.1 2018-09-26 下午 4:40
13 | */
14 | public class ObjectInfo {
15 |
16 | private String name;
17 |
18 | /**
19 | * 源码在哪个类
20 | */
21 | private Class> type;
22 |
23 | private String comment;
24 |
25 | private List fieldInfos = new ArrayList<>();
26 |
27 | /**
28 | * Getter method for property name.
29 | *
30 | * @return property value of name
31 | */
32 | public String getName() {
33 | return name;
34 | }
35 |
36 | /**
37 | * Setter method for property name.
38 | *
39 | * @param name value to be assigned to property name
40 | */
41 | public void setName(String name) {
42 | this.name = name;
43 | }
44 |
45 | /**
46 | * Getter method for property type.
47 | *
48 | * @return property value of type
49 | */
50 | public Class> getType() {
51 | return type;
52 | }
53 |
54 | /**
55 | * Setter method for property type.
56 | *
57 | * @param type value to be assigned to property type
58 | */
59 | public void setType(Class> type) {
60 | this.type = type;
61 | }
62 |
63 | /**
64 | * Getter method for property comment.
65 | *
66 | * @return property value of comment
67 | */
68 | public String getComment() {
69 | return comment;
70 | }
71 |
72 | /**
73 | * Setter method for property comment.
74 | *
75 | * @param comment value to be assigned to property comment
76 | */
77 | public void setComment(String comment) {
78 | this.comment = comment;
79 | }
80 |
81 | /**
82 | * Getter method for property fieldInfos.
83 | *
84 | * @return property value of fieldInfos
85 | */
86 | public List getFieldInfos() {
87 | return fieldInfos;
88 | }
89 |
90 | /**
91 | * Setter method for property fieldInfos.
92 | *
93 | * @param fieldInfos value to be assigned to property fieldInfos
94 | */
95 | public void setFieldInfos(List fieldInfos) {
96 | this.fieldInfos = fieldInfos;
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/super-java-doc-core/src/main/java/com/uifuture/supercore/resolver/DocTagResolver.java:
--------------------------------------------------------------------------------
1 | /**
2 | * uifuture.com
3 | * Copyright (C) 2013-2018 All Rights Reserved.
4 | */
5 | package com.uifuture.supercore.resolver;
6 |
7 | import com.uifuture.supercore.framework.AbstractFramework;
8 | import com.uifuture.supercore.model.ApiModule;
9 |
10 | import java.util.List;
11 |
12 | /**
13 | * 注释解析器接口,所有的解析器实现都要继承此接口
14 | *