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
f20179e3
Commit
f20179e3
authored
Apr 04, 2020
by
duanledexianxianxian
😁
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
♻
Refactoring code.
parent
8f321eae
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
141 additions
and
86 deletions
+141
-86
apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/CompilationUnitHelper.java
.../kim/apidoc/core/common/helper/CompilationUnitHelper.java
+3
-3
apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/EnumHelper.java
...in/java/com/kim/apidoc/core/common/helper/EnumHelper.java
+40
-0
apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/OptionalHelper.java
...ava/com/kim/apidoc/core/common/helper/OptionalHelper.java
+2
-2
apidoc-core/src/main/java/com/kim/apidoc/core/parser/VisitorParser.java
...c/main/java/com/kim/apidoc/core/parser/VisitorParser.java
+29
-17
apidoc-core/src/main/java/com/kim/apidoc/core/schema/Appendix.java
...re/src/main/java/com/kim/apidoc/core/schema/Appendix.java
+0
-61
apidoc-core/src/main/java/com/kim/apidoc/core/schema/Chapter.java
...ore/src/main/java/com/kim/apidoc/core/schema/Chapter.java
+8
-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
+7
-1
apidoc-core/src/main/java/com/kim/apidoc/core/schema/Project.java
...ore/src/main/java/com/kim/apidoc/core/schema/Project.java
+16
-0
apidoc-core/src/main/java/com/kim/apidoc/core/schema/Section.java
...ore/src/main/java/com/kim/apidoc/core/schema/Section.java
+14
-0
apidoc-springmvc/src/test/java/com/kim/apidoc/example/common/Role.java
...mvc/src/test/java/com/kim/apidoc/example/common/Role.java
+21
-1
build.gradle
build.gradle
+1
-1
No files found.
apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/CompilationUnitHelper.java
View file @
f20179e3
...
@@ -7,11 +7,11 @@ import java.util.Optional;
...
@@ -7,11 +7,11 @@ import java.util.Optional;
public
class
CompilationUnitHelper
{
public
class
CompilationUnitHelper
{
public
static
Optional
<
CompilationUnit
>
getCompilationUnit
(
Node
node
){
public
static
Optional
<
CompilationUnit
>
getCompilationUnit
(
Node
node
)
{
if
(
node
instanceof
CompilationUnit
)
{
if
(
node
instanceof
CompilationUnit
)
{
return
Optional
.
of
((
CompilationUnit
)
node
);
return
Optional
.
of
((
CompilationUnit
)
node
);
}
}
if
(
node
.
getParentNode
().
isPresent
()){
if
(
node
.
getParentNode
().
isPresent
())
{
return
getCompilationUnit
(
node
.
getParentNode
().
get
());
return
getCompilationUnit
(
node
.
getParentNode
().
get
());
}
}
return
Optional
.
empty
();
return
Optional
.
empty
();
...
...
apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/EnumHelper.java
0 → 100644
View file @
f20179e3
package
com.kim.apidoc.core.common.helper
;
import
com.github.javaparser.ast.body.EnumDeclaration
;
import
com.github.javaparser.resolution.declarations.ResolvedEnumConstantDeclaration
;
import
com.github.javaparser.resolution.declarations.ResolvedEnumDeclaration
;
import
com.kim.apidoc.core.schema.Section
;
public
class
EnumHelper
{
public
static
String
getNames
(
ResolvedEnumDeclaration
enumDeclaration
)
{
StringBuilder
sb
=
new
StringBuilder
();
for
(
ResolvedEnumConstantDeclaration
resolvedEnumConstantDeclaration
:
enumDeclaration
.
getEnumConstants
())
{
if
(
sb
.
length
()
>
0
)
{
sb
.
append
(
","
);
}
sb
.
append
(
resolvedEnumConstantDeclaration
.
getName
());
}
return
sb
.
toString
();
}
public
static
Section
toDetails
(
EnumDeclaration
declaration
)
{
Section
section
=
new
Section
();
section
.
setId
(
declaration
.
getNameAsString
());
section
.
setName
(
declaration
.
getNameAsString
());
section
.
setNameAndDescription
(
declaration
.
getNameAsString
());
//Map<String, Row> rows = Maps.newLinkedHashMap();
//for (EnumConstantDeclaration constant : declaration.getEntries()) {
// Row row=new Row();
// row.setKey(constant.getNameAsString());
// for (Expression expression : constant.getArguments()) {
// Object value = Expressions.getValue(expression);
// cell.add(String.valueOf(value));
// }
// cells.add(cell);
//}
return
section
;
}
}
apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/OptionalHelper.java
View file @
f20179e3
...
@@ -5,9 +5,9 @@ import java.util.Optional;
...
@@ -5,9 +5,9 @@ import java.util.Optional;
public
class
OptionalHelper
{
public
class
OptionalHelper
{
@SafeVarargs
@SafeVarargs
public
static
<
T
>
Optional
<
T
>
any
(
Optional
<
T
>
...
optionals
)
{
public
static
<
T
>
Optional
<
T
>
any
(
Optional
<
T
>
...
optionals
)
{
for
(
Optional
<
T
>
optional
:
optionals
)
{
for
(
Optional
<
T
>
optional
:
optionals
)
{
if
(
optional
.
isPresent
())
{
if
(
optional
.
isPresent
())
{
return
optional
;
return
optional
;
}
}
}
}
...
...
apidoc-core/src/main/java/com/kim/apidoc/core/parser/VisitorParser.java
View file @
f20179e3
package
com.kim.apidoc.core.parser
;
package
com.kim.apidoc.core.parser
;
import
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration
;
import
com.github.javaparser.ast.body.EnumDeclaration
;
import
com.github.javaparser.ast.body.MethodDeclaration
;
import
com.github.javaparser.ast.comments.Comment
;
import
com.github.javaparser.ast.comments.Comment
;
import
com.github.javaparser.ast.comments.JavadocComment
;
import
com.github.javaparser.ast.comments.JavadocComment
;
import
com.github.javaparser.ast.visitor.VoidVisitorAdapter
;
import
com.github.javaparser.javadoc.Javadoc
;
import
com.github.javaparser.javadoc.Javadoc
;
import
com.github.javaparser.javadoc.JavadocBlockTag
;
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.kim.apidoc.core.common.helper.OptionalHelper
;
import
com.
github.javaparser.ast.body.ClassOrInterfaceDeclaration
;
import
com.
kim.apidoc.core.schema.Chapter
;
import
com.
github.javaparser.ast.body.MethodDeclaration
;
import
com.
kim.apidoc.core.schema.Node
;
import
com.
github.javaparser.ast.visitor.VoidVisitorAdapter
;
import
com.
kim.apidoc.core.schema.Project
;
import
jdk.nashorn.internal.runtime.options.Op
tion
;
import
com.kim.apidoc.core.schema.Sec
tion
;
import
java.util.Optional
;
import
java.util.Optional
;
import
static
com
.
kim
.
apidoc
.
core
.
schema
.
Chapter
.
NODE_CHAPTER
;
/**
/**
* The type Visitor parser.
* The type Visitor parser.
*/
*/
...
@@ -33,6 +37,11 @@ public class VisitorParser extends VoidVisitorAdapter<Node> {
...
@@ -33,6 +37,11 @@ public class VisitorParser extends VoidVisitorAdapter<Node> {
this
.
parserStrategy
=
parserStrategy
;
this
.
parserStrategy
=
parserStrategy
;
}
}
@Override
public
void
visit
(
final
EnumDeclaration
enumDeclaration
,
final
Node
arg
)
{
super
.
visit
(
enumDeclaration
,
arg
);
}
/**
/**
* 类或者接口声明
* 类或者接口声明
*
*
...
@@ -41,14 +50,7 @@ public class VisitorParser extends VoidVisitorAdapter<Node> {
...
@@ -41,14 +50,7 @@ public class VisitorParser extends VoidVisitorAdapter<Node> {
*/
*/
@Override
@Override
public
void
visit
(
final
ClassOrInterfaceDeclaration
classOrInterfaceDeclaration
,
final
Node
arg
)
{
public
void
visit
(
final
ClassOrInterfaceDeclaration
classOrInterfaceDeclaration
,
final
Node
arg
)
{
if
(
arg
instanceof
Project
&&
isExistTag
(
classOrInterfaceDeclaration
,
"code"
))
{
if
(
arg
instanceof
Project
)
{
}
if
(
arg
instanceof
Project
&&
isExistTag
(
classOrInterfaceDeclaration
,
"resultData"
))
{
}
if
(
arg
instanceof
Project
&&
parserStrategy
.
accept
(
classOrInterfaceDeclaration
))
{
Project
project
=
(
Project
)
arg
;
Project
project
=
(
Project
)
arg
;
// 章节
// 章节
Chapter
chapter
=
new
Chapter
();
Chapter
chapter
=
new
Chapter
();
...
@@ -59,9 +61,19 @@ public class VisitorParser extends VoidVisitorAdapter<Node> {
...
@@ -59,9 +61,19 @@ public class VisitorParser extends VoidVisitorAdapter<Node> {
OptionalHelper
.
any
(
chapter
.
getTag
(
"book"
),
chapter
.
getTag
(
"group"
))
OptionalHelper
.
any
(
chapter
.
getTag
(
"book"
),
chapter
.
getTag
(
"group"
))
.
ifPresent
(
tag
->
chapter
.
setBookName
(
tag
.
getContent
()));
.
ifPresent
(
tag
->
chapter
.
setBookName
(
tag
.
getContent
()));
parserStrategy
.
visit
(
classOrInterfaceDeclaration
,
chapter
);
if
(
parserStrategy
.
accept
(
classOrInterfaceDeclaration
))
{
project
.
addChapter
(
chapter
);
chapter
.
setType
(
NODE_CHAPTER
);
super
.
visit
(
classOrInterfaceDeclaration
,
chapter
);
parserStrategy
.
visit
(
classOrInterfaceDeclaration
,
chapter
);
project
.
addChapter
(
chapter
);
super
.
visit
(
classOrInterfaceDeclaration
,
chapter
);
}
else
if
(
isExistTag
(
classOrInterfaceDeclaration
,
"code"
))
{
//chapter.setType(NODE_APPENDIX);
//if (null==project.getAppendixChapter(chapter.getBookName())){
// project.addChapter(chapter);
//}
super
.
visit
(
classOrInterfaceDeclaration
,
arg
);
}
else
if
(
isExistTag
(
classOrInterfaceDeclaration
,
"resultData"
))
{
}
}
}
}
}
...
...
apidoc-core/src/main/java/com/kim/apidoc/core/schema/Appendix.java
deleted
100644 → 0
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/Chapter.java
View file @
f20179e3
...
@@ -15,6 +15,14 @@ import java.util.TreeSet;
...
@@ -15,6 +15,14 @@ import java.util.TreeSet;
@Setter
@Setter
@Getter
@Getter
public
class
Chapter
extends
Node
{
public
class
Chapter
extends
Node
{
/**
* 章节节点.
*/
public
static
final
String
NODE_CHAPTER
=
"NODE_CHAPTER"
;
/**
* 附录节点.
*/
public
static
final
String
NODE_APPENDIX
=
"NODE_APPENDIX"
;
/**
/**
* The Book name.
* The Book name.
...
...
apidoc-core/src/main/java/com/kim/apidoc/core/schema/Node.java
View file @
f20179e3
...
@@ -22,7 +22,10 @@ import java.util.Optional;
...
@@ -22,7 +22,10 @@ import java.util.Optional;
@Setter
@Setter
@Getter
@Getter
public
class
Node
implements
Comparable
<
Node
>
{
public
class
Node
implements
Comparable
<
Node
>
{
/**
* 节点类型
*/
String
type
;
/**
/**
* 节点编号
* 节点编号
*/
*/
...
@@ -52,6 +55,9 @@ public class Node implements Comparable<Node> {
...
@@ -52,6 +55,9 @@ public class Node implements Comparable<Node> {
@Override
@Override
public
int
compareTo
(
@Nonnull
Node
other
)
{
public
int
compareTo
(
@Nonnull
Node
other
)
{
if
(
this
.
type
!=
null
&&
other
.
type
!=
null
)
{
return
this
.
type
.
compareTo
(
other
.
type
);
}
if
(
this
.
index
!=
other
.
index
)
{
if
(
this
.
index
!=
other
.
index
)
{
return
this
.
index
-
other
.
index
;
return
this
.
index
-
other
.
index
;
}
}
...
...
apidoc-core/src/main/java/com/kim/apidoc/core/schema/Project.java
View file @
f20179e3
...
@@ -2,9 +2,12 @@ package com.kim.apidoc.core.schema;
...
@@ -2,9 +2,12 @@ package com.kim.apidoc.core.schema;
import
lombok.Getter
;
import
lombok.Getter
;
import
lombok.Setter
;
import
lombok.Setter
;
import
org.apache.commons.lang3.StringUtils
;
import
java.util.*
;
import
java.util.*
;
import
static
com
.
kim
.
apidoc
.
core
.
schema
.
Chapter
.
NODE_APPENDIX
;
/**
/**
* 项目
* 项目
*
*
...
@@ -39,4 +42,17 @@ public class Project extends Node {
...
@@ -39,4 +42,17 @@ public class Project extends Node {
}
}
books
.
get
(
chapter
.
getBookName
()).
getChapters
().
add
(
chapter
);
books
.
get
(
chapter
.
getBookName
()).
getChapters
().
add
(
chapter
);
}
}
public
Chapter
getAppendixChapter
(
String
bookName
)
{
if
(
StringUtils
.
isBlank
(
bookName
))
{
bookName
=
Book
.
DEFAULT
;
}
if
(
books
.
containsKey
(
bookName
))
{
Optional
<
Chapter
>
chapterOptional
=
books
.
get
(
bookName
).
getChapters
().
stream
().
filter
(
x
->
NODE_APPENDIX
.
equals
(
x
.
getType
())).
findFirst
();
if
(
chapterOptional
.
isPresent
())
{
return
chapterOptional
.
get
();
}
}
return
null
;
}
}
}
apidoc-core/src/main/java/com/kim/apidoc/core/schema/Section.java
View file @
f20179e3
...
@@ -67,6 +67,20 @@ public class Section extends Node {
...
@@ -67,6 +67,20 @@ public class Section extends Node {
*/
*/
Object
rawResponse
;
Object
rawResponse
;
/**
* 全局编码列表
*/
Map
<
String
,
Row
>
codeRows
=
new
LinkedHashMap
<>();
/**
* Add code rows.
*
* @param row the row
*/
public
void
addCodeRows
(
Row
row
)
{
codeRows
.
put
(
row
.
getKey
(),
row
);
}
/**
/**
* Add request row.
* Add request row.
*
*
...
...
apidoc-springmvc/src/test/java/com/kim/apidoc/example/common/Role.java
View file @
f20179e3
...
@@ -2,14 +2,34 @@ package com.kim.apidoc.example.common;
...
@@ -2,14 +2,34 @@ package com.kim.apidoc.example.common;
/**
/**
* 用户角色
* 用户角色
*
* @code
* @code
*/
*/
public
enum
Role
{
public
enum
Role
{
ADMIN
(
"管理员"
),
USER
(
"用户"
),
VIP
(
"会员"
);
/**
* Admin role.
*/
ADMIN
(
"管理员"
),
/**
* User role.
*/
USER
(
"用户"
),
/**
* Vip role.
*/
VIP
(
"会员"
);
/**
* The Text.
*/
String
text
;
String
text
;
/**
* Instantiates a new Role.
*
* @param text the text
*/
Role
(
String
text
)
{
Role
(
String
text
)
{
this
.
text
=
text
;
this
.
text
=
text
;
}
}
...
...
build.gradle
View file @
f20179e3
...
@@ -18,7 +18,7 @@ allprojects {
...
@@ -18,7 +18,7 @@ allprojects {
dependencies
{
dependencies
{
compile
'ch.qos.logback:logback-classic:1.2.3'
compile
'ch.qos.logback:logback-classic:1.2.3'
compile
group:
'org.apache.commons'
,
name:
'commons-lang3'
,
version:
'3.10'
compileOnly
'org.projectlombok:lombok:1.18.4'
compileOnly
'org.projectlombok:lombok:1.18.4'
annotationProcessor
'org.projectlombok:lombok:1.18.6'
annotationProcessor
'org.projectlombok:lombok:1.18.6'
...
...
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