use settingsInfo

This commit is contained in:
林万程
2022-12-09 22:37:41 +08:00
parent cae3095d0e
commit b0f939888d
10 changed files with 55 additions and 55 deletions

View File

@@ -68,12 +68,12 @@ public class JavaLangDoc extends BaseTagLangDoc<PsiDocComment> {
}
@Override
public @Nullable <T extends SettingsInfo> String resolveDocPrint(@NotNull T lineInfo, @NotNull PsiElement resolve) {
@Nullable String resolveDocPrint = super.resolveDocPrint(lineInfo, resolve);
public @Nullable <T extends SettingsInfo> String resolveDocPrint(@NotNull T settingsInfo, @NotNull PsiElement resolve) {
@Nullable String resolveDocPrint = super.resolveDocPrint(settingsInfo, resolve);
if (resolveDocPrint != null) {
return resolveDocPrint;
}
if (lineInfo.appSettings.fromParam && resolve instanceof PsiParameter) {
if (settingsInfo.appSettings.fromParam && resolve instanceof PsiParameter) {
return paramDoc((PsiParameter) resolve);
}
return null;
@@ -105,10 +105,11 @@ public class JavaLangDoc extends BaseTagLangDoc<PsiDocComment> {
@Nullable
@Override
protected PsiDocComment toDocElement(@NotNull PsiElement resolve) {
protected <T extends SettingsInfo> PsiDocComment toDocElement(@NotNull T settingsInfo,
@NotNull PsiElement resolve) {
if (resolve instanceof PsiDocCommentOwner) {
@NotNull PsiDocCommentOwner psiDocCommentOwner = (PsiDocCommentOwner) resolve;
return OwnerToPsiDocSkip.refDoc(psiDocCommentOwner);
return OwnerToPsiDocSkip.refDoc(settingsInfo, psiDocCommentOwner);
}
return null;
}

View File

@@ -24,7 +24,7 @@ public class JavaTree {
@Nullable
public static <T extends SettingsInfo> String treeDoc(@NotNull T settingsInfo, ProjectViewNode<?> node,
@NotNull Project project) {
@Nullable PsiDocComment docComment = nodeDoc(node, project);
@Nullable PsiDocComment docComment = nodeDoc(settingsInfo, node, project);
if (docComment == null) {
return null;
}
@@ -32,7 +32,8 @@ public class JavaTree {
}
@Nullable
static PsiDocComment nodeDoc(ProjectViewNode<?> node, @NotNull Project project) {
static <T extends SettingsInfo> PsiDocComment nodeDoc(@NotNull T settingsInfo, ProjectViewNode<?> node,
@NotNull Project project) {
if (node instanceof PsiFileNode) {
PsiFile psiFile = ((PsiFileNode) node).getValue();
return OwnerToPsiDocUtils.fileDoc(psiFile);
@@ -50,7 +51,7 @@ public class JavaTree {
if (type instanceof PsiClassReferenceType) {
@NotNull PsiClassReferenceType psiClassReferenceType = (PsiClassReferenceType) type;
@NotNull PsiJavaCodeReferenceElement reference = psiClassReferenceType.getReference();
return NewCallRefToPsiDoc.javaCodeDoc(reference);
return NewCallRefToPsiDoc.javaCodeDoc(settingsInfo, reference);
}
}

View File

@@ -35,7 +35,7 @@ public class KotlinLangDoc extends BaseTagLangDoc<KDocSection> {
@Override
@Nullable
protected KDocSection toDocElement(@NotNull PsiElement resolve) {
protected <T extends SettingsInfo> KDocSection toDocElement(@NotNull T settingsInfo, @NotNull PsiElement resolve) {
if (resolve instanceof PsiPackageBase) {
return null;
}

View File

@@ -4,6 +4,8 @@ import com.intellij.psi.PsiDocCommentOwner;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiJavaCodeReferenceElement;
import com.intellij.psi.javadoc.PsiDocComment;
import io.github.linwancen.plugin.show.bean.SettingsInfo;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
@@ -14,7 +16,8 @@ public class NewCallRefToPsiDoc {
private NewCallRefToPsiDoc() {}
@Nullable
public static PsiDocComment javaCodeDoc(@Nullable PsiJavaCodeReferenceElement ref) {
public static <T extends SettingsInfo> PsiDocComment javaCodeDoc(@NotNull T settingsInfo,
@Nullable PsiJavaCodeReferenceElement ref) {
if (ref == null) {
return null;
}
@@ -25,7 +28,7 @@ public class NewCallRefToPsiDoc {
// ignore
}
if (resolve instanceof PsiDocCommentOwner) {
return OwnerToPsiDocSkip.refDoc(((PsiDocCommentOwner) resolve));
return OwnerToPsiDocSkip.refDoc(settingsInfo, ((PsiDocCommentOwner) resolve));
}
return null;
}

View File

@@ -3,9 +3,8 @@ package io.github.linwancen.plugin.show.java.line;
import com.intellij.psi.PsiDocCommentOwner;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.javadoc.PsiDocComment;
import io.github.linwancen.plugin.show.bean.SettingsInfo;
import io.github.linwancen.plugin.show.java.doc.OwnerToPsiDocUtils;
import io.github.linwancen.plugin.show.settings.AppSettingsState;
import io.github.linwancen.plugin.show.settings.ProjectSettingsState;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -16,18 +15,17 @@ public class OwnerToPsiDocSkip {
private OwnerToPsiDocSkip() {}
public static PsiDocComment refDoc(@Nullable PsiDocCommentOwner docOwner) {
public static <T extends SettingsInfo> PsiDocComment refDoc(@NotNull T settingsInfo,
@Nullable PsiDocCommentOwner docOwner) {
if (docOwner == null) {
return null;
}
@NotNull AppSettingsState appSettings = AppSettingsState.getInstance();
@NotNull ProjectSettingsState projectSettings = ProjectSettingsState.getInstance(docOwner.getProject());
if (SkipUtils.skipSign(docOwner, appSettings, projectSettings)) {
if (SkipUtils.skipSign(settingsInfo, docOwner)) {
return null;
}
@Nullable PsiDocComment docComment = docOwner instanceof PsiMethod
? OwnerToPsiDocUtils.methodDoc(((PsiMethod) docOwner))
: OwnerToPsiDocUtils.srcOrByteCodeDoc(docOwner);
return SkipUtils.skipDoc(docComment, appSettings, projectSettings);
return SkipUtils.skipDoc(settingsInfo, docComment);
}
}

View File

@@ -4,9 +4,9 @@ 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.bean.FuncEnum;
import io.github.linwancen.plugin.show.bean.SettingsInfo;
import io.github.linwancen.plugin.show.lang.base.DocSkip;
import io.github.linwancen.plugin.show.settings.AppSettingsState;
import io.github.linwancen.plugin.show.settings.ProjectSettingsState;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -15,19 +15,19 @@ class SkipUtils {
private SkipUtils() {}
static boolean skipSign(PsiElement psiElement, @NotNull AppSettingsState appSettings,
@NotNull ProjectSettingsState projectSettings) {
@Nullable String text = psiName(psiElement, appSettings);
static <T extends SettingsInfo> boolean skipSign(@NotNull T settingsInfo, PsiElement psiElement) {
@Nullable String text = psiName(settingsInfo, psiElement);
if (text == null) {
return true;
}
return DocSkip.skipSign(appSettings, projectSettings, text);
return DocSkip.skipSign(settingsInfo, text);
}
private static @Nullable String psiName(@Nullable PsiElement psiElement, @NotNull AppSettingsState appSettings) {
@Nullable
private static <T extends SettingsInfo> String psiName(@NotNull T settingsInfo, @Nullable PsiElement psiElement) {
if (psiElement instanceof PsiClass) {
@NotNull PsiClass psiClass = (PsiClass) psiElement;
if (appSettings.skipAnnotation && psiClass.isAnnotationType()) {
if (settingsInfo.appSettings.skipAnnotation && psiClass.isAnnotationType()) {
return null;
}
return psiClass.getQualifiedName();
@@ -51,16 +51,15 @@ class SkipUtils {
return null;
}
static PsiDocComment skipDoc(@Nullable PsiDocComment doc, @NotNull AppSettingsState appSettings,
@NotNull ProjectSettingsState projectSettings) {
static <T extends SettingsInfo> PsiDocComment skipDoc(@NotNull T settingsInfo, @Nullable PsiDocComment doc) {
if (doc == null) {
return null;
}
if (appSettings.skipBlank && isBlank(doc)) {
if (settingsInfo.appSettings.skipBlank && isBlank(doc)) {
return null;
}
String text = doc.getText();
boolean skip = DocSkip.skipDoc(appSettings, projectSettings, text);
boolean skip = DocSkip.skipDoc(settingsInfo, text);
return skip ? null : doc;
}

View File

@@ -55,7 +55,7 @@ public class SqlLangDoc extends BaseLangDoc {
}
for (@NotNull DbElement dbElement : relatedDbElements) {
@Nullable String refDoc = dbElement.getComment();
if (refDoc != null && !DocSkip.skipDoc(lineInfo.appSettings, lineInfo.projectSettings, refDoc)) {
if (refDoc != null && !DocSkip.skipDoc(lineInfo, refDoc)) {
return refDoc;
}
}

View File

@@ -119,7 +119,7 @@ public abstract class BaseLangDoc extends EditorLinePainter {
protected String refElementDoc(@NotNull LineInfo lineInfo,
@NotNull PsiElement refElement) {
@Nullable String refDoc = refDoc(lineInfo, refElement);
if (refDoc != null && !DocSkip.skipDoc(lineInfo.appSettings, lineInfo.projectSettings, refDoc)) {
if (refDoc != null && !DocSkip.skipDoc(lineInfo, refDoc)) {
return refDoc;
}
return null;

View File

@@ -8,12 +8,13 @@ import org.jetbrains.annotations.Nullable;
public abstract class BaseTagLangDoc<DocElement> extends BaseLangDoc {
@Override
public @Nullable <T extends SettingsInfo> String resolveDocPrint(@NotNull T lineInfo, @NotNull PsiElement resolve) {
@Nullable DocElement docElement = toDocElement(resolve);
public @Nullable <T extends SettingsInfo> String resolveDocPrint(@NotNull T settingsInfo,
@NotNull PsiElement resolve) {
@Nullable DocElement docElement = toDocElement(settingsInfo, resolve);
if (docElement == null) {
return null;
}
return docElementToStr(lineInfo, docElement);
return docElementToStr(settingsInfo, docElement);
}
@Nullable
@@ -44,7 +45,8 @@ public abstract class BaseTagLangDoc<DocElement> extends BaseLangDoc {
}
@Nullable
protected abstract DocElement toDocElement(@NotNull PsiElement resolve);
protected abstract <T extends SettingsInfo> DocElement toDocElement(@NotNull T settingsInfo,
@NotNull PsiElement resolve);
/**
* cut / * # not filter text

View File

@@ -1,7 +1,6 @@
package io.github.linwancen.plugin.show.lang.base;
import io.github.linwancen.plugin.show.settings.AppSettingsState;
import io.github.linwancen.plugin.show.settings.ProjectSettingsState;
import io.github.linwancen.plugin.show.bean.SettingsInfo;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -11,38 +10,35 @@ public class DocSkip {
private DocSkip() {}
public static boolean skipSign(@NotNull AppSettingsState appSettings,
@NotNull ProjectSettingsState projectSettings, String text) {
return skipText(text,
projectSettings.globalFilterEffective, appSettings.lineInclude, appSettings.lineExclude,
projectSettings.projectFilterEffective, projectSettings.lineInclude, projectSettings.lineExclude);
public static <T extends SettingsInfo> boolean skipSign(@NotNull T settingsInfo, String text) {
return skipText(settingsInfo, text,
settingsInfo.appSettings.lineInclude, settingsInfo.appSettings.lineExclude,
settingsInfo.projectSettings.lineInclude, settingsInfo.projectSettings.lineExclude);
}
private static final Pattern NOT_ASCII_PATTERN = Pattern.compile("[^\u0000-\u007f]");
public static boolean skipDoc(@NotNull AppSettingsState appSettings,
@NotNull ProjectSettingsState projectSettings, @NotNull String text) {
if (appSettings.skipAscii && !NOT_ASCII_PATTERN.matcher(text).find()) {
public static <T extends SettingsInfo> boolean skipDoc(@NotNull T settingsInfo, @NotNull String text) {
if (settingsInfo.appSettings.skipAscii && !NOT_ASCII_PATTERN.matcher(text).find()) {
return true;
}
return skipText(text,
projectSettings.globalFilterEffective, appSettings.docInclude, appSettings.docExclude,
projectSettings.projectFilterEffective, projectSettings.docInclude, projectSettings.docExclude);
return skipText(settingsInfo, text,
settingsInfo.appSettings.docInclude, settingsInfo.appSettings.docExclude,
settingsInfo.projectSettings.docInclude, settingsInfo.projectSettings.docExclude);
}
static boolean skipText(@Nullable String text,
boolean appFilterEffective, @NotNull Pattern appDocInclude, @NotNull Pattern appDocExclude,
boolean projectFilterEffective, @NotNull Pattern projectDocInclude,
@NotNull Pattern projectDocExclude
static <T extends SettingsInfo> boolean skipText(@NotNull T settingsInfo, @Nullable String text,
@NotNull Pattern appDocInclude, @NotNull Pattern appDocExclude,
@NotNull Pattern projectDocInclude, @NotNull Pattern projectDocExclude
) {
if (text == null) {
return true;
}
if (appFilterEffective
if (settingsInfo.projectSettings.globalFilterEffective
&& skipText(text, appDocInclude, appDocExclude)) {
return true;
}
if (projectFilterEffective) {
if (settingsInfo.projectSettings.projectFilterEffective) {
return skipText(text, projectDocInclude, projectDocExclude);
}
return false;