1.5 Support find next when not comment | 支持没有注释时查找下一个对象

This commit is contained in:
林万程
2022-02-26 03:10:43 +08:00
parent 35e2548967
commit 89a0c1cd60
32 changed files with 495 additions and 252 deletions

View File

@@ -1,35 +0,0 @@
package io.github.linwancen.plugin.comment.utils;
import com.intellij.psi.*;
import com.intellij.psi.javadoc.PsiDocComment;
import org.jetbrains.annotations.Nullable;
public class CommentFactory {
private CommentFactory() {}
public static PsiDocComment fromSrcOrByteCode(PsiDocCommentOwner psiElement) {
PsiElement navElement = psiElement.getNavigationElement();
if (navElement instanceof PsiDocCommentOwner) {
psiElement = (PsiDocCommentOwner) navElement;
}
return psiElement.getDocComment();
}
@Nullable
public static PsiDocComment from(PsiFile psiFile) {
if (!(psiFile instanceof PsiJavaFile)) {
return null;
}
PsiJavaFile psiJavaFile = (PsiJavaFile) psiFile;
if (PsiPackage.PACKAGE_INFO_FILE.equals(psiFile.getName())) {
return PsiPackageCommentFactory.fromPackageInfoFile(psiFile);
}
PsiClass[] classes = psiJavaFile.getClasses();
if (classes.length == 0) {
return null;
}
PsiClass psiClass = classes[0];
return fromSrcOrByteCode(psiClass);
}
}

View File

@@ -1,81 +0,0 @@
package io.github.linwancen.plugin.comment.utils;
import com.intellij.psi.*;
import com.intellij.psi.util.PsiTreeUtil;
import org.jetbrains.annotations.Nullable;
public class ResolveElementUtils {
private ResolveElementUtils() {}
@Nullable
public static PsiElement resolveElementOf(PsiElement element, PsiElement psiIdentifier,
int startOffset, int endOffset) {
PsiElement newPsiElement = resolveElementForExecutable(element, startOffset, endOffset);
if (newPsiElement != null) {
return newPsiElement;
}
PsiReference psiReference = parentPsiReference(psiIdentifier, endOffset);
if (psiReference != null) {
return psiReference.resolve();
}
return null;
}
@Nullable
private static PsiElement resolveElementForExecutable(PsiElement element, int startOffset, int endOffset) {
if (element == null) {
return null;
}
// method call
PsiMethodCallExpression call =
PsiTreeUtil.getParentOfType(element, PsiMethodCallExpression.class, false, startOffset);
if (call != null) {
// skip double comment when method call in new line:
// someObject // someMethodComment
// .someMethod(); // someMethodComment
if ((call.getNode().getStartOffset() + call.getNode().getTextLength()) > endOffset) {
return null;
}
try {
return call.resolveMethod();
} catch (Exception e) {
return null;
}
}
// new and Class should same line
PsiNewExpression newExp = PsiTreeUtil.getParentOfType(element, PsiNewExpression.class, false, startOffset);
if (newExp != null) {
PsiMethod psiMethod = newExp.resolveMethod();
if (psiMethod != null) {
return psiMethod;
}
PsiJavaCodeReferenceElement classReference = newExp.getClassReference();
if (classReference != null) {
return classReference.resolve();
}
}
return null;
}
/**
* ::/class/field
*/
@Nullable
private static PsiReference parentPsiReference(PsiElement element, int endOffset) {
if (element == null) {
return null;
}
PsiElement parent;
while ((parent = element.getParent()) instanceof PsiReference) {
if (parent.getTextRange().getEndOffset() > endOffset) {
break;
}
element = parent;
}
if (element instanceof PsiReference) {
return (PsiReference) element;
}
return null;
}
}

View File

@@ -1,4 +1,4 @@
package io.github.linwancen.plugin.comment;
package io.github.linwancen.plugin.show;
import com.intellij.lang.java.JavaLanguage;
import com.intellij.openapi.editor.Document;
@@ -7,10 +7,13 @@ import com.intellij.openapi.editor.LineExtensionInfo;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
import com.intellij.psi.FileViewProvider;
import com.intellij.psi.PsiManager;
import com.intellij.psi.javadoc.PsiDocComment;
import io.github.linwancen.plugin.comment.settings.AppSettingsState;
import io.github.linwancen.plugin.comment.utils.*;
import io.github.linwancen.plugin.show.doc.DocTextUtils;
import io.github.linwancen.plugin.show.line.LineDocLeftToRightUtils;
import io.github.linwancen.plugin.show.line.LineDocRightToLeftUtils;
import io.github.linwancen.plugin.show.settings.AppSettingsState;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -30,9 +33,8 @@ public class LineEnd extends EditorLinePainter {
return null;
}
FileViewProvider viewProvider = PsiManager.getInstance(project).findViewProvider(file);
PsiElement psiElement = resolveElementFrom(viewProvider, lineNumber);
PsiDocComment docComment = psiDocCommentFrom(psiElement);
String comment = PsiDocCommentUtils.getCommentText(docComment);
PsiDocComment docComment = docOwnerFrom(viewProvider, lineNumber);
String comment = DocTextUtils.text(docComment);
if (comment == null) {
return null;
}
@@ -40,7 +42,7 @@ public class LineEnd extends EditorLinePainter {
return Collections.singletonList(info);
}
private static @Nullable PsiElement resolveElementFrom(FileViewProvider viewProvider, int lineNumber) {
private static @Nullable PsiDocComment docOwnerFrom(FileViewProvider viewProvider, int lineNumber) {
if (viewProvider == null || !viewProvider.hasLanguage(JavaLanguage.INSTANCE)) {
return null;
}
@@ -57,37 +59,8 @@ public class LineEnd extends EditorLinePainter {
return null;
}
if (AppSettingsState.getInstance().findElementRightToLeft) {
return ResolveElementRightToLeftUtils.resolveElement(viewProvider, startOffset, endOffset);
return LineDocRightToLeftUtils.rightDoc(viewProvider, startOffset, endOffset);
}
return ResolveElementLeftToRightUtils.resolveElement(viewProvider, document, startOffset, endOffset);
}
@Nullable
private PsiDocComment psiDocCommentFrom(PsiElement psiElement) {
if (psiElement == null) {
return null;
}
if (psiElement instanceof PsiClass) {
PsiClass psiClass = (PsiClass) psiElement;
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(), psiMethod.getProject())) {
return null;
}
return PsiMethodCommentFactory.from(psiMethod);
}
if (psiElement instanceof PsiField) {
PsiField psiField = (PsiField) psiElement;
if (SkipUtils.skip(psiField.getContainingClass(), psiField.getProject())) {
return null;
}
return CommentFactory.fromSrcOrByteCode(psiField);
}
return null;
return LineDocLeftToRightUtils.leftDoc(viewProvider, document, startOffset, endOffset);
}
}

View File

@@ -1,4 +1,4 @@
package io.github.linwancen.plugin.comment;
package io.github.linwancen.plugin.show;
import com.intellij.ide.projectView.PresentationData;
import com.intellij.ide.projectView.ProjectViewNode;
@@ -13,11 +13,9 @@ import com.intellij.psi.*;
import com.intellij.psi.javadoc.PsiDocComment;
import com.intellij.ui.ColoredTreeCellRenderer;
import com.intellij.ui.SimpleTextAttributes;
import io.github.linwancen.plugin.comment.settings.AppSettingsState;
import io.github.linwancen.plugin.comment.utils.CommentFactory;
import io.github.linwancen.plugin.comment.utils.PsiDocCommentUtils;
import io.github.linwancen.plugin.comment.utils.PsiMethodCommentFactory;
import io.github.linwancen.plugin.comment.utils.PsiPackageCommentFactory;
import io.github.linwancen.plugin.show.doc.DocUtils;
import io.github.linwancen.plugin.show.doc.DocTextUtils;
import io.github.linwancen.plugin.show.settings.AppSettingsState;
import org.jetbrains.annotations.Nullable;
import java.util.List;
@@ -42,7 +40,7 @@ public class Tree implements ProjectViewNodeDecorator {
return;
}
String commentText = PsiDocCommentUtils.getCommentText(docComment);
String commentText = DocTextUtils.text(docComment);
if (commentText == null) {
return;
}
@@ -57,33 +55,33 @@ public class Tree implements ProjectViewNodeDecorator {
private PsiDocComment psiDocCommentOf(ProjectViewNode<?> node, Project project) {
if (node instanceof PsiFileNode) {
PsiFile psiFile = ((PsiFileNode) node).getValue();
return CommentFactory.from(psiFile);
return DocUtils.fileDoc(psiFile);
}
if (node instanceof PsiDirectoryNode) {
PsiDirectory psiDirectory = ((PsiDirectoryNode) node).getValue();
return PsiPackageCommentFactory.from(psiDirectory);
return DocUtils.dirDoc(psiDirectory);
}
if (node instanceof PsiMethodNode) {
// On Show Members
PsiMethod psiMethod = ((PsiMethodNode) node).getValue();
return PsiMethodCommentFactory.from(psiMethod);
return DocUtils.methodDoc(psiMethod);
}
if (node instanceof PsiFieldNode) {
// On Show Members
PsiField psiField = ((PsiFieldNode) node).getValue();
return CommentFactory.fromSrcOrByteCode(psiField);
return DocUtils.srcOrByteCodeDoc(psiField);
}
if (node instanceof ClassTreeNode) {
// On Packages View, Project Files View, Show Members
PsiClass psiClass = ((ClassTreeNode) node).getValue();
return CommentFactory.fromSrcOrByteCode(psiClass);
return DocUtils.srcOrByteCodeDoc(psiClass);
}
if (node instanceof PackageElementNode) {
// On Packages View
PsiPackage psiPackage = ((PackageElementNode) node).getValue().getPackage();
return PsiPackageCommentFactory.from(psiPackage);
return DocUtils.packageDoc(psiPackage);
}
// On Packages View, Project Files View
@@ -95,7 +93,7 @@ public class Tree implements ProjectViewNodeDecorator {
if (psiDirectory == null) {
return null;
}
return PsiPackageCommentFactory.from(psiDirectory);
return DocUtils.dirDoc(psiDirectory);
}
@Override

View File

@@ -1,4 +1,4 @@
package io.github.linwancen.plugin.comment.utils;
package io.github.linwancen.plugin.show.doc;
import com.intellij.psi.PsiElement;
import com.intellij.psi.javadoc.PsiDocComment;
@@ -9,12 +9,12 @@ import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
public class PsiDocCommentUtils {
public class DocTextUtils {
private PsiDocCommentUtils() {}
private DocTextUtils() {}
@Nullable
public static String getCommentText(@Nullable PsiDocComment psiDocComment) {
public static String text(@Nullable PsiDocComment psiDocComment) {
if (psiDocComment == null) {
return null;
}

View File

@@ -0,0 +1,58 @@
package io.github.linwancen.plugin.show.doc;
import com.intellij.psi.*;
import com.intellij.psi.javadoc.PsiDocComment;
import org.jetbrains.annotations.Nullable;
public class DocUtils {
private DocUtils() {}
public static PsiDocComment srcOrByteCodeDoc(PsiDocCommentOwner psiDocCommentOwner) {
PsiElement navElement = psiDocCommentOwner.getNavigationElement();
if (navElement instanceof PsiDocCommentOwner) {
psiDocCommentOwner = (PsiDocCommentOwner) navElement;
}
return psiDocCommentOwner.getDocComment();
}
@Nullable
public static PsiDocComment methodDoc(PsiMethod psiMethod) {
return MethodDocUtils.methodSupperNewPropDoc(psiMethod);
}
@Nullable
public static PsiDocComment packageDoc(PsiPackage psiPackage) {
PsiDirectory[] psiDirectories = psiPackage.getDirectories();
for (PsiDirectory psiDirectory : psiDirectories) {
PsiDocComment psiDocComment = dirDoc(psiDirectory);
if (psiDocComment != null) {
return psiDocComment;
}
}
return null;
}
@Nullable
public static PsiDocComment fileDoc(PsiFile psiFile) {
if (!(psiFile instanceof PsiJavaFile)) {
return null;
}
PsiJavaFile psiJavaFile = (PsiJavaFile) psiFile;
if (PsiPackage.PACKAGE_INFO_FILE.equals(psiFile.getName())) {
return PackageDocUtils.fromPackageInfoFile(psiFile);
}
PsiClass[] classes = psiJavaFile.getClasses();
if (classes.length == 0) {
return null;
}
PsiClass psiClass = classes[0];
return srcOrByteCodeDoc(psiClass);
}
@Nullable
public static PsiDocComment dirDoc(PsiDirectory psiDirectory) {
PsiFile file = psiDirectory.findFile(PsiPackage.PACKAGE_INFO_FILE);
return PackageDocUtils.fromPackageInfoFile(file);
}
}

View File

@@ -1,4 +1,4 @@
package io.github.linwancen.plugin.comment.utils;
package io.github.linwancen.plugin.show.doc;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
@@ -7,12 +7,12 @@ import com.intellij.psi.PsiMethod;
import com.intellij.psi.javadoc.PsiDocComment;
import org.jetbrains.annotations.Nullable;
public class PsiMethodCommentFactory {
class MethodDocUtils {
private PsiMethodCommentFactory() {}
private MethodDocUtils() {}
@Nullable
public static PsiDocComment from(PsiMethod psiMethod) {
static PsiDocComment methodSupperNewPropDoc(PsiMethod psiMethod) {
// .class
PsiElement navElement = psiMethod.getNavigationElement();
if (navElement instanceof PsiMethod) {
@@ -25,7 +25,7 @@ public class PsiMethodCommentFactory {
}
// supper
PsiDocComment superDoc = supperMethodComment(psiMethod);
PsiDocComment superDoc = supperMethodDoc(psiMethod);
if (superDoc != null) {
return superDoc;
}
@@ -42,14 +42,14 @@ public class PsiMethodCommentFactory {
}
// get/set/is - PropertyDescriptor getReadMethod() getWriteMethod()
return propMethodComment(psiMethod, clazz);
return propMethodDoc(psiMethod, clazz);
}
@Nullable
public static PsiDocComment supperMethodComment(PsiMethod psiMethod) {
private static PsiDocComment supperMethodDoc(PsiMethod psiMethod) {
PsiMethod[] superMethods = psiMethod.findSuperMethods();
for (PsiMethod superMethod : superMethods) {
PsiDocComment superDoc = from(superMethod);
PsiDocComment superDoc = DocUtils.methodDoc(superMethod);
if (superDoc != null) {
return superDoc;
}
@@ -58,7 +58,7 @@ public class PsiMethodCommentFactory {
}
@Nullable
public static PsiDocComment propMethodComment(PsiMethod psiMethod, PsiClass psiClass) {
private static PsiDocComment propMethodDoc(PsiMethod psiMethod, PsiClass psiClass) {
String name = psiMethod.getName();
if (name.length() > 3 && (name.startsWith("get") || name.startsWith("set"))) {
name = name.substring(3);

View File

@@ -1,39 +1,19 @@
package io.github.linwancen.plugin.comment.utils;
package io.github.linwancen.plugin.show.doc;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiDirectory;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiPackage;
import com.intellij.psi.impl.source.tree.JavaDocElementType;
import com.intellij.psi.impl.source.tree.JavaElementType;
import com.intellij.psi.javadoc.PsiDocComment;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class PsiPackageCommentFactory {
class PackageDocUtils {
private PsiPackageCommentFactory() {}
private PackageDocUtils() {}
@Nullable
public static PsiDocComment from(PsiPackage psiPackage) {
PsiDirectory[] psiDirectories = psiPackage.getDirectories();
for (PsiDirectory psiDirectory : psiDirectories) {
PsiDocComment psiDocComment = from(psiDirectory);
if (psiDocComment != null) {
return psiDocComment;
}
}
return null;
}
@Nullable
public static PsiDocComment from(PsiDirectory psiDirectory) {
PsiFile packageInfoFile = psiDirectory.findFile(PsiPackage.PACKAGE_INFO_FILE);
return fromPackageInfoFile(packageInfoFile);
}
@Nullable
public static PsiDocComment fromPackageInfoFile(PsiFile packageInfoFile) {
static PsiDocComment fromPackageInfoFile(PsiFile packageInfoFile) {
if (packageInfoFile == null) {
return null;
}

View File

@@ -1,4 +1,4 @@
package io.github.linwancen.plugin.comment.utils;
package io.github.linwancen.plugin.show.line;
import com.intellij.lang.java.JavaLanguage;
import com.intellij.openapi.editor.Document;
@@ -6,20 +6,21 @@ import com.intellij.openapi.util.TextRange;
import com.intellij.psi.FileViewProvider;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiIdentifier;
import com.intellij.psi.javadoc.PsiDocComment;
import com.intellij.psi.util.PsiTreeUtil;
import org.jetbrains.annotations.Nullable;
public class ResolveElementLeftToRightUtils {
public class LineDocLeftToRightUtils {
private ResolveElementLeftToRightUtils() {}
private LineDocLeftToRightUtils() {}
protected static final String[] KEYS = {
static final String[] KEYS = {
"=",
};
@Nullable
public static PsiElement resolveElement(FileViewProvider viewProvider, Document document,
int startOffset, int endOffset) {
public static PsiDocComment leftDoc(FileViewProvider viewProvider, Document document,
int startOffset, int endOffset) {
String text = document.getText(new TextRange(startOffset, endOffset));
int offset = 0;
for (String s : KEYS) {
@@ -47,12 +48,12 @@ public class ResolveElementLeftToRightUtils {
startOffset = 0;
}
PsiElement element = viewProvider.findElementAt(offset, JavaLanguage.INSTANCE);
PsiIdentifier psiIdentifier = psiIdentifier(element, endOffset);
return ResolveElementUtils.resolveElementOf(psiIdentifier, psiIdentifier, startOffset, endOffset);
PsiIdentifier psiIdentifier = leftIdentifier(element, endOffset);
return LineDocUtils.elementDoc(psiIdentifier, psiIdentifier, startOffset, endOffset);
}
@Nullable
private static PsiIdentifier psiIdentifier(PsiElement element, int endOffset) {
private static PsiIdentifier leftIdentifier(PsiElement element, int endOffset) {
if (element == null) {
return null;
}

View File

@@ -1,18 +1,19 @@
package io.github.linwancen.plugin.comment.utils;
package io.github.linwancen.plugin.show.line;
import com.intellij.lang.java.JavaLanguage;
import com.intellij.psi.FileViewProvider;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiIdentifier;
import com.intellij.psi.javadoc.PsiDocComment;
import com.intellij.psi.util.PsiTreeUtil;
import org.jetbrains.annotations.Nullable;
public class ResolveElementRightToLeftUtils {
public class LineDocRightToLeftUtils {
private ResolveElementRightToLeftUtils() {}
private LineDocRightToLeftUtils() {}
@Nullable
public static PsiElement resolveElement(FileViewProvider viewProvider, int startOffset, int endOffset) {
public static PsiDocComment rightDoc(FileViewProvider viewProvider, int startOffset, int endOffset) {
// End is always white, can not -1 because @see class.name need it
PsiElement element = viewProvider.findElementAt(endOffset, JavaLanguage.INSTANCE);
if (element == null) {
@@ -29,6 +30,6 @@ public class ResolveElementRightToLeftUtils {
if (identifier != null && identifier.getTextRange().getStartOffset() < startOffset) {
identifier = null;
}
return ResolveElementUtils.resolveElementOf(element, identifier, startOffset, endOffset);
return LineDocUtils.elementDoc(element, identifier, startOffset, endOffset);
}
}

View File

@@ -0,0 +1,143 @@
package io.github.linwancen.plugin.show.line;
import com.intellij.psi.*;
import com.intellij.psi.impl.source.javadoc.PsiDocMethodOrFieldRef;
import com.intellij.psi.javadoc.PsiDocComment;
import com.intellij.psi.util.PsiTreeUtil;
import org.jetbrains.annotations.Nullable;
class LineDocUtils {
private LineDocUtils() {}
@Nullable
static PsiDocComment elementDoc(PsiElement element, PsiElement psiIdentifier,
int startOffset, int endOffset) {
if (element != null) {
PsiDocComment executableDoc = parentMethodDoc(element, startOffset, endOffset);
if (executableDoc != null) {
return executableDoc;
}
PsiDocComment newDoc = parentNewDoc(element, startOffset);
if (newDoc != null) {
return newDoc;
}
PsiDocComment docRefDoc = docRefDoc(element);
if (docRefDoc != null) {
return docRefDoc;
}
}
return refDoc(psiIdentifier, endOffset);
}
@Nullable
private static PsiDocComment parentMethodDoc(PsiElement element, int startOffset, int endOffset) {
// method call
PsiMethodCallExpression call =
PsiTreeUtil.getParentOfType(element, PsiMethodCallExpression.class, false, startOffset);
if (call == null) {
return null;
}
if ((call.getNode().getStartOffset() + call.getNode().getTextLength()) > endOffset) {
return null;
}
try {
PsiDocComment methodComment = SkipDocUtils.methodDoc(call.resolveMethod());
if (methodComment != null) {
return methodComment;
}
} catch (Exception ignored) {
// ignored
}
return null;
}
@Nullable
private static PsiDocComment parentNewDoc(PsiElement element, int startOffset) {
// new and Class should same line, so not need if endOffset
PsiNewExpression newExp = PsiTreeUtil.getParentOfType(element, PsiNewExpression.class, false, startOffset);
if (newExp == null) {
return null;
}
PsiDocComment methodComment = SkipDocUtils.methodDoc(newExp.resolveMethod());
if (methodComment != null) {
return methodComment;
}
PsiJavaCodeReferenceElement classReference = newExp.getClassReference();
return javaCodeDoc(classReference);
}
/**
* ::/class/field
*/
@Nullable
private static PsiDocComment refDoc(PsiElement element, int endOffset) {
if (element == null) {
return null;
}
// while for xx.xx.xx... when left to right, only once when right to left
PsiElement parent;
while ((parent = element.getParent()) instanceof PsiReference) {
if (parent.getTextRange().getEndOffset() > endOffset) {
break;
}
element = parent;
}
if (element instanceof PsiReference) {
PsiElement resolve = ((PsiReference) element).resolve();
if (resolve instanceof PsiDocCommentOwner) {
return SkipDocUtils.refDoc(((PsiDocCommentOwner) resolve));
}
}
// for right to left field
if (parent instanceof PsiDocCommentOwner) {
return SkipDocUtils.refDoc(((PsiDocCommentOwner) parent));
}
// for right to left for
if (parent instanceof PsiForeachStatement) {
PsiParameter iterationParameter = ((PsiForeachStatement) parent).getIterationParameter();
PsiTypeElement typeElement = iterationParameter.getTypeElement();
if (typeElement == null) {
return null;
}
PsiJavaCodeReferenceElement ref = typeElement.getInnermostComponentReferenceElement();
return javaCodeDoc(ref);
}
return null;
}
@Nullable
private static PsiDocComment javaCodeDoc(PsiJavaCodeReferenceElement ref) {
if (ref == null) {
return null;
}
PsiElement resolve = ref.resolve();
if (resolve instanceof PsiDocCommentOwner) {
return SkipDocUtils.refDoc(((PsiDocCommentOwner) resolve));
}
return null;
}
@Nullable
private static PsiDocComment docRefDoc(PsiElement element) {
PsiElement parent = element.getParent();
if (parent instanceof PsiDocMethodOrFieldRef) {
element = parent;
}
if (element instanceof PsiDocMethodOrFieldRef) {
PsiReference reference = element.getReference();
if (reference == null) {
return null;
}
PsiElement resolve = reference.resolve();
if (resolve instanceof PsiMethod) {
return SkipDocUtils.methodDoc(((PsiMethod) resolve));
}
if (resolve instanceof PsiDocCommentOwner) {
return SkipDocUtils.refDoc(((PsiDocCommentOwner) resolve));
}
}
return null;
}
}

View File

@@ -0,0 +1,37 @@
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.DocUtils;
import org.jetbrains.annotations.Nullable;
class SkipDocUtils {
private SkipDocUtils() {}
static PsiDocComment methodDoc(@Nullable PsiMethod psiMethod) {
if (skip(psiMethod)) {
return null;
}
return DocUtils.methodDoc(psiMethod);
}
static PsiDocComment refDoc(@Nullable PsiDocCommentOwner docOwner) {
if (skip(docOwner)) {
return null;
}
return DocUtils.srcOrByteCodeDoc(docOwner);
}
static boolean skip(@Nullable PsiDocCommentOwner docOwner) {
if (docOwner == null) {
return true;
}
if (docOwner instanceof PsiClass) {
return SkipUtils.skip((PsiClass) docOwner, docOwner.getProject());
}
return SkipUtils.skip(docOwner.getContainingClass(), docOwner.getProject());
}
}

View File

@@ -1,15 +1,15 @@
package io.github.linwancen.plugin.comment.utils;
package io.github.linwancen.plugin.show.line;
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;
import io.github.linwancen.plugin.show.settings.AppSettingsState;
import io.github.linwancen.plugin.show.settings.ProjectSettingsState;
public class SkipUtils {
class SkipUtils {
private SkipUtils() {}
public static boolean skip(PsiClass psiClass, Project project) {
static boolean skip(PsiClass psiClass, Project project) {
if (psiClass == null) {
return true;
}
@@ -29,21 +29,21 @@ public class SkipUtils {
return false;
}
protected static boolean skipName(String name, String[] includeArray, String[] excludeArray) {
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) {
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) {
static boolean exclude(String name, String[] projectLineEndExcludeArray) {
for (String s : projectLineEndExcludeArray) {
if (name.startsWith(s)) {
return true;

View File

@@ -1,4 +1,4 @@
package io.github.linwancen.plugin.comment.settings;
package io.github.linwancen.plugin.show.settings;
import com.intellij.ui.IdeBorderFactory;
import com.intellij.ui.components.JBLabel;

View File

@@ -1,4 +1,4 @@
package io.github.linwancen.plugin.comment.settings;
package io.github.linwancen.plugin.show.settings;
import com.intellij.ui.ColorPanel;
import com.intellij.ui.IdeBorderFactory;

View File

@@ -1,4 +1,4 @@
package io.github.linwancen.plugin.comment.settings;
package io.github.linwancen.plugin.show.settings;
import com.intellij.openapi.editor.colors.EditorColorsManager;
import com.intellij.openapi.options.Configurable;

View File

@@ -1,4 +1,4 @@
package io.github.linwancen.plugin.comment.settings;
package io.github.linwancen.plugin.show.settings;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.PersistentStateComponent;

View File

@@ -1,4 +1,4 @@
package io.github.linwancen.plugin.comment.settings;
package io.github.linwancen.plugin.show.settings;
import com.intellij.ui.components.JBCheckBox;
import com.intellij.util.ui.FormBuilder;

View File

@@ -1,4 +1,4 @@
package io.github.linwancen.plugin.comment.settings;
package io.github.linwancen.plugin.show.settings;
import com.intellij.application.options.ModuleAwareProjectConfigurable;
import com.intellij.openapi.module.Module;

View File

@@ -1,4 +1,4 @@
package io.github.linwancen.plugin.comment.settings;
package io.github.linwancen.plugin.show.settings;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.ServiceManager;

View File

@@ -1,4 +1,4 @@
package io.github.linwancen.plugin.comment.settings;
package io.github.linwancen.plugin.show.settings;
import org.jetbrains.annotations.NotNull;