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
638a3728
Commit
638a3728
authored
Apr 13, 2020
by
duanledexianxianxian
😁
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
♻
Refactoring code.
parent
ac2eb0d4
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
29 additions
and
21 deletions
+29
-21
apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/AnnotationHelper.java
...a/com/kim/apidoc/core/common/helper/AnnotationHelper.java
+3
-3
apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/ClassDeclarationHelper.java
...kim/apidoc/core/common/helper/ClassDeclarationHelper.java
+14
-5
apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/CommentHelper.java
...java/com/kim/apidoc/core/common/helper/CommentHelper.java
+9
-9
apidoc-springmvc/src/main/java/com/kim/apidoc/springmvc/SpringParser.java
.../src/main/java/com/kim/apidoc/springmvc/SpringParser.java
+2
-3
apidoc-springmvc/src/test/java/com/kim/apidoc/springmvc/SpringTest.java
...vc/src/test/java/com/kim/apidoc/springmvc/SpringTest.java
+1
-1
No files found.
apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/AnnotationHelper.java
View file @
638a3728
...
@@ -24,7 +24,7 @@ public class AnnotationHelper {
...
@@ -24,7 +24,7 @@ public class AnnotationHelper {
}
}
if
(
annotationExpr
.
isNormalAnnotationExpr
())
{
if
(
annotationExpr
.
isNormalAnnotationExpr
())
{
for
(
MemberValuePair
pair
:
annotationExpr
.
asNormalAnnotationExpr
().
getPairs
())
{
for
(
MemberValuePair
pair
:
annotationExpr
.
asNormalAnnotationExpr
().
getPairs
())
{
if
(
Objects
.
equals
(
key
,
pair
.
getNameAsString
())){
if
(
Objects
.
equals
(
key
,
pair
.
getNameAsString
()))
{
return
Optional
.
of
(
pair
.
getValue
());
return
Optional
.
of
(
pair
.
getValue
());
}
}
}
}
...
@@ -32,10 +32,10 @@ public class AnnotationHelper {
...
@@ -32,10 +32,10 @@ public class AnnotationHelper {
return
Optional
.
empty
();
return
Optional
.
empty
();
}
}
public
static
Optional
<
Expression
>
getAnyAttribute
(
AnnotationExpr
annotationExpr
,
String
...
keys
)
{
public
static
Optional
<
Expression
>
getAnyAttribute
(
AnnotationExpr
annotationExpr
,
String
...
keys
)
{
for
(
String
key
:
keys
)
{
for
(
String
key
:
keys
)
{
Optional
<
Expression
>
optional
=
getAttribute
(
annotationExpr
,
key
);
Optional
<
Expression
>
optional
=
getAttribute
(
annotationExpr
,
key
);
if
(
optional
.
isPresent
())
{
if
(
optional
.
isPresent
())
{
return
optional
;
return
optional
;
}
}
}
}
...
...
apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/ClassDeclarationHelper.java
View file @
638a3728
package
com.kim.apidoc.core.common.helper
;
package
com.kim.apidoc.core.common.helper
;
import
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration
;
import
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration
;
import
com.github.javaparser.ast.body.FieldDeclaration
;
import
com.github.javaparser.ast.type.ClassOrInterfaceType
;
import
com.github.javaparser.ast.type.ClassOrInterfaceType
;
import
com.github.javaparser.resolution.types.ResolvedReferenceType
;
import
com.github.javaparser.resolution.types.ResolvedReferenceType
;
import
com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration
;
import
com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration
;
import
com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration
;
import
com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.Optional
;
@Slf4j
@Slf4j
...
@@ -28,9 +25,9 @@ public class ClassDeclarationHelper {
...
@@ -28,9 +25,9 @@ public class ClassDeclarationHelper {
if
(
resolvedReferenceType
.
getTypeDeclaration
()
instanceof
JavaParserClassDeclaration
)
{
if
(
resolvedReferenceType
.
getTypeDeclaration
()
instanceof
JavaParserClassDeclaration
)
{
JavaParserClassDeclaration
typeDeclaration
=
(
JavaParserClassDeclaration
)
resolvedReferenceType
.
getTypeDeclaration
();
JavaParserClassDeclaration
typeDeclaration
=
(
JavaParserClassDeclaration
)
resolvedReferenceType
.
getTypeDeclaration
();
return
Optional
.
of
(
typeDeclaration
.
getWrappedNode
());
return
Optional
.
of
(
typeDeclaration
.
getWrappedNode
());
}
else
if
(
resolvedReferenceType
.
getTypeDeclaration
()
instanceof
ReflectionClassDeclaration
)
{
}
else
if
(
resolvedReferenceType
.
getTypeDeclaration
()
instanceof
ReflectionClassDeclaration
)
{
ReflectionClassDeclaration
typeDeclaration
=
(
ReflectionClassDeclaration
)
resolvedReferenceType
.
getTypeDeclaration
();
ReflectionClassDeclaration
typeDeclaration
=
(
ReflectionClassDeclaration
)
resolvedReferenceType
.
getTypeDeclaration
();
System
.
out
.
println
(
"type Declaration:"
+
typeDeclaration
);
System
.
out
.
println
(
"type Declaration:"
+
typeDeclaration
);
//TODO
//TODO
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
...
@@ -39,4 +36,16 @@ public class ClassDeclarationHelper {
...
@@ -39,4 +36,16 @@ public class ClassDeclarationHelper {
return
Optional
.
empty
();
return
Optional
.
empty
();
}
}
public
static
String
getClassOrInterfacePackageName
(
ClassOrInterfaceDeclaration
classOrInterfaceDeclaration
)
{
final
String
[]
result
=
{
null
};
classOrInterfaceDeclaration
.
findCompilationUnit
().
ifPresent
(
x
->
{
x
.
getPackageDeclaration
().
ifPresent
(
y
->
{
result
[
0
]
=
y
.
getNameAsString
()
+
"."
+
classOrInterfaceDeclaration
.
getName
();
});
});
return
result
[
0
];
}
}
}
apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/CommentHelper.java
View file @
638a3728
...
@@ -26,7 +26,7 @@ public class CommentHelper {
...
@@ -26,7 +26,7 @@ public class CommentHelper {
* @param description the description
* @param description the description
* @return string
* @return string
*/
*/
public
static
String
getDescription
(
JavadocDescription
description
){
public
static
String
getDescription
(
JavadocDescription
description
)
{
return
description
.
getElements
()
return
description
.
getElements
()
.
stream
()
.
stream
()
.
filter
(
e
->
!(
e
instanceof
JavadocInlineTag
))
.
filter
(
e
->
!(
e
instanceof
JavadocInlineTag
))
...
@@ -39,8 +39,8 @@ public class CommentHelper {
...
@@ -39,8 +39,8 @@ public class CommentHelper {
* @param comment the comment
* @param comment the comment
* @return the string
* @return the string
*/
*/
public
static
String
getContent
(
Comment
comment
){
public
static
String
getContent
(
Comment
comment
)
{
if
(!
comment
.
isJavadocComment
())
{
if
(!
comment
.
isJavadocComment
())
{
return
comment
.
getContent
();
return
comment
.
getContent
();
}
}
return
getDescription
(
comment
.
asJavadocComment
().
parse
().
getDescription
());
return
getDescription
(
comment
.
asJavadocComment
().
parse
().
getDescription
());
...
@@ -53,11 +53,11 @@ public class CommentHelper {
...
@@ -53,11 +53,11 @@ public class CommentHelper {
* @param it the it
* @param it the it
* @return the string
* @return the string
*/
*/
public
static
String
getComment
(
MethodUsage
it
){
public
static
String
getComment
(
MethodUsage
it
)
{
if
(
it
.
getDeclaration
()
instanceof
JavaParserMethodDeclaration
)
{
if
(
it
.
getDeclaration
()
instanceof
JavaParserMethodDeclaration
)
{
MethodDeclaration
wrappedNode
=
((
JavaParserMethodDeclaration
)
it
.
getDeclaration
()).
getWrappedNode
();
MethodDeclaration
wrappedNode
=
((
JavaParserMethodDeclaration
)
it
.
getDeclaration
()).
getWrappedNode
();
Optional
<
Comment
>
optional
=
wrappedNode
.
getComment
();
Optional
<
Comment
>
optional
=
wrappedNode
.
getComment
();
if
(
optional
.
isPresent
())
{
if
(
optional
.
isPresent
())
{
return
CommentHelper
.
getContent
(
optional
.
get
());
return
CommentHelper
.
getContent
(
optional
.
get
());
}
}
}
}
...
@@ -70,14 +70,14 @@ public class CommentHelper {
...
@@ -70,14 +70,14 @@ public class CommentHelper {
* @param it the it
* @param it the it
* @return the string
* @return the string
*/
*/
public
static
String
getComment
(
ResolvedFieldDeclaration
it
){
public
static
String
getComment
(
ResolvedFieldDeclaration
it
)
{
if
(
it
instanceof
JavaParserFieldDeclaration
)
{
if
(
it
instanceof
JavaParserFieldDeclaration
)
{
FieldDeclaration
wrappedNode
=
((
JavaParserFieldDeclaration
)
it
).
getWrappedNode
();
FieldDeclaration
wrappedNode
=
((
JavaParserFieldDeclaration
)
it
).
getWrappedNode
();
Optional
<
Comment
>
optional
=
wrappedNode
.
getComment
();
Optional
<
Comment
>
optional
=
wrappedNode
.
getComment
();
if
(
optional
.
isPresent
())
{
if
(
optional
.
isPresent
())
{
return
CommentHelper
.
getContent
(
optional
.
get
());
return
CommentHelper
.
getContent
(
optional
.
get
());
}
}
}
else
if
(
it
instanceof
JavaParserClassDeclaration
)
{
}
else
if
(
it
instanceof
JavaParserClassDeclaration
)
{
JavaParserClassDeclaration
classDeclaration
=
(
JavaParserClassDeclaration
)
it
;
JavaParserClassDeclaration
classDeclaration
=
(
JavaParserClassDeclaration
)
it
;
}
}
return
null
;
return
null
;
...
...
apidoc-springmvc/src/main/java/com/kim/apidoc/springmvc/SpringParser.java
View file @
638a3728
...
@@ -10,9 +10,7 @@ import com.kim.apidoc.core.ApiDoc;
...
@@ -10,9 +10,7 @@ import com.kim.apidoc.core.ApiDoc;
import
com.kim.apidoc.core.common.URI
;
import
com.kim.apidoc.core.common.URI
;
import
com.kim.apidoc.core.common.description.ObjectTypeDescription
;
import
com.kim.apidoc.core.common.description.ObjectTypeDescription
;
import
com.kim.apidoc.core.common.description.TypeDescription
;
import
com.kim.apidoc.core.common.description.TypeDescription
;
import
com.kim.apidoc.core.common.helper.AnnotationHelper
;
import
com.kim.apidoc.core.common.helper.*
;
import
com.kim.apidoc.core.common.helper.ExpressionHelper
;
import
com.kim.apidoc.core.common.helper.StringHelper
;
import
com.kim.apidoc.core.parser.ParserStrategy
;
import
com.kim.apidoc.core.parser.ParserStrategy
;
import
com.kim.apidoc.core.schema.Chapter
;
import
com.kim.apidoc.core.schema.Chapter
;
import
com.kim.apidoc.core.schema.Header
;
import
com.kim.apidoc.core.schema.Header
;
...
@@ -313,6 +311,7 @@ public class SpringParser implements ParserStrategy {
...
@@ -313,6 +311,7 @@ public class SpringParser implements ParserStrategy {
ClassOrInterfaceType
returnType
=
new
ClassOrInterfaceType
();
ClassOrInterfaceType
returnType
=
new
ClassOrInterfaceType
();
returnType
.
setName
(
resultDataClassOrInterfaceDeclaration
.
getName
());
returnType
.
setName
(
resultDataClassOrInterfaceDeclaration
.
getName
());
returnType
.
setTypeArguments
(
n
.
getType
());
returnType
.
setTypeArguments
(
n
.
getType
());
n
.
findCompilationUnit
().
get
().
addImport
(
ClassDeclarationHelper
.
getClassOrInterfacePackageName
(
resultDataClassOrInterfaceDeclaration
));
n
.
setType
(
returnType
);
n
.
setType
(
returnType
);
}
}
TypeDescription
description
=
ApiDoc
.
getInstance
().
getTypeResolvers
().
resolve
(
n
.
getType
());
TypeDescription
description
=
ApiDoc
.
getInstance
().
getTypeResolvers
().
resolve
(
n
.
getType
());
...
...
apidoc-springmvc/src/test/java/com/kim/apidoc/springmvc/SpringTest.java
View file @
638a3728
...
@@ -17,7 +17,7 @@ public class SpringTest {
...
@@ -17,7 +17,7 @@ public class SpringTest {
Context
context
=
new
Context
();
Context
context
=
new
Context
();
context
.
setId
(
"test"
);
context
.
setId
(
"test"
);
context
.
setName
(
"测试项目"
);
context
.
setName
(
"测试项目"
);
context
.
addSource
(
Paths
.
get
(
"
F:\\@project@\\@
dianli@\\tool\\apidoc\\apidoc-springmvc\\src\\test\\java"
));
context
.
addSource
(
Paths
.
get
(
"
K:\\@project-
dianli@\\tool\\apidoc\\apidoc-springmvc\\src\\test\\java"
));
// context.setCss("https://darshandsoni.com/asciidoctor-skins/css/monospace.css");
// context.setCss("https://darshandsoni.com/asciidoctor-skins/css/monospace.css");
ApiDoc
apigcc
=
new
ApiDoc
(
context
);
ApiDoc
apigcc
=
new
ApiDoc
(
context
);
...
...
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