Skip to content

Commit

Permalink
- 重载方法异常
Browse files Browse the repository at this point in the history
- fix:#81
- IDEA-2023.3 读取注视 ReadWriteLock 异常
- 增加识别 `@RequestParam("file") MultipartFile file`;fix:#52
- 增加字段名称设置,支持 `com.fasterxml.jackson.annotation.JsonProperty` 注解自定义名称,且支持设置;fix:#72
  • Loading branch information
liuzhihang committed Dec 23, 2023
1 parent 75cca49 commit 8d7060f
Show file tree
Hide file tree
Showing 23 changed files with 314 additions and 204 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@

### Added

### Changed
- 增加识别 `@RequestParam("file") MultipartFile file`;fix:#52
- 增加字段名称设置,支持 `com.fasterxml.jackson.annotation.JsonProperty` 注解自定义名称,且支持设置;fix:#72

- 移除编辑文档功能,编辑文档,可以直接修改注释,或者修改生成后的文档
### Changed

### Deprecated

### Removed

### Fixed

- 重载方法异常
- fix:#81
- IDEA-2023.3 读取注视 ReadWriteLock 异常

### Security
4 changes: 1 addition & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import org.jetbrains.changelog.ChangelogSectionUrlBuilder
import org.jetbrains.changelog.ExtensionsKt

plugins {
id 'org.jetbrains.intellij' version '1.15.0'
id 'org.jetbrains.intellij' version '1.16.1'
id 'org.jetbrains.changelog' version '2.1.2'
}

Expand All @@ -22,8 +22,6 @@ repositories {
}

dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
compileOnly group: 'org.projectlombok', name: 'lombok', version: '1.18.20'
annotationProcessor group: 'org.projectlombok', name: 'lombok', version: '1.18.20'
}
Expand Down
10 changes: 6 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ org.gradle.caching=true
# ????
pluginGroup=com.liuzhihang.toolkit
pluginName=Doc View
pluginVersion=1.3.5
pluginSinceBuild=203.0
pluginVersion=1.3.6
pluginSinceBuild=222.0
pluginUntilBuild=
pluginDescription=parts/description.html
platformType=IC
platformVersion=2023.2
platformVersion=2023.3
# ,-Dide.browser.jcef.log.level=verbose,-Duser.language=en-US
runIdeJvmArgs=-Dfile.encoding=utf-8
runIdeJvmArgs=-Dfile.encoding=utf-8
# Gradle Releases -> https://github.com/gradle/gradle/releases
gradleVersion=8.5
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ public void actionPerformed(@NotNull AnActionEvent e) {

SimpleNode selectedNode = simpleTree.getSelectedNode();

if (selectedNode instanceof DocViewNode) {
DocViewNode docViewNode = (DocViewNode) selectedNode;
if (selectedNode instanceof DocViewNode docViewNode) {
uploadService().upload(project, docViewNode.docViewList());
}
}
Expand Down
18 changes: 17 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 @@ -56,8 +56,17 @@ public class Settings implements PersistentStateComponent<Settings> {
* 字段是否必填
*/
private String required = "DocView.Required";

/**
* 是否使用注解
*/
private Boolean requiredUseCommentTag = true;

/**
* 字段名称取 JsonProperty 注解
*/
private Boolean fieldNameJsonProperty = true;

/**
* 是否合并导出
*/
Expand Down Expand Up @@ -116,6 +125,14 @@ public class Settings implements PersistentStateComponent<Settings> {
add(LombokConstant.NON_NULL);
}};

/**
* 字段名称注解
*/
private Set<String> fieldNameAnnotation = new HashSet<>() {{
add("com.fasterxml.jackson.annotation.JsonProperty");
}};


/**
* 排除字段
*/
Expand All @@ -127,7 +144,6 @@ public class Settings implements PersistentStateComponent<Settings> {
* 排除字段
*/
private Set<String> excludeParameterType = new HashSet<>() {{
add("org.springframework.core.io.InputStreamSource");
add("javax.servlet.ServletResponse");
add("javax.servlet.ServletRequest");
}};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,11 @@ public JComponent createComponent() {

@Override
public boolean isModified() {

return settingsForm.isModified();
}

@Override
public void apply() throws ConfigurationException {

settingsForm.apply();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.liuzhihang.doc.view.constant;

/**
* JsonProperty 配置
*
* @author liuzhihang
* @since 2023/12/23 18:42
*/
public class JsonPropertyConstant {
private JsonPropertyConstant() {
}

/**
* 注解 @JsonProperty 的全路径
*/
public static final String JSON_PROPERTY = "com.fasterxml.jackson.annotation.JsonProperty";

}
22 changes: 18 additions & 4 deletions src/main/java/com/liuzhihang/doc/view/service/DocViewService.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@
import com.liuzhihang.doc.view.utils.DubboPsiUtils;
import com.liuzhihang.doc.view.utils.FeignPsiUtil;
import com.liuzhihang.doc.view.utils.SpringPsiUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.jetbrains.annotations.NotNull;

import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
* DocView 服务类
Expand Down Expand Up @@ -83,8 +86,20 @@ default List<DocView> buildDoc(@NotNull PsiClass targetClass, PsiMethod targetMe
// 每个方法都要生成
if (targetMethod == null) {
// 生成文档列表
return buildClassDoc(targetClass);

List<DocView> docViews = buildClassDoc(targetClass);
// 处理重复的名字, 如果名字重复,则在后缀加上随机数
Set<String> nameSet = docViews.stream().map(DocView::getName).collect(Collectors.toSet());
for (int i = 0; i < docViews.size(); i++) {
DocView docView = docViews.get(i);
String currentName = docView.getName();
if (nameSet.contains(currentName)) {
nameSet.remove(currentName);
} else {
docView.setName(docView.getName() + "_" + RandomStringUtils.randomAlphabetic(5) + i);
}

}
return docViews;
}

throw new DocViewException(DocViewBundle.message("notify.error.not.support"));
Expand All @@ -108,7 +123,6 @@ default List<DocView> buildDoc(@NotNull PsiClass targetClass, PsiMethod targetMe
* @param psiMethod 当前方法
* @return 文档
*/
@NotNull
DocView buildClassMethodDoc(PsiClass psiClass, @NotNull PsiMethod psiMethod);
@NotNull DocView buildClassMethodDoc(PsiClass psiClass, @NotNull PsiMethod psiMethod);

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public boolean checkMethod(@NotNull PsiMethod targetMethod) {

/**
* 创建类的文档
* <p>
* 可能会存在重载方法,所以这里需要对重载进行处理
*
* @param psiClass 当前类
* @return 类的所有接口文档
Expand All @@ -47,7 +49,6 @@ public List<DocView> buildClassDoc(@NotNull PsiClass psiClass) {
List<DocView> docViewList = new LinkedList<>();

for (PsiMethod method : psiClass.getMethods()) {

if (!DubboPsiUtils.isDubboMethod(method)) {
continue;
}
Expand All @@ -70,7 +71,6 @@ public List<DocView> buildClassDoc(@NotNull PsiClass psiClass) {
@NotNull
@Override
public DocView buildClassMethodDoc(@NotNull PsiClass psiClass, @NotNull PsiMethod psiMethod) {

DocView docView = new DocView();
docView.setPsiClass(psiClass);
docView.setPsiMethod(psiMethod);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.intellij.psi.PsiMethod;
import com.intellij.psi.PsiParameter;
import com.intellij.psi.PsiType;
import com.liuzhihang.doc.view.config.Settings;
import com.liuzhihang.doc.view.dto.DocView;
import com.liuzhihang.doc.view.enums.ContentTypeEnum;
import com.liuzhihang.doc.view.enums.FrameworkEnum;
Expand Down Expand Up @@ -54,8 +53,6 @@ public List<DocView> buildClassDoc(@NotNull PsiClass psiClass) {
@Override
public DocView buildClassMethodDoc(PsiClass psiClass, @NotNull PsiMethod psiMethod) {

Settings settings = Settings.getInstance(psiClass.getProject());

DocView docView = new DocView();
docView.setPsiClass(psiClass);
docView.setPsiMethod(psiMethod);
Expand All @@ -82,7 +79,7 @@ public DocView buildClassMethodDoc(PsiClass psiClass, @NotNull PsiMethod psiMeth
PsiParameter requestBodyParam = SpringPsiUtils.requestBodyParam(psiMethod);
if (requestBodyParam != null) {
docView.setReqBody(SpringPsiUtils.buildBody(requestBodyParam));
docView.setReqBodyExample(SpringPsiUtils.reqBodyJson(requestBodyParam, settings));
docView.setReqBodyExample(SpringPsiUtils.reqBodyJson(requestBodyParam));
}
}
} else {
Expand Down
20 changes: 19 additions & 1 deletion src/main/java/com/liuzhihang/doc/view/ui/Settings.form
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
</component>
</children>
</grid>
<grid id="9f7a3" binding="requirePanel" layout-manager="GridLayoutManager" row-count="4" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="9f7a3" binding="requirePanel" layout-manager="GridLayoutManager" row-count="5" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
Expand Down Expand Up @@ -250,6 +250,24 @@
<toolTipText resource-bundle="messages/DocViewBundle" key="settings.doc.required.comment.tag.tip"/>
</properties>
</component>
<component id="8c3b5" class="javax.swing.JCheckBox" binding="fieldNameJsonPropertyCheckBox">
<constraints>
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<selected value="true"/>
<text resource-bundle="messages/DocViewBundle" key="settings.doc.field.name.JsonProperty"/>
<toolTipText resource-bundle="messages/DocViewBundle" key="settings.doc.field.name.JsonProperty.tip"/>
</properties>
</component>
<component id="96da4" class="javax.swing.JLabel">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/DocViewBundle" key="settings.doc.field.name"/>
</properties>
</component>
</children>
</grid>
<grid id="c2db5" binding="titlePanel" layout-manager="GridLayoutManager" row-count="1" column-count="6" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
Expand Down
Loading

0 comments on commit 8d7060f

Please sign in to comment.