diff --git a/build.gradle b/build.gradle
index 12c4a2f..cd77d96 100644
--- a/build.gradle
+++ b/build.gradle
@@ -4,7 +4,7 @@ plugins {
}
group 'com.liuzhihang'
-version '1.1.3'
+version '1.1.4'
JavaVersion.VERSION_11
diff --git a/parts/changeNotes.html b/parts/changeNotes.html
index e35e86c..2e78682 100644
--- a/parts/changeNotes.html
+++ b/parts/changeNotes.html
@@ -3,18 +3,20 @@
English introduction
- - 1.1.3
+
- 1.1.4
- - Solve the bug that parameter recursion causes exception
+ - Document name and title can be obtained from comments
+ - Fix null pointer exception
- More records
中文介绍
- - 1.1.3
+
- 1.1.4
- - 解决参数递归导致异常的 bug
+ - 文档名称和标题支持从注释获取
+ - 修复空指针异常
- 更多记录
diff --git a/src/main/java/com/liuzhihang/doc/view/config/Settings.java b/src/main/java/com/liuzhihang/doc/view/config/Settings.java
index d4bf784..af4b659 100644
--- a/src/main/java/com/liuzhihang/doc/view/config/Settings.java
+++ b/src/main/java/com/liuzhihang/doc/view/config/Settings.java
@@ -34,6 +34,7 @@ public class Settings implements PersistentStateComponent {
*/
private String titleTag = "DocView.Title";
private Boolean titleUseCommentTag = true;
+ private Boolean titleClassComment = true;
private Boolean titleUseFullClassName = true;
private Boolean titleUseSimpleClassName = true;
@@ -44,6 +45,7 @@ public class Settings implements PersistentStateComponent {
private Boolean nameUseSwagger3 = true;
private Boolean nameUseSwagger = true;
private Boolean nameUseCommentTag = true;
+ private Boolean nameMethodComment = true;
/**
* 文档描述
diff --git a/src/main/java/com/liuzhihang/doc/view/dto/Body.java b/src/main/java/com/liuzhihang/doc/view/dto/Body.java
index ccf3b99..309a38e 100644
--- a/src/main/java/com/liuzhihang/doc/view/dto/Body.java
+++ b/src/main/java/com/liuzhihang/doc/view/dto/Body.java
@@ -2,7 +2,8 @@
import com.intellij.psi.PsiElement;
-import lombok.Data;
+import lombok.Getter;
+import lombok.Setter;
import java.util.LinkedList;
import java.util.List;
@@ -11,7 +12,8 @@
* @author liuzhihang
* @date 2020/2/27 16:39
*/
-@Data
+@Getter
+@Setter
public class Body {
/**
diff --git a/src/main/java/com/liuzhihang/doc/view/dto/DocView.java b/src/main/java/com/liuzhihang/doc/view/dto/DocView.java
index d2ef387..ba5556d 100644
--- a/src/main/java/com/liuzhihang/doc/view/dto/DocView.java
+++ b/src/main/java/com/liuzhihang/doc/view/dto/DocView.java
@@ -86,12 +86,12 @@ public class DocView {
/**
* 请求参数
*/
- private Body reqRootBody;
+ private Body reqRootBody = new Body();
/**
* 返回参数
*/
- private Body respRootBody;
+ private Body respRootBody = new Body();
/**
diff --git a/src/main/java/com/liuzhihang/doc/view/ui/PreviewForm.java b/src/main/java/com/liuzhihang/doc/view/ui/PreviewForm.java
index 5031b7c..90b1d2b 100644
--- a/src/main/java/com/liuzhihang/doc/view/ui/PreviewForm.java
+++ b/src/main/java/com/liuzhihang/doc/view/ui/PreviewForm.java
@@ -55,11 +55,12 @@
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.event.MouseEvent;
+import java.time.LocalTime;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;
import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.stream.Collectors;
/**
* @author liuzhihang
@@ -492,9 +493,23 @@ public void actionPerformed(@NotNull AnActionEvent e) {
private void buildDoc() {
- docViewMap = docViewList.stream().collect(Collectors.toMap(DocView::getName, docView -> docView));
+ // 取注释之后,可能会重复名字,不能用 stream
+ docViewMap = new HashMap<>();
+ Vector nameVector = new Vector<>();
+
+ for (DocView docView : docViewList) {
+
+ if (nameVector.contains(docView.getName())) {
+ String name = docView.getName() + "-" + LocalTime.now().getNano();
+ docViewMap.put(name, docView);
+ nameVector.add(name);
+ } else {
+ docViewMap.put(docView.getName(), docView);
+ nameVector.add(docView.getName());
+ }
+
+ }
- Vector nameVector = docViewList.stream().map(DocView::getName).collect(Collectors.toCollection(Vector::new));
catalogList.setListData(nameVector);
diff --git a/src/main/java/com/liuzhihang/doc/view/ui/Settings.form b/src/main/java/com/liuzhihang/doc/view/ui/Settings.form
index 88fb3e2..affcdc5 100644
--- a/src/main/java/com/liuzhihang/doc/view/ui/Settings.form
+++ b/src/main/java/com/liuzhihang/doc/view/ui/Settings.form
@@ -31,7 +31,7 @@
-
+
@@ -50,7 +50,7 @@
-
+
@@ -73,7 +73,7 @@
-
+
@@ -81,6 +81,14 @@
+
+
+
+
+
+
+
+
@@ -244,7 +252,7 @@
-
+
@@ -263,12 +271,12 @@
-
+
-
+
@@ -276,12 +284,20 @@
-
+
+
+
+
+
+
+
+
+
diff --git a/src/main/java/com/liuzhihang/doc/view/ui/SettingsForm.java b/src/main/java/com/liuzhihang/doc/view/ui/SettingsForm.java
index b686a89..4565f91 100644
--- a/src/main/java/com/liuzhihang/doc/view/ui/SettingsForm.java
+++ b/src/main/java/com/liuzhihang/doc/view/ui/SettingsForm.java
@@ -33,11 +33,13 @@ public class SettingsForm {
private JCheckBox titleCommentTagCheckBox;
private JCheckBox titleFullClassNameCheckBox;
private JCheckBox titleSimpleClassNameCheckBox;
+ private JCheckBox titleClassCommentCheckBox;
private JPanel namePanel;
private JCheckBox nameSwagger3CheckBox;
private JCheckBox nameSwaggerCheckBox;
private JCheckBox nameCommentTagCheckBox;
+ private JCheckBox nameMethodCommentCheckBox;
private JPanel docDescPanel;
private JCheckBox descSwagger3CheckBox;
@@ -46,6 +48,7 @@ public class SettingsForm {
private JPanel requirePanel;
private JCheckBox requireCommentTagCheckBox;
+
public SettingsForm(@NotNull Project project) {
this.project = project;
@@ -91,9 +94,11 @@ public boolean isModified() {
return titleCommentTagCheckBox.isSelected() != settings.getTitleUseCommentTag()
|| titleFullClassNameCheckBox.isSelected() != settings.getTitleUseFullClassName()
|| titleSimpleClassNameCheckBox.isSelected() != settings.getTitleUseSimpleClassName()
+ || titleClassCommentCheckBox.isSelected() != settings.getTitleClassComment()
|| nameSwagger3CheckBox.isSelected() != settings.getNameUseSwagger3()
|| nameSwaggerCheckBox.isSelected() != settings.getNameUseSwagger()
|| nameCommentTagCheckBox.isSelected() != settings.getNameUseCommentTag()
+ || nameMethodCommentCheckBox.isSelected() != settings.getNameMethodComment()
|| descSwagger3CheckBox.isSelected() != settings.getDescUseSwagger3()
|| descSwaggerCheckBox.isSelected() != settings.getDescUseSwagger()
|| requireCommentTagCheckBox.isSelected() != settings.getRequiredUseCommentTag();
@@ -105,9 +110,11 @@ public void apply() {
settings.setTitleUseCommentTag(titleCommentTagCheckBox.isSelected());
settings.setTitleUseFullClassName(titleFullClassNameCheckBox.isSelected());
settings.setTitleUseSimpleClassName(titleSimpleClassNameCheckBox.isSelected());
+ settings.setTitleClassComment(titleClassCommentCheckBox.isSelected());
settings.setNameUseSwagger3(nameSwagger3CheckBox.isSelected());
settings.setNameUseSwagger(nameSwaggerCheckBox.isSelected());
settings.setNameUseCommentTag(nameCommentTagCheckBox.isSelected());
+ settings.setNameMethodComment(nameMethodCommentCheckBox.isSelected());
settings.setDescUseSwagger3(descSwagger3CheckBox.isSelected());
settings.setDescUseSwagger(descSwaggerCheckBox.isSelected());
settings.setRequiredUseCommentTag(requireCommentTagCheckBox.isSelected());
@@ -117,11 +124,13 @@ public void apply() {
public void reset() {
Settings settings = Settings.getInstance(project);
titleCommentTagCheckBox.setSelected(settings.getTitleUseCommentTag());
+ titleClassCommentCheckBox.setSelected(settings.getTitleClassComment());
titleFullClassNameCheckBox.setSelected(settings.getTitleUseFullClassName());
titleSimpleClassNameCheckBox.setSelected(settings.getTitleUseSimpleClassName());
nameSwagger3CheckBox.setSelected(settings.getNameUseSwagger3());
nameSwaggerCheckBox.setSelected(settings.getNameUseSwagger());
nameCommentTagCheckBox.setSelected(settings.getNameUseCommentTag());
+ nameMethodCommentCheckBox.setSelected(settings.getNameMethodComment());
descSwagger3CheckBox.setSelected(settings.getDescUseSwagger3());
descSwaggerCheckBox.setSelected(settings.getDescUseSwagger());
requireCommentTagCheckBox.setSelected(settings.getRequiredUseCommentTag());
diff --git a/src/main/java/com/liuzhihang/doc/view/utils/DocViewUtils.java b/src/main/java/com/liuzhihang/doc/view/utils/DocViewUtils.java
index 9286607..ac45df2 100644
--- a/src/main/java/com/liuzhihang/doc/view/utils/DocViewUtils.java
+++ b/src/main/java/com/liuzhihang/doc/view/utils/DocViewUtils.java
@@ -48,6 +48,16 @@ public static String getTitle(@NotNull PsiClass psiClass) {
}
}
+ if (settings.getTitleClassComment()) {
+ // 获取类注释
+
+ String comment = CustomPsiCommentUtils.getComment(psiClass.getDocComment());
+
+ if (StringUtils.isNotBlank(comment)) {
+ return comment;
+ }
+ }
+
if (settings.getTitleUseFullClassName()) {
// 获取全类名
String fullClassName = psiClass.getQualifiedName();
@@ -110,6 +120,17 @@ public static String getName(@NotNull PsiMethod psiMethod) {
return comment;
}
}
+
+ if (settings.getNameMethodComment()) {
+ // 获取类注释
+
+ String comment = CustomPsiCommentUtils.getComment(psiMethod.getDocComment());
+
+ if (StringUtils.isNotBlank(comment)) {
+ return comment;
+ }
+ }
+
return psiMethod.getName();
}
diff --git a/src/main/resources/messages/DocViewBundle.properties b/src/main/resources/messages/DocViewBundle.properties
index 8a93245..a7d3fc7 100644
--- a/src/main/resources/messages/DocViewBundle.properties
+++ b/src/main/resources/messages/DocViewBundle.properties
@@ -61,6 +61,7 @@ settings.doc.title=\u6587\u6863\u6807\u9898
settings.doc.title.tip=\u5F39\u51FA\u7A97\u53E3\u7684\u6807\u9898, \u4F1A\u6309\u7167\u987A\u5E8F\u4F9D\u6B21\u83B7\u53D6
settings.doc.title.comment.tag=@DocView.Title
settings.doc.title.comment.tag.tip=\u7C7B\u6CE8\u91CA\u4E2D\u7684\u6807\u7B7E
+settings.doc.title.class.comment=\u7C7B\u6CE8\u91CA
settings.doc.title.full=\u5168\u7C7B\u540D
settings.doc.title.simple=\u7C7B\u540D
settings.doc.name=\u63A5\u53E3\u540D
@@ -71,6 +72,7 @@ settings.doc.name.swagger=@ApiOperation
settings.doc.name.swagger.tip=Swagger @ApiOperation \u6CE8\u89E3\u7684 value \u5C5E\u6027
settings.doc.name.comment.tag=@DocView.Name
settings.doc.name.comment.tag.tip=\u65B9\u6CD5\u6CE8\u91CA\u4E2D\u7684\u6807\u7B7E
+settings.doc.name.method.comment=\u65B9\u6CD5\u6CE8\u91CA
settings.doc.name.method=\u65B9\u6CD5\u540D
settings.doc.desc=\u63A5\u53E3\u63CF\u8FF0
settings.doc.desc.tip=\u63A5\u53E3\u63CF\u8FF0: \u6309\u7167\u987A\u5E8F\u4F9D\u6B21\u83B7\u53D6