Skip to content

Commit

Permalink
1. 树列表渲染
Browse files Browse the repository at this point in the history
2. 完善注释展示
  • Loading branch information
liuzhihang committed Aug 5, 2021
1 parent df4d31d commit 4be8239
Show file tree
Hide file tree
Showing 18 changed files with 206 additions and 230 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.intellij.codeInsight.AnnotationUtil;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiFile;
Expand Down Expand Up @@ -37,10 +38,10 @@ public void actionPerformed(AnActionEvent e) {
PsiFile psiFile = e.getData(CommonDataKeys.PSI_FILE);
Editor editor = e.getData(CommonDataKeys.EDITOR);


if (editor == null || project == null || psiFile == null) {
if (editor == null || project == null || psiFile == null || DumbService.isDumb(project)) {
return;
}

// 获取Java类或者接口
PsiClass targetClass = CustomPsiUtils.getTargetClass(editor, psiFile);

Expand Down Expand Up @@ -84,7 +85,7 @@ public void update(@NotNull AnActionEvent e) {

Presentation presentation = e.getPresentation();

if (editor == null || project == null || psiFile == null) {
if (editor == null || project == null || psiFile == null || DumbService.isDumb(project)) {
presentation.setEnabledAndVisible(false);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.intellij.codeInsight.AnnotationUtil;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiFile;
Expand Down Expand Up @@ -38,9 +39,11 @@ public void actionPerformed(AnActionEvent e) {
Editor editor = e.getData(CommonDataKeys.EDITOR);


if (editor == null || project == null || psiFile == null) {
if (editor == null || project == null || psiFile == null || DumbService.isDumb(project)) {
return;
}


// 获取Java类或者接口
PsiClass targetClass = CustomPsiUtils.getTargetClass(editor, psiFile);

Expand Down Expand Up @@ -89,7 +92,7 @@ public void update(@NotNull AnActionEvent e) {

Presentation presentation = e.getPresentation();

if (editor == null || project == null || psiFile == null) {
if (editor == null || project == null || psiFile == null || DumbService.isDumb(project)) {
presentation.setEnabledAndVisible(false);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.options.ShowSettingsUtil;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiFile;
Expand Down Expand Up @@ -45,9 +46,14 @@ public void actionPerformed(@NotNull AnActionEvent e) {
Editor editor = e.getData(CommonDataKeys.EDITOR);


if (editor == null || project == null || psiFile == null) {
if (editor == null || project == null || psiFile == null || DumbService.isDumb(project)) {
return;
}

if (DumbService.isDumb(project)) {
return;
}

// 获取Java类或者接口
PsiClass targetClass = CustomPsiUtils.getTargetClass(editor, psiFile);

Expand Down Expand Up @@ -106,7 +112,7 @@ public void update(@NotNull AnActionEvent e) {

Presentation presentation = e.getPresentation();

if (editor == null || project == null || psiFile == null) {
if (editor == null || project == null || psiFile == null || DumbService.isDumb(project)) {
presentation.setEnabledAndVisible(false);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.options.ShowSettingsUtil;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiFile;
Expand Down Expand Up @@ -45,9 +46,10 @@ public void actionPerformed(@NotNull AnActionEvent e) {
Editor editor = e.getData(CommonDataKeys.EDITOR);


if (editor == null || project == null || psiFile == null) {
if (editor == null || project == null || psiFile == null || DumbService.isDumb(project)) {
return;
}

// 获取Java类或者接口
PsiClass targetClass = CustomPsiUtils.getTargetClass(editor, psiFile);

Expand Down Expand Up @@ -108,11 +110,12 @@ public void update(@NotNull AnActionEvent e) {

Presentation presentation = e.getPresentation();

if (editor == null || project == null || psiFile == null) {
if (editor == null || project == null || psiFile == null || DumbService.isDumb(project)) {
presentation.setEnabledAndVisible(false);
return;
}


PsiClass targetClass = CustomPsiUtils.getTargetClass(editor, psiFile);

if (targetClass == null || targetClass.isAnnotationType() || targetClass.isEnum()) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/liuzhihang/doc/view/config/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.intellij.openapi.components.Storage;
import com.intellij.openapi.project.Project;
import com.intellij.util.xmlb.XmlSerializerUtil;
import com.liuzhihang.doc.view.constant.Constant;
import com.liuzhihang.doc.view.constant.LombokConstant;
import com.liuzhihang.doc.view.constant.SpringConstant;
import com.liuzhihang.doc.view.constant.ValidationConstant;
Expand All @@ -26,7 +27,7 @@
* @date 2020/2/27 19:02
*/
@Data
@State(name = "DocViewSettingsComponent", storages = {@Storage("DocViewSettings.xml")})
@State(name = "DocViewSettingsComponent", storages = {@Storage(Constant.DOC_VIEW + "/settings.xml")})
public class Settings implements PersistentStateComponent<Settings> {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.intellij.openapi.components.Storage;
import com.intellij.openapi.project.Project;
import com.intellij.util.xmlb.XmlSerializerUtil;
import com.liuzhihang.doc.view.constant.Constant;
import lombok.Data;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand All @@ -17,7 +18,7 @@
* @date 2020/11/22 13:51
*/
@Data
@State(name = "DocViewShowDocSettingsComment", storages = {@Storage("DocViewShowDocSettings.xml")})
@State(name = "DocViewShowDocSettingsComment", storages = {@Storage(Constant.DOC_VIEW + "/ShowDocSettings.xml")})
public class ShowDocSettings implements PersistentStateComponent<ShowDocSettings> {

private String url;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.intellij.openapi.project.Project;
import com.intellij.util.xmlb.XmlSerializerUtil;
import com.liuzhihang.doc.view.DocViewBundle;
import com.liuzhihang.doc.view.constant.Constant;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -16,7 +17,7 @@
* @author liuzhihang
* @date 2020/11/22 13:51
*/
@State(name = "TemplateSettingsComponent", storages = {@Storage("DocViewTemplateSettings.xml")})
@State(name = "TemplateSettingsComponent", storages = {@Storage(Constant.DOC_VIEW + "/TemplateSettings.xml")})
public class TemplateSettings implements PersistentStateComponent<TemplateSettings> {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.intellij.openapi.components.Storage;
import com.intellij.openapi.project.Project;
import com.intellij.util.xmlb.XmlSerializerUtil;
import com.liuzhihang.doc.view.constant.Constant;
import lombok.Data;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand All @@ -17,7 +18,7 @@
* @date 2020/11/22 13:51
*/
@Data
@State(name = "DocViewYApiSettingsComment", storages = {@Storage("DocViewYApiSettings.xml")})
@State(name = "DocViewYApiSettingsComment", storages = {@Storage(Constant.DOC_VIEW + "/YApiSettings.xml")})
public class YApiSettings implements PersistentStateComponent<YApiSettings> {

private String url;
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/liuzhihang/doc/view/constant/Constant.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.liuzhihang.doc.view.constant;

/**
* @author liuzhihang
* @date 2021/8/5 18:12
*/
public class Constant {
private Constant() {
}

public static final String DOC_VIEW = "DocView";
}
6 changes: 3 additions & 3 deletions src/main/java/com/liuzhihang/doc/view/dto/DocViewData.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public class DocViewData {
/**
* 返回参数
*/
private final List<DocViewParamData> responseDocViewParamDataList;
private final List<DocViewParamData> responseParamDataList;
private final String responseParam;


Expand Down Expand Up @@ -109,8 +109,8 @@ public DocViewData(DocView docView) {
this.requestBody = paramMarkdown(requestBodyDataList);
this.requestExample = buildReqExample(docView.getReqExampleType(), docView.getReqExample());

this.responseDocViewParamDataList = buildBodyDataList(docView.getRespRootBody().getChildList());
this.responseParam = paramMarkdown(responseDocViewParamDataList);
this.responseParamDataList = buildBodyDataList(docView.getRespRootBody().getChildList());
this.responseParam = paramMarkdown(responseParamDataList);
this.responseExample = buildRespExample(docView.getReqExampleType(), docView.getRespExample());

}
Expand Down
18 changes: 2 additions & 16 deletions src/main/java/com/liuzhihang/doc/view/ui/DocEditor.form
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,7 @@
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="2cd9" class="javax.swing.JTable" binding="requestParamTable">
<constraints/>
<properties>
<rowHeight value="25"/>
</properties>
</component>
</children>
<children/>
</scrollpane>
</children>
</grid>
Expand All @@ -148,14 +141,7 @@
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="d1c3c" class="javax.swing.JTable" binding="responseParamTable" default-binding="true">
<constraints/>
<properties>
<rowHeight value="25"/>
</properties>
</component>
</children>
<children/>
</scrollpane>
</children>
</grid>
Expand Down
63 changes: 42 additions & 21 deletions src/main/java/com/liuzhihang/doc/view/ui/DocEditorForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@
import com.liuzhihang.doc.view.dto.DocViewData;
import com.liuzhihang.doc.view.dto.DocViewParamData;
import com.liuzhihang.doc.view.service.impl.WriterService;
import com.liuzhihang.doc.view.ui.treetable.ParamTreeTableModel;
import com.liuzhihang.doc.view.ui.treetable.ParamTreeTableUtils;
import com.liuzhihang.doc.view.utils.CustomPsiCommentUtils;
import com.liuzhihang.doc.view.utils.DocViewUtils;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.jdesktop.swingx.JXTreeTable;
import org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -76,10 +81,10 @@ public class DocEditorForm {
private JTextArea methodTextArea;

private JScrollPane requestParamScrollPane;
private JTable requestParamTable;
private JXTreeTable requestTreeTable;

private JScrollPane responseParamScrollPane;
private JTable responseParamTable;
private JXTreeTable responseTreeTable;

private JBPopup popup;

Expand Down Expand Up @@ -175,27 +180,40 @@ private void initRequestParamTable() {

// 边框
responseParamScrollPane.setBorder(JBUI.Borders.empty());
responseParamTable.setBorder(JBUI.Borders.empty());

ParamTableModel paramTableModel = new ParamTableModel(docViewData.getResponseDocViewParamDataList());
responseParamTable.setModel(paramTableModel);

ParamTableUI.rowSetting(responseParamTable);
ParamTableUI.columnSetting(responseParamTable);
DocViewParamData paramData = new DocViewParamData();

DefaultMutableTreeTableNode rootNode = new DefaultMutableTreeTableNode(paramData);
ParamTreeTableUtils.createTreeData(rootNode, docViewData.getResponseParamDataList());

ParamTreeTableModel treeTableModel = new ParamTreeTableModel(rootNode);

requestTreeTable = new JXTreeTable(treeTableModel);

ParamTreeTableUtils.render(requestTreeTable);

responseParamScrollPane.setViewportView(requestTreeTable);

}

private void initResponseParamTable() {

// 边框
requestParamScrollPane.setBorder(JBUI.Borders.empty());
requestParamTable.setBorder(JBUI.Borders.empty());

ParamTableModel paramTableModel = new ParamTableModel(docViewData.getRequestBodyDataList());
requestParamTable.setModel(paramTableModel);
DocViewParamData paramData = new DocViewParamData();

ParamTableUI.rowSetting(requestParamTable);
ParamTableUI.columnSetting(requestParamTable);
DefaultMutableTreeTableNode rootNode = new DefaultMutableTreeTableNode(paramData);
ParamTreeTableUtils.createTreeData(rootNode, docViewData.getRequestBodyDataList());

ParamTreeTableModel treeTableModel = new ParamTreeTableModel(rootNode);

responseTreeTable = new JXTreeTable(treeTableModel);

ParamTreeTableUtils.render(responseTreeTable);

requestParamScrollPane.setViewportView(responseTreeTable);

}

Expand Down Expand Up @@ -359,15 +377,15 @@ private void initTailRightToolbar() {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {

if (requestParamTable.isEditing()) {
requestParamTable.getCellEditor().stopCellEditing();
if (requestTreeTable.isEditing()) {
requestTreeTable.getCellEditor().stopCellEditing();
}
if (responseParamTable.isEditing()) {
responseParamTable.getCellEditor().stopCellEditing();
if (responseTreeTable.isEditing()) {
responseTreeTable.getCellEditor().stopCellEditing();
}
generateMethodComment();
generateComment((ParamTableModel) requestParamTable.getModel());
generateComment((ParamTableModel) responseParamTable.getModel());
generateComment((ParamTreeTableModel) requestTreeTable.getTreeTableModel());
generateComment((ParamTreeTableModel) requestTreeTable.getTreeTableModel());
popup.cancel();
}
});
Expand Down Expand Up @@ -432,16 +450,19 @@ private void generateMethodComment() {

/**
* 变动的字段生成注释
*
* @param paramTreeTableModel
*/
private void generateComment(ParamTableModel paramTableModel) {
private void generateComment(ParamTreeTableModel paramTreeTableModel) {

Map<PsiElement, DocViewParamData> modifyBodyMap = paramTableModel.getModifyBodyMap();
Map<PsiElement, DocViewParamData> modifyBodyMap = paramTreeTableModel.getModifiedMap();

for (PsiElement element : modifyBodyMap.keySet()) {
DocViewParamData data = modifyBodyMap.get(element);
String comment;

if (data.getRequired()) {
// 原来有注解, 则不添加注释
if (!DocViewUtils.isRequired((PsiField) element) && data.getRequired()) {
comment = "/** "
+ data.getDesc() + "\n"
+ "* @" + Settings.getInstance(project).getRequired()
Expand Down
Loading

0 comments on commit 4be8239

Please sign in to comment.