1.14 skip Annotation, skip only English (ASCII) | 忽略注解与忽略纯英文
This commit is contained in:
@@ -58,7 +58,7 @@ public class LineEnd extends EditorLinePainter {
|
||||
|
||||
@Nullable
|
||||
private static String doc(@NotNull Document document, int lineNumber,
|
||||
@Nullable Project project,
|
||||
@NotNull Project project,
|
||||
@Nullable VirtualFile file,
|
||||
@Nullable FileViewProvider viewProvider) {
|
||||
// lineNumber start 0, as 1 <= 1 should return
|
||||
|
||||
@@ -7,6 +7,8 @@ import com.intellij.psi.javadoc.PsiInlineDocTag;
|
||||
import io.github.linwancen.plugin.show.settings.AppSettingsState;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class PsiDocToStrDoc {
|
||||
|
||||
private PsiDocToStrDoc() {}
|
||||
@@ -24,10 +26,9 @@ public class PsiDocToStrDoc {
|
||||
if (appendElementText(sb, element)) {
|
||||
lineCount++;
|
||||
}
|
||||
if (appSettings.lineEndCount > 0
|
||||
&& lineCount >= appSettings.lineEndCount
|
||||
|| appSettings.lineEndLen > 0
|
||||
&& sb.length() >= appSettings.lineEndLen) {
|
||||
boolean countOver = appSettings.lineEndCount > 0 && lineCount >= appSettings.lineEndCount;
|
||||
boolean lenOver = appSettings.lineEndLen > 0 && sb.length() >= appSettings.lineEndLen;
|
||||
if (countOver || lenOver) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -41,16 +42,24 @@ public class PsiDocToStrDoc {
|
||||
private static boolean appendElementText(StringBuilder sb, PsiElement element) {
|
||||
if (element instanceof PsiDocToken) {
|
||||
PsiDocToken psiDocToken = (PsiDocToken) element;
|
||||
sb.append(psiDocToken.getText().trim().replace("<br>", "")).append(" ");
|
||||
sb.append(deleteHtml(psiDocToken.getText()));
|
||||
sb.append(" ");
|
||||
return true;
|
||||
}
|
||||
if (element instanceof PsiInlineDocTag) {
|
||||
PsiInlineDocTag psiInlineDocTag = (PsiInlineDocTag) element;
|
||||
PsiElement[] children = psiInlineDocTag.getChildren();
|
||||
if (children.length > 2) {
|
||||
sb.append(children[2].getText().trim().replace("<br>", "")).append(" ");
|
||||
sb.append(deleteHtml(children[2].getText()));
|
||||
sb.append(" ");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static final Pattern HTML_PATTERN = Pattern.compile("<[^>]++>");
|
||||
|
||||
private static String deleteHtml(String s) {
|
||||
return HTML_PATTERN.matcher(s.trim()).replaceAll("");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,10 +12,14 @@ 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() {}
|
||||
|
||||
@@ -37,10 +41,15 @@ public class FileViewToDocStrUtils {
|
||||
if (viewProvider == null) {
|
||||
return null;
|
||||
}
|
||||
PsiDocComment docComment = AppSettingsState.getInstance().findElementRightToLeft
|
||||
AppSettingsState setting = AppSettingsState.getInstance();
|
||||
PsiDocComment docComment = setting.findElementRightToLeft
|
||||
? FileViewToPsiDocRightToLeft.rightDoc(viewProvider, startOffset, endOffset)
|
||||
: FileViewToPsiDocLeftToRight.leftDoc(viewProvider, document, startOffset, endOffset);
|
||||
return PsiDocToStrDoc.text(docComment);
|
||||
String strDoc = PsiDocToStrDoc.text(docComment);
|
||||
if (setting.skipAscii && strDoc != null && !NOT_ASCII_PATTERN.matcher(strDoc).find()) {
|
||||
return null;
|
||||
}
|
||||
return strDoc;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -18,8 +18,11 @@ class PsiClassSkip {
|
||||
if (name == null) {
|
||||
return true;
|
||||
}
|
||||
ProjectSettingsState projectSettings = ProjectSettingsState.getInstance(project);
|
||||
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;
|
||||
@@ -30,22 +33,22 @@ class PsiClassSkip {
|
||||
return false;
|
||||
}
|
||||
|
||||
static boolean skipName(String name, String[] includeArray, String[] excludeArray) {
|
||||
if (exclude(name, excludeArray)) {
|
||||
static boolean skipName(String name, String[] include, String[] exclude) {
|
||||
if (exclude(name, exclude)) {
|
||||
return true;
|
||||
}
|
||||
return !include(name, includeArray);
|
||||
return !include(name, include);
|
||||
}
|
||||
|
||||
static boolean include(String name, String[] lineEndIncludeArray) {
|
||||
if (lineEndIncludeArray.length == 0) {
|
||||
static boolean include(String name, String[] include) {
|
||||
if (include.length == 0) {
|
||||
return true;
|
||||
}
|
||||
return exclude(name, lineEndIncludeArray);
|
||||
return exclude(name, include);
|
||||
}
|
||||
|
||||
static boolean exclude(String name, String[] projectLineEndExcludeArray) {
|
||||
for (String s : projectLineEndExcludeArray) {
|
||||
static boolean exclude(String name, String[] exclude) {
|
||||
for (String s : exclude) {
|
||||
if (name.startsWith(s)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -20,8 +20,8 @@ public abstract class AbstractSettingsComponent {
|
||||
.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)
|
||||
.addLabeledComponent(new JBLabel("line end include className start with: "), lineEndInclude, 1, true)
|
||||
.addLabeledComponent(new JBLabel("line end exclude className start with: "), lineEndExclude, 1, true)
|
||||
.getPanel();
|
||||
lineEndFilter.setBorder(IdeBorderFactory.createTitledBorder(
|
||||
"Line End Comment"));
|
||||
|
||||
@@ -20,6 +20,8 @@ public class AppSettingsComponent extends AbstractSettingsComponent {
|
||||
private final JBCheckBox fromNew = new JBCheckBox("new ");
|
||||
private final JBCheckBox fromRef = new JBCheckBox("ref ");
|
||||
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 ColorPanel lineEndColor = new ColorPanel();
|
||||
private final ColorPanel lineEndJsonColor = new ColorPanel();
|
||||
private final JBCheckBox findElementRightToLeft = new JBCheckBox("Find element right to left");
|
||||
@@ -54,7 +56,7 @@ public class AppSettingsComponent extends AbstractSettingsComponent {
|
||||
FormBuilder formBuilder = FormBuilder.createFormBuilder()
|
||||
.addComponent(JPanelFactory.of(findElementRightToLeft))
|
||||
.addSeparator()
|
||||
.addComponent(JPanelFactory.of(fromCall, fromNew, fromRef, inJson), 1)
|
||||
.addComponent(JPanelFactory.of(fromCall, fromNew, fromRef, inJson, skipAnnotation, skipAscii), 1)
|
||||
.addSeparator()
|
||||
.addComponent(text)
|
||||
.addSeparator();
|
||||
@@ -118,6 +120,22 @@ public class AppSettingsComponent extends AbstractSettingsComponent {
|
||||
inJson.setSelected(newStatus);
|
||||
}
|
||||
|
||||
public boolean getSkipAnnotation() {
|
||||
return skipAnnotation.isSelected();
|
||||
}
|
||||
|
||||
public void setSkipAnnotation(boolean newStatus) {
|
||||
skipAnnotation.setSelected(newStatus);
|
||||
}
|
||||
|
||||
public boolean getSkipAscii() {
|
||||
return skipAscii.isSelected();
|
||||
}
|
||||
|
||||
public void setSkipAscii(boolean newStatus) {
|
||||
skipAscii.setSelected(newStatus);
|
||||
}
|
||||
|
||||
public Color getLineEndColor() {
|
||||
return lineEndColor.getSelectedColor();
|
||||
}
|
||||
|
||||
@@ -37,6 +37,8 @@ public class AppSettingsConfigurable implements Configurable {
|
||||
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;
|
||||
@@ -56,6 +58,8 @@ public class AppSettingsConfigurable implements Configurable {
|
||||
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();
|
||||
@@ -80,6 +84,8 @@ public class AppSettingsConfigurable implements Configurable {
|
||||
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);
|
||||
|
||||
@@ -37,11 +37,13 @@ public class AppSettingsState implements PersistentStateComponent<AppSettingsSta
|
||||
public boolean fromNew = true;
|
||||
public boolean fromRef = true;
|
||||
public boolean inJson = true;
|
||||
public boolean skipAnnotation = true;
|
||||
public boolean skipAscii = false;
|
||||
|
||||
public String lineEndInclude = "";
|
||||
public String lineEndExclude = "java.";
|
||||
public String lineEndExclude = "java";
|
||||
public String[] lineEndIncludeArray = {};
|
||||
public String[] lineEndExcludeArray = {"java."};
|
||||
public String[] lineEndExcludeArray = {"java"};
|
||||
|
||||
public static AppSettingsState getInstance() {
|
||||
AppSettingsState service = ApplicationManager.getApplication().getService(AppSettingsState.class);
|
||||
|
||||
@@ -16,6 +16,7 @@ public class ProjectSettingsState implements PersistentStateComponent<ProjectSet
|
||||
|
||||
public boolean globalFilterEffective = true;
|
||||
public boolean projectFilterEffective = false;
|
||||
|
||||
public String lineEndInclude = "";
|
||||
public String lineEndExclude = "";
|
||||
public String[] lineEndIncludeArray = {};
|
||||
|
||||
Reference in New Issue
Block a user