1.17 skip doc text or class/member name by regexp | 根据正则表达式跳过指定注释文本或类成员名字的注释
This commit is contained in:
@@ -12,15 +12,11 @@ import io.github.linwancen.plugin.show.settings.AppSettingsState;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* call LineExt, ~LeftToRight, ~RightToLeft
|
||||
*/
|
||||
public class FileViewToDocStrUtils {
|
||||
|
||||
public static final Pattern NOT_ASCII_PATTERN = Pattern.compile("[^\u0000-\u007f]");
|
||||
|
||||
private FileViewToDocStrUtils() {}
|
||||
|
||||
/**
|
||||
@@ -59,9 +55,6 @@ public class FileViewToDocStrUtils {
|
||||
if (text.endsWith(strDoc)) {
|
||||
return null;
|
||||
}
|
||||
if (setting.skipAscii && !NOT_ASCII_PATTERN.matcher(strDoc).find()) {
|
||||
return null;
|
||||
}
|
||||
return strDoc;
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ class NewCallRefToPsiDoc {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
PsiDocComment methodComment = OwnerToPsiDocSkip.methodDoc(call.resolveMethod());
|
||||
PsiDocComment methodComment = OwnerToPsiDocSkip.refDoc(call.resolveMethod());
|
||||
if (methodComment != null) {
|
||||
return methodComment;
|
||||
}
|
||||
@@ -80,7 +80,7 @@ class NewCallRefToPsiDoc {
|
||||
if (newExp == null) {
|
||||
return null;
|
||||
}
|
||||
PsiDocComment methodComment = OwnerToPsiDocSkip.methodDoc(newExp.resolveMethod());
|
||||
PsiDocComment methodComment = OwnerToPsiDocSkip.refDoc(newExp.resolveMethod());
|
||||
if (methodComment != null) {
|
||||
return methodComment;
|
||||
}
|
||||
@@ -149,7 +149,7 @@ class NewCallRefToPsiDoc {
|
||||
}
|
||||
PsiElement resolve = reference.resolve();
|
||||
if (resolve instanceof PsiMethod) {
|
||||
return OwnerToPsiDocSkip.methodDoc(((PsiMethod) resolve));
|
||||
return OwnerToPsiDocSkip.refDoc(((PsiMethod) resolve));
|
||||
}
|
||||
if (resolve instanceof PsiDocCommentOwner) {
|
||||
return OwnerToPsiDocSkip.refDoc(((PsiDocCommentOwner) resolve));
|
||||
|
||||
@@ -1,43 +1,32 @@
|
||||
package io.github.linwancen.plugin.show.line;
|
||||
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiDocCommentOwner;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.javadoc.PsiDocComment;
|
||||
import io.github.linwancen.plugin.show.doc.OwnerToPsiDocUtils;
|
||||
import io.github.linwancen.plugin.show.settings.AppSettingsState;
|
||||
import io.github.linwancen.plugin.show.settings.ProjectSettingsState;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* call RefToPsiDoc, PsiClassSkip
|
||||
* call OwnerToPsiDocUtils, SkipUtils
|
||||
*/
|
||||
class OwnerToPsiDocSkip {
|
||||
|
||||
private OwnerToPsiDocSkip() {}
|
||||
|
||||
static PsiDocComment methodDoc(@Nullable PsiMethod psiMethod) {
|
||||
if (skip(psiMethod)) {
|
||||
return null;
|
||||
}
|
||||
return OwnerToPsiDocUtils.methodDoc(psiMethod);
|
||||
}
|
||||
|
||||
static PsiDocComment refDoc(@Nullable PsiDocCommentOwner docOwner) {
|
||||
if (skip(docOwner)) {
|
||||
if (docOwner == null) {
|
||||
return null;
|
||||
}
|
||||
if (docOwner instanceof PsiMethod) {
|
||||
return OwnerToPsiDocUtils.methodDoc(((PsiMethod) docOwner));
|
||||
AppSettingsState appSettings = AppSettingsState.getInstance();
|
||||
ProjectSettingsState projectSettings = ProjectSettingsState.getInstance(docOwner.getProject());
|
||||
if (SkipUtils.skipSign(docOwner, appSettings, projectSettings)) {
|
||||
return null;
|
||||
}
|
||||
return OwnerToPsiDocUtils.srcOrByteCodeDoc(docOwner);
|
||||
}
|
||||
|
||||
private static boolean skip(@Nullable PsiDocCommentOwner docOwner) {
|
||||
if (docOwner == null) {
|
||||
return true;
|
||||
}
|
||||
if (docOwner instanceof PsiClass) {
|
||||
return PsiClassSkip.skip((PsiClass) docOwner, docOwner.getProject());
|
||||
}
|
||||
return PsiClassSkip.skip(docOwner.getContainingClass(), docOwner.getProject());
|
||||
PsiDocComment docComment = docOwner instanceof PsiMethod
|
||||
? OwnerToPsiDocUtils.methodDoc(((PsiMethod) docOwner))
|
||||
: OwnerToPsiDocUtils.srcOrByteCodeDoc(docOwner);
|
||||
return SkipUtils.skipDoc(docComment, appSettings, projectSettings);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
package io.github.linwancen.plugin.show.line;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import io.github.linwancen.plugin.show.settings.AppSettingsState;
|
||||
import io.github.linwancen.plugin.show.settings.ProjectSettingsState;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class PsiClassSkip {
|
||||
|
||||
private PsiClassSkip() {}
|
||||
|
||||
static boolean skip(PsiClass psiClass, @NotNull Project project) {
|
||||
if (psiClass == null) {
|
||||
return true;
|
||||
}
|
||||
String name = psiClass.getQualifiedName();
|
||||
if (name == null) {
|
||||
return true;
|
||||
}
|
||||
AppSettingsState appSettings = AppSettingsState.getInstance();
|
||||
if (appSettings.skipAnnotation && psiClass.isAnnotationType()) {
|
||||
return true;
|
||||
}
|
||||
ProjectSettingsState projectSettings = ProjectSettingsState.getInstance(project);
|
||||
if (projectSettings.globalFilterEffective
|
||||
&& skipName(name, appSettings.lineEndIncludeArray, appSettings.lineEndExcludeArray)) {
|
||||
return true;
|
||||
}
|
||||
if (projectSettings.projectFilterEffective) {
|
||||
return skipName(name, projectSettings.lineEndIncludeArray, projectSettings.lineEndExcludeArray);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static boolean skipName(String name, String[] include, String[] exclude) {
|
||||
if (exclude(name, exclude)) {
|
||||
return true;
|
||||
}
|
||||
return !include(name, include);
|
||||
}
|
||||
|
||||
static boolean include(String name, String[] include) {
|
||||
if (include.length == 0) {
|
||||
return true;
|
||||
}
|
||||
return exclude(name, include);
|
||||
}
|
||||
|
||||
static boolean exclude(String name, String[] exclude) {
|
||||
for (String s : exclude) {
|
||||
if (name.startsWith(s)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package io.github.linwancen.plugin.show.line;
|
||||
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiMember;
|
||||
import com.intellij.psi.javadoc.PsiDocComment;
|
||||
import io.github.linwancen.plugin.show.settings.AppSettingsState;
|
||||
import io.github.linwancen.plugin.show.settings.ProjectSettingsState;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
class SkipUtils {
|
||||
|
||||
private SkipUtils() {}
|
||||
|
||||
static boolean skipSign(PsiElement psiElement, AppSettingsState appSettings, ProjectSettingsState projectSettings) {
|
||||
if (psiElement == null) {
|
||||
return true;
|
||||
}
|
||||
String text;
|
||||
if (psiElement instanceof PsiClass) {
|
||||
text = ((PsiClass) psiElement).getQualifiedName();
|
||||
} else if (psiElement instanceof PsiMember) {
|
||||
PsiMember psiMember = (PsiMember) psiElement;
|
||||
text = psiMember.getContainingClass() + "." + psiMember.getName();
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
return skipText(text,
|
||||
projectSettings.globalFilterEffective, appSettings.lineInclude, appSettings.lineExclude,
|
||||
projectSettings.projectFilterEffective, projectSettings.lineInclude, projectSettings.lineExclude);
|
||||
}
|
||||
|
||||
public static final Pattern NOT_ASCII_PATTERN = Pattern.compile("[^\u0000-\u007f]");
|
||||
|
||||
static PsiDocComment skipDoc(PsiDocComment doc, AppSettingsState appSettings, ProjectSettingsState projectSettings) {
|
||||
if (doc == null) {
|
||||
return null;
|
||||
}
|
||||
if (appSettings.skipBlank && isBlank(doc)) {
|
||||
return null;
|
||||
}
|
||||
String text = doc.getText();
|
||||
if (appSettings.skipAscii && !NOT_ASCII_PATTERN.matcher(text).find()) {
|
||||
return null;
|
||||
}
|
||||
boolean skip = skipText(text,
|
||||
projectSettings.globalFilterEffective, appSettings.docInclude, appSettings.docExclude,
|
||||
projectSettings.projectFilterEffective, projectSettings.docInclude, projectSettings.docExclude);
|
||||
return skip ? null : doc;
|
||||
}
|
||||
|
||||
private static boolean isBlank(PsiDocComment doc) {
|
||||
PsiElement[] elements = doc.getDescriptionElements();
|
||||
for (PsiElement element : elements) {
|
||||
String text = element.getText();
|
||||
if (StringUtils.isNotBlank(text)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean skipText(String text,
|
||||
boolean appFilterEffective, Pattern appDocInclude, Pattern appDocExclude,
|
||||
boolean projectFilterEffective, Pattern projectDocInclude, Pattern projectDocExclude
|
||||
) {
|
||||
if (text == null) {
|
||||
return true;
|
||||
}
|
||||
if (appFilterEffective
|
||||
&& skipText(text, appDocInclude, appDocExclude)) {
|
||||
return true;
|
||||
}
|
||||
if (projectFilterEffective) {
|
||||
return skipText(text, projectDocInclude, projectDocExclude);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static boolean skipText(String text, Pattern include, Pattern exclude) {
|
||||
if (exclude(text, exclude)) {
|
||||
return true;
|
||||
}
|
||||
return !include(text, include);
|
||||
}
|
||||
|
||||
static boolean include(String text, Pattern include) {
|
||||
if (include.pattern().length() == 0) {
|
||||
return true;
|
||||
}
|
||||
return include.matcher(text).find();
|
||||
}
|
||||
|
||||
static boolean exclude(String text, Pattern exclude) {
|
||||
if (exclude.pattern().length() == 0) {
|
||||
return false;
|
||||
}
|
||||
return exclude.matcher(text).find();
|
||||
}
|
||||
}
|
||||
@@ -10,18 +10,22 @@ import javax.swing.*;
|
||||
|
||||
public abstract class AbstractSettingsComponent {
|
||||
|
||||
protected final JBTextField lineEndInclude = new JBTextField();
|
||||
protected final JBTextField lineEndExclude = new JBTextField();
|
||||
protected final JBTextField lineInclude = new JBTextField();
|
||||
protected final JBTextField lineExclude = new JBTextField();
|
||||
|
||||
public final JBTextField docInclude = new JBTextField();
|
||||
public final JBTextField docExclude = 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."))
|
||||
.addComponent(new JBLabel("Separated by '|' (Regexp), use '' to include all or exclude none."))
|
||||
.addSeparator()
|
||||
.addLabeledComponent(new JBLabel("line end include className start with: "), lineEndInclude, 1, true)
|
||||
.addLabeledComponent(new JBLabel("line end exclude className start with: "), lineEndExclude, 1, true)
|
||||
.addLabeledComponent(new JBLabel("className include Regexp: "), lineInclude, 1, true)
|
||||
.addLabeledComponent(new JBLabel("className include Regexp: "), lineExclude, 1, true)
|
||||
.addSeparator()
|
||||
.addLabeledComponent(new JBLabel("comment include Regexp: "), docInclude, 1, true)
|
||||
.addLabeledComponent(new JBLabel("comment include Regexp: "), docExclude, 1, true)
|
||||
.getPanel();
|
||||
lineEndFilter.setBorder(IdeBorderFactory.createTitledBorder(
|
||||
"Line End Comment"));
|
||||
@@ -29,20 +33,39 @@ public abstract class AbstractSettingsComponent {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getLineEndInclude() {
|
||||
return lineEndInclude.getText();
|
||||
public String getLineInclude() {
|
||||
return lineInclude.getText();
|
||||
}
|
||||
|
||||
public void setLineEndInclude(@NotNull String newText) {
|
||||
lineEndInclude.setText(newText);
|
||||
public void setLineInclude(@NotNull String newText) {
|
||||
lineInclude.setText(newText);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getLineEndExclude() {
|
||||
return lineEndExclude.getText();
|
||||
public String getLineExclude() {
|
||||
return lineExclude.getText();
|
||||
}
|
||||
|
||||
public void setLineEndExclude(@NotNull String newText) {
|
||||
lineEndExclude.setText(newText);
|
||||
public void setLineExclude(@NotNull String newText) {
|
||||
lineExclude.setText(newText);
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
public String getDocInclude() {
|
||||
return docInclude.getText();
|
||||
}
|
||||
|
||||
public void setDocInclude(@NotNull String newText) {
|
||||
docInclude.setText(newText);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getDocExclude() {
|
||||
return docExclude.getText();
|
||||
}
|
||||
|
||||
public void setDocExclude(@NotNull String newText) {
|
||||
docExclude.setText(newText);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package io.github.linwancen.plugin.show.settings;
|
||||
|
||||
public class AbstractSettingsConfigurable {
|
||||
|
||||
private AbstractSettingsConfigurable() {}
|
||||
|
||||
static boolean isModified(AbstractSettingsState settings, AbstractSettingsComponent component, boolean modified) {
|
||||
modified |= !component.getLineInclude().equals(settings.getLineInclude());
|
||||
modified |= !component.getLineExclude().equals(settings.getLineExclude());
|
||||
modified |= !component.getDocInclude().equals(settings.getDocInclude());
|
||||
modified |= !component.getDocExclude().equals(settings.getDocExclude());
|
||||
return modified;
|
||||
}
|
||||
|
||||
static void apply(AbstractSettingsState settings, AbstractSettingsComponent component) {
|
||||
settings.setLineInclude(component.getLineInclude());
|
||||
settings.setLineExclude(component.getLineExclude());
|
||||
settings.setDocInclude(component.getDocInclude());
|
||||
settings.setDocExclude(component.getDocExclude());
|
||||
}
|
||||
|
||||
static void reset(AbstractSettingsState settings, AbstractSettingsComponent component) {
|
||||
component.setLineInclude(settings.getLineInclude());
|
||||
component.setLineExclude(settings.getLineExclude());
|
||||
component.setDocInclude(settings.getDocInclude());
|
||||
component.setDocExclude(settings.getDocExclude());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package io.github.linwancen.plugin.show.settings;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public abstract class AbstractSettingsState {
|
||||
|
||||
public transient Pattern lineInclude = Pattern.compile("");
|
||||
public transient Pattern lineExclude = Pattern.compile("^java");
|
||||
public transient Pattern docInclude = Pattern.compile("");
|
||||
public transient Pattern docExclude = Pattern.compile("");
|
||||
|
||||
public String getLineInclude() {
|
||||
return lineInclude.pattern();
|
||||
}
|
||||
|
||||
public void setLineInclude(String lineInclude) {
|
||||
this.lineInclude = Pattern.compile(lineInclude);
|
||||
}
|
||||
|
||||
public String getLineExclude() {
|
||||
return lineExclude.pattern();
|
||||
}
|
||||
|
||||
public void setLineExclude(String lineExclude) {
|
||||
this.lineExclude = Pattern.compile(lineExclude);
|
||||
}
|
||||
|
||||
public String getDocInclude() {
|
||||
return docInclude.pattern();
|
||||
}
|
||||
|
||||
public void setDocInclude(String docInclude) {
|
||||
this.docInclude = Pattern.compile(docInclude);
|
||||
}
|
||||
|
||||
public String getDocExclude() {
|
||||
return docExclude.pattern();
|
||||
}
|
||||
|
||||
public void setDocExclude(String docExclude) {
|
||||
this.docExclude = Pattern.compile(docExclude);
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ public class AppSettingsComponent extends AbstractSettingsComponent {
|
||||
private final JBCheckBox inJson = new JBCheckBox("in json ");
|
||||
private final JBCheckBox skipAnnotation = new JBCheckBox("skip @ ");
|
||||
private final JBCheckBox skipAscii = new JBCheckBox("skip English ");
|
||||
private final JBCheckBox skipBlank = new JBCheckBox("skip Blank ");
|
||||
private final ColorPanel lineEndColor = new ColorPanel();
|
||||
private final ColorPanel lineEndJsonColor = new ColorPanel();
|
||||
private final JBCheckBox findElementRightToLeft = new JBCheckBox("Find element right to left");
|
||||
@@ -49,14 +50,14 @@ public class AppSettingsComponent extends AbstractSettingsComponent {
|
||||
@NotNull
|
||||
protected JPanel lineEndFilterPanel() {
|
||||
JPanel text = JPanelFactory.of(
|
||||
new JBLabel("object count: "), lineEndCount,
|
||||
new JBLabel("line count: "), lineEndCount,
|
||||
new JBLabel("text color: "), lineEndColor,
|
||||
new JBLabel("json text color: "), lineEndJsonColor,
|
||||
new JBLabel("prefix: "), lineEndPrefix);
|
||||
FormBuilder formBuilder = FormBuilder.createFormBuilder()
|
||||
.addComponent(JPanelFactory.of(findElementRightToLeft))
|
||||
.addSeparator()
|
||||
.addComponent(JPanelFactory.of(fromCall, fromNew, fromRef, inJson, skipAnnotation, skipAscii), 1)
|
||||
.addComponent(JPanelFactory.of(fromCall, fromNew, fromRef, inJson, skipAnnotation, skipAscii, skipBlank), 1)
|
||||
.addSeparator()
|
||||
.addComponent(text)
|
||||
.addSeparator();
|
||||
@@ -136,6 +137,14 @@ public class AppSettingsComponent extends AbstractSettingsComponent {
|
||||
skipAscii.setSelected(newStatus);
|
||||
}
|
||||
|
||||
public boolean getSkipBlank() {
|
||||
return skipBlank.isSelected();
|
||||
}
|
||||
|
||||
public void setSkipBlank(boolean newStatus) {
|
||||
skipBlank.setSelected(newStatus);
|
||||
}
|
||||
|
||||
public Color getLineEndColor() {
|
||||
return lineEndColor.getSelectedColor();
|
||||
}
|
||||
|
||||
@@ -33,19 +33,24 @@ public class AppSettingsConfigurable implements Configurable {
|
||||
AppSettingsState settings = AppSettingsState.getInstance();
|
||||
boolean modified = mySettingsComponent.getShowTreeComment() != settings.showTreeComment;
|
||||
modified |= mySettingsComponent.getShowLineEndComment() != settings.showLineEndComment;
|
||||
|
||||
modified |= !mySettingsComponent.getLineEndCount().equals(String.valueOf(settings.lineEndCount));
|
||||
modified |= !mySettingsComponent.getLineEndColor().equals(settings.lineEndTextAttr.getForegroundColor());
|
||||
modified |= !mySettingsComponent.getLineEndJsonColor().equals(settings.lineEndJsonTextAttr.getForegroundColor());
|
||||
modified |= !mySettingsComponent.getLineEndPrefix().equals(settings.lineEndPrefix);
|
||||
|
||||
modified |= mySettingsComponent.getFindElementRightToLeft() != settings.findElementRightToLeft;
|
||||
|
||||
modified |= mySettingsComponent.getFromCall() != settings.fromCall;
|
||||
modified |= mySettingsComponent.getFromNew() != settings.fromNew;
|
||||
modified |= mySettingsComponent.getFromRef() != settings.fromRef;
|
||||
modified |= mySettingsComponent.getInJson() != settings.inJson;
|
||||
modified |= mySettingsComponent.getSkipAnnotation() != settings.skipAnnotation;
|
||||
modified |= mySettingsComponent.getSkipAscii() != settings.skipAscii;
|
||||
modified |= !mySettingsComponent.getLineEndColor().equals(settings.lineEndTextAttr.getForegroundColor());
|
||||
modified |= !mySettingsComponent.getLineEndJsonColor().equals(settings.lineEndJsonTextAttr.getForegroundColor());
|
||||
modified |= mySettingsComponent.getFindElementRightToLeft() != settings.findElementRightToLeft;
|
||||
modified |= !mySettingsComponent.getLineEndInclude().equals(settings.lineEndInclude);
|
||||
modified |= !mySettingsComponent.getLineEndExclude().equals(settings.lineEndExclude);
|
||||
modified |= !mySettingsComponent.getLineEndPrefix().equals(settings.lineEndPrefix);
|
||||
modified |= !mySettingsComponent.getLineEndCount().equals(String.valueOf(settings.lineEndCount));
|
||||
modified |= mySettingsComponent.getSkipBlank() != settings.skipBlank;
|
||||
|
||||
modified = AbstractSettingsConfigurable.isModified(settings, mySettingsComponent, modified);
|
||||
|
||||
return modified;
|
||||
}
|
||||
|
||||
@@ -54,25 +59,27 @@ public class AppSettingsConfigurable implements Configurable {
|
||||
AppSettingsState settings = AppSettingsState.getInstance();
|
||||
settings.showTreeComment = mySettingsComponent.getShowTreeComment();
|
||||
settings.showLineEndComment = mySettingsComponent.getShowLineEndComment();
|
||||
|
||||
try {
|
||||
settings.lineEndCount = Integer.parseInt(mySettingsComponent.getLineEndCount());
|
||||
} catch (NumberFormatException e) {
|
||||
mySettingsComponent.setLineEndCount(String.valueOf(settings.lineEndCount));
|
||||
}
|
||||
settings.lineEndTextAttr.setForegroundColor(mySettingsComponent.getLineEndColor());
|
||||
settings.lineEndJsonTextAttr.setForegroundColor(mySettingsComponent.getLineEndJsonColor());
|
||||
settings.lineEndPrefix = mySettingsComponent.getLineEndPrefix();
|
||||
|
||||
settings.findElementRightToLeft = mySettingsComponent.getFindElementRightToLeft();
|
||||
|
||||
settings.fromCall = mySettingsComponent.getFromCall();
|
||||
settings.fromNew = mySettingsComponent.getFromNew();
|
||||
settings.fromRef = mySettingsComponent.getFromRef();
|
||||
settings.inJson = mySettingsComponent.getInJson();
|
||||
settings.skipAnnotation = mySettingsComponent.getSkipAnnotation();
|
||||
settings.skipAscii = mySettingsComponent.getSkipAscii();
|
||||
settings.lineEndTextAttr.setForegroundColor(mySettingsComponent.getLineEndColor());
|
||||
settings.lineEndJsonTextAttr.setForegroundColor(mySettingsComponent.getLineEndJsonColor());
|
||||
settings.findElementRightToLeft = mySettingsComponent.getFindElementRightToLeft();
|
||||
settings.lineEndInclude = mySettingsComponent.getLineEndInclude();
|
||||
settings.lineEndExclude = mySettingsComponent.getLineEndExclude();
|
||||
settings.lineEndIncludeArray = SplitUtils.split(settings.lineEndInclude);
|
||||
settings.lineEndExcludeArray = SplitUtils.split(settings.lineEndExclude);
|
||||
settings.lineEndPrefix = mySettingsComponent.getLineEndPrefix();
|
||||
try {
|
||||
settings.lineEndCount = Integer.parseInt(mySettingsComponent.getLineEndCount());
|
||||
} catch (NumberFormatException e) {
|
||||
mySettingsComponent.setLineEndCount(String.valueOf(settings.lineEndCount));
|
||||
}
|
||||
settings.skipBlank = mySettingsComponent.getSkipBlank();
|
||||
|
||||
AbstractSettingsConfigurable.apply(settings, mySettingsComponent);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -80,19 +87,23 @@ public class AppSettingsConfigurable implements Configurable {
|
||||
AppSettingsState settings = AppSettingsState.getInstance();
|
||||
mySettingsComponent.setShowTreeComment(settings.showTreeComment);
|
||||
mySettingsComponent.setShowLineEndComment(settings.showLineEndComment);
|
||||
|
||||
mySettingsComponent.setLineEndCount(String.valueOf(settings.lineEndCount));
|
||||
mySettingsComponent.setLineEndColor(settings.lineEndTextAttr.getForegroundColor());
|
||||
mySettingsComponent.setLineEndJsonColor(settings.lineEndJsonTextAttr.getForegroundColor());
|
||||
mySettingsComponent.setLineEndPrefix(settings.lineEndPrefix);
|
||||
|
||||
mySettingsComponent.setFindElementRightToLeft(settings.findElementRightToLeft);
|
||||
|
||||
mySettingsComponent.setFromCall(settings.fromCall);
|
||||
mySettingsComponent.setFromNew(settings.fromNew);
|
||||
mySettingsComponent.setFromRef(settings.fromRef);
|
||||
mySettingsComponent.setInJson(settings.inJson);
|
||||
mySettingsComponent.setSkipAnnotation(settings.skipAnnotation);
|
||||
mySettingsComponent.setSkipAscii(settings.skipAscii);
|
||||
mySettingsComponent.setLineEndColor(settings.lineEndTextAttr.getForegroundColor());
|
||||
mySettingsComponent.setLineEndJsonColor(settings.lineEndJsonTextAttr.getForegroundColor());
|
||||
mySettingsComponent.setFindElementRightToLeft(settings.findElementRightToLeft);
|
||||
mySettingsComponent.setLineEndInclude(settings.lineEndInclude);
|
||||
mySettingsComponent.setLineEndExclude(settings.lineEndExclude);
|
||||
mySettingsComponent.setLineEndPrefix(settings.lineEndPrefix);
|
||||
mySettingsComponent.setLineEndCount(String.valueOf(settings.lineEndCount));
|
||||
mySettingsComponent.setSkipBlank(settings.skipBlank);
|
||||
|
||||
AbstractSettingsConfigurable.reset(settings, mySettingsComponent);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,7 +18,7 @@ import java.math.BigInteger;
|
||||
name = "io.github.linwancen.plugin.show.settings.AppSettingsState",
|
||||
storages = @Storage("ShowCommentGlobal.xml")
|
||||
)
|
||||
public class AppSettingsState implements PersistentStateComponent<AppSettingsState> {
|
||||
public class AppSettingsState extends AbstractSettingsState implements PersistentStateComponent<AppSettingsState> {
|
||||
|
||||
public boolean showTreeComment = true;
|
||||
public boolean showLineEndComment = true;
|
||||
@@ -39,11 +39,7 @@ public class AppSettingsState implements PersistentStateComponent<AppSettingsSta
|
||||
public boolean inJson = true;
|
||||
public boolean skipAnnotation = true;
|
||||
public boolean skipAscii = false;
|
||||
|
||||
public String lineEndInclude = "";
|
||||
public String lineEndExclude = "java";
|
||||
public String[] lineEndIncludeArray = {};
|
||||
public String[] lineEndExcludeArray = {"java"};
|
||||
public boolean skipBlank = true;
|
||||
|
||||
public static AppSettingsState getInstance() {
|
||||
AppSettingsState service = ApplicationManager.getApplication().getService(AppSettingsState.class);
|
||||
|
||||
@@ -33,7 +33,7 @@ public class ProjectSettingsComponent extends AbstractSettingsComponent {
|
||||
}
|
||||
|
||||
public JComponent getPreferredFocusedComponent() {
|
||||
return lineEndInclude;
|
||||
return lineInclude;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -46,20 +46,16 @@ public class ProjectSettingsConfigurable extends ModuleAwareProjectConfigurable<
|
||||
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);
|
||||
modified = AbstractSettingsConfigurable.isModified(settings, mySettingsComponent, modified);
|
||||
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);
|
||||
AbstractSettingsConfigurable.apply(settings, mySettingsComponent);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -67,8 +63,7 @@ public class ProjectSettingsConfigurable extends ModuleAwareProjectConfigurable<
|
||||
ProjectSettingsState settings = ProjectSettingsState.getInstance(getProject());
|
||||
mySettingsComponent.setGlobalFilterEffective(settings.globalFilterEffective);
|
||||
mySettingsComponent.setProjectFilterEffective(settings.projectFilterEffective);
|
||||
mySettingsComponent.setLineEndInclude(settings.lineEndInclude);
|
||||
mySettingsComponent.setLineEndExclude(settings.lineEndExclude);
|
||||
AbstractSettingsConfigurable.reset(settings, mySettingsComponent);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -12,16 +12,11 @@ import org.jetbrains.annotations.Nullable;
|
||||
name = "io.github.linwancen.plugin.show.settings.ProjectSettingsState",
|
||||
storages = @Storage("ShowCommentProject.xml")
|
||||
)
|
||||
public class ProjectSettingsState implements PersistentStateComponent<ProjectSettingsState> {
|
||||
public class ProjectSettingsState extends AbstractSettingsState 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(@NotNull Project project) {
|
||||
ProjectSettingsState service = project.getService(ProjectSettingsState.class);
|
||||
if (service == null) {
|
||||
|
||||
@@ -4,12 +4,12 @@
|
||||
77 不能被细分项
|
||||
88 条件名
|
||||
|
||||
9\( ( 数字
|
||||
A\( ( 字母
|
||||
X\( ( 字母数字
|
||||
V\( ( 隐式小数
|
||||
S\( ( 符号
|
||||
P\( ( 假定小数
|
||||
9\( ( 数字
|
||||
A\( ( 字母
|
||||
X\( ( 字母数字
|
||||
V\( ( 隐式小数
|
||||
S\( ( 符号
|
||||
P\( ( 假定小数
|
||||
|
||||
数据
|
||||
VALUE =
|
||||
|
@@ -6,9 +6,10 @@ import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.function.BiPredicate;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @see PsiClassSkip
|
||||
* @see SkipUtils
|
||||
*/
|
||||
class PsiClassSkipTest {
|
||||
|
||||
@@ -16,17 +17,17 @@ class PsiClassSkipTest {
|
||||
public static final boolean x = false;
|
||||
|
||||
String[] names = {"java", "io.a", "io.b"};
|
||||
String[][] includes = {
|
||||
{},
|
||||
{"java"},
|
||||
{"io"},
|
||||
{"java", "io"},
|
||||
Pattern[] includes = {
|
||||
Pattern.compile(""),
|
||||
Pattern.compile("java"),
|
||||
Pattern.compile("io"),
|
||||
Pattern.compile("java|io"),
|
||||
};
|
||||
String[][] excludes = {
|
||||
{},
|
||||
{"java"},
|
||||
{"io.b"},
|
||||
{"java", "io.b"},
|
||||
Pattern[] excludes = {
|
||||
Pattern.compile(""),
|
||||
Pattern.compile("java"),
|
||||
Pattern.compile("io\\.b"),
|
||||
Pattern.compile("java|io\\.b"),
|
||||
};
|
||||
|
||||
@Test
|
||||
@@ -62,10 +63,10 @@ class PsiClassSkipTest {
|
||||
|
||||
private void loopTest(String name, boolean[][] results) {
|
||||
for (int includeIndex = 0, includesLength = includes.length; includeIndex < includesLength; includeIndex++) {
|
||||
String[] include = includes[includeIndex];
|
||||
Pattern include = includes[includeIndex];
|
||||
for (int excludeIndex = 0, excludesLength = excludes.length; excludeIndex < excludesLength; excludeIndex++) {
|
||||
String[] exclude = excludes[excludeIndex];
|
||||
boolean isSkip = PsiClassSkip.skipName(name, include, exclude);
|
||||
Pattern exclude = excludes[excludeIndex];
|
||||
boolean isSkip = SkipUtils.skipText(name, include, exclude);
|
||||
String tip =
|
||||
name + "==" + JsonOutput.toJson(include) + "!=" + JsonOutput.toJson(exclude) + "=>" + isSkip;
|
||||
System.out.println(tip);
|
||||
@@ -85,7 +86,7 @@ class PsiClassSkipTest {
|
||||
{x, o, o}, // {"io"},
|
||||
{o, o, o}, // {"java", "io"},
|
||||
};
|
||||
loopTest(PsiClassSkip::include, results);
|
||||
loopTest(SkipUtils::include, results);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -97,12 +98,12 @@ class PsiClassSkipTest {
|
||||
{x, o, o}, // {"io"},
|
||||
{o, o, o}, // {"java", "io"},
|
||||
};
|
||||
loopTest(PsiClassSkip::exclude, results);
|
||||
loopTest(SkipUtils::exclude, results);
|
||||
}
|
||||
|
||||
private void loopTest(BiPredicate<String, String[]> biPredicate, boolean[][] results) {
|
||||
private void loopTest(BiPredicate<String, Pattern> biPredicate, boolean[][] results) {
|
||||
for (int includeIndex = 0, includesLength = includes.length; includeIndex < includesLength; includeIndex++) {
|
||||
String[] include = includes[includeIndex];
|
||||
Pattern include = includes[includeIndex];
|
||||
for (int nameIndex = 0, namesLength = names.length; nameIndex < namesLength; nameIndex++) {
|
||||
String name = names[nameIndex];
|
||||
boolean result = biPredicate.test(name, include);
|
||||
|
||||
Reference in New Issue
Block a user