Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
apidoc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
duanledexianxianxian
apidoc
Commits
8f321eae
Commit
8f321eae
authored
Mar 30, 2020
by
duanledexianxianxian
😁
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
生成markdown api文档
parent
01c179c7
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
109 additions
and
12 deletions
+109
-12
apidoc-core/src/main/java/com/kim/apidoc/core/parser/VisitorParser.java
...c/main/java/com/kim/apidoc/core/parser/VisitorParser.java
+44
-8
apidoc-core/src/main/java/com/kim/apidoc/core/schema/Appendix.java
...re/src/main/java/com/kim/apidoc/core/schema/Appendix.java
+61
-0
apidoc-core/src/main/java/com/kim/apidoc/core/schema/Node.java
...c-core/src/main/java/com/kim/apidoc/core/schema/Node.java
+4
-4
No files found.
apidoc-core/src/main/java/com/kim/apidoc/core/parser/VisitorParser.java
View file @
8f321eae
package
com.kim.apidoc.core.parser
;
import
com.github.javaparser.ast.comments.Comment
;
import
com.github.javaparser.ast.comments.JavadocComment
;
import
com.
kim.apidoc.core.schema.Chapter
;
import
com.
kim.apidoc.core.schema.Node
;
import
com.kim.apidoc.core.
schema.Project
;
import
com.kim.apidoc.core.schema.
Section
;
import
com.
github.javaparser.javadoc.Javadoc
;
import
com.
github.javaparser.javadoc.JavadocBlockTag
;
import
com.kim.apidoc.core.
common.helper.CommentHelper
;
import
com.kim.apidoc.core.schema.
*
;
import
com.kim.apidoc.core.common.helper.OptionalHelper
;
import
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration
;
import
com.github.javaparser.ast.body.MethodDeclaration
;
import
com.github.javaparser.ast.visitor.VoidVisitorAdapter
;
import
jdk.nashorn.internal.runtime.options.Option
;
import
java.util.Optional
;
/**
* The type Visitor parser.
...
...
@@ -37,8 +41,14 @@ public class VisitorParser extends VoidVisitorAdapter<Node> {
*/
@Override
public
void
visit
(
final
ClassOrInterfaceDeclaration
classOrInterfaceDeclaration
,
final
Node
arg
)
{
if
(
arg
instanceof
Project
&&
isExistTag
(
classOrInterfaceDeclaration
,
"code"
))
{
}
if
(
arg
instanceof
Project
&&
isExistTag
(
classOrInterfaceDeclaration
,
"resultData"
))
{
}
if
(
arg
instanceof
Project
)
{
if
(
arg
instanceof
Project
&&
parserStrategy
.
accept
(
classOrInterfaceDeclaration
)
)
{
Project
project
=
(
Project
)
arg
;
// 章节
Chapter
chapter
=
new
Chapter
();
...
...
@@ -49,14 +59,40 @@ public class VisitorParser extends VoidVisitorAdapter<Node> {
OptionalHelper
.
any
(
chapter
.
getTag
(
"book"
),
chapter
.
getTag
(
"group"
))
.
ifPresent
(
tag
->
chapter
.
setBookName
(
tag
.
getContent
()));
if
(
parserStrategy
.
accept
(
classOrInterfaceDeclaration
))
{
parserStrategy
.
visit
(
classOrInterfaceDeclaration
,
chapter
);
}
project
.
addChapter
(
chapter
);
super
.
visit
(
classOrInterfaceDeclaration
,
chapter
);
}
}
/**
* 处理特殊的tag
*
* @param classOrInterfaceDeclaration the class or interface declaration
* @param tag the tag
* @return boolean boolean
*/
private
Boolean
isExistTag
(
ClassOrInterfaceDeclaration
classOrInterfaceDeclaration
,
String
tag
)
{
if
(
classOrInterfaceDeclaration
.
getComment
().
isPresent
())
{
Comment
comment
=
classOrInterfaceDeclaration
.
getComment
().
get
();
if
(!
comment
.
isJavadocComment
())
{
return
false
;
}
Javadoc
javadoc
=
comment
.
asJavadocComment
().
parse
();
Optional
<
JavadocBlockTag
>
blockTagOptional
=
javadoc
.
getBlockTags
().
stream
().
filter
(
blockTag
->
{
return
tag
.
equalsIgnoreCase
(
blockTag
.
getTagName
());
}).
findFirst
();
if
(
blockTagOptional
.
isPresent
())
{
return
true
;
}
}
return
false
;
}
@Override
public
void
visit
(
JavadocComment
n
,
Node
arg
)
{
super
.
visit
(
n
,
arg
);
...
...
apidoc-core/src/main/java/com/kim/apidoc/core/schema/Appendix.java
0 → 100644
View file @
8f321eae
package
com.kim.apidoc.core.schema
;
import
com.github.fengyuchenglun.core.common.Cell
;
import
com.github.fengyuchenglun.core.resolver.ast.Enums
;
import
com.github.fengyuchenglun.core.resolver.ast.Fields
;
import
com.github.javaparser.ast.body.BodyDeclaration
;
import
com.github.javaparser.ast.comments.JavadocComment
;
import
com.github.javaparser.ast.nodeTypes.NodeWithSimpleName
;
import
lombok.Getter
;
import
lombok.Setter
;
import
javax.annotation.Nullable
;
import
java.util.ArrayList
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
* 附录
*/
@Setter
@Getter
public
class
Appendix
extends
Node
{
Map
<
String
,
Row
>
rows
=
new
LinkedHashMap
<>();
public
boolean
isEmpty
()
{
return
cells
.
isEmpty
();
}
@Nullable
public
static
Appendix
parse
(
JavadocComment
n
)
{
// 无注释
if
(!
n
.
getCommentedNode
().
isPresent
())
{
return
null
;
}
// 注释所在的类或者枚举
final
com
.
github
.
javaparser
.
ast
.
Node
node
=
n
.
getCommentedNode
().
get
();
if
(!(
node
instanceof
BodyDeclaration
)){
return
null
;
}
final
BodyDeclaration
bodyDeclaration
=
(
BodyDeclaration
)
node
;
// 不是枚举与接口/类
if
(!
bodyDeclaration
.
isEnumDeclaration
()
&&
!
bodyDeclaration
.
isClassOrInterfaceDeclaration
()){
return
null
;
}
Appendix
appendix
=
new
Appendix
();
// 枚举
if
(
bodyDeclaration
.
isEnumDeclaration
())
{
appendix
.
getRows
().
addAll
(
Enums
.
toDetails
(
bodyDeclaration
.
asEnumDeclaration
()));
}
else
if
(
bodyDeclaration
.
isClassOrInterfaceDeclaration
())
{
appendix
.
getRows
().
addAll
(
Fields
.
getConstants
(
bodyDeclaration
.
asClassOrInterfaceDeclaration
()));
}
if
(
node
instanceof
NodeWithSimpleName
)
{
appendix
.
setName
(((
NodeWithSimpleName
)
node
).
getNameAsString
());
}
appendix
.
accept
(
node
.
getComment
());
return
appendix
;
}
}
apidoc-core/src/main/java/com/kim/apidoc/core/schema/Node.java
View file @
8f321eae
package
com.kim.apidoc.core.schema
;
import
com.github.javaparser.ast.comments.Comment
;
import
com.github.javaparser.javadoc.Javadoc
;
import
com.kim.apidoc.core.Context
;
import
com.kim.apidoc.core.common.helper.CommentHelper
;
import
com.kim.apidoc.core.common.helper.StringHelper
;
import
com.github.javaparser.ast.comments.Comment
;
import
com.github.javaparser.javadoc.Javadoc
;
import
lombok.Getter
;
import
lombok.Setter
;
...
...
@@ -120,7 +120,7 @@ public class Node implements Comparable<Node> {
* @return the param tag
*/
public
Optional
<
Tag
>
getParamTag
(
String
id
)
{
return
Optional
.
ofNullable
(
tags
.
get
(
"param:"
+
id
));
return
Optional
.
ofNullable
(
tags
.
get
(
"param:"
+
id
));
}
/**
...
...
@@ -130,7 +130,7 @@ public class Node implements Comparable<Node> {
*/
public
void
putTag
(
Tag
tag
)
{
String
id
=
tag
.
id
;
if
(
StringHelper
.
nonBlank
(
tag
.
getKey
()))
{
if
(
StringHelper
.
nonBlank
(
tag
.
getKey
()))
{
id
+=
":"
+
tag
.
getKey
();
}
tags
.
put
(
id
,
tag
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment