From 452101843ca3e01a2b4e7ca0743efe712c7bf3a7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9E=97=E4=B8=87=E7=A8=8B?= <1498425439@qq.com>
Date: Sun, 13 Feb 2022 02:40:11 +0800
Subject: [PATCH] =?UTF-8?q?1.2=20Add=20end-of-line=20comment=20class=20pre?=
=?UTF-8?q?fix=20filter=20settings=20|=20=E6=B7=BB=E5=8A=A0=E8=A1=8C?=
=?UTF-8?q?=E6=9C=AB=E6=B3=A8=E9=87=8A=E7=B1=BB=E5=89=8D=E7=BC=80=E8=BF=87?=
=?UTF-8?q?=E6=BB=A4=E9=85=8D=E7=BD=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 19 ++-
build.gradle | 7 +-
.../linwancen/plugin/comment/LineEnd.java | 4 +-
.../settings/AbstractSettingsComponent.java | 48 ++++++++
.../settings/AppSettingsComponent.java | 27 ++--
.../settings/AppSettingsConfigurable.java | 34 +++--
.../comment/settings/AppSettingsState.java | 13 +-
.../settings/ProjectSettingsComponent.java | 55 +++++++++
.../settings/ProjectSettingsConfigurable.java | 79 ++++++++++++
.../settings/ProjectSettingsState.java | 40 ++++++
.../plugin/comment/settings/SplitUtils.java | 20 +++
.../plugin/comment/utils/SkipUtils.java | 42 ++++++-
src/main/resources/META-INF/plugin.xml | 23 +++-
.../plugin/comment/utils/SkipUtilsTest.java | 116 ++++++++++++++++++
14 files changed, 492 insertions(+), 35 deletions(-)
create mode 100644 src/main/java/io/github/linwancen/plugin/comment/settings/AbstractSettingsComponent.java
create mode 100644 src/main/java/io/github/linwancen/plugin/comment/settings/ProjectSettingsComponent.java
create mode 100644 src/main/java/io/github/linwancen/plugin/comment/settings/ProjectSettingsConfigurable.java
create mode 100644 src/main/java/io/github/linwancen/plugin/comment/settings/ProjectSettingsState.java
create mode 100644 src/main/java/io/github/linwancen/plugin/comment/settings/SplitUtils.java
create mode 100644 src/test/java/io/github/linwancen/plugin/comment/utils/SkipUtilsTest.java
diff --git a/README.md b/README.md
index 40d835a..a8d6264 100644
--- a/README.md
+++ b/README.md
@@ -2,9 +2,22 @@
IDEA 智能注释插件
English Note:
-- Show javadoc comments for calling methods at the end of the line.
- Show javadoc comments in the Project view Tree structure.
+- Show javadoc comments for calling methods at the end of the line.
+- One of the above features
+ can be turned off in the settings -> Tools -> Show Comment Global.
+- The color of end-of-line comments
+ can be modified in the settings -> Tools -> Show Comment Global.
+- End-of-line comment class prefix filter
+ can be modified in settings -> Tools -> Show Comment Project.
Chinese Note:
-- 在行末显示调用方法的文档注释。
-- 在结构树显示文档注释。
\ No newline at end of file
+- 在结构树显示 当前节点 的文档注释。
+- 在行末尾显示 调用方法 的文档注释。
+- 可以在设置中 关闭 上面其中一个功能。
+- 可以在设置中 修改 行末注释的颜色。
+- 可以在设置中 修改 行末注释类前缀过滤。
+
+Change Log:
+- 1.1 Add end-of-line text color settings | 添加行末文本颜色配置
+- 1.2 Add end-of-line comment class prefix filter settings | 添加行末注释类前缀过滤配置
\ No newline at end of file
diff --git a/build.gradle b/build.gradle
index fc8cc6b..bf7f115 100644
--- a/build.gradle
+++ b/build.gradle
@@ -4,7 +4,7 @@ plugins {
}
group 'io.github.linwancen'
-version '1.1.0.' + (new Date().format('yyyy.MM.dd_HH.mm'))
+version '1.2.0.' + (new Date().format('yyyy.MM.dd_HH.mm'))
apply plugin: 'java'
@@ -37,7 +37,10 @@ patchPluginXml {
sinceBuild = '201.1'
untilBuild = ''
changeNotes = """
- 1.1 Add end-of-line text color settings | 添加行末文本颜色配置
+
+ - 1.1 Add end-of-line text color settings 添加行末文本颜色配置
+
- 1.2 Add end-of-line comment class prefix filter settings 添加行末注释类前缀配置
+
"""
}
diff --git a/src/main/java/io/github/linwancen/plugin/comment/LineEnd.java b/src/main/java/io/github/linwancen/plugin/comment/LineEnd.java
index e16aef6..d90edf0 100644
--- a/src/main/java/io/github/linwancen/plugin/comment/LineEnd.java
+++ b/src/main/java/io/github/linwancen/plugin/comment/LineEnd.java
@@ -53,14 +53,14 @@ public class LineEnd extends EditorLinePainter {
}
if (psiElement instanceof PsiClass) {
PsiClass psiClass = (PsiClass) psiElement;
- if (SkipUtils.skip(psiClass)) {
+ if (SkipUtils.skip(psiClass, psiClass.getProject())) {
return null;
}
return CommentFactory.fromSrcOrByteCode(psiClass);
}
if (psiElement instanceof PsiMethod) {
PsiMethod psiMethod = (PsiMethod) psiElement;
- if (SkipUtils.skip(psiMethod.getContainingClass())) {
+ if (SkipUtils.skip(psiMethod.getContainingClass(), psiMethod.getProject())) {
return null;
}
return PsiMethodCommentFactory.from(psiMethod);
diff --git a/src/main/java/io/github/linwancen/plugin/comment/settings/AbstractSettingsComponent.java b/src/main/java/io/github/linwancen/plugin/comment/settings/AbstractSettingsComponent.java
new file mode 100644
index 0000000..dc73d33
--- /dev/null
+++ b/src/main/java/io/github/linwancen/plugin/comment/settings/AbstractSettingsComponent.java
@@ -0,0 +1,48 @@
+package io.github.linwancen.plugin.comment.settings;
+
+import com.intellij.ui.IdeBorderFactory;
+import com.intellij.ui.components.JBLabel;
+import com.intellij.ui.components.JBTextField;
+import com.intellij.util.ui.FormBuilder;
+import org.jetbrains.annotations.NotNull;
+
+import javax.swing.*;
+
+public abstract class AbstractSettingsComponent {
+
+ protected final JBTextField lineEndInclude = new JBTextField();
+ protected final JBTextField lineEndExclude = new JBTextField();
+
+
+ @NotNull
+ protected JPanel commonLineEndFilter(FormBuilder formBuilder) {
+ JPanel lineEndFilter = formBuilder
+ .addComponent(new JBLabel("Separated by ',' or ' ' etc."))
+ .addComponent(new JBLabel("Use '' to include all or exclude none."))
+ .addSeparator()
+ .addLabeledComponent(new JBLabel("line end include start with: "), lineEndInclude, 1, true)
+ .addLabeledComponent(new JBLabel("line end exclude start with: "), lineEndExclude, 1, true)
+ .getPanel();
+ lineEndFilter.setBorder(IdeBorderFactory.createTitledBorder(
+ "Line End Comment"));
+ return lineEndFilter;
+ }
+
+ @NotNull
+ public String getLineEndInclude() {
+ return lineEndInclude.getText();
+ }
+
+ public void setLineEndInclude(@NotNull String newText) {
+ lineEndInclude.setText(newText);
+ }
+
+ @NotNull
+ public String getLineEndExclude() {
+ return lineEndExclude.getText();
+ }
+
+ public void setLineEndExclude(@NotNull String newText) {
+ lineEndExclude.setText(newText);
+ }
+}
diff --git a/src/main/java/io/github/linwancen/plugin/comment/settings/AppSettingsComponent.java b/src/main/java/io/github/linwancen/plugin/comment/settings/AppSettingsComponent.java
index 4201e6c..9e91c79 100644
--- a/src/main/java/io/github/linwancen/plugin/comment/settings/AppSettingsComponent.java
+++ b/src/main/java/io/github/linwancen/plugin/comment/settings/AppSettingsComponent.java
@@ -4,11 +4,12 @@ import com.intellij.ui.ColorPanel;
import com.intellij.ui.IdeBorderFactory;
import com.intellij.ui.components.JBCheckBox;
import com.intellij.util.ui.FormBuilder;
+import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.awt.*;
-public class AppSettingsComponent {
+public class AppSettingsComponent extends AbstractSettingsComponent {
private final JPanel myMainPanel;
private final JBCheckBox showTreeComment = new JBCheckBox("Show tree comment ");
@@ -16,22 +17,31 @@ public class AppSettingsComponent {
private final ColorPanel lineEndColor = new ColorPanel();
public AppSettingsComponent() {
+ myMainPanel = FormBuilder.createFormBuilder()
+ .addComponent(showPanel(), 1)
+ .addComponent(colorPanel(), 1)
+ .addComponent(commonLineEndFilter(FormBuilder.createFormBuilder()), 1)
+ .addComponentFillVertically(new JPanel(), 0)
+ .getPanel();
+ }
+
+ @NotNull
+ private JPanel showPanel() {
JPanel comment = FormBuilder.createFormBuilder()
.addComponent(showTreeComment, 1)
.addComponent(showLineEndComment, 1)
.getPanel();
- comment.setBorder(IdeBorderFactory.createTitledBorder("Comment"));
+ comment.setBorder(IdeBorderFactory.createTitledBorder("Show"));
+ return comment;
+ }
+ @NotNull
+ private JPanel colorPanel() {
JPanel color = FormBuilder.createFormBuilder()
.addLabeledComponent(new JLabel("line end text color:"), lineEndColor)
.getPanel();
color.setBorder(IdeBorderFactory.createTitledBorder("Color"));
-
- myMainPanel = FormBuilder.createFormBuilder()
- .addComponent(comment, 1)
- .addComponent(color, 1)
- .addComponentFillVertically(new JPanel(), 0)
- .getPanel();
+ return color;
}
public JPanel getPanel() {
@@ -42,6 +52,7 @@ public class AppSettingsComponent {
return showTreeComment;
}
+
public boolean getShowTreeComment() {
return showTreeComment.isSelected();
}
diff --git a/src/main/java/io/github/linwancen/plugin/comment/settings/AppSettingsConfigurable.java b/src/main/java/io/github/linwancen/plugin/comment/settings/AppSettingsConfigurable.java
index e3660dc..5ccd693 100644
--- a/src/main/java/io/github/linwancen/plugin/comment/settings/AppSettingsConfigurable.java
+++ b/src/main/java/io/github/linwancen/plugin/comment/settings/AppSettingsConfigurable.java
@@ -2,13 +2,11 @@ package io.github.linwancen.plugin.comment.settings;
import com.intellij.openapi.editor.colors.EditorColorsManager;
import com.intellij.openapi.options.Configurable;
-import com.intellij.ui.Gray;
import com.intellij.ui.JBColor;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
-import java.awt.*;
public class AppSettingsConfigurable implements Configurable {
@@ -17,7 +15,7 @@ public class AppSettingsConfigurable implements Configurable {
@Nls(capitalization = Nls.Capitalization.Title)
@Override
public String getDisplayName() {
- return "Show Comment.";
+ return "Show Comment Global.";
}
@Override
@@ -37,7 +35,13 @@ public class AppSettingsConfigurable implements Configurable {
AppSettingsState settings = AppSettingsState.getInstance();
boolean modified = mySettingsComponent.getShowTreeComment() != settings.showTreeComment;
modified |= mySettingsComponent.getShowLineEndComment() != settings.showLineEndComment;
- modified |= !mySettingsComponent.getLineEndColor().equals(settings.lineEndTextAttr.getForegroundColor());
+ if (EditorColorsManager.getInstance().isDarkEditor()) {
+ modified |= !mySettingsComponent.getLineEndColor().equals(settings.lineEndColorDark);
+ } else {
+ modified |= !mySettingsComponent.getLineEndColor().equals(settings.lineEndColorBright);
+ }
+ modified |= !mySettingsComponent.getLineEndInclude().equals(settings.lineEndInclude);
+ modified |= !mySettingsComponent.getLineEndExclude().equals(settings.lineEndExclude);
return modified;
}
@@ -46,15 +50,17 @@ public class AppSettingsConfigurable implements Configurable {
AppSettingsState settings = AppSettingsState.getInstance();
settings.showTreeComment = mySettingsComponent.getShowTreeComment();
settings.showLineEndComment = mySettingsComponent.getShowLineEndComment();
- settings.lineEndTextAttr.setForegroundColor(jbColor());
- }
-
- private JBColor jbColor() {
if (EditorColorsManager.getInstance().isDarkEditor()) {
- return new JBColor(new Color(98, 151, 85), mySettingsComponent.getLineEndColor());
+ settings.lineEndColorDark = mySettingsComponent.getLineEndColor();
} else {
- return new JBColor(mySettingsComponent.getLineEndColor(), Gray._140);
+ settings.lineEndColorBright = mySettingsComponent.getLineEndColor();
}
+ JBColor jbColor = new JBColor(settings.lineEndColorBright, settings.lineEndColorDark);
+ settings.lineEndTextAttr.setForegroundColor(jbColor);
+ settings.lineEndInclude = mySettingsComponent.getLineEndInclude();
+ settings.lineEndExclude = mySettingsComponent.getLineEndExclude();
+ settings.lineEndIncludeArray = SplitUtils.split(settings.lineEndInclude);
+ settings.lineEndExcludeArray = SplitUtils.split(settings.lineEndExclude);
}
@Override
@@ -62,7 +68,13 @@ public class AppSettingsConfigurable implements Configurable {
AppSettingsState settings = AppSettingsState.getInstance();
mySettingsComponent.setShowTreeComment(settings.showTreeComment);
mySettingsComponent.setShowLineEndComment(settings.showLineEndComment);
- mySettingsComponent.setLineEndColor(settings.lineEndTextAttr.getForegroundColor());
+ if (EditorColorsManager.getInstance().isDarkEditor()) {
+ mySettingsComponent.setLineEndColor(settings.lineEndColorDark);
+ } else {
+ mySettingsComponent.setLineEndColor(settings.lineEndColorBright);
+ }
+ mySettingsComponent.setLineEndInclude(settings.lineEndInclude);
+ mySettingsComponent.setLineEndExclude(settings.lineEndExclude);
}
@Override
diff --git a/src/main/java/io/github/linwancen/plugin/comment/settings/AppSettingsState.java b/src/main/java/io/github/linwancen/plugin/comment/settings/AppSettingsState.java
index c49f326..c4e9cbb 100644
--- a/src/main/java/io/github/linwancen/plugin/comment/settings/AppSettingsState.java
+++ b/src/main/java/io/github/linwancen/plugin/comment/settings/AppSettingsState.java
@@ -15,17 +15,24 @@ import java.awt.*;
@State(
name = "io.github.linwancen.plugin.comment.settings.AppSettingsState",
- storages = @Storage("ShowCommentPlugin.xml")
+ storages = @Storage("ShowCommentGlobal.xml")
)
public class AppSettingsState implements PersistentStateComponent {
public boolean showLineEndComment = true;
public boolean showTreeComment = true;
- private static final JBColor lineEndColor = new JBColor(new Color(98, 151, 85), Gray._140);
- public final TextAttributes lineEndTextAttr = new TextAttributes(lineEndColor,
+ @SuppressWarnings("all")
+ public Color lineEndColorBright = new Color(98, 151, 85);
+ public Color lineEndColorDark = Gray._140;
+ public final TextAttributes lineEndTextAttr = new TextAttributes(new JBColor(lineEndColorBright, lineEndColorDark),
null, null, null, Font.ITALIC);
+ public String lineEndInclude = "";
+ public String lineEndExclude = "java.";
+ public String[] lineEndIncludeArray = {};
+ public String[] lineEndExcludeArray = {"java."};
+
public static AppSettingsState getInstance() {
return ApplicationManager.getApplication().getService(AppSettingsState.class);
}
diff --git a/src/main/java/io/github/linwancen/plugin/comment/settings/ProjectSettingsComponent.java b/src/main/java/io/github/linwancen/plugin/comment/settings/ProjectSettingsComponent.java
new file mode 100644
index 0000000..7ea7cb4
--- /dev/null
+++ b/src/main/java/io/github/linwancen/plugin/comment/settings/ProjectSettingsComponent.java
@@ -0,0 +1,55 @@
+package io.github.linwancen.plugin.comment.settings;
+
+import com.intellij.ui.components.JBCheckBox;
+import com.intellij.util.ui.FormBuilder;
+import org.jetbrains.annotations.NotNull;
+
+import javax.swing.*;
+
+public class ProjectSettingsComponent extends AbstractSettingsComponent {
+
+ private final JPanel myMainPanel;
+ private final JBCheckBox globalFilterEffective = new JBCheckBox("Global Include Exclude Effective");
+ private final JBCheckBox projectFilterEffective = new JBCheckBox("Project Include Exclude Effective");
+
+ public ProjectSettingsComponent() {
+ myMainPanel = FormBuilder.createFormBuilder()
+ .addComponent(lineEndFilterPanel(), 1)
+ .addComponentFillVertically(new JPanel(), 0)
+ .getPanel();
+ }
+
+ @NotNull
+ protected JPanel lineEndFilterPanel() {
+ FormBuilder formBuilder = FormBuilder.createFormBuilder()
+ .addComponent(globalFilterEffective)
+ .addComponent(projectFilterEffective)
+ .addSeparator();
+ return commonLineEndFilter(formBuilder);
+ }
+
+ public JPanel getPanel() {
+ return myMainPanel;
+ }
+
+ public JComponent getPreferredFocusedComponent() {
+ return lineEndInclude;
+ }
+
+
+ public boolean getGlobalFilterEffective() {
+ return globalFilterEffective.isSelected();
+ }
+
+ public void setGlobalFilterEffective(boolean newStatus) {
+ globalFilterEffective.setSelected(newStatus);
+ }
+
+ public boolean getProjectFilterEffective() {
+ return projectFilterEffective.isSelected();
+ }
+
+ public void setProjectFilterEffective(boolean newStatus) {
+ projectFilterEffective.setSelected(newStatus);
+ }
+}
diff --git a/src/main/java/io/github/linwancen/plugin/comment/settings/ProjectSettingsConfigurable.java b/src/main/java/io/github/linwancen/plugin/comment/settings/ProjectSettingsConfigurable.java
new file mode 100644
index 0000000..e01f620
--- /dev/null
+++ b/src/main/java/io/github/linwancen/plugin/comment/settings/ProjectSettingsConfigurable.java
@@ -0,0 +1,79 @@
+package io.github.linwancen.plugin.comment.settings;
+
+import com.intellij.application.options.ModuleAwareProjectConfigurable;
+import com.intellij.openapi.module.Module;
+import com.intellij.openapi.project.Project;
+import org.jetbrains.annotations.Nls;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import javax.swing.*;
+
+public class ProjectSettingsConfigurable extends ModuleAwareProjectConfigurable {
+
+ public ProjectSettingsConfigurable(@NotNull Project project) {
+ super(project, "show comment displayName", "show comment helpTopic");
+ }
+
+ @NotNull
+ @Override
+ protected ProjectSettingsConfigurable createModuleConfigurable(Module module) {
+ return new ProjectSettingsConfigurable(module.getProject());
+ }
+
+ private ProjectSettingsComponent mySettingsComponent;
+
+ @Nls(capitalization = Nls.Capitalization.Title)
+ @Override
+ public String getDisplayName() {
+ return "Show Comment Project.";
+ }
+
+ @Override
+ public JComponent getPreferredFocusedComponent() {
+ return mySettingsComponent.getPreferredFocusedComponent();
+ }
+
+ @Nullable
+ @Override
+ public JComponent createComponent() {
+ mySettingsComponent = new ProjectSettingsComponent();
+ return mySettingsComponent.getPanel();
+ }
+
+ @Override
+ public boolean isModified() {
+ ProjectSettingsState settings = ProjectSettingsState.getInstance(getProject());
+ boolean modified = mySettingsComponent.getGlobalFilterEffective() != settings.globalFilterEffective;
+ modified |= mySettingsComponent.getProjectFilterEffective() != settings.projectFilterEffective;
+ modified |= !mySettingsComponent.getLineEndExclude().equals(settings.lineEndInclude);
+ modified |= !mySettingsComponent.getLineEndInclude().equals(settings.lineEndExclude);
+ return modified;
+ }
+
+ @Override
+ public void apply() {
+ ProjectSettingsState settings = ProjectSettingsState.getInstance(getProject());
+ settings.lineEndInclude = mySettingsComponent.getLineEndInclude();
+ settings.lineEndExclude = mySettingsComponent.getLineEndExclude();
+ settings.globalFilterEffective = mySettingsComponent.getGlobalFilterEffective();
+ settings.projectFilterEffective = mySettingsComponent.getProjectFilterEffective();
+ settings.lineEndIncludeArray = SplitUtils.split(settings.lineEndInclude);
+ settings.lineEndExcludeArray = SplitUtils.split(settings.lineEndExclude);
+ }
+
+ @Override
+ public void reset() {
+ ProjectSettingsState settings = ProjectSettingsState.getInstance(getProject());
+ mySettingsComponent.setGlobalFilterEffective(settings.globalFilterEffective);
+ mySettingsComponent.setProjectFilterEffective(settings.projectFilterEffective);
+ mySettingsComponent.setLineEndInclude(settings.lineEndInclude);
+ mySettingsComponent.setLineEndExclude(settings.lineEndExclude);
+ }
+
+ @Override
+ public void disposeUIResources() {
+ mySettingsComponent = null;
+ }
+
+}
diff --git a/src/main/java/io/github/linwancen/plugin/comment/settings/ProjectSettingsState.java b/src/main/java/io/github/linwancen/plugin/comment/settings/ProjectSettingsState.java
new file mode 100644
index 0000000..a2c517d
--- /dev/null
+++ b/src/main/java/io/github/linwancen/plugin/comment/settings/ProjectSettingsState.java
@@ -0,0 +1,40 @@
+package io.github.linwancen.plugin.comment.settings;
+
+import com.intellij.openapi.components.PersistentStateComponent;
+import com.intellij.openapi.components.ServiceManager;
+import com.intellij.openapi.components.State;
+import com.intellij.openapi.components.Storage;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.project.ProjectManager;
+import com.intellij.util.xmlb.XmlSerializerUtil;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+@State(
+ name = "io.github.linwancen.plugin.comment.settings.ProjectSettingsState",
+ storages = @Storage("ShowCommentProject.xml")
+)
+public class ProjectSettingsState implements PersistentStateComponent {
+
+ public boolean globalFilterEffective = true;
+ public boolean projectFilterEffective = false;
+ public String lineEndInclude = "";
+ public String lineEndExclude = "";
+ public String[] lineEndIncludeArray = {};
+ public String[] lineEndExcludeArray = {};
+
+ public static ProjectSettingsState getInstance(Project project) {
+ return ServiceManager.getService(project, ProjectSettingsState.class);
+ }
+
+ @Nullable
+ @Override
+ public ProjectSettingsState getState() {
+ return this;
+ }
+
+ @Override
+ public void loadState(@NotNull ProjectSettingsState state) {
+ XmlSerializerUtil.copyBean(state, this);
+ }
+}
diff --git a/src/main/java/io/github/linwancen/plugin/comment/settings/SplitUtils.java b/src/main/java/io/github/linwancen/plugin/comment/settings/SplitUtils.java
new file mode 100644
index 0000000..805deb8
--- /dev/null
+++ b/src/main/java/io/github/linwancen/plugin/comment/settings/SplitUtils.java
@@ -0,0 +1,20 @@
+package io.github.linwancen.plugin.comment.settings;
+
+import org.jetbrains.annotations.NotNull;
+
+import java.util.Arrays;
+import java.util.regex.Pattern;
+
+class SplitUtils {
+
+ private SplitUtils() {}
+
+ private static final Pattern SPLIT_PATTERN = Pattern.compile("[^\\w.*]");
+
+ @NotNull
+ static String[] split(String lineEndExclude) {
+ return Arrays.stream(SPLIT_PATTERN.split(lineEndExclude))
+ .filter(s -> !s.isEmpty())
+ .toArray(String[]::new);
+ }
+}
diff --git a/src/main/java/io/github/linwancen/plugin/comment/utils/SkipUtils.java b/src/main/java/io/github/linwancen/plugin/comment/utils/SkipUtils.java
index 9605d56..b7e35c5 100644
--- a/src/main/java/io/github/linwancen/plugin/comment/utils/SkipUtils.java
+++ b/src/main/java/io/github/linwancen/plugin/comment/utils/SkipUtils.java
@@ -1,16 +1,54 @@
package io.github.linwancen.plugin.comment.utils;
+import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiClass;
+import io.github.linwancen.plugin.comment.settings.AppSettingsState;
+import io.github.linwancen.plugin.comment.settings.ProjectSettingsState;
public class SkipUtils {
private SkipUtils() {}
- public static boolean skip(PsiClass psiClass) {
+ public static boolean skip(PsiClass psiClass, Project project) {
if (psiClass == null) {
return true;
}
String name = psiClass.getQualifiedName();
- return name == null || name.startsWith("java");
+ if (name == null) {
+ return true;
+ }
+ ProjectSettingsState projectSettings = ProjectSettingsState.getInstance(project);
+ AppSettingsState appSettings = AppSettingsState.getInstance();
+ if (projectSettings.globalFilterEffective
+ && skipName(name, appSettings.lineEndIncludeArray, appSettings.lineEndExcludeArray)) {
+ return true;
+ }
+ if (projectSettings.projectFilterEffective) {
+ return skipName(name, projectSettings.lineEndIncludeArray, projectSettings.lineEndExcludeArray);
+ }
+ return false;
+ }
+
+ protected static boolean skipName(String name, String[] includeArray, String[] excludeArray) {
+ if (exclude(name, excludeArray)) {
+ return true;
+ }
+ return !include(name, includeArray);
+ }
+
+ protected static boolean include(String name, String[] lineEndIncludeArray) {
+ if (lineEndIncludeArray.length == 0) {
+ return true;
+ }
+ return exclude(name, lineEndIncludeArray);
+ }
+
+ protected static boolean exclude(String name, String[] projectLineEndExcludeArray) {
+ for (String s : projectLineEndExcludeArray) {
+ if (name.startsWith(s)) {
+ return true;
+ }
+ }
+ return false;
}
}
diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml
index 7946ca3..1e32779 100644
--- a/src/main/resources/META-INF/plugin.xml
+++ b/src/main/resources/META-INF/plugin.xml
@@ -6,13 +6,22 @@
- Show javadoc comments for calling methods at the end of the line.
Show javadoc comments in the Project view Tree structure.
+ Show javadoc comments for calling methods at the end of the line.
+ One of the above features
+ can be turned off in the settings -> Tools -> Show Comment Global.
+ The color of end-of-line comments
+ can be modified in the settings -> Tools -> Show Comment Global.
+ End-of-line comment class prefix filter
+ can be modified in settings -> Tools -> Show Comment Project.
Chinese Note:
- - 在行末显示调用方法的文档注释。
-
- 在结构树显示文档注释。
+
- 在结构树显示 当前节点 的文档注释。
+
- 在行末尾显示 调用方法 的文档注释。
+
- 可以在设置中 关闭 上面其中一个功能。
+
- 可以在设置中 修改 行末注释的颜色。
+
- 可以在设置中 修改 行末注释类前缀过滤。
]]>
@@ -28,8 +37,14 @@
+ displayName="Show Comment Global"/>
+
+
+
diff --git a/src/test/java/io/github/linwancen/plugin/comment/utils/SkipUtilsTest.java b/src/test/java/io/github/linwancen/plugin/comment/utils/SkipUtilsTest.java
new file mode 100644
index 0000000..15d1263
--- /dev/null
+++ b/src/test/java/io/github/linwancen/plugin/comment/utils/SkipUtilsTest.java
@@ -0,0 +1,116 @@
+package io.github.linwancen.plugin.comment.utils;
+
+
+import groovy.json.JsonOutput;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.util.function.BiPredicate;
+
+/**
+ * @see SkipUtils
+ */
+public class SkipUtilsTest {
+
+ public static final boolean o = true;
+ public static final boolean x = false;
+
+ String[] names = {"java", "io.a", "io.b"};
+ String[][] includes = {
+ {},
+ {"java"},
+ {"io"},
+ {"java", "io"},
+ };
+ String[][] excludes = {
+ {},
+ {"java"},
+ {"io.b"},
+ {"java", "io.b"},
+ };
+
+ @Test
+ public void skipName() {
+ // o include, x skip
+ boolean[][][] results = {{
+ // "java" -- name
+ // {}, {"java"}, {"io.b"}, {"java", "io.b"} -- exclude
+ {o, x, o, x}, // {},
+ {o, x, o, x}, // {"java"},
+ {x, x, x, x}, // {"io"},
+ {o, x, o, x}, // {"java", "io"},
+ }, {
+ // "io.a" -- name
+ // {}, {"java"}, {"io.b"}, {"java", "io.b"} -- exclude
+ {o, o, o, o}, // {},
+ {x, x, x, x}, // {"java"},
+ {o, o, o, o}, // {"io"},
+ {o, o, o, o}, // {"java", "io"},
+ }, {
+ // "io.b" -- name
+ // {}, {"java"}, {"io.b"}, {"java", "io.b"} -- exclude
+ {o, o, x, x}, // {},
+ {x, x, x, x}, // {"java"},
+ {o, o, x, x}, // {"io"},
+ {o, o, x, x}, // {"java", "io"},
+ }};
+ for (int i = 0, namesLength = names.length; i < namesLength; i++) {
+ String name = names[i];
+ loopTest(name, results[i]);
+ }
+ }
+
+ private void loopTest(String name, boolean[][] results) {
+ for (int includeIndex = 0, includesLength = includes.length; includeIndex < includesLength; includeIndex++) {
+ String[] include = includes[includeIndex];
+ for (int excludeIndex = 0, excludesLength = excludes.length; excludeIndex < excludesLength; excludeIndex++) {
+ String[] exclude = excludes[excludeIndex];
+ boolean isSkip = SkipUtils.skipName(name, include, exclude);
+ String tip =
+ name + "==" + JsonOutput.toJson(include) + "!=" + JsonOutput.toJson(exclude) + "=>" + isSkip;
+ System.out.println(tip);
+ // o true include, x false skip, so use '!'
+ Assertions.assertEquals(!results[includeIndex][excludeIndex], isSkip, tip);
+ }
+ System.out.println();
+ }
+ }
+
+ @Test
+ public void include() {
+ boolean[][] results = {
+ // {"java", "io.a", "io.b"} -- name
+ {o, o, o}, // {},
+ {o, x, x}, // {"java"},
+ {x, o, o}, // {"io"},
+ {o, o, o}, // {"java", "io"},
+ };
+ loopTest(SkipUtils::include, results);
+ }
+
+ @Test
+ public void exclude() {
+ boolean[][] results = {
+ // {"java", "io.a", "io.b"} ... names
+ {x, x, x}, // {},
+ {o, x, x}, // {"java"},
+ {x, o, o}, // {"io"},
+ {o, o, o}, // {"java", "io"},
+ };
+ loopTest(SkipUtils::exclude, results);
+ }
+
+ private void loopTest(BiPredicate biPredicate, boolean[][] results) {
+ for (int includeIndex = 0, includesLength = includes.length; includeIndex < includesLength; includeIndex++) {
+ String[] include = includes[includeIndex];
+ for (int nameIndex = 0, namesLength = names.length; nameIndex < namesLength; nameIndex++) {
+ String name = names[nameIndex];
+ boolean result = biPredicate.test(name, include);
+ String tip = name + "==" + JsonOutput.toJson(include) + "=>" + result;
+ System.out.println(tip);
+ Assertions.assertEquals(results[includeIndex][nameIndex], result, tip);
+ }
+ System.out.println();
+ }
+ }
+}
\ No newline at end of file