feat(JavaLangDoc): 2.15 java anno doc | java 注解注释
This commit is contained in:
@@ -112,6 +112,7 @@ Show doc comment at the Project view Tree, line End, json, other
|
||||
|
||||
<h2>English Change Notes:</h2>
|
||||
<ul>
|
||||
<li>2.15 Add line-end-comment java anno doc
|
||||
<li>2.14 Add line-end-comment java enum doc for Yes(1, "Yes")
|
||||
<li>2.13 ★ Cache for 2023.3
|
||||
<li>2.12 Add project-view-tree support Markdown and Asciidoc
|
||||
@@ -155,6 +156,7 @@ Show doc comment at the Project view Tree, line End, json, other
|
||||
|
||||
<h2>中文更新说明:</h2>
|
||||
<ul>
|
||||
<li>2.15 增加 行末注释 java 注解注释
|
||||
<li>2.14 增加 行末注释 java 枚举注释用于 Yes(1, "是")
|
||||
<li>2.13 ★ 缓存用于支持 2023.3
|
||||
<li>2.12 增加 文件树注释 支持 Markdown and Asciidoc
|
||||
|
||||
@@ -4,7 +4,7 @@ plugins {
|
||||
}
|
||||
|
||||
group 'io.github.linwancen'
|
||||
version '2.14.0.' + (new Date().format('yyyy.MM.dd_HH.mm'))
|
||||
version '2.15.0.' + (new Date().format('yyyy.MM.dd_HH.mm'))
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
@@ -88,6 +88,7 @@ patchPluginXml {
|
||||
changeNotes = """
|
||||
<h2>English Change Notes:</h2>
|
||||
<ul>
|
||||
<li>2.15 Add line-end-comment java anno doc
|
||||
<li>2.14 Add line-end-comment java enum doc for Yes(1, "Yes")
|
||||
<li>2.13 ★ Cache for 2023.3
|
||||
<li>2.12 Add project-view-tree support Markdown and Asciidoc
|
||||
@@ -131,6 +132,7 @@ patchPluginXml {
|
||||
|
||||
<h2>中文更新说明:</h2>
|
||||
<ul>
|
||||
<li>2.15 增加 行末注释 java 注解注释
|
||||
<li>2.14 增加 行末注释 java 枚举注释用于 Yes(1, "是")
|
||||
<li>2.13 ★ 缓存用于支持 2023.3
|
||||
<li>2.12 增加 文件树注释 支持 Markdown and Asciidoc
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.intellij.psi.javadoc.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import io.github.linwancen.plugin.show.bean.LineInfo;
|
||||
import io.github.linwancen.plugin.show.bean.SettingsInfo;
|
||||
import io.github.linwancen.plugin.show.java.doc.AnnoDoc;
|
||||
import io.github.linwancen.plugin.show.java.doc.EnumDoc;
|
||||
import io.github.linwancen.plugin.show.java.doc.OwnerToPsiDocUtils;
|
||||
import io.github.linwancen.plugin.show.java.doc.ParamDoc;
|
||||
@@ -85,10 +86,12 @@ public class JavaLangDoc extends BaseTagLangDoc<PsiDocComment> {
|
||||
}
|
||||
if (info.appSettings.fromParam && resolve instanceof PsiParameter) {
|
||||
return ParamDoc.paramDoc((PsiParameter) resolve);
|
||||
}
|
||||
if (info.appSettings.enumDoc && resolve instanceof PsiEnumConstant) {
|
||||
} else if (info.appSettings.enumDoc && resolve instanceof PsiEnumConstant) {
|
||||
return EnumDoc.enumDoc((PsiEnumConstant) resolve);
|
||||
}
|
||||
if (resolve instanceof PsiJvmModifiersOwner) {
|
||||
return AnnoDoc.annoDoc(info, (PsiJvmModifiersOwner) resolve);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
package io.github.linwancen.plugin.show.java.doc;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.JavaPsiFacade;
|
||||
import com.intellij.psi.PsiAnnotation;
|
||||
import com.intellij.psi.PsiAnnotationMemberValue;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiConstantEvaluationHelper;
|
||||
import com.intellij.psi.PsiDocCommentOwner;
|
||||
import com.intellij.psi.PsiField;
|
||||
import com.intellij.psi.PsiJvmModifiersOwner;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import io.github.linwancen.plugin.show.bean.SettingsInfo;
|
||||
import io.github.linwancen.plugin.show.settings.GlobalSettingsState;
|
||||
import io.github.linwancen.plugin.show.settings.ProjectSettingsState;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class AnnoDoc {
|
||||
|
||||
@Nullable
|
||||
public static <T extends SettingsInfo> String annoDoc(@NotNull T info, @NotNull PsiJvmModifiersOwner owner) {
|
||||
@NotNull ProjectSettingsState projectSettings = info.projectSettings;
|
||||
@NotNull GlobalSettingsState globalSettings = info.globalSettings;
|
||||
// annoDocEffect first because default false
|
||||
if (projectSettings.annoDocEffect && projectSettings.projectFilterEffective) {
|
||||
@Nullable String doc = annoDocArr(owner, projectSettings.annoDoc);
|
||||
if (StringUtils.isNotBlank(doc)) {
|
||||
return doc;
|
||||
}
|
||||
}
|
||||
if (globalSettings.annoDocEffect && projectSettings.globalFilterEffective) {
|
||||
return annoDocArr(owner, globalSettings.annoDoc);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String annoDocArr(@NotNull PsiJvmModifiersOwner owner, @NotNull String[][] lines) {
|
||||
for (@NotNull String[] arr : lines) {
|
||||
if (arr.length < 3) {
|
||||
continue;
|
||||
}
|
||||
@Nullable String s = annoDocMatch(owner, arr);
|
||||
if (s != null) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String annoDocMatch(@NotNull PsiJvmModifiersOwner owner, @NotNull String[] arr) {
|
||||
if (typeMatch(owner, arr[0])) {
|
||||
return annoDocName(owner, arr);
|
||||
}
|
||||
if (owner instanceof PsiMethod && "field".equals(arr[0])) {
|
||||
@Nullable PsiField psiField = PsiMethodToPsiDoc.propMethodField((PsiMethod) owner);
|
||||
if (psiField != null) {
|
||||
return annoDocName(psiField, arr);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean typeMatch(PsiJvmModifiersOwner owner, @NotNull String type) {
|
||||
switch (type) {
|
||||
case "field":
|
||||
return owner instanceof PsiField;
|
||||
case "method":
|
||||
return owner instanceof PsiMethod;
|
||||
case "class":
|
||||
return owner instanceof PsiClass;
|
||||
case "!doc":
|
||||
return !(owner instanceof PsiDocCommentOwner);
|
||||
case "all":
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String annoDocName(@NotNull PsiJvmModifiersOwner owner, @NotNull String[] arr) {
|
||||
@Nullable PsiAnnotation annotation = owner.getAnnotation(arr[1]);
|
||||
if (annotation == null) {
|
||||
return null;
|
||||
}
|
||||
for (int i = 2; i < arr.length; i++) {
|
||||
@Nullable PsiAnnotationMemberValue value = annotation.findAttributeValue(arr[i]);
|
||||
@Nullable String s = annoDocValue(value);
|
||||
if (s != null) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String annoDocValue(PsiAnnotationMemberValue value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
@NotNull Project project = value.getProject();
|
||||
@NotNull PsiConstantEvaluationHelper helper = JavaPsiFacade.getInstance(project).getConstantEvaluationHelper();
|
||||
@Nullable Object o = helper.computeConstantExpression(value);
|
||||
if (o == null) {
|
||||
return null;
|
||||
}
|
||||
String doc = o.toString();
|
||||
if (doc.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return doc;
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,8 @@ public abstract class AbstractSettingsComponent {
|
||||
|
||||
private final JBCheckBox docGetEffect = new JBCheckBox("");
|
||||
private final JBTextField docGet = new JBTextField();
|
||||
private final JBCheckBox annoDocEffect = new JBCheckBox("");
|
||||
private final JBTextArea annoDoc = new JBTextArea();
|
||||
private final JBCheckBox dirDocEffect = new JBCheckBox("");
|
||||
private final JBTextArea dirDoc = new JBTextArea();
|
||||
private final JBCheckBox fileDocEffect = new JBCheckBox("");
|
||||
@@ -50,9 +52,11 @@ public abstract class AbstractSettingsComponent {
|
||||
.addLabeledComponent(new JBLabel(ShowBundle.message("comment.include.regexp")), docInclude, 1, true)
|
||||
.addLabeledComponent(new JBLabel(ShowBundle.message("comment.exclude.regexp")), docExclude, 1, true)
|
||||
.addSeparator();
|
||||
@NotNull JPanel label = JPanelFactory.of(docGetEffect, new JBLabel(ShowBundle.message("get.doc.regexp")));
|
||||
JPanel panel = builder
|
||||
.addLabeledComponent(label, docGet, 1, true).getPanel();
|
||||
@NotNull JPanel getLabel = JPanelFactory.of(docGetEffect, new JBLabel(ShowBundle.message("get.doc.regexp")));
|
||||
builder = builder.addLabeledComponent(getLabel, docGet, 1, true);
|
||||
@NotNull JPanel annoLabel = JPanelFactory.of(annoDocEffect, new JBLabel(ShowBundle.message("anno.doc")));
|
||||
builder = builder.addLabeledComponent(annoLabel, annoDoc, 1, true);
|
||||
JPanel panel = builder.getPanel();
|
||||
panel.setBorder(IdeBorderFactory.createTitledBorder(ShowBundle.message("line.end.comment")));
|
||||
return panel;
|
||||
}
|
||||
@@ -142,6 +146,24 @@ public abstract class AbstractSettingsComponent {
|
||||
}
|
||||
|
||||
|
||||
public boolean getAnnoDocEffect() {
|
||||
return annoDocEffect.isSelected();
|
||||
}
|
||||
|
||||
public void setAnnoDocEffect(boolean newStatus) {
|
||||
annoDocEffect.setSelected(newStatus);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getAnnoDoc() {
|
||||
return annoDoc.getText();
|
||||
}
|
||||
|
||||
public void setAnnoDoc(@NotNull String newText) {
|
||||
annoDoc.setText(newText);
|
||||
}
|
||||
|
||||
|
||||
public boolean getDirEffect() {
|
||||
return dirDocEffect.isSelected();
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ public class AbstractSettingsConfigurable {
|
||||
modified |= !component.getDocExclude().equals(settings.getDocExclude());
|
||||
modified |= component.getDocGetEffect() != settings.docGetEffect;
|
||||
modified |= !component.getDocGet().equals(settings.getDocGet());
|
||||
modified |= component.getAnnoDocEffect() != settings.annoDocEffect;
|
||||
modified |= !component.getAnnoDoc().equals(settings.getAnnoDoc());
|
||||
modified |= component.getDirEffect() != settings.dirDocEffect;
|
||||
modified |= !component.getDirDoc().equals(settings.getDirDoc());
|
||||
modified |= component.getFileEffect() != settings.fileDocEffect;
|
||||
@@ -36,6 +38,8 @@ public class AbstractSettingsConfigurable {
|
||||
settings.setDocExclude(component.getDocExclude());
|
||||
settings.docGetEffect = component.getDocGetEffect();
|
||||
settings.setDocGet(component.getDocGet());
|
||||
settings.annoDocEffect = component.getAnnoDocEffect();
|
||||
settings.setAnnoDoc(component.getAnnoDoc());
|
||||
settings.dirDocEffect = component.getDirEffect();
|
||||
settings.setDirDoc(component.getDirDoc());
|
||||
settings.fileDocEffect = component.getFileEffect();
|
||||
@@ -51,6 +55,8 @@ public class AbstractSettingsConfigurable {
|
||||
component.setDocExclude(settings.getDocExclude());
|
||||
component.setDocGetEffect(settings.docGetEffect);
|
||||
component.setDocGet(settings.getDocGet());
|
||||
component.setAnnoDocEffect(settings.annoDocEffect);
|
||||
component.setAnnoDoc(settings.getAnnoDoc());
|
||||
component.setDirEffect(settings.dirDocEffect);
|
||||
component.setDirDoc(settings.getDirDoc());
|
||||
component.setFileEffect(settings.fileDocEffect);
|
||||
|
||||
@@ -2,9 +2,11 @@ package io.github.linwancen.plugin.show.settings;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public abstract class AbstractSettingsState {
|
||||
|
||||
@@ -25,6 +27,13 @@ public abstract class AbstractSettingsState {
|
||||
@NotNull
|
||||
public transient Pattern docGet = Pattern.compile(".+?(?:[。\\r\\n]|\\. )");
|
||||
|
||||
public boolean annoDocEffect = true;
|
||||
@NotNull
|
||||
public transient String[][] annoDoc = {
|
||||
{"field", "io.swagger.annotations.ApiModelProperty", "value"},
|
||||
{"field", "io.swagger.v3.oas.annotations.media.Schema", "title"},
|
||||
};
|
||||
|
||||
public boolean dirDocEffect = true;
|
||||
@NotNull
|
||||
public transient Map<String, Pattern[]> dirDoc = new LinkedHashMap<>() {{
|
||||
@@ -93,6 +102,23 @@ public abstract class AbstractSettingsState {
|
||||
}
|
||||
|
||||
|
||||
public String getAnnoDoc() {
|
||||
return Arrays.stream(annoDoc)
|
||||
.map(a -> String.join("#", a))
|
||||
.collect(Collectors.joining("\n"));
|
||||
}
|
||||
|
||||
public static final Pattern LINE_PATTERN = Pattern.compile("[\\r\\n]++");
|
||||
public static final Pattern METHOD_PATTERN = Pattern.compile("#");
|
||||
|
||||
public void setAnnoDoc(@NotNull String s) {
|
||||
String[] split = LINE_PATTERN.split(s);
|
||||
this.annoDoc = Arrays.stream(split)
|
||||
.map(METHOD_PATTERN::split)
|
||||
.toArray(String[][]::new);
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
public String getDirDoc() {
|
||||
return PatternMapUtils.toString(dirDoc);
|
||||
|
||||
@@ -19,6 +19,8 @@ public class ProjectSettingsState extends AbstractSettingsState implements Persi
|
||||
|
||||
public ProjectSettingsState() {
|
||||
this.lineExclude = Pattern.compile("");
|
||||
this.annoDocEffect = false;
|
||||
this.annoDoc = new String[][]{};
|
||||
this.dirDocEffect = false;
|
||||
this.dirDoc = Collections.emptyMap();
|
||||
this.fileDocEffect = false;
|
||||
|
||||
@@ -30,6 +30,7 @@ sign.exclude.regexp=className#memberName exclude Regexp:
|
||||
comment.include.regexp=comment include Regexp:
|
||||
comment.exclude.regexp=comment exclude Regexp:
|
||||
get.doc.regexp=get doc Regexp, last () when had, default is first sentence .+?(?:[\u3002\r\n]|. ) :
|
||||
anno.doc=anno doc, class/method/field/!doc/all#AnnoFullName#methodName#methodName2, Separated by \\n:
|
||||
dir.doc.regexp=dir doc, fileName||Regexp1||Regexp2\\n:
|
||||
file.doc.regexp=file doc, fileExtension||Regexp1||Regexp2\\n:
|
||||
|
||||
|
||||
@@ -29,9 +29,10 @@ sign.include.regexp=\u7C7B#\u65B9\u6CD5 \u5305\u542B \u6B63\u5219\uFF1A
|
||||
sign.exclude.regexp=\u7C7B#\u65B9\u6CD5 \u6392\u9664 \u6B63\u5219\uFF1A
|
||||
comment.include.regexp=\u6CE8\u91CA \u5305\u542B \u6B63\u5219\uFF1A
|
||||
comment.exclude.regexp=\u6CE8\u91CA \u6392\u9664 \u6B63\u5219\uFF1A
|
||||
get.doc.regexp=\u6CE8\u91CA\u63D0\u53D6\u6B63\u5219\uFF0C\u82E5\u6709 () \u5219\u53D6\u6700\u540E\u4E00\u4E2A\uFF0C\u9ED8\u8BA4\u6B63\u5219\u662F\u7B2C\u4E00\u53E5 .+?(?:[\u3002\r\n]|. ) :
|
||||
dir.doc.regexp=\u76EE\u5F55\u6CE8\u91CA, \u6587\u4EF6\u540D||\u6B63\u52191||\u6B63\u52192\\n:
|
||||
file.doc.regexp=\u6587\u4EF6\u6CE8\u91CA, \u6587\u4EF6\u62D3\u5C55\u540D||\u6B63\u52191||\u6B63\u52192\\n:
|
||||
get.doc.regexp=\u6CE8\u91CA\u63D0\u53D6\u6B63\u5219\uFF0C\u82E5\u6709 () \u5219\u53D6\u6700\u540E\u4E00\u4E2A\uFF0C\u9ED8\u8BA4\u6B63\u5219\u662F\u7B2C\u4E00\u53E5 .+?(?:[\u3002\r\n]|. )\uFF1A
|
||||
anno.doc=\u6CE8\u89E3\u6CE8\u91CA\uFF0Cclass/method/field/!doc/all#\u6CE8\u89E3\u5168\u540D#\u65B9\u6CD5\u540D1#\u65B9\u6CD5\u540D2 \u6362\u884C\u5206\u9694\uFF1A
|
||||
dir.doc.regexp=\u76EE\u5F55\u6CE8\u91CA\uFF0C\u6587\u4EF6\u540D||\u6B63\u52191||\u6B63\u52192\\n\uFF1A
|
||||
file.doc.regexp=\u6587\u4EF6\u6CE8\u91CA\uFF0C\u6587\u4EF6\u62D3\u5C55\u540D||\u6B63\u52191||\u6B63\u52192\\n\uFF1A
|
||||
|
||||
global.settings.effective=\u5168\u5C40\u914D\u7F6E\u751F\u6548
|
||||
project.settings.effective=\u9879\u76EE\u914D\u7F6E\u751F\u6548
|
||||
|
||||
@@ -14,6 +14,8 @@ public class Ref implements Face {
|
||||
Face noneNewDoc = new Ref();
|
||||
Child child = new Child(true);
|
||||
Child field = child.field.field;
|
||||
Child af = child.annoField;
|
||||
Child gaf = child.getAnnoField();
|
||||
boolean bool = child.field.bool;
|
||||
Face fun = Child::setFun;
|
||||
child
|
||||
|
||||
@@ -4,4 +4,6 @@ package io.github.linwancen.plugin.show.demo.java.obj;
|
||||
* MyAnno
|
||||
*/
|
||||
public @interface Anno {
|
||||
String value() default "";
|
||||
String myFun() default "";
|
||||
}
|
||||
|
||||
@@ -51,4 +51,16 @@ public class Child extends Parent implements Face {
|
||||
public void setField(Child field) {
|
||||
this.field = field;
|
||||
}
|
||||
|
||||
|
||||
@Anno("Anno")
|
||||
public Child annoField;
|
||||
|
||||
public Child getAnnoField() {
|
||||
return annoField;
|
||||
}
|
||||
|
||||
public void setAnnoField(Child annoField) {
|
||||
this.annoField = annoField;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user