2.11 description from pom.xml or build.gradle | 模块描述

This commit is contained in:
林万程
2023-10-12 00:46:51 +08:00
parent a2486a36dd
commit d5813e57a7
13 changed files with 179 additions and 10 deletions

View File

@@ -1,5 +1,4 @@
# Show Comment Plugin
IDEA 智能注释插件
# 智能注释插件 Show Comment Plugin IDEA
[![Version](https://img.shields.io/jetbrains/plugin/v/io.github.linwancen.show-comment.svg)](https://plugins.jetbrains.com/plugin/18553-show-comment/versions)
[![Downloads](https://img.shields.io/jetbrains/plugin/d/io.github.linwancen.show-comment.svg)](https://plugins.jetbrains.com/plugin/18553-show-comment)
@@ -113,6 +112,7 @@ Show doc comment at the Project view Tree, line End, json, other
<h2>English Change Notes:</h2>
<ul>
<li>2.11 Add project-view-tree description from pom.xml and build.gradle
<li>2.10 Add line-end-comment not doc comment
<li>2.09 Add line-end-comment support Python doc strings
<li>2.08 Add i18n and chinese
@@ -152,6 +152,7 @@ Show doc comment at the Project view Tree, line End, json, other
<h2>中文更新说明:</h2>
<ul>
<li>2.11 增加 文件树注释 模块描述 来自 pom.xml 和 build.gradle
<li>2.10 增加 行末注释 非文档注释
<li>2.09 增加 行末注释 支持 Python 文档字符串
<li>2.08 增加 多语言与中文支持

View File

@@ -4,8 +4,7 @@ plugins {
}
group 'io.github.linwancen'
version '2.10.0.' + (new Date().format('yyyy.MM.dd_HH.mm'))
description "Show comment at the Project View Tree, line End, JSON, other"
version '2.11.0.' + (new Date().format('yyyy.MM.dd_HH.mm'))
repositories {
mavenCentral()
@@ -88,6 +87,7 @@ patchPluginXml {
changeNotes = """
<h2>English Change Notes:</h2>
<ul>
<li>2.11 Add project-view-tree description from pom.xml and build.gradle
<li>2.10 Add line-end-comment not doc comment
<li>2.09 Add line-end-comment support Python doc strings
<li>2.08 Add i18n and chinese
@@ -127,6 +127,7 @@ patchPluginXml {
<h2>中文更新说明:</h2>
<ul>
<li>2.11 增加 文件树注释 模块描述 来自 pom.xml 和 build.gradle
<li>2.10 增加 行末注释 非文档注释
<li>2.09 增加 行末注释 支持 Python 文档字符串
<li>2.08 增加 多语言与中文支持

View File

@@ -16,6 +16,7 @@ import io.github.linwancen.plugin.show.bean.SettingsInfo;
import io.github.linwancen.plugin.show.ext.TreeExt;
import io.github.linwancen.plugin.show.lang.base.BaseLangDoc;
import io.github.linwancen.plugin.show.settings.AppSettingsState;
import io.github.linwancen.plugin.show.tree.ProjectDoc;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
@@ -69,6 +70,10 @@ public class Tree implements ProjectViewNodeDecorator {
return doc;
}
@NotNull SettingsInfo settingsInfo = SettingsInfo.of(project, FuncEnum.TREE);
@Nullable String projectDoc = ProjectDoc.projectDoc(node, settingsInfo);
if (projectDoc != null) {
return projectDoc;
}
Object value = node.getValue();
if (value instanceof PsiElement) {
@NotNull PsiElement psiElement = (PsiElement) value;

View File

@@ -18,7 +18,7 @@ public class Prev {
@Nullable
public static PsiElement prevRefChild(@NotNull LineInfo lineInfo, @NotNull PsiElement element,
@NotNull Class<? extends PsiElement> refClass) {
PsiElement prevParent = refClassParent(element, refClass);
@Nullable PsiElement prevParent = refClassParent(element, refClass);
while ((element = PsiTreeUtil.prevVisibleLeaf(element)) != null) {
if (element.getTextRange().getEndOffset() < lineInfo.startOffset) {
return null;

View File

@@ -3,11 +3,13 @@ package io.github.linwancen.plugin.show.settings;
import com.intellij.ui.IdeBorderFactory;
import com.intellij.ui.components.JBCheckBox;
import com.intellij.ui.components.JBLabel;
import com.intellij.ui.components.JBTextArea;
import com.intellij.ui.components.JBTextField;
import com.intellij.util.ui.FormBuilder;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import javax.swing.text.JTextComponent;
public abstract class AbstractSettingsComponent {
@@ -19,6 +21,8 @@ public abstract class AbstractSettingsComponent {
private final JBCheckBox docGetEffect = new JBCheckBox("");
private final JBTextField docGet = new JBTextField();
private final JBCheckBox projectDocEffect = new JBCheckBox("");
private final JBTextArea projectDoc = new JBTextArea();
@NotNull
protected JPanel commonLineEndFilter(FormBuilder formBuilder) {
@@ -31,15 +35,16 @@ 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();
formBuilder = add(formBuilder, docGetEffect, this.docGet, ShowBundle.message("get.doc.regexp"));
formBuilder = add(formBuilder, docGetEffect, docGet, ShowBundle.message("get.doc.regexp"));
formBuilder = add(formBuilder, projectDocEffect, projectDoc, ShowBundle.message("project.doc.regexp"));
JPanel lineEndFilter = formBuilder.getPanel();
lineEndFilter.setBorder(IdeBorderFactory.createTitledBorder(ShowBundle.message("line.end.comment")));
return lineEndFilter;
}
protected FormBuilder add(@NotNull FormBuilder formBuilder, JBCheckBox jbCheckBox,
@NotNull JBTextField jbTextField, @NotNull String tip) {
return formBuilder.addLabeledComponent(JPanelFactory.of(jbCheckBox, new JBLabel(tip)), jbTextField, 1, true);
@NotNull JTextComponent jTextComponent, @NotNull String tip) {
return formBuilder.addLabeledComponent(JPanelFactory.of(jbCheckBox, new JBLabel(tip)), jTextComponent, 1, true);
}
@NotNull
@@ -96,4 +101,22 @@ public abstract class AbstractSettingsComponent {
public void setDocGet(@NotNull String newText) {
docGet.setText(newText);
}
public boolean getProjectEffect() {
return projectDocEffect.isSelected();
}
public void setProjectEffect(boolean newStatus) {
projectDocEffect.setSelected(newStatus);
}
@NotNull
public String getProjectDoc() {
return projectDoc.getText();
}
public void setProjectDoc(@NotNull String newText) {
projectDoc.setText(newText);
}
}

View File

@@ -14,6 +14,8 @@ public class AbstractSettingsConfigurable {
modified |= !component.getDocExclude().equals(settings.getDocExclude());
modified |= component.getDocGetEffect() != settings.docGetEffect;
modified |= !component.getDocGet().equals(settings.getDocGet());
modified |= component.getProjectEffect() != settings.projectDocEffect;
modified |= !component.getProjectDoc().equals(settings.getProjectDoc());
return modified;
}
@@ -24,6 +26,8 @@ public class AbstractSettingsConfigurable {
settings.setDocExclude(component.getDocExclude());
settings.docGetEffect = component.getDocGetEffect();
settings.setDocGet(component.getDocGet());
settings.projectDocEffect = component.getProjectEffect();
settings.setProjectDoc(component.getProjectDoc());
}
static void reset(@NotNull AbstractSettingsState settings, @NotNull AbstractSettingsComponent component) {
@@ -33,5 +37,7 @@ public class AbstractSettingsConfigurable {
component.setDocExclude(settings.getDocExclude());
component.setDocGetEffect(settings.docGetEffect);
component.setDocGet(settings.getDocGet());
component.setProjectEffect(settings.projectDocEffect);
component.setProjectDoc(settings.getProjectDoc());
}
}

View File

@@ -2,7 +2,10 @@ package io.github.linwancen.plugin.show.settings;
import org.jetbrains.annotations.NotNull;
import java.util.function.Function;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public abstract class AbstractSettingsState {
@@ -17,6 +20,18 @@ public abstract class AbstractSettingsState {
public boolean docGetEffect = false;
@NotNull
public transient Pattern docGet = Pattern.compile(".+?(?:[。\\r\\n]|\\. )");
public boolean projectDocEffect = true;
@NotNull
public transient Pattern[][] projectDoc = {
{
Pattern.compile("pom.xml"),
Pattern.compile("<description>([^<]++)</description>"),
Pattern.compile("<name>\\$\\{[^}]*+\\}([^<]++)</name>"),
},
{Pattern.compile("build.gradle"), Pattern.compile("^description[^'\"]*+['\"]([^'\"]++)['\"]")},
{Pattern.compile("build.gradle.kts"), Pattern.compile("^description[^'\"]*+['\"]([^'\"]++)['\"]")},
{Pattern.compile("README.md"), Pattern.compile("^# (.*)")},
};
public String getLineInclude() {
return lineInclude.pattern();
@@ -59,4 +74,32 @@ public abstract class AbstractSettingsState {
public void setDocGet(@NotNull String docExclude) {
this.docGet = Pattern.compile(docExclude);
}
public static final Function<Pattern[], String> TO_LINE = patterns -> Stream.of(patterns)
.map(Pattern::pattern)
.collect(Collectors.joining("||"));
public String getProjectDoc() {
return Stream.of(projectDoc)
.map(TO_LINE)
.collect(Collectors.joining("\n"));
}
private static final Pattern LINE_PATTERN = Pattern.compile("[\\r\\n]++");
private static final Pattern SPLIT_PATTERN = Pattern.compile("\\|\\|");
public void setProjectDoc(@NotNull String projectDoc) {
String[] projectDocLines = LINE_PATTERN.split(projectDoc);
@NotNull Pattern[][] patterns = new Pattern[projectDocLines.length][];
for (int i = 0; i < projectDocLines.length; i++) {
String[] projectDocs = SPLIT_PATTERN.split(projectDocLines[i]);
patterns[i] = new Pattern[projectDocs.length];
for (int j = 0; j < projectDocs.length; j++) {
patterns[i][j] = Pattern.compile(projectDocs[j]);
}
}
this.projectDoc = patterns;
}
}

View File

@@ -49,7 +49,7 @@ public class GlobalSettingsConfigurable implements Configurable {
reset(settings, mySettingsComponent);
}
static void reset(@NotNull GlobalSettingsState settings, GlobalSettingsComponent mySettingsComponent1) {
static void reset(@NotNull GlobalSettingsState settings, @NotNull GlobalSettingsComponent mySettingsComponent1) {
AbstractSettingsConfigurable.reset(settings, mySettingsComponent1);
}

View File

@@ -66,7 +66,7 @@ public class ProjectSettingsConfigurable extends ModuleAwareProjectConfigurable<
reset(settings, mySettingsComponent);
}
static void reset(@NotNull ProjectSettingsState settings, ProjectSettingsComponent mySettingsComponent1) {
static void reset(@NotNull ProjectSettingsState settings, @NotNull ProjectSettingsComponent mySettingsComponent1) {
mySettingsComponent1.setGlobalFilterEffective(settings.globalFilterEffective);
mySettingsComponent1.setProjectFilterEffective(settings.projectFilterEffective);
AbstractSettingsConfigurable.reset(settings, mySettingsComponent1);

View File

@@ -8,12 +8,20 @@ import com.intellij.util.xmlb.XmlSerializerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.regex.Pattern;
@State(
name = "io.github.linwancen.plugin.show.settings.ProjectSettingsState",
storages = @Storage("ShowCommentProject.xml")
)
public class ProjectSettingsState extends AbstractSettingsState implements PersistentStateComponent<ProjectSettingsState> {
public ProjectSettingsState() {
this.lineExclude = Pattern.compile("");
this.projectDocEffect = false;
this.projectDoc = new Pattern[][]{};
}
public static final ProjectSettingsState DEFAULT_SETTING = new ProjectSettingsState();
public boolean globalFilterEffective = true;

View File

@@ -0,0 +1,80 @@
package io.github.linwancen.plugin.show.tree;
import com.intellij.ide.projectView.ProjectViewNode;
import com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode;
import com.intellij.lang.FileASTNode;
import com.intellij.psi.PsiDirectory;
import com.intellij.psi.PsiFile;
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.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ProjectDoc {
public static String projectDoc(ProjectViewNode<?> node, @NotNull SettingsInfo settingsInfo) {
if (!(node instanceof PsiDirectoryNode)) {
return null;
}
@NotNull PsiDirectoryNode psiDirectoryNode = (PsiDirectoryNode) node;
@Nullable PsiDirectory psiDirectory = psiDirectoryNode.getValue();
if (psiDirectory == null) {
return null;
}
@NotNull ProjectSettingsState projectSettings = settingsInfo.projectSettings;
@NotNull GlobalSettingsState globalSettings = settingsInfo.globalSettings;
if (projectSettings.projectFilterEffective && projectSettings.projectDocEffect) {
return projectDirDoc(psiDirectory, projectSettings.projectDoc);
} else if (projectSettings.globalFilterEffective && globalSettings.projectDocEffect) {
return projectDirDoc(psiDirectory, globalSettings.projectDoc);
} else {
return null;
}
}
@Nullable
private static String projectDirDoc(@NotNull PsiDirectory psiDirectory, @NotNull Pattern[][] projectDoc) {
for (@NotNull Pattern[] patterns : projectDoc) {
@Nullable String patternsDoc = patternsDoc(psiDirectory, patterns);
if (patternsDoc != null) {
return patternsDoc;
}
}
return null;
}
@Nullable
private static String patternsDoc(@NotNull PsiDirectory psiDirectory, @NotNull Pattern[] patterns) {
if (patterns.length < 2) {
return null;
}
Pattern filePattern = patterns[0];
String fileName = filePattern.pattern();
@Nullable PsiFile file = psiDirectory.findFile(fileName);
if (file == null) {
return null;
}
@Nullable FileASTNode fileNode = file.getNode();
if (fileNode == null) {
return null;
}
@NotNull String text = fileNode.getText();
for (int i = 1; i < patterns.length; i++) {
@NotNull Matcher matcher = patterns[i].matcher(text);
if (matcher.find()) {
String group = matcher.group(1);
if (group != null) {
group = group.trim();
if (!group.isEmpty()) {
return group;
}
}
}
}
return null;
}
}

View File

@@ -26,6 +26,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]|. ) :
project.doc.regexp=project doc, fileName||Regexp1||Regexp2\\n:
global.settings.effective=Global Settings Effective
project.settings.effective=Project Settings Effective

View File

@@ -26,6 +26,7 @@ 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]|. ) :
project.doc.regexp=\u9879\u76EE\u6CE8\u91CA, \u6587\u4EF6\u540D||\u6B63\u52191||\u6B63\u52192\\n:
global.settings.effective=\u5168\u5C40\u914D\u7F6E\u751F\u6548
project.settings.effective=\u9879\u76EE\u914D\u7F6E\u751F\u6548