1.2 Add end-of-line comment class prefix filter settings | 添加行末注释类前缀过滤配置
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<AppSettingsState> {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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<ProjectSettingsConfigurable> {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<ProjectSettingsState> {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user