diff --git a/README.md b/README.md index 941148d..4cacb04 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ Show doc comment at the Project view Tree, line End, json etc.
  • 1.5 Add line-end-comment find next loop when none
  • 1.4 Add line-end-comment find element right to left
  • 1.3 ★ project-view-tree file and member comment -
  • 1.2 Add line-end-comment settings fro class prefix filter +
  • 1.2 Add line-end-comment settings for class prefix filter
  • 1.1 Add line-end-comment settings for text color diff --git a/build.gradle b/build.gradle index 56b1128..73cb8be 100644 --- a/build.gradle +++ b/build.gradle @@ -110,7 +110,7 @@ patchPluginXml {
  • 1.5 Add line-end-comment find next loop when none
  • 1.4 Add line-end-comment find element right to left
  • 1.3 ★ project-view-tree file and member comment -
  • 1.2 Add line-end-comment settings fro class prefix filter +
  • 1.2 Add line-end-comment settings for class prefix filter
  • 1.1 Add line-end-comment settings for text color diff --git a/src/main/idea/io/github/linwancen/plugin/show/java/JavaLangDoc.java b/src/main/idea/io/github/linwancen/plugin/show/java/JavaLangDoc.java index c871213..717a310 100644 --- a/src/main/idea/io/github/linwancen/plugin/show/java/JavaLangDoc.java +++ b/src/main/idea/io/github/linwancen/plugin/show/java/JavaLangDoc.java @@ -34,27 +34,28 @@ public class JavaLangDoc extends BaseTagLangDoc { } @Override - public @Nullable String treeDoc(T settingsInfo, ProjectViewNode node, Project project) { + public @Nullable String treeDoc(@NotNull T settingsInfo, ProjectViewNode node, + @NotNull Project project) { return JavaTree.treeDoc(settingsInfo, node, project); } @Override protected @Nullable String refDoc(@NotNull T lineInfo, @NotNull PsiElement ref) { if ("Override".equals(ref.getText())) { - PsiMethod psiMethod = PsiTreeUtil.getParentOfType(ref, PsiMethod.class); + @Nullable PsiMethod psiMethod = PsiTreeUtil.getParentOfType(ref, PsiMethod.class); if (psiMethod == null) { return null; } // must supper - PsiDocComment psiDocComment = OwnerToPsiDocUtils.supperMethodDoc(psiMethod); + @Nullable PsiDocComment psiDocComment = OwnerToPsiDocUtils.supperMethodDoc(psiMethod); return docElementToStr(lineInfo, psiDocComment); } if (lineInfo.appSettings.fromNew) { PsiElement parent = ref.getParent(); if (parent instanceof PsiNewExpression) { - PsiNewExpression psiNewExpression = (PsiNewExpression) parent; + @NotNull PsiNewExpression psiNewExpression = (PsiNewExpression) parent; try { - PsiMethod resolve = psiNewExpression.resolveMethod(); + @Nullable PsiMethod resolve = psiNewExpression.resolveMethod(); if (resolve != null) { return resolveDocPrint(lineInfo, resolve); } @@ -68,7 +69,7 @@ public class JavaLangDoc extends BaseTagLangDoc { @Override public @Nullable String resolveDocPrint(@NotNull T lineInfo, @NotNull PsiElement resolve) { - String resolveDocPrint = super.resolveDocPrint(lineInfo, resolve); + @Nullable String resolveDocPrint = super.resolveDocPrint(lineInfo, resolve); if (resolveDocPrint != null) { return resolveDocPrint; } @@ -80,20 +81,20 @@ public class JavaLangDoc extends BaseTagLangDoc { @Nullable private String paramDoc(@NotNull PsiParameter psiParameter) { - PsiMethod method = PsiTreeUtil.getParentOfType(psiParameter, PsiMethod.class); + @Nullable PsiMethod method = PsiTreeUtil.getParentOfType(psiParameter, PsiMethod.class); if (method == null) { return null; } - PsiDocComment psiDocComment = OwnerToPsiDocUtils.methodDoc(method); + @Nullable PsiDocComment psiDocComment = OwnerToPsiDocUtils.methodDoc(method); if (psiDocComment == null) { return null; } - String name = psiParameter.getName(); - PsiDocTag[] params = psiDocComment.findTagsByName("param"); - for (PsiDocTag param : params) { - PsiDocTagValue value = param.getValueElement(); + @NotNull String name = psiParameter.getName(); + @NotNull PsiDocTag[] params = psiDocComment.findTagsByName("param"); + for (@NotNull PsiDocTag param : params) { + @Nullable PsiDocTagValue value = param.getValueElement(); if (value != null && name.equals(value.getText())) { - PsiElement[] dataElements = param.getDataElements(); + @NotNull PsiElement[] dataElements = param.getDataElements(); if (dataElements.length > 1) { return dataElements[1].getText(); } @@ -106,7 +107,7 @@ public class JavaLangDoc extends BaseTagLangDoc { @Override protected PsiDocComment toDocElement(@NotNull PsiElement resolve) { if (resolve instanceof PsiDocCommentOwner) { - PsiDocCommentOwner psiDocCommentOwner = (PsiDocCommentOwner) resolve; + @NotNull PsiDocCommentOwner psiDocCommentOwner = (PsiDocCommentOwner) resolve; return OwnerToPsiDocSkip.refDoc(psiDocCommentOwner); } return null; @@ -115,9 +116,9 @@ public class JavaLangDoc extends BaseTagLangDoc { @NotNull @Override protected String descDoc(@NotNull T lineInfo, @NotNull PsiDocComment psiDocComment) { - StringBuilder sb = new StringBuilder(); + @NotNull StringBuilder sb = new StringBuilder(); int lineCount = 0; - PsiElement[] elements = psiDocComment.getDescriptionElements(); + @NotNull PsiElement[] elements = psiDocComment.getDescriptionElements(); for (PsiElement element : elements) { if (appendElementText(sb, element)) { lineCount++; @@ -132,14 +133,14 @@ public class JavaLangDoc extends BaseTagLangDoc { /** * @return is new line */ - private static boolean appendElementText(StringBuilder sb, PsiElement element) { + private static boolean appendElementText(@NotNull StringBuilder sb, PsiElement element) { if (element instanceof PsiDocToken) { - PsiDocToken psiDocToken = (PsiDocToken) element; + @NotNull PsiDocToken psiDocToken = (PsiDocToken) element; DocFilter.addHtml(sb, psiDocToken.getText()); } if (element instanceof PsiInlineDocTag) { - PsiInlineDocTag psiInlineDocTag = (PsiInlineDocTag) element; - PsiElement[] children = psiInlineDocTag.getChildren(); + @NotNull PsiInlineDocTag psiInlineDocTag = (PsiInlineDocTag) element; + @NotNull PsiElement[] children = psiInlineDocTag.getChildren(); if (children.length > 3) { DocFilter.addHtml(sb, children[3].getText()); } @@ -150,10 +151,10 @@ public class JavaLangDoc extends BaseTagLangDoc { @Override protected void appendTag(@NotNull T lineInfo, @NotNull StringBuilder tagStrBuilder, @NotNull PsiDocComment psiDocComment, @NotNull String name) { - PsiDocTag[] tags = psiDocComment.findTagsByName(name); - for (PsiDocTag tag : tags) { + @NotNull PsiDocTag[] tags = psiDocComment.findTagsByName(name); + for (@NotNull PsiDocTag tag : tags) { // @see @param should use getDataElements() - PsiDocTagValue value = tag.getValueElement(); + @Nullable PsiDocTagValue value = tag.getValueElement(); if (value != null) { DocFilter.addHtml(tagStrBuilder, value.getText()); } diff --git a/src/main/idea/io/github/linwancen/plugin/show/java/JavaTree.java b/src/main/idea/io/github/linwancen/plugin/show/java/JavaTree.java index 07fbf46..8713e9d 100644 --- a/src/main/idea/io/github/linwancen/plugin/show/java/JavaTree.java +++ b/src/main/idea/io/github/linwancen/plugin/show/java/JavaTree.java @@ -14,6 +14,7 @@ import io.github.linwancen.plugin.show.bean.SettingsInfo; import io.github.linwancen.plugin.show.java.doc.OwnerToPsiDocUtils; import io.github.linwancen.plugin.show.java.line.NewCallRefToPsiDoc; import io.github.linwancen.plugin.show.settings.AppSettingsState; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public class JavaTree { @@ -21,8 +22,9 @@ public class JavaTree { private JavaTree() {} @Nullable - public static String treeDoc(T settingsInfo, ProjectViewNode node, Project project) { - PsiDocComment docComment = nodeDoc(node, project); + public static String treeDoc(@NotNull T settingsInfo, ProjectViewNode node, + @NotNull Project project) { + @Nullable PsiDocComment docComment = nodeDoc(node, project); if (docComment == null) { return null; } @@ -30,7 +32,7 @@ public class JavaTree { } @Nullable - static PsiDocComment nodeDoc(ProjectViewNode node, Project project) { + static PsiDocComment nodeDoc(ProjectViewNode node, @NotNull Project project) { if (node instanceof PsiFileNode) { PsiFile psiFile = ((PsiFileNode) node).getValue(); return OwnerToPsiDocUtils.fileDoc(psiFile); @@ -44,26 +46,26 @@ public class JavaTree { // On Show Members PsiField psiField = ((PsiFieldNode) node).getValue(); // for @Autowire Bean - PsiType type = psiField.getType(); + @NotNull PsiType type = psiField.getType(); if (type instanceof PsiClassReferenceType) { - PsiClassReferenceType psiClassReferenceType = (PsiClassReferenceType) type; - PsiJavaCodeReferenceElement reference = psiClassReferenceType.getReference(); + @NotNull PsiClassReferenceType psiClassReferenceType = (PsiClassReferenceType) type; + @NotNull PsiJavaCodeReferenceElement reference = psiClassReferenceType.getReference(); return NewCallRefToPsiDoc.javaCodeDoc(reference); } } if (node instanceof PackageElementNode) { // On Packages View - PsiPackage psiPackage = ((PackageElementNode) node).getValue().getPackage(); + @NotNull PsiPackage psiPackage = ((PackageElementNode) node).getValue().getPackage(); return packageDoc(psiPackage); } // On Packages View, Project Files View - VirtualFile virtualFile = node.getVirtualFile(); + @Nullable VirtualFile virtualFile = node.getVirtualFile(); if (virtualFile == null || !virtualFile.isDirectory()) { return null; } - PsiDirectory psiDirectory = PsiManager.getInstance(project).findDirectory(virtualFile); + @Nullable PsiDirectory psiDirectory = PsiManager.getInstance(project).findDirectory(virtualFile); if (psiDirectory == null) { return null; } @@ -71,17 +73,17 @@ public class JavaTree { } @Nullable - static PsiDocComment dirDoc(PsiDirectory child) { + static PsiDocComment dirDoc(@NotNull PsiDirectory child) { while (true) { - PsiDocComment docComment = OwnerToPsiDocUtils.dirDoc(child); + @Nullable PsiDocComment docComment = OwnerToPsiDocUtils.dirDoc(child); if (docComment != null) { return docComment; } - AppSettingsState instance = AppSettingsState.getInstance(); + @NotNull AppSettingsState instance = AppSettingsState.getInstance(); if (!instance.compact) { return null; } - PsiDirectory parent = child.getParent(); + @Nullable PsiDirectory parent = child.getParent(); if (parent == null) { return null; } @@ -93,13 +95,13 @@ public class JavaTree { } @Nullable - static PsiDocComment packageDoc(PsiPackage child) { + static PsiDocComment packageDoc(@NotNull PsiPackage child) { while (true) { - PsiDocComment docComment = OwnerToPsiDocUtils.packageDoc(child); + @Nullable PsiDocComment docComment = OwnerToPsiDocUtils.packageDoc(child); if (docComment != null) { return docComment; } - PsiPackage parent = child.getParentPackage(); + @Nullable PsiPackage parent = child.getParentPackage(); if (parent == null) { return null; } diff --git a/src/main/idea/io/github/linwancen/plugin/show/java/JsonJumpJava.java b/src/main/idea/io/github/linwancen/plugin/show/java/JsonJumpJava.java index 9f4af59..0913ff5 100644 --- a/src/main/idea/io/github/linwancen/plugin/show/java/JsonJumpJava.java +++ b/src/main/idea/io/github/linwancen/plugin/show/java/JsonJumpJava.java @@ -11,6 +11,7 @@ import com.intellij.util.ProcessingContext; import io.github.linwancen.plugin.show.java.doc.PsiClassUtils; import io.github.linwancen.plugin.show.jump.JsonRef; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Arrays; @@ -25,7 +26,8 @@ public class JsonJumpJava extends PsiReferenceContributor { @Override public @NotNull PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) { - JsonProperty jsonProp = PsiTreeUtil.getParentOfType(element, JsonProperty.class, true); + @Nullable JsonProperty jsonProp = PsiTreeUtil.getParentOfType( + element, JsonProperty.class, true); if (jsonProp == null) { return PsiReference.EMPTY_ARRAY; } @@ -34,15 +36,15 @@ public class JsonJumpJava extends PsiReferenceContributor { return PsiReference.EMPTY_ARRAY; } - Project project = element.getProject(); - List psiFields = new ArrayList<>(); - List tips = new ArrayList<>(); - PsiClass[] psiClasses = PsiClassUtils.encClass(virtualFile, project); - List jsonPath = jsonPath(jsonProp); + @NotNull Project project = element.getProject(); + @NotNull List psiFields = new ArrayList<>(); + @NotNull List tips = new ArrayList<>(); + @NotNull PsiClass[] psiClasses = PsiClassUtils.encClass(virtualFile, project); + @NotNull List jsonPath = jsonPath(jsonProp); put(project, psiFields, tips, psiClasses, jsonPath, jsonPath.size() - 1); - List list = new ArrayList<>(); - for (PsiField psiField : psiFields) { + @NotNull List list = new ArrayList<>(); + for (@NotNull PsiField psiField : psiFields) { list.add(new JsonRef<>(element, psiField, tips)); } return list.toArray(new PsiReference[0]); @@ -51,30 +53,30 @@ public class JsonJumpJava extends PsiReferenceContributor { } @NotNull - private static List jsonPath(JsonProperty jsonProp) { - ArrayList jsonPath = new ArrayList<>(); + private static List jsonPath(@NotNull JsonProperty jsonProp) { + @NotNull ArrayList jsonPath = new ArrayList<>(); do { jsonPath.add(jsonProp.getName()); } while ((jsonProp = PsiTreeUtil.getParentOfType(jsonProp, JsonProperty.class)) != null); return jsonPath; } - private static void put(Project project, List psiFields, List tips, - PsiClass[] psiClasses, List jsonPath, int level) { + private static void put(@NotNull Project project, @NotNull List psiFields, @NotNull List tips, + @NotNull PsiClass[] psiClasses, @NotNull List jsonPath, int level) { String name = jsonPath.get(level); - for (PsiClass psiClass : psiClasses) { + for (@NotNull PsiClass psiClass : psiClasses) { if (level == 1) { tips.addAll(Arrays.asList(psiClass.getAllFields())); } - PsiField psiField = psiClass.findFieldByName(name, true); + @Nullable PsiField psiField = psiClass.findFieldByName(name, true); if (psiField == null) { continue; } if (level == 0) { psiFields.add(psiField); } else { - String classFullName = PsiClassUtils.toClassFullName(psiField); - PsiClass[] classes = PsiClassUtils.fullNameToClass(classFullName, project); + @NotNull String classFullName = PsiClassUtils.toClassFullName(psiField); + @NotNull PsiClass[] classes = PsiClassUtils.fullNameToClass(classFullName, project); put(project, psiFields, tips, classes, jsonPath, level - 1); } } diff --git a/src/main/idea/io/github/linwancen/plugin/show/java/KotlinLangDoc.java b/src/main/idea/io/github/linwancen/plugin/show/java/KotlinLangDoc.java index b1ee817..e01a554 100644 --- a/src/main/idea/io/github/linwancen/plugin/show/java/KotlinLangDoc.java +++ b/src/main/idea/io/github/linwancen/plugin/show/java/KotlinLangDoc.java @@ -39,7 +39,7 @@ public class KotlinLangDoc extends BaseTagLangDoc { if (resolve instanceof PsiPackageBase) { return null; } - KDoc kDoc = PsiTreeUtil.getChildOfType(resolve, KDoc.class); + @Nullable KDoc kDoc = PsiTreeUtil.getChildOfType(resolve, KDoc.class); if (kDoc == null) { return null; } @@ -48,18 +48,18 @@ public class KotlinLangDoc extends BaseTagLangDoc { @NotNull @Override - protected String descDoc(@NotNull T lineInfo, @NotNull KDocSection kDocSection) { - String content = kDocSection.getContent(); + protected String descDoc(@NotNull T lineInfo, @NotNull KDocSection kDocSection) { + @NotNull String content = kDocSection.getContent(); return DocFilter.cutDoc(content, lineInfo.appSettings, false); } @Override protected void appendTag(@NotNull T lineInfo, @NotNull StringBuilder tagStrBuilder, @NotNull KDocSection kDocSection, @NotNull String name) { - List tags = kDocSection.findTagsByName(name); - for (KDocTag tag : tags) { - String content = tag.getContent(); - String cutDoc = DocFilter.cutDoc(content, lineInfo.appSettings, false); + @NotNull List tags = kDocSection.findTagsByName(name); + for (@NotNull KDocTag tag : tags) { + @NotNull String content = tag.getContent(); + @NotNull String cutDoc = DocFilter.cutDoc(content, lineInfo.appSettings, false); tagStrBuilder.append(cutDoc); } } diff --git a/src/main/idea/io/github/linwancen/plugin/show/java/doc/OwnerToPsiDocUtils.java b/src/main/idea/io/github/linwancen/plugin/show/java/doc/OwnerToPsiDocUtils.java index ff30dec..d078f68 100644 --- a/src/main/idea/io/github/linwancen/plugin/show/java/doc/OwnerToPsiDocUtils.java +++ b/src/main/idea/io/github/linwancen/plugin/show/java/doc/OwnerToPsiDocUtils.java @@ -13,7 +13,8 @@ public class OwnerToPsiDocUtils { private OwnerToPsiDocUtils() {} - public static PsiDocComment srcOrByteCodeDoc(PsiDocCommentOwner psiDocCommentOwner) { + @Nullable + public static PsiDocComment srcOrByteCodeDoc(@NotNull PsiDocCommentOwner psiDocCommentOwner) { PsiElement navElement = psiDocCommentOwner.getNavigationElement(); if (navElement instanceof PsiDocCommentOwner) { psiDocCommentOwner = (PsiDocCommentOwner) navElement; @@ -27,7 +28,7 @@ public class OwnerToPsiDocUtils { } @Nullable - public static PsiDocComment supperMethodDoc(PsiMethod psiMethod) { + public static PsiDocComment supperMethodDoc(@NotNull PsiMethod psiMethod) { return PsiMethodToPsiDoc.supperMethodDoc(psiMethod); } @@ -36,14 +37,14 @@ public class OwnerToPsiDocUtils { if (psiPackage == null) { return null; } - String name = psiPackage.getName(); + @Nullable String name = psiPackage.getName(); if (name == null || name.length() == 0) { return null; } - PsiDirectory[] psiDirectories = psiPackage.getDirectories(); - for (PsiDirectory psiDirectory : psiDirectories) { - PsiFile file = psiDirectory.findFile(PsiPackage.PACKAGE_INFO_FILE); - PsiDocComment psiDocComment = PackageFileToPsiDoc.fromPackageInfoFile(file); + @NotNull PsiDirectory[] psiDirectories = psiPackage.getDirectories(); + for (@NotNull PsiDirectory psiDirectory : psiDirectories) { + @Nullable PsiFile file = psiDirectory.findFile(PsiPackage.PACKAGE_INFO_FILE); + @Nullable PsiDocComment psiDocComment = PackageFileToPsiDoc.fromPackageInfoFile(file); if (psiDocComment != null) { return psiDocComment; } @@ -55,14 +56,14 @@ public class OwnerToPsiDocUtils { public static PsiDocComment fileDoc(PsiFile psiFile) { if (!(psiFile instanceof PsiClassOwner)) { // for SPI - PsiClass[] psiClasses = PsiClassUtils.nameToClass(psiFile.getName(), psiFile.getProject()); + @NotNull PsiClass[] psiClasses = PsiClassUtils.nameToClass(psiFile.getName(), psiFile.getProject()); // for "xxx ClassName.xxx" if (psiClasses.length == 0) { VirtualFile virtualFile = psiFile.getVirtualFile(); psiClasses = PsiClassUtils.encClass(virtualFile, psiFile.getProject()); } - for (PsiClass psiClass : psiClasses) { - PsiDocComment docComment = srcOrByteCodeDoc(psiClass); + for (@NotNull PsiClass psiClass : psiClasses) { + @Nullable PsiDocComment docComment = srcOrByteCodeDoc(psiClass); if (docComment != null) { // Inaccurate when there are classes with the same name return docComment; @@ -73,8 +74,8 @@ public class OwnerToPsiDocUtils { if (PsiPackage.PACKAGE_INFO_FILE.equals(psiFile.getName())) { return PackageFileToPsiDoc.fromPackageInfoFile(psiFile); } - PsiClassOwner psiClassOwner = (PsiClassOwner) psiFile; - PsiClass[] classes = psiClassOwner.getClasses(); + @NotNull PsiClassOwner psiClassOwner = (PsiClassOwner) psiFile; + @NotNull PsiClass[] classes = psiClassOwner.getClasses(); if (classes.length == 0) { return null; } @@ -83,8 +84,8 @@ public class OwnerToPsiDocUtils { } @Nullable - public static PsiDocComment dirDoc(PsiDirectory psiDirectory) { - PsiPackage psiPackage = JavaDirectoryService.getInstance().getPackage(psiDirectory); + public static PsiDocComment dirDoc(@NotNull PsiDirectory psiDirectory) { + @Nullable PsiPackage psiPackage = JavaDirectoryService.getInstance().getPackage(psiDirectory); return packageDoc(psiPackage); } } diff --git a/src/main/idea/io/github/linwancen/plugin/show/java/doc/PackageFileToPsiDoc.java b/src/main/idea/io/github/linwancen/plugin/show/java/doc/PackageFileToPsiDoc.java index 6855283..1bb7a82 100644 --- a/src/main/idea/io/github/linwancen/plugin/show/java/doc/PackageFileToPsiDoc.java +++ b/src/main/idea/io/github/linwancen/plugin/show/java/doc/PackageFileToPsiDoc.java @@ -13,7 +13,7 @@ class PackageFileToPsiDoc { private PackageFileToPsiDoc() {} @Nullable - static PsiDocComment fromPackageInfoFile(PsiFile packageInfoFile) { + static PsiDocComment fromPackageInfoFile(@Nullable PsiFile packageInfoFile) { if (packageInfoFile == null) { return null; } @@ -21,15 +21,16 @@ class PackageFileToPsiDoc { if (astNode == null) { return null; } - ASTNode docCommentNode = findRelevantCommentNode(astNode); + @Nullable ASTNode docCommentNode = findRelevantCommentNode(astNode); if (docCommentNode == null) { return null; } return (PsiDocComment) docCommentNode; } + @Nullable private static ASTNode findRelevantCommentNode(@NotNull ASTNode fileNode) { - ASTNode node = fileNode.findChildByType(JavaElementType.PACKAGE_STATEMENT); + @Nullable ASTNode node = fileNode.findChildByType(JavaElementType.PACKAGE_STATEMENT); if (node == null) node = fileNode.getLastChildNode(); while (node != null && node.getElementType() != JavaDocElementType.DOC_COMMENT) { node = node.getTreePrev(); diff --git a/src/main/idea/io/github/linwancen/plugin/show/java/doc/PsiClassUtils.java b/src/main/idea/io/github/linwancen/plugin/show/java/doc/PsiClassUtils.java index af34b81..a4aa8d4 100644 --- a/src/main/idea/io/github/linwancen/plugin/show/java/doc/PsiClassUtils.java +++ b/src/main/idea/io/github/linwancen/plugin/show/java/doc/PsiClassUtils.java @@ -21,8 +21,8 @@ public class PsiClassUtils { @NotNull public static PsiClass[] encClass(@NotNull VirtualFile virtualFile, @NotNull Project project) { - String fileName = virtualFile.getNameWithoutExtension(); - Matcher matcher = JSON_PATTERN.matcher(fileName); + @NotNull String fileName = virtualFile.getNameWithoutExtension(); + @NotNull Matcher matcher = JSON_PATTERN.matcher(fileName); if (!matcher.find()) { return new PsiClass[0]; } @@ -58,10 +58,10 @@ public class PsiClassUtils { } @NotNull - public static String toClassFullName(PsiField psiField) { + public static String toClassFullName(@NotNull PsiField psiField) { // Array // use replace simpler than getDeepComponentType() - String typeName = psiField.getType().getCanonicalText().replace("[]", ""); + @NotNull String typeName = psiField.getType().getCanonicalText().replace("[]", ""); // List // use substring() because clsFieldImpl.getInnermostComponentReferenceElement() == null int index = typeName.indexOf("<"); diff --git a/src/main/idea/io/github/linwancen/plugin/show/java/doc/PsiMethodToPsiDoc.java b/src/main/idea/io/github/linwancen/plugin/show/java/doc/PsiMethodToPsiDoc.java index a9a96ee..02ba2fd 100644 --- a/src/main/idea/io/github/linwancen/plugin/show/java/doc/PsiMethodToPsiDoc.java +++ b/src/main/idea/io/github/linwancen/plugin/show/java/doc/PsiMethodToPsiDoc.java @@ -20,19 +20,19 @@ class PsiMethodToPsiDoc { psiMethod = (PsiMethod) navElement; } - PsiDocComment docComment = psiMethod.getDocComment(); + @Nullable PsiDocComment docComment = psiMethod.getDocComment(); if (docComment != null) { return docComment; } // supper - PsiDocComment superDoc = supperMethodDoc(psiMethod); + @Nullable PsiDocComment superDoc = supperMethodDoc(psiMethod); if (superDoc != null) { return superDoc; } - PsiClass clazz = psiMethod.getContainingClass(); + @Nullable PsiClass clazz = psiMethod.getContainingClass(); if (clazz == null) { return null; } @@ -47,10 +47,10 @@ class PsiMethodToPsiDoc { } @Nullable - static PsiDocComment supperMethodDoc(PsiMethod psiMethod) { - PsiMethod[] superMethods = psiMethod.findSuperMethods(); - for (PsiMethod superMethod : superMethods) { - PsiDocComment superDoc = OwnerToPsiDocUtils.methodDoc(superMethod); + static PsiDocComment supperMethodDoc(@NotNull PsiMethod psiMethod) { + @NotNull PsiMethod[] superMethods = psiMethod.findSuperMethods(); + for (@NotNull PsiMethod superMethod : superMethods) { + @Nullable PsiDocComment superDoc = OwnerToPsiDocUtils.methodDoc(superMethod); if (superDoc != null) { return superDoc; } @@ -59,8 +59,8 @@ class PsiMethodToPsiDoc { } @Nullable - private static PsiDocComment propMethodDoc(PsiMethod psiMethod, PsiClass psiClass) { - String name = psiMethod.getName(); + private static PsiDocComment propMethodDoc(@NotNull PsiMethod psiMethod, @NotNull PsiClass psiClass) { + @NotNull String name = psiMethod.getName(); if (name.length() > 3 && (name.startsWith("get") || name.startsWith("set"))) { name = name.substring(3); } else if (name.length() > 2 && name.startsWith("is")) { @@ -68,10 +68,10 @@ class PsiMethodToPsiDoc { } else { return null; } - char[] chars = name.toCharArray(); + @NotNull char[] chars = name.toCharArray(); chars[0] += 32; name = String.valueOf(chars); - PsiField fieldByName = psiClass.findFieldByName(name, false); + @Nullable PsiField fieldByName = psiClass.findFieldByName(name, false); if (fieldByName == null) { return null; } diff --git a/src/main/idea/io/github/linwancen/plugin/show/java/line/NewCallRefToPsiDoc.java b/src/main/idea/io/github/linwancen/plugin/show/java/line/NewCallRefToPsiDoc.java index 3f4d203..0c0d8de 100644 --- a/src/main/idea/io/github/linwancen/plugin/show/java/line/NewCallRefToPsiDoc.java +++ b/src/main/idea/io/github/linwancen/plugin/show/java/line/NewCallRefToPsiDoc.java @@ -14,11 +14,11 @@ public class NewCallRefToPsiDoc { private NewCallRefToPsiDoc() {} @Nullable - public static PsiDocComment javaCodeDoc(PsiJavaCodeReferenceElement ref) { + public static PsiDocComment javaCodeDoc(@Nullable PsiJavaCodeReferenceElement ref) { if (ref == null) { return null; } - PsiElement resolve = null; + @Nullable PsiElement resolve = null; try { resolve = ref.resolve(); } catch (Throwable ignore) { diff --git a/src/main/idea/io/github/linwancen/plugin/show/java/line/OwnerToPsiDocSkip.java b/src/main/idea/io/github/linwancen/plugin/show/java/line/OwnerToPsiDocSkip.java index 7baccce..873c7bb 100644 --- a/src/main/idea/io/github/linwancen/plugin/show/java/line/OwnerToPsiDocSkip.java +++ b/src/main/idea/io/github/linwancen/plugin/show/java/line/OwnerToPsiDocSkip.java @@ -6,6 +6,7 @@ import com.intellij.psi.javadoc.PsiDocComment; 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; /** @@ -19,12 +20,12 @@ public class OwnerToPsiDocSkip { if (docOwner == null) { return null; } - AppSettingsState appSettings = AppSettingsState.getInstance(); - ProjectSettingsState projectSettings = ProjectSettingsState.getInstance(docOwner.getProject()); + @NotNull AppSettingsState appSettings = AppSettingsState.getInstance(); + @NotNull ProjectSettingsState projectSettings = ProjectSettingsState.getInstance(docOwner.getProject()); if (SkipUtils.skipSign(docOwner, appSettings, projectSettings)) { return null; } - PsiDocComment docComment = docOwner instanceof PsiMethod + @Nullable PsiDocComment docComment = docOwner instanceof PsiMethod ? OwnerToPsiDocUtils.methodDoc(((PsiMethod) docOwner)) : OwnerToPsiDocUtils.srcOrByteCodeDoc(docOwner); return SkipUtils.skipDoc(docComment, appSettings, projectSettings); diff --git a/src/main/idea/io/github/linwancen/plugin/show/java/line/SkipUtils.java b/src/main/idea/io/github/linwancen/plugin/show/java/line/SkipUtils.java index 12a3c31..c966765 100644 --- a/src/main/idea/io/github/linwancen/plugin/show/java/line/SkipUtils.java +++ b/src/main/idea/io/github/linwancen/plugin/show/java/line/SkipUtils.java @@ -8,39 +8,41 @@ 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; class SkipUtils { private SkipUtils() {} - static boolean skipSign(PsiElement psiElement, AppSettingsState appSettings, ProjectSettingsState projectSettings) { - String text = psiName(psiElement, appSettings); + static boolean skipSign(PsiElement psiElement, @NotNull AppSettingsState appSettings, + @NotNull ProjectSettingsState projectSettings) { + @Nullable String text = psiName(psiElement, appSettings); if (text == null) { return true; } return DocSkip.skipSign(appSettings, projectSettings, text); } - private static @Nullable String psiName(@Nullable PsiElement psiElement, AppSettingsState appSettings) { + private static @Nullable String psiName(@Nullable PsiElement psiElement, @NotNull AppSettingsState appSettings) { if (psiElement instanceof PsiClass) { - PsiClass psiClass = (PsiClass) psiElement; + @NotNull PsiClass psiClass = (PsiClass) psiElement; if (appSettings.skipAnnotation && psiClass.isAnnotationType()) { return null; } return psiClass.getQualifiedName(); } else if (psiElement instanceof PsiMember) { - PsiMember psiMember = (PsiMember) psiElement; - StringBuilder sb = new StringBuilder(); - PsiClass psiClass = psiMember.getContainingClass(); + @NotNull PsiMember psiMember = (PsiMember) psiElement; + @NotNull StringBuilder sb = new StringBuilder(); + @Nullable PsiClass psiClass = psiMember.getContainingClass(); if (psiClass != null) { - String className = psiClass.getQualifiedName(); + @Nullable String className = psiClass.getQualifiedName(); if (className != null) { sb.append(className); } } sb.append("#"); - String name = psiMember.getName(); + @Nullable String name = psiMember.getName(); if (name != null) { sb.append(name); } @@ -49,7 +51,8 @@ class SkipUtils { return null; } - static PsiDocComment skipDoc(PsiDocComment doc, AppSettingsState appSettings, ProjectSettingsState projectSettings) { + static PsiDocComment skipDoc(@Nullable PsiDocComment doc, @NotNull AppSettingsState appSettings, + @NotNull ProjectSettingsState projectSettings) { if (doc == null) { return null; } @@ -61,9 +64,9 @@ class SkipUtils { return skip ? null : doc; } - private static boolean isBlank(PsiDocComment doc) { - PsiElement[] elements = doc.getDescriptionElements(); - for (PsiElement element : elements) { + private static boolean isBlank(@NotNull PsiDocComment doc) { + @NotNull PsiElement[] elements = doc.getDescriptionElements(); + for (@NotNull PsiElement element : elements) { String text = element.getText(); if (StringUtils.isNotBlank(text)) { return false; diff --git a/src/main/java/io/github/linwancen/plugin/show/CopyReferenceSimple.java b/src/main/java/io/github/linwancen/plugin/show/CopyReferenceSimple.java index e5a0bfc..0e0b6f2 100644 --- a/src/main/java/io/github/linwancen/plugin/show/CopyReferenceSimple.java +++ b/src/main/java/io/github/linwancen/plugin/show/CopyReferenceSimple.java @@ -10,6 +10,7 @@ import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.List; import java.util.regex.Pattern; @@ -27,16 +28,17 @@ public class CopyReferenceSimple extends CopyReferenceAction { private static final Pattern QUALIFIED_PATTERN = Pattern.compile("[\\w.]+\\."); + @Nullable @Override - protected String getQualifiedName(Editor editor, List elements) { + protected String getQualifiedName(@NotNull Editor editor, List elements) { String qualifiedName = super.getQualifiedName(editor, elements); if (qualifiedName == null) { - Document document = editor.getDocument(); - Project project = editor.getProject(); + @NotNull Document document = editor.getDocument(); + @Nullable Project project = editor.getProject(); if (project == null) { return null; } - PsiFile file = PsiDocumentManager.getInstance(project).getCachedPsiFile(document); + @Nullable PsiFile file = PsiDocumentManager.getInstance(project).getCachedPsiFile(document); if (file != null) { // getFileFqn(file) => file.getName() return file.getName() + ":" + (editor.getCaretModel().getLogicalPosition().line + 1); diff --git a/src/main/java/io/github/linwancen/plugin/show/LineEnd.java b/src/main/java/io/github/linwancen/plugin/show/LineEnd.java index f211b39..055dc52 100644 --- a/src/main/java/io/github/linwancen/plugin/show/LineEnd.java +++ b/src/main/java/io/github/linwancen/plugin/show/LineEnd.java @@ -24,7 +24,7 @@ public class LineEnd extends EditorLinePainter { @Override public @Nullable Collection getLineExtensions(@NotNull Project project, @NotNull VirtualFile file, int lineNumber) { - AppSettingsState settings = AppSettingsState.getInstance(); + @NotNull AppSettingsState settings = AppSettingsState.getInstance(); if (!settings.showLineEndComment) { return null; } @@ -34,30 +34,30 @@ public class LineEnd extends EditorLinePainter { if (!file.exists()) { return null; } - LineInfo lineInfo = LineInfo.of(file, project, lineNumber); - String doc = lineDocSkipHave(lineInfo); + @Nullable LineInfo lineInfo = LineInfo.of(file, project, lineNumber); + @Nullable String doc = lineDocSkipHave(lineInfo); if (doc == null) { return null; } - TextAttributes textAttr = file.getFileType().equals(JsonFileType.INSTANCE) + @NotNull TextAttributes textAttr = file.getFileType().equals(JsonFileType.INSTANCE) || file.getFileType().equals(Json5FileType.INSTANCE) ? settings.lineEndJsonTextAttr : settings.lineEndTextAttr; - LineExtensionInfo info = new LineExtensionInfo(settings.lineEndPrefix + doc, textAttr); + @NotNull LineExtensionInfo info = new LineExtensionInfo(settings.lineEndPrefix + doc, textAttr); return Collections.singletonList(info); } @NotNull public static String textWithDoc(@NotNull FileInfo fileInfo, int startLine, int endLine) { - StringBuilder sb = new StringBuilder(); + @NotNull StringBuilder sb = new StringBuilder(); for (int i = startLine; i <= endLine; i++) { - LineInfo lineInfo = LineInfo.of(fileInfo, i); + @Nullable LineInfo lineInfo = LineInfo.of(fileInfo, i); if (lineInfo == null) { sb.append("\n"); continue; } sb.append(lineInfo.text); - String doc = lineDocSkipHave(lineInfo); + @Nullable String doc = lineDocSkipHave(lineInfo); if (doc != null) { sb.append(lineInfo.appSettings.lineEndPrefix).append(doc); } @@ -70,11 +70,11 @@ public class LineEnd extends EditorLinePainter { } private static @Nullable String lineDocSkipHave(@Nullable LineInfo lineInfo) { - String doc = lineDoc(lineInfo); + @Nullable String doc = lineDoc(lineInfo); if (doc == null) { return null; } - String trimDoc = doc.trim(); + @NotNull String trimDoc = doc.trim(); if (lineInfo.text.trim().endsWith(trimDoc)) { return null; } @@ -86,7 +86,7 @@ public class LineEnd extends EditorLinePainter { return null; } // override some text - String doc = LineExt.doc(lineInfo); + @Nullable String doc = LineExt.doc(lineInfo); if (doc != null) { return doc; } diff --git a/src/main/java/io/github/linwancen/plugin/show/LineEndAdd.java b/src/main/java/io/github/linwancen/plugin/show/LineEndAdd.java index 1d53708..f3b057f 100644 --- a/src/main/java/io/github/linwancen/plugin/show/LineEndAdd.java +++ b/src/main/java/io/github/linwancen/plugin/show/LineEndAdd.java @@ -13,6 +13,7 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileVisitor; import io.github.linwancen.plugin.show.bean.FileInfo; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * on ProjectViewPopupMenu @@ -21,22 +22,22 @@ public class LineEndAdd extends DumbAwareAction { @Override public void actionPerformed(@NotNull AnActionEvent event) { - Project project = event.getProject(); + @Nullable Project project = event.getProject(); if (project == null) { return; } - VirtualFile[] files = event.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY); + @Nullable VirtualFile[] files = event.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY); if (files == null) { return; } - ListPopup confirmation = JBPopupFactory.getInstance().createConfirmation( + @NotNull ListPopup confirmation = JBPopupFactory.getInstance().createConfirmation( "Add Line Comment?", "Add and replace files!", "Don't add.", () -> ApplicationManager.getApplication().runReadAction(() -> addDocAll(project, files)), 2); confirmation.showInFocusCenter(); } private void addDocAll(@NotNull Project project, @NotNull VirtualFile[] files) { - for (VirtualFile file : files) { + for (@NotNull VirtualFile file : files) { VfsUtilCore.visitChildrenRecursively(file, new VirtualFileVisitor() { @Override public boolean visitFile(@NotNull VirtualFile file) { @@ -50,13 +51,13 @@ public class LineEndAdd extends DumbAwareAction { } private void addDoc(@NotNull Project project, @NotNull VirtualFile file) { - FileInfo fileInfo = FileInfo.of(file, project); + @Nullable FileInfo fileInfo = FileInfo.of(file, project); if (fileInfo == null) { return; } int startLine = 0; int endLine = fileInfo.document.getLineCount() - 1; - String textWithDoc = LineEnd.textWithDoc(fileInfo, startLine, endLine); + @NotNull String textWithDoc = LineEnd.textWithDoc(fileInfo, startLine, endLine); WriteCommandAction.runWriteCommandAction(project, () -> fileInfo.document.replaceString(0, fileInfo.document.getTextLength() - 1, textWithDoc) ); diff --git a/src/main/java/io/github/linwancen/plugin/show/LineEndCopy.java b/src/main/java/io/github/linwancen/plugin/show/LineEndCopy.java index 8f840cd..fc33e65 100644 --- a/src/main/java/io/github/linwancen/plugin/show/LineEndCopy.java +++ b/src/main/java/io/github/linwancen/plugin/show/LineEndCopy.java @@ -9,6 +9,7 @@ import com.intellij.openapi.ide.CopyPasteManager; import com.intellij.openapi.project.DumbAwareAction; import io.github.linwancen.plugin.show.bean.FileInfo; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.awt.datatransfer.StringSelection; @@ -23,16 +24,16 @@ public class LineEndCopy extends DumbAwareAction { } private void copyWithDoc(@NotNull AnActionEvent event) { - FileInfo fileInfo = FileInfo.of(event); + @Nullable FileInfo fileInfo = FileInfo.of(event); if (fileInfo == null) { return; } int startLine = 0; int endLine = fileInfo.document.getLineCount() - 1; // if select - Editor editor = event.getData(CommonDataKeys.EDITOR); + @Nullable Editor editor = event.getData(CommonDataKeys.EDITOR); if (editor != null) { - Caret primaryCaret = editor.getCaretModel().getPrimaryCaret(); + @NotNull Caret primaryCaret = editor.getCaretModel().getPrimaryCaret(); int start = primaryCaret.getSelectionStart(); int end = primaryCaret.getSelectionEnd(); try { @@ -42,8 +43,8 @@ public class LineEndCopy extends DumbAwareAction { return; } } - String textWithDoc = LineEnd.textWithDoc(fileInfo, startLine, endLine); - StringSelection content = new StringSelection(textWithDoc); + @NotNull String textWithDoc = LineEnd.textWithDoc(fileInfo, startLine, endLine); + @NotNull StringSelection content = new StringSelection(textWithDoc); CopyPasteManager.getInstance().setContents(content); } } \ No newline at end of file diff --git a/src/main/java/io/github/linwancen/plugin/show/Tree.java b/src/main/java/io/github/linwancen/plugin/show/Tree.java index 3d3e461..09a6789 100644 --- a/src/main/java/io/github/linwancen/plugin/show/Tree.java +++ b/src/main/java/io/github/linwancen/plugin/show/Tree.java @@ -25,11 +25,11 @@ import java.util.List; public class Tree implements ProjectViewNodeDecorator { @Override - public void decorate(ProjectViewNode node, PresentationData data) { + public void decorate(@NotNull ProjectViewNode node, @NotNull PresentationData data) { if (!AppSettingsState.getInstance().showTreeComment) { return; } - Project project = node.getProject(); + @Nullable Project project = node.getProject(); if (project == null) { return; } @@ -37,11 +37,11 @@ public class Tree implements ProjectViewNodeDecorator { return; } ApplicationManager.getApplication().runReadAction(() -> { - String doc = treeDoc(node, project); + @Nullable String doc = treeDoc(node, project); if (doc == null) { return; } - List coloredText = data.getColoredText(); + @NotNull List coloredText = data.getColoredText(); if (coloredText.isEmpty()) { data.addText(data.getPresentableText(), SimpleTextAttributes.REGULAR_ATTRIBUTES); } @@ -50,23 +50,23 @@ public class Tree implements ProjectViewNodeDecorator { } @Nullable - private String treeDoc(ProjectViewNode node, @NotNull Project project) { - String doc = TreeExt.doc(node); + private String treeDoc(@NotNull ProjectViewNode node, @NotNull Project project) { + @Nullable String doc = TreeExt.doc(node); if (doc != null) { return doc; } - SettingsInfo settingsInfo = SettingsInfo.of(project, FuncEnum.TREE); + @NotNull SettingsInfo settingsInfo = SettingsInfo.of(project, FuncEnum.TREE); Object value = node.getValue(); if (value instanceof PsiElement) { - PsiElement psiElement = (PsiElement) value; - String docPrint = BaseLangDoc.resolveDoc(settingsInfo, psiElement); + @NotNull PsiElement psiElement = (PsiElement) value; + @Nullable String docPrint = BaseLangDoc.resolveDoc(settingsInfo, psiElement); if (docPrint != null) { return docPrint; } } - Collection langDocs = BaseLangDoc.LANG_DOC_MAP.values(); - for (BaseLangDoc langDoc : langDocs) { - String s = langDoc.treeDoc(settingsInfo, node, project); + @NotNull Collection langDocs = BaseLangDoc.LANG_DOC_MAP.values(); + for (@NotNull BaseLangDoc langDoc : langDocs) { + @Nullable String s = langDoc.treeDoc(settingsInfo, node, project); if (s != null) { return s; } diff --git a/src/main/java/io/github/linwancen/plugin/show/bean/FileInfo.java b/src/main/java/io/github/linwancen/plugin/show/bean/FileInfo.java index 564b50e..48a8662 100644 --- a/src/main/java/io/github/linwancen/plugin/show/bean/FileInfo.java +++ b/src/main/java/io/github/linwancen/plugin/show/bean/FileInfo.java @@ -27,30 +27,30 @@ public class FileInfo extends SettingsInfo { this.document = document; } - public static @Nullable FileInfo of(@NotNull VirtualFile file, @NotNull Project project){ - Document document = FileDocumentManager.getInstance().getDocument(file); + public static @Nullable FileInfo of(@NotNull VirtualFile file, @NotNull Project project) { + @Nullable Document document = FileDocumentManager.getInstance().getDocument(file); if (document == null) { return null; } - FileViewProvider viewProvider = PsiManager.getInstance(project).findViewProvider(file); + @Nullable FileViewProvider viewProvider = PsiManager.getInstance(project).findViewProvider(file); if (viewProvider == null) { return null; } return new FileInfo(file, document, project, viewProvider, FuncEnum.LINE); } - public static @Nullable FileInfo of(@NotNull AnActionEvent event){ - PsiFile psiFile = event.getData(CommonDataKeys.PSI_FILE); + public static @Nullable FileInfo of(@NotNull AnActionEvent event) { + @Nullable PsiFile psiFile = event.getData(CommonDataKeys.PSI_FILE); if (psiFile == null) { return null; } - FileViewProvider viewProvider = psiFile.getViewProvider(); - Document document = viewProvider.getDocument(); + @NotNull FileViewProvider viewProvider = psiFile.getViewProvider(); + @Nullable Document document = viewProvider.getDocument(); if (document == null) { return null; } - VirtualFile file = viewProvider.getVirtualFile(); - Project project = psiFile.getProject(); + @NotNull VirtualFile file = viewProvider.getVirtualFile(); + @NotNull Project project = psiFile.getProject(); return new FileInfo(file, document, project, viewProvider, FuncEnum.LINE); } } diff --git a/src/main/java/io/github/linwancen/plugin/show/bean/FuncEnum.java b/src/main/java/io/github/linwancen/plugin/show/bean/FuncEnum.java index 60d1478..61cde1a 100644 --- a/src/main/java/io/github/linwancen/plugin/show/bean/FuncEnum.java +++ b/src/main/java/io/github/linwancen/plugin/show/bean/FuncEnum.java @@ -1,9 +1,11 @@ package io.github.linwancen.plugin.show.bean; +import org.jetbrains.annotations.NotNull; + import java.util.LinkedHashMap; public enum FuncEnum { - /** tree: project view tree */ + /** tree: project view tree */ TREE("tree", "project view tree"), /** line: code line end */ LINE("line", "code line end"), @@ -17,16 +19,18 @@ public enum FuncEnum { this.desc = desc; } + @NotNull @Override public String toString() { return code + '-' + desc; } + @NotNull private static final LinkedHashMap map; static { map = new LinkedHashMap<>(); - for (FuncEnum value : values()) { + for (@NotNull FuncEnum value : values()) { map.put(value.code, value); } } diff --git a/src/main/java/io/github/linwancen/plugin/show/bean/LineInfo.java b/src/main/java/io/github/linwancen/plugin/show/bean/LineInfo.java index 316ede5..9dba4d9 100644 --- a/src/main/java/io/github/linwancen/plugin/show/bean/LineInfo.java +++ b/src/main/java/io/github/linwancen/plugin/show/bean/LineInfo.java @@ -22,7 +22,7 @@ public class LineInfo extends FileInfo { } public static @Nullable LineInfo of(@NotNull VirtualFile file, @NotNull Project project, int lineNumber) { - FileInfo fileInfo = of(file, project); + @Nullable FileInfo fileInfo = of(file, project); if (fileInfo == null) { return null; } @@ -40,7 +40,7 @@ public class LineInfo extends FileInfo { if (startOffset == endOffset) { return null; } - String text = fileInfo.document.getText(new TextRange(startOffset, endOffset)); + @NotNull String text = fileInfo.document.getText(new TextRange(startOffset, endOffset)); return new LineInfo(fileInfo, text, lineNumber, startOffset, endOffset); } catch (Exception e) { return null; diff --git a/src/main/java/io/github/linwancen/plugin/show/bean/SettingsInfo.java b/src/main/java/io/github/linwancen/plugin/show/bean/SettingsInfo.java index fc8bb59..daf18ac 100644 --- a/src/main/java/io/github/linwancen/plugin/show/bean/SettingsInfo.java +++ b/src/main/java/io/github/linwancen/plugin/show/bean/SettingsInfo.java @@ -16,11 +16,12 @@ public class SettingsInfo { this.projectSettings = ProjectSettingsState.getInstance(project); } - public static @NotNull SettingsInfo of(@NotNull Project project, FuncEnum funcEnum) { + public static @NotNull SettingsInfo of(@NotNull Project project, @NotNull FuncEnum funcEnum) { return new SettingsInfo(project, funcEnum); } /** treeTags/lineTags */ + @NotNull public String[] tagNames() { return funcEnum == FuncEnum.TREE ? appSettings.treeTags diff --git a/src/main/java/io/github/linwancen/plugin/show/ext/GetFromDocMap.java b/src/main/java/io/github/linwancen/plugin/show/ext/GetFromDocMap.java index c01a4f3..62f4015 100644 --- a/src/main/java/io/github/linwancen/plugin/show/ext/GetFromDocMap.java +++ b/src/main/java/io/github/linwancen/plugin/show/ext/GetFromDocMap.java @@ -13,7 +13,7 @@ class GetFromDocMap { @Nullable static String get(@NotNull Map>> docMap, @NotNull String... words) { - List keywordDoc = list(docMap, words); + @NotNull List keywordDoc = list(docMap, words); if (keywordDoc.size() >= 2) { return keywordDoc.get(1); } @@ -22,7 +22,7 @@ class GetFromDocMap { @NotNull private static List list(@NotNull Map>> docMap, @NotNull String... words) { - for (Map.Entry>> entry : docMap.entrySet()) { + for (@NotNull Map.Entry>> entry : docMap.entrySet()) { Map> map = entry.getValue(); for (String word : words) { List wordDoc = map.get(word); diff --git a/src/main/java/io/github/linwancen/plugin/show/ext/LineExt.java b/src/main/java/io/github/linwancen/plugin/show/ext/LineExt.java index c09b64b..53c137b 100644 --- a/src/main/java/io/github/linwancen/plugin/show/ext/LineExt.java +++ b/src/main/java/io/github/linwancen/plugin/show/ext/LineExt.java @@ -16,8 +16,8 @@ public class LineExt { public static @Nullable String doc(@NotNull LineInfo lineInfo) { int i = lineInfo.text.indexOf(lineInfo.appSettings.lineEndPrefix); - String code = i <= 0 ? lineInfo.text : lineInfo.text.substring(0, i); - String extDoc = LineExt.extDoc(lineInfo, code); + @NotNull String code = i <= 0 ? lineInfo.text : lineInfo.text.substring(0, i); + @Nullable String extDoc = LineExt.extDoc(lineInfo, code); if (extDoc == null) { return null; } @@ -28,20 +28,21 @@ public class LineExt { return extDoc; } + @Nullable public static String extDoc(@NotNull LineInfo lineInfo, @NotNull String code) { - String path = lineInfo.file.getPath(); - String name = lineInfo.file.getName(); - String ext = lineInfo.file.getExtension(); - Map>> keyMap = ConfCache.keyMap(path, name, ext); + @NotNull String path = lineInfo.file.getPath(); + @NotNull String name = lineInfo.file.getName(); + @Nullable String ext = lineInfo.file.getExtension(); + @NotNull Map>> keyMap = ConfCache.keyMap(path, name, ext); if (keyMap.isEmpty()) { return null; } - Pattern pattern = ConfCache.pattern(lineInfo.project, keyMap, path); + @Nullable Pattern pattern = ConfCache.pattern(lineInfo.project, keyMap, path); if (pattern == null || pattern.pattern().length() == 0) { return null; } - Map>> docMap = ConfCache.docMap(path, name, ext); - Map>> treeMap = ConfCache.treeMap(path, name, ext); + @NotNull Map>> docMap = ConfCache.docMap(path, name, ext); + @NotNull Map>> treeMap = ConfCache.treeMap(path, name, ext); if (docMap.isEmpty() && treeMap.isEmpty()) { return null; } @@ -49,7 +50,7 @@ public class LineExt { code = cblNotAndOr(code); } String[] words = pattern.split(code); - Matcher matcher = pattern.matcher(code); + @NotNull Matcher matcher = pattern.matcher(code); return extDoc(keyMap, matcher, docMap, words, treeMap); } @@ -57,12 +58,12 @@ public class LineExt { private static final Pattern AND_OR_PATTERN = Pattern.compile("(AND|OR) ?'"); @NotNull - private static String cblNotAndOr(String text) { + private static String cblNotAndOr(@NotNull String text) { // maybe faster than regexp if (!text.contains("=")) { return text; } - Matcher matcher = DICT_PATTERN.matcher(text); + @NotNull Matcher matcher = DICT_PATTERN.matcher(text); if (!matcher.find()) { return text; } @@ -81,13 +82,13 @@ public class LineExt { @NotNull Map>> treeMap) { boolean haveDoc = false; boolean haveKey = false; - StringBuilder sb = new StringBuilder(); - for (String s : words) { + @NotNull StringBuilder sb = new StringBuilder(); + for (@NotNull String s : words) { haveDoc |= appendDoc(sb, s, docMap, treeMap); haveKey = appendKeyDoc(sb, matcher, keyMap); } while (haveKey) { - haveKey = appendKeyDoc(sb, matcher, keyMap); + haveKey = appendKeyDoc(sb, matcher, keyMap); } if (!haveDoc) { return null; @@ -102,12 +103,12 @@ public class LineExt { if (word.length() == 0) { return false; } - String wordDoc = GetFromDocMap.get(docMap, word); + @Nullable String wordDoc = GetFromDocMap.get(docMap, word); if (wordDoc != null) { sb.append(wordDoc); return true; } - String treeDoc = GetFromDocMap.get(treeMap, word); + @Nullable String treeDoc = GetFromDocMap.get(treeMap, word); if (treeDoc != null) { sb.append(treeDoc); return true; @@ -118,14 +119,14 @@ public class LineExt { } private static boolean appendKeyDoc(@NotNull StringBuilder sb, - @NotNull Matcher matcher, - @NotNull Map>> keyMap) { + @NotNull Matcher matcher, + @NotNull Map>> keyMap) { if (!matcher.find()) { return false; } String keyword = matcher.group(); // "" if no doc - String keyDoc = GetFromDocMap.get(keyMap, keyword); + @Nullable String keyDoc = GetFromDocMap.get(keyMap, keyword); if (keyDoc != null) { sb.append(" ").append(keyDoc); } diff --git a/src/main/java/io/github/linwancen/plugin/show/ext/TreeExt.java b/src/main/java/io/github/linwancen/plugin/show/ext/TreeExt.java index 0bae0ae..8464246 100644 --- a/src/main/java/io/github/linwancen/plugin/show/ext/TreeExt.java +++ b/src/main/java/io/github/linwancen/plugin/show/ext/TreeExt.java @@ -13,21 +13,23 @@ public class TreeExt { private TreeExt() {} - public static @Nullable String doc(ProjectViewNode node) { - VirtualFile file = node.getVirtualFile(); + public static @Nullable String doc(@NotNull ProjectViewNode node) { + @Nullable VirtualFile file = node.getVirtualFile(); if (file == null) { return null; } return TreeExt.extDoc(file); } + @Nullable public static String extDoc(@NotNull VirtualFile file) { - Map>> docMap = ConfCache.treeMap(file.getPath(), file.getName(), file.getPath()); - String[] words = { + @NotNull Map>> docMap = ConfCache.treeMap( + file.getPath(), file.getName(), file.getPath()); + @NotNull String[] words = { file.getName(), file.getNameWithoutExtension(), }; - String extDoc = GetFromDocMap.get(docMap, words); + @Nullable String extDoc = GetFromDocMap.get(docMap, words); if (extDoc == null) { return null; } diff --git a/src/main/java/io/github/linwancen/plugin/show/ext/conf/ConfCache.java b/src/main/java/io/github/linwancen/plugin/show/ext/conf/ConfCache.java index aea67c5..6d3c810 100644 --- a/src/main/java/io/github/linwancen/plugin/show/ext/conf/ConfCache.java +++ b/src/main/java/io/github/linwancen/plugin/show/ext/conf/ConfCache.java @@ -76,7 +76,7 @@ public class ConfCache { TREE_CACHE.clear(); } - static void remove(@NotNull VirtualFile file, String name) { + static void remove(@NotNull VirtualFile file, @Nullable String name) { if (name != null) { int i = name.lastIndexOf('.'); name = name.substring(0, i); @@ -93,7 +93,7 @@ public class ConfCache { } static void copy(@NotNull VirtualFile file, @NotNull VirtualFile newFile) { - String name = file.getNameWithoutExtension(); + @NotNull String name = file.getNameWithoutExtension(); if (name.endsWith(KEY_MID_EXT)) { copyCache(file, newFile, KEY_CACHE); } else if (name.endsWith(DOC_MID_EXT)) { @@ -117,9 +117,9 @@ public class ConfCache { static void loadAll(@NotNull Project project) { DumbService.getInstance(project).runReadActionInSmartMode(() -> ApplicationManager.getApplication().runReadAction(() -> { - Collection files = FilenameIndex.getAllFilesByExt(project, EXT); - StringBuilder sb = new StringBuilder(); - for (VirtualFile file : files) { + @NotNull Collection files = FilenameIndex.getAllFilesByExt(project, EXT); + @NotNull StringBuilder sb = new StringBuilder(); + for (@NotNull VirtualFile file : files) { load(project, file); sb.append(file.getName()).append("\n"); } @@ -139,16 +139,16 @@ public class ConfCache { if (!ConfCache.EXT.equals(file.getExtension())) { return; } - Document document = FileDocumentManager.getInstance().getDocument(file); + @Nullable Document document = FileDocumentManager.getInstance().getDocument(file); if (document == null) { return; } - String text = document.getText(); - String name = file.getNameWithoutExtension(); + @NotNull String text = document.getText(); + @NotNull String name = file.getNameWithoutExtension(); // this pattern would skip empty line String[] lines = LINE_PATTERN.split(text); if (name.endsWith(KEY_MID_EXT)) { - String matchName = name.substring(0, name.length() - KEY_MID_EXT.length()); + @NotNull String matchName = name.substring(0, name.length() - KEY_MID_EXT.length()); int i = matchName.lastIndexOf("."); if (i > 0) { EXT_IN_KEY_CACHE.add(matchName.substring(i + 1)); diff --git a/src/main/java/io/github/linwancen/plugin/show/ext/conf/ConfCacheGetUtils.java b/src/main/java/io/github/linwancen/plugin/show/ext/conf/ConfCacheGetUtils.java index 20130ff..0c4c79e 100644 --- a/src/main/java/io/github/linwancen/plugin/show/ext/conf/ConfCacheGetUtils.java +++ b/src/main/java/io/github/linwancen/plugin/show/ext/conf/ConfCacheGetUtils.java @@ -32,13 +32,13 @@ class ConfCacheGetUtils { static TreeMap filterPathNameExt(@NotNull String confMidExt, @NotNull Map cache, @NotNull String path, @NotNull String name, @Nullable String ext) { - TreeMap map = new TreeMap<>(); + @NotNull TreeMap map = new TreeMap<>(); int max = path.length(); int length = String.valueOf(max).length(); - for (Map.Entry entry : cache.entrySet()) { + for (@NotNull Map.Entry entry : cache.entrySet()) { VirtualFile confFile = entry.getKey(); - String confName = confFile.getNameWithoutExtension(); - String confPath = confFile.getPath(); + @NotNull String confName = confFile.getNameWithoutExtension(); + @NotNull String confPath = confFile.getPath(); int level = level(path, confPath); if (level == 0) { continue; @@ -76,12 +76,12 @@ class ConfCacheGetUtils { static TreeMap filterPath(@SuppressWarnings("SameParameterValue") @NotNull Map cache, @NotNull String path, String name, String ext) { - TreeMap map = new TreeMap<>(); + @NotNull TreeMap map = new TreeMap<>(); int max = path.length(); int length = String.valueOf(max).length(); - for (Map.Entry entry : cache.entrySet()) { + for (@NotNull Map.Entry entry : cache.entrySet()) { VirtualFile confFile = entry.getKey(); - String confPath = confFile.getPath(); + @NotNull String confPath = confFile.getPath(); int level = level(path, confPath); if (level == 0) { continue; @@ -119,7 +119,7 @@ class ConfCacheGetUtils { } @NotNull - private static String srcPath(String path) { + private static String srcPath(@NotNull String path) { int i = path.indexOf('!'); if (i != -1) { return path.substring(i + 1); @@ -131,7 +131,7 @@ class ConfCacheGetUtils { return path; } - private static boolean match(String path, String confPath) { + private static boolean match(@NotNull String path, @NotNull String confPath) { if (confPath.equals(path) || SKIP_PATH.equals(confPath)) { return true; } diff --git a/src/main/java/io/github/linwancen/plugin/show/ext/conf/ConfFactory.java b/src/main/java/io/github/linwancen/plugin/show/ext/conf/ConfFactory.java index 84bba8d..effffce 100644 --- a/src/main/java/io/github/linwancen/plugin/show/ext/conf/ConfFactory.java +++ b/src/main/java/io/github/linwancen/plugin/show/ext/conf/ConfFactory.java @@ -29,11 +29,11 @@ class ConfFactory { @Nullable static Pattern buildPattern(@Nullable Project project, @NotNull String path, @NotNull Map>> map) { - Set exclude = new LinkedSet<>(); - StringBuilder sb = new StringBuilder(); - for (Map> keyMap : map.values()) { + @NotNull Set exclude = new LinkedSet<>(); + @NotNull StringBuilder sb = new StringBuilder(); + for (@NotNull Map> keyMap : map.values()) { // key() is escape - for (List list : keyMap.values()) { + for (@NotNull List list : keyMap.values()) { String key = list.get(0); if (key.startsWith("?")) { exclude.add(key.substring(1)); @@ -45,7 +45,7 @@ class ConfFactory { if (sb.length() > 0) { sb.delete(sb.length() - 1, sb.length()); } - String regex = sb.toString(); + @NotNull String regex = sb.toString(); Pattern pattern = PATTERN_CACHE.get(regex); if (pattern != null) { return pattern; @@ -54,7 +54,7 @@ class ConfFactory { sb.insert(0, path); sb.insert(0, "\n"); try { - Pattern compile = Pattern.compile(regex); + @NotNull Pattern compile = Pattern.compile(regex); PATTERN_CACHE.put(regex, compile); REGEXP_LOG.createNotification("Ext doc keyword regexp compile success", regex.length() + " chars", sb.toString(), NotificationType.INFORMATION).notify(project); @@ -74,9 +74,9 @@ class ConfFactory { @NotNull static Map> buildMap(@Nullable Project project, @NotNull String path, @NotNull String[] lines, boolean isKey) { - Map> map = new LinkedHashMap<>(); - for (String line : lines) { - List words = Splitter.on('\t').splitToList(line); + @NotNull Map> map = new LinkedHashMap<>(); + for (@NotNull String line : lines) { + @NotNull List words = Splitter.on('\t').splitToList(line); if (!words.isEmpty()) { String key = words.get(0); if (key.length() == 0) { diff --git a/src/main/java/io/github/linwancen/plugin/show/ext/conf/ConfFileChangeListener.java b/src/main/java/io/github/linwancen/plugin/show/ext/conf/ConfFileChangeListener.java index fc802a8..0f13696 100644 --- a/src/main/java/io/github/linwancen/plugin/show/ext/conf/ConfFileChangeListener.java +++ b/src/main/java/io/github/linwancen/plugin/show/ext/conf/ConfFileChangeListener.java @@ -4,6 +4,7 @@ import com.intellij.openapi.fileEditor.FileEditorManagerEvent; import com.intellij.openapi.fileEditor.FileEditorManagerListener; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * call ConfCache.loadFile @@ -12,7 +13,7 @@ public class ConfFileChangeListener implements FileEditorManagerListener { @Override public void selectionChanged(@NotNull FileEditorManagerEvent event) { - VirtualFile file = event.getOldFile(); + @Nullable VirtualFile file = event.getOldFile(); if (file == null) { return; } diff --git a/src/main/java/io/github/linwancen/plugin/show/ext/conf/ConfFileListener.java b/src/main/java/io/github/linwancen/plugin/show/ext/conf/ConfFileListener.java index a5cde1f..7e44182 100644 --- a/src/main/java/io/github/linwancen/plugin/show/ext/conf/ConfFileListener.java +++ b/src/main/java/io/github/linwancen/plugin/show/ext/conf/ConfFileListener.java @@ -4,6 +4,7 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.newvfs.BulkFileListener; import com.intellij.openapi.vfs.newvfs.events.*; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.List; @@ -14,18 +15,18 @@ public class ConfFileListener implements BulkFileListener { @Override public void after(@NotNull List events) { - for (VFileEvent event : events) { + for (@NotNull VFileEvent event : events) { forEvent(event); } } - private static void forEvent(VFileEvent event) { - VirtualFile file = event.getFile(); + private static void forEvent(@NotNull VFileEvent event) { + @Nullable VirtualFile file = event.getFile(); if (file == null) { return; } if (event instanceof VFilePropertyChangeEvent) { - VFilePropertyChangeEvent changeEvent = (VFilePropertyChangeEvent) event; + @NotNull VFilePropertyChangeEvent changeEvent = (VFilePropertyChangeEvent) event; if ("name".equals(changeEvent.getPropertyName())) { String oldName = changeEvent.getOldValue().toString(); if (oldName.endsWith(ConfCache.EXT)) { @@ -45,8 +46,8 @@ public class ConfFileListener implements BulkFileListener { return; } if (event instanceof VFileCopyEvent) { - VFileCopyEvent copyEvent = (VFileCopyEvent) event; - VirtualFile newFile = copyEvent.findCreatedFile(); + @NotNull VFileCopyEvent copyEvent = (VFileCopyEvent) event; + @Nullable VirtualFile newFile = copyEvent.findCreatedFile(); if (newFile == null) { return; } diff --git a/src/main/java/io/github/linwancen/plugin/show/ext/conf/ReloadExtDocAction.java b/src/main/java/io/github/linwancen/plugin/show/ext/conf/ReloadExtDocAction.java index 4272c72..9d9fd06 100644 --- a/src/main/java/io/github/linwancen/plugin/show/ext/conf/ReloadExtDocAction.java +++ b/src/main/java/io/github/linwancen/plugin/show/ext/conf/ReloadExtDocAction.java @@ -4,6 +4,7 @@ import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.project.Project; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * call ConfCache.loadAll @@ -11,7 +12,7 @@ import org.jetbrains.annotations.NotNull; public class ReloadExtDocAction extends AnAction { @Override public void actionPerformed(@NotNull AnActionEvent e) { - Project project = e.getProject(); + @Nullable Project project = e.getProject(); if (project == null) { return; } diff --git a/src/main/java/io/github/linwancen/plugin/show/jump/JsonRef.java b/src/main/java/io/github/linwancen/plugin/show/jump/JsonRef.java index b34df07..de127cd 100644 --- a/src/main/java/io/github/linwancen/plugin/show/jump/JsonRef.java +++ b/src/main/java/io/github/linwancen/plugin/show/jump/JsonRef.java @@ -8,7 +8,9 @@ import java.util.List; public class JsonRef extends PsiReferenceBase implements PsiPolyVariantReference { + @NotNull final T psiField; + @NotNull final List tips; public JsonRef(@NotNull PsiElement element, @NotNull T psiField, @NotNull List tips) { diff --git a/src/main/java/io/github/linwancen/plugin/show/lang/GoLangDoc.java b/src/main/java/io/github/linwancen/plugin/show/lang/GoLangDoc.java index 23832d6..3b76728 100644 --- a/src/main/java/io/github/linwancen/plugin/show/lang/GoLangDoc.java +++ b/src/main/java/io/github/linwancen/plugin/show/lang/GoLangDoc.java @@ -31,7 +31,7 @@ public class GoLangDoc extends BaseLangDoc { @Override public @Nullable String resolveDocRaw(@NotNull T lineInfo, @NotNull PsiElement resolve) { - List comments = GoDocumentationProvider.getCommentsForElement(resolve); + @NotNull List comments = GoDocumentationProvider.getCommentsForElement(resolve); return GoDocumentationProvider.getCommentText(comments, false); } } diff --git a/src/main/java/io/github/linwancen/plugin/show/lang/JsLangDoc.java b/src/main/java/io/github/linwancen/plugin/show/lang/JsLangDoc.java index 7ad174b..30ce8d8 100644 --- a/src/main/java/io/github/linwancen/plugin/show/lang/JsLangDoc.java +++ b/src/main/java/io/github/linwancen/plugin/show/lang/JsLangDoc.java @@ -29,12 +29,12 @@ public class JsLangDoc extends BaseLangDoc { @Override public @Nullable String resolveDocRaw(@NotNull T lineInfo, @NotNull PsiElement resolve) { - PsiComment psiComment = JSDocumentationUtils.findOwnDocCommentForImplicitElement(resolve); + @Nullable PsiComment psiComment = JSDocumentationUtils.findOwnDocCommentForImplicitElement(resolve); if (psiComment == null) { return null; } String text = psiComment.getText(); - if (text!=null) { + if (text != null) { return text; } if (!lineInfo.appSettings.jsDoc) { diff --git a/src/main/java/io/github/linwancen/plugin/show/lang/JsonLangDoc.java b/src/main/java/io/github/linwancen/plugin/show/lang/JsonLangDoc.java index 789053e..5dd737e 100644 --- a/src/main/java/io/github/linwancen/plugin/show/lang/JsonLangDoc.java +++ b/src/main/java/io/github/linwancen/plugin/show/lang/JsonLangDoc.java @@ -25,7 +25,7 @@ public class JsonLangDoc extends BaseLangDoc { @Override public @Nullable String findRefDoc(@NotNull LineInfo lineInfo, @NotNull PsiElement element) { - PsiElement start = lineInfo.viewProvider.findElementAt(lineInfo.startOffset); + @Nullable PsiElement start = lineInfo.viewProvider.findElementAt(lineInfo.startOffset); if (start == null) { return null; } @@ -41,10 +41,10 @@ public class JsonLangDoc extends BaseLangDoc { if (!(ref instanceof JsonProperty)) { return null; } - JsonProperty jsonProperty = (JsonProperty) ref; - PsiReference[] references = jsonProperty.getNameElement().getReferences(); - for (PsiReference reference : references) { - PsiElement resolve = null; + @NotNull JsonProperty jsonProperty = (JsonProperty) ref; + @NotNull PsiReference[] references = jsonProperty.getNameElement().getReferences(); + for (@NotNull PsiReference reference : references) { + @Nullable PsiElement resolve = null; try { resolve = reference.resolve(); } catch (Throwable ignore) { @@ -53,7 +53,7 @@ public class JsonLangDoc extends BaseLangDoc { if (resolve == null) { continue; } - String doc = BaseLangDoc.resolveDoc(lineInfo, resolve); + @Nullable String doc = BaseLangDoc.resolveDoc(lineInfo, resolve); if (doc != null) { return doc; } diff --git a/src/main/java/io/github/linwancen/plugin/show/lang/SqlLangDoc.java b/src/main/java/io/github/linwancen/plugin/show/lang/SqlLangDoc.java index f6bf7a1..585cc8f 100644 --- a/src/main/java/io/github/linwancen/plugin/show/lang/SqlLangDoc.java +++ b/src/main/java/io/github/linwancen/plugin/show/lang/SqlLangDoc.java @@ -39,8 +39,8 @@ public class SqlLangDoc extends BaseLangDoc { } catch (Throwable e) { return null; } - for (DbElement dbElement : relatedDbElements) { - String refDoc = dbElement.getComment(); + for (@NotNull DbElement dbElement : relatedDbElements) { + @Nullable String refDoc = dbElement.getComment(); if (refDoc != null && !DocSkip.skipDoc(lineInfo.appSettings, lineInfo.projectSettings, refDoc)) { return refDoc; } diff --git a/src/main/java/io/github/linwancen/plugin/show/lang/base/BaseLangDoc.java b/src/main/java/io/github/linwancen/plugin/show/lang/base/BaseLangDoc.java index 9d68596..99adab5 100644 --- a/src/main/java/io/github/linwancen/plugin/show/lang/base/BaseLangDoc.java +++ b/src/main/java/io/github/linwancen/plugin/show/lang/base/BaseLangDoc.java @@ -41,7 +41,7 @@ public abstract class BaseLangDoc extends EditorLinePainter { } public static @Nullable String langDoc(@NotNull LineInfo lineInfo) { - PsiElement element = lineInfo.viewProvider.findElementAt(lineInfo.endOffset); + @Nullable PsiElement element = lineInfo.viewProvider.findElementAt(lineInfo.endOffset); if (element == null) { // file end element = lineInfo.viewProvider.findElementAt(lineInfo.endOffset - 1); @@ -49,7 +49,7 @@ public abstract class BaseLangDoc extends EditorLinePainter { return null; } } - Language language = PsiElementTo.language(element); + @NotNull Language language = PsiElementTo.language(element); BaseLangDoc lineEnd = LANG_DOC_MAP.get(language.getID()); if (lineEnd != null && lineEnd.show(lineInfo)) { return lineEnd.findRefDoc(lineInfo, element); @@ -64,15 +64,15 @@ public abstract class BaseLangDoc extends EditorLinePainter { */ @Nullable public String findRefDoc(@NotNull LineInfo lineInfo, @NotNull PsiElement element) { - Class refClass = getRefClass(); + @Nullable Class refClass = getRefClass(); if (refClass == null) { return null; } - String doc = null; - PsiElement refElement = element; + @Nullable String doc = null; + @Nullable PsiElement refElement = element; while ((refElement = Prev.prevRefChild(lineInfo, refElement, refClass)) != null) { PsiElement parent = refElement.getParent(); - String filterDoc = refElementDoc(lineInfo, parent); + @Nullable String filterDoc = refElementDoc(lineInfo, parent); if (filterDoc != null) { doc = filterDoc; refElement = parent; @@ -90,7 +90,7 @@ public abstract class BaseLangDoc extends EditorLinePainter { String text = refElement.getText(); boolean set = text.startsWith("set"); PsiElement parent = refElement.getParent(); - String before = refElementDoc(lineInfo, parent); + @Nullable String before = refElementDoc(lineInfo, parent); if (before != null) { doc = mergeDoc(set, lineInfo.appSettings.getToSet, before, doc); } @@ -115,9 +115,10 @@ public abstract class BaseLangDoc extends EditorLinePainter { /** * Override like SQL */ + @Nullable protected String refElementDoc(@NotNull T lineInfo, @NotNull PsiElement refElement) { - String refDoc = refDoc(lineInfo, refElement); + @Nullable String refDoc = refDoc(lineInfo, refElement); if (refDoc != null && !DocSkip.skipDoc(lineInfo.appSettings, lineInfo.projectSettings, refDoc)) { return refDoc; } @@ -130,22 +131,23 @@ public abstract class BaseLangDoc extends EditorLinePainter { @Nullable protected String refDoc(@NotNull T lineInfo, @NotNull PsiElement ref) { // kotlin ref.getReference() == null but ref.getReferences().length == 2 - PsiReference[] references = ref.getReferences(); + @NotNull PsiReference[] references = ref.getReferences(); if (references.length < 1) { return null; } - for (PsiReference reference : references) { - PsiElement resolve; + for (@NotNull PsiReference reference : references) { + @Nullable PsiElement resolve; try { resolve = reference.resolve(); } catch (Throwable e) { - // 2021.3: Slow operations are prohibited on EDT. See SlowOperations.assertSlowOperationsAreAllowed javadoc. + // 2021.3: Slow operations are prohibited on EDT. + // See SlowOperations.assertSlowOperationsAreAllowed javadoc. return null; } if (resolve == null) { return null; } - String resolveDoc = resolveDoc(lineInfo, resolve); + @Nullable String resolveDoc = resolveDoc(lineInfo, resolve); if (resolveDoc != null) { return resolveDoc; } @@ -153,9 +155,10 @@ public abstract class BaseLangDoc extends EditorLinePainter { return null; } - public static @Nullable String resolveDoc(T settingsInfo, PsiElement psiElement) { + public static @Nullable String resolveDoc(@NotNull T settingsInfo, + @NotNull PsiElement psiElement) { // support like java <-> kotlin - Language language = PsiElementTo.language(psiElement); + @NotNull Language language = PsiElementTo.language(psiElement); BaseLangDoc lineEnd = LANG_DOC_MAP.get(language.getID()); if (lineEnd == null) { return null; @@ -168,12 +171,12 @@ public abstract class BaseLangDoc extends EditorLinePainter { */ @Nullable protected String resolveDocPrint(@NotNull T lineInfo, @NotNull PsiElement resolve) { - String s = resolveDocRaw(lineInfo, resolve); + @Nullable String s = resolveDocRaw(lineInfo, resolve); if (s == null) { return null; } - String cutDoc = DocFilter.cutDoc(s, lineInfo.appSettings, true); - String filterDoc = DocFilter.filterDoc(cutDoc, lineInfo.appSettings, lineInfo.projectSettings); + @NotNull String cutDoc = DocFilter.cutDoc(s, lineInfo.appSettings, true); + @NotNull String filterDoc = DocFilter.filterDoc(cutDoc, lineInfo.appSettings, lineInfo.projectSettings); if (filterDoc.trim().length() == 0) { return null; } @@ -185,17 +188,18 @@ public abstract class BaseLangDoc extends EditorLinePainter { */ @Nullable protected String resolveDocRaw(@NotNull T lineInfo, @NotNull PsiElement resolve) { - FileViewProvider viewProvider = PsiElementTo.viewProvider(resolve); + @Nullable FileViewProvider viewProvider = PsiElementTo.viewProvider(resolve); if (viewProvider == null) { return null; } - String doc = ResolveDoc.fromLineEnd(lineInfo, resolve, viewProvider); + @Nullable String doc = ResolveDoc.fromLineEnd(lineInfo, resolve, viewProvider); if (doc != null) { return doc; } return ResolveDoc.fromLineUp(lineInfo, resolve, viewProvider, keywords()); } + @NotNull protected List keywords() { return Collections.emptyList(); } diff --git a/src/main/java/io/github/linwancen/plugin/show/lang/base/BaseTagLangDoc.java b/src/main/java/io/github/linwancen/plugin/show/lang/base/BaseTagLangDoc.java index b701fb5..c027387 100644 --- a/src/main/java/io/github/linwancen/plugin/show/lang/base/BaseTagLangDoc.java +++ b/src/main/java/io/github/linwancen/plugin/show/lang/base/BaseTagLangDoc.java @@ -9,7 +9,7 @@ public abstract class BaseTagLangDoc extends BaseLangDoc { @Override public @Nullable String resolveDocPrint(@NotNull T lineInfo, @NotNull PsiElement resolve) { - DocElement docElement = toDocElement(resolve); + @Nullable DocElement docElement = toDocElement(resolve); if (docElement == null) { return null; } @@ -22,12 +22,12 @@ public abstract class BaseTagLangDoc extends BaseLangDoc { return null; } // desc - String descDoc = descDoc(lineInfo, docElement).trim(); - String desc = DocFilter.filterDoc(descDoc, lineInfo.appSettings, lineInfo.projectSettings); + @NotNull String descDoc = descDoc(lineInfo, docElement).trim(); + @NotNull String desc = DocFilter.filterDoc(descDoc, lineInfo.appSettings, lineInfo.projectSettings); // tag - StringBuilder tagStrBuilder = new StringBuilder(); - String[] names = lineInfo.tagNames(); - for (String name : names) { + @NotNull StringBuilder tagStrBuilder = new StringBuilder(); + @NotNull String[] names = lineInfo.tagNames(); + for (@NotNull String name : names) { appendTag(lineInfo, tagStrBuilder, docElement, name); } if (desc.length() > 0) { @@ -36,7 +36,7 @@ public abstract class BaseTagLangDoc extends BaseLangDoc { } tagStrBuilder.insert(0, desc); } - String text = tagStrBuilder.toString().trim(); + @NotNull String text = tagStrBuilder.toString().trim(); if (text.length() == 0) { return null; } diff --git a/src/main/java/io/github/linwancen/plugin/show/lang/base/DocFilter.java b/src/main/java/io/github/linwancen/plugin/show/lang/base/DocFilter.java index 0ff93a9..088a7b3 100644 --- a/src/main/java/io/github/linwancen/plugin/show/lang/base/DocFilter.java +++ b/src/main/java/io/github/linwancen/plugin/show/lang/base/DocFilter.java @@ -3,7 +3,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 org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -33,10 +32,10 @@ public class DocFilter { */ @NotNull public static String cutDoc(String text, - AppSettingsState appSettings, boolean deletePrefix) { + @NotNull AppSettingsState appSettings, boolean deletePrefix) { String[] split = LINE_SEPARATOR_PATTERN.split(text); int lineCount = 0; - StringBuilder sb = new StringBuilder(); + @NotNull StringBuilder sb = new StringBuilder(); for (String s : split) { if (deletePrefix) { s = DOC_PATTERN.matcher(s).replaceAll(""); @@ -64,8 +63,8 @@ public class DocFilter { */ @NotNull public static String filterDoc(@NotNull String text, - AppSettingsState appSettings, - ProjectSettingsState projectSettings) { + @NotNull AppSettingsState appSettings, + @NotNull ProjectSettingsState projectSettings) { // docGetEffect first because default false if (projectSettings.docGetEffect && projectSettings.projectFilterEffective) { return filterDoc(text, projectSettings.docGet); @@ -79,7 +78,7 @@ public class DocFilter { @NotNull public static String filterDoc(@NotNull String text, @NotNull Pattern docGet) { // if effect skip check empty - Matcher m = docGet.matcher(text); + @NotNull Matcher m = docGet.matcher(text); if (m.find()) { return m.group(m.groupCount()); } @@ -93,7 +92,7 @@ public class DocFilter { * trim end with space */ public static void addHtml(@NotNull StringBuilder sb, @NotNull String s) { - String deleteHtml = HTML_PATTERN.matcher(s).replaceAll("").trim(); + @NotNull String deleteHtml = HTML_PATTERN.matcher(s).replaceAll("").trim(); if (deleteHtml.length() > 0) { sb.append(deleteHtml).append(" "); } diff --git a/src/main/java/io/github/linwancen/plugin/show/lang/base/DocSkip.java b/src/main/java/io/github/linwancen/plugin/show/lang/base/DocSkip.java index 4bc531f..c60b61f 100644 --- a/src/main/java/io/github/linwancen/plugin/show/lang/base/DocSkip.java +++ b/src/main/java/io/github/linwancen/plugin/show/lang/base/DocSkip.java @@ -3,6 +3,7 @@ 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 org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.regex.Pattern; @@ -10,7 +11,8 @@ public class DocSkip { private DocSkip() {} - public static boolean skipSign(AppSettingsState appSettings, ProjectSettingsState projectSettings, String text) { + 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); @@ -18,7 +20,8 @@ public class DocSkip { private static final Pattern NOT_ASCII_PATTERN = Pattern.compile("[^\u0000-\u007f]"); - public static boolean skipDoc(AppSettingsState appSettings, ProjectSettingsState projectSettings, String text) { + public static boolean skipDoc(@NotNull AppSettingsState appSettings, + @NotNull ProjectSettingsState projectSettings, @NotNull String text) { if (appSettings.skipAscii && !NOT_ASCII_PATTERN.matcher(text).find()) { return true; } @@ -27,9 +30,10 @@ public class DocSkip { projectSettings.projectFilterEffective, projectSettings.docInclude, projectSettings.docExclude); } - static boolean skipText(String text, - boolean appFilterEffective, Pattern appDocInclude, Pattern appDocExclude, - boolean projectFilterEffective, Pattern projectDocInclude, Pattern projectDocExclude + static boolean skipText(@Nullable String text, + boolean appFilterEffective, @NotNull Pattern appDocInclude, @NotNull Pattern appDocExclude, + boolean projectFilterEffective, @NotNull Pattern projectDocInclude, + @NotNull Pattern projectDocExclude ) { if (text == null) { return true; @@ -44,21 +48,21 @@ public class DocSkip { return false; } - static boolean skipText(@NotNull String text, Pattern include, Pattern exclude) { + static boolean skipText(@NotNull String text, @NotNull Pattern include, @NotNull Pattern exclude) { if (exclude(text, exclude)) { return true; } return !include(text, include); } - static boolean include(@NotNull String text, Pattern include) { + static boolean include(@NotNull String text, @NotNull Pattern include) { if (include.pattern().length() == 0) { return true; } return include.matcher(text).find(); } - static boolean exclude(@NotNull String text, Pattern exclude) { + static boolean exclude(@NotNull String text, @NotNull Pattern exclude) { if (exclude.pattern().length() == 0) { return false; } diff --git a/src/main/java/io/github/linwancen/plugin/show/lang/base/Prev.java b/src/main/java/io/github/linwancen/plugin/show/lang/base/Prev.java index 25d00c7..8fdc0ed 100644 --- a/src/main/java/io/github/linwancen/plugin/show/lang/base/Prev.java +++ b/src/main/java/io/github/linwancen/plugin/show/lang/base/Prev.java @@ -15,6 +15,7 @@ public class Prev { private Prev() {} + @Nullable public static PsiElement prevRefChild(@NotNull LineInfo lineInfo, @NotNull PsiElement element, @NotNull Class refClass) { PsiElement prevParent = element.getParent(); @@ -22,7 +23,7 @@ public class Prev { if (element.getTextRange().getEndOffset() < lineInfo.startOffset) { return null; } - PsiElement parent = refClassParent(element, refClass); + @Nullable PsiElement parent = refClassParent(element, refClass); if (parent != null) { // skip b in a.b.c if (prevParent.getTextRange().getEndOffset() < lineInfo.endOffset @@ -42,6 +43,7 @@ public class Prev { "{-~" + "]++"); + @Nullable private static PsiElement refClassParent(@NotNull PsiElement element, @NotNull Class refClass) { String text = element.getText(); @@ -67,7 +69,7 @@ public class Prev { public static @Nullable PsiElement prevCompactElement( @SuppressWarnings("unused") @NotNull T lineInfo, @NotNull PsiElement resolve, @NotNull Document document) { - PsiElement element = PsiTreeUtil.prevVisibleLeaf(resolve); + @Nullable PsiElement element = PsiTreeUtil.prevVisibleLeaf(resolve); if (element == null) { return null; } @@ -79,7 +81,7 @@ public class Prev { } catch (Exception e) { return null; } - String replace = spaceText.replace("\n", ""); + @NotNull String replace = spaceText.replace("\n", ""); if (spaceText.length() - replace.length() > 1) { return null; } diff --git a/src/main/java/io/github/linwancen/plugin/show/lang/base/PsiElementTo.java b/src/main/java/io/github/linwancen/plugin/show/lang/base/PsiElementTo.java index a0f59a7..6c8c841 100644 --- a/src/main/java/io/github/linwancen/plugin/show/lang/base/PsiElementTo.java +++ b/src/main/java/io/github/linwancen/plugin/show/lang/base/PsiElementTo.java @@ -13,7 +13,7 @@ public class PsiElementTo { private PsiElementTo() {} - public static @Nullable FileViewProvider viewProvider(PsiElement resolve) { + public static @Nullable FileViewProvider viewProvider(@NotNull PsiElement resolve) { PsiFile psiFile = resolve.getContainingFile(); if (psiFile == null) { return null; @@ -26,8 +26,8 @@ public class PsiElementTo { } public static @NotNull Language language(@NotNull PsiElement element) { - Language lang = element.getLanguage(); - Language base = lang.getBaseLanguage(); + @NotNull Language lang = element.getLanguage(); + @Nullable Language base = lang.getBaseLanguage(); if (base != null) { return base; } diff --git a/src/main/java/io/github/linwancen/plugin/show/lang/base/ResolveDoc.java b/src/main/java/io/github/linwancen/plugin/show/lang/base/ResolveDoc.java index dff973d..83c8385 100644 --- a/src/main/java/io/github/linwancen/plugin/show/lang/base/ResolveDoc.java +++ b/src/main/java/io/github/linwancen/plugin/show/lang/base/ResolveDoc.java @@ -19,7 +19,7 @@ public class ResolveDoc { public static String fromLineEnd(@SuppressWarnings("unused") @NotNull T lineInfo, @NotNull PsiElement resolve, @NotNull FileViewProvider resolveViewProvider) { - Document document = resolveViewProvider.getDocument(); + @Nullable Document document = resolveViewProvider.getDocument(); if (document == null) { return null; } @@ -33,11 +33,11 @@ public class ResolveDoc { return null; } // end over will return last - PsiElement psiElement = resolveViewProvider.findElementAt(resolveEndOffset); + @Nullable PsiElement psiElement = resolveViewProvider.findElementAt(resolveEndOffset); if (psiElement == null) { return null; } - PsiElement docElement = PsiTreeUtil.prevVisibleLeaf(psiElement); + @Nullable PsiElement docElement = PsiTreeUtil.prevVisibleLeaf(psiElement); if (!(docElement instanceof PsiComment)) { return null; } @@ -51,14 +51,14 @@ public class ResolveDoc { @Nullable public static String fromLineUp(@NotNull T lineInfo, - PsiElement resolve, + @NotNull PsiElement resolve, @NotNull FileViewProvider resolveViewProvider, @NotNull List keywords) { - Document document = resolveViewProvider.getDocument(); + @Nullable Document document = resolveViewProvider.getDocument(); if (document == null) { return null; } - PsiElement psiElement = Prev.prevCompactElement(lineInfo, resolve, document); + @Nullable PsiElement psiElement = Prev.prevCompactElement(lineInfo, resolve, document); if (!keywords.isEmpty()) { while (psiElement != null) { String text = psiElement.getText(); @@ -69,7 +69,7 @@ public class ResolveDoc { } } } - StringBuilder sb = new StringBuilder(); + @NotNull StringBuilder sb = new StringBuilder(); while (psiElement instanceof PsiComment) { String text = psiElement.getText(); if (text != null) { diff --git a/src/main/java/io/github/linwancen/plugin/show/settings/AbstractSettingsComponent.java b/src/main/java/io/github/linwancen/plugin/show/settings/AbstractSettingsComponent.java index 4d613c9..b092fe6 100644 --- a/src/main/java/io/github/linwancen/plugin/show/settings/AbstractSettingsComponent.java +++ b/src/main/java/io/github/linwancen/plugin/show/settings/AbstractSettingsComponent.java @@ -38,7 +38,8 @@ public abstract class AbstractSettingsComponent { return lineEndFilter; } - protected FormBuilder add(FormBuilder formBuilder, JBCheckBox jbCheckBox, JBTextField jbTextField, String tip) { + protected FormBuilder add(@NotNull FormBuilder formBuilder, JBCheckBox jbCheckBox, + @NotNull JBTextField jbTextField, @NotNull String tip) { return formBuilder.addLabeledComponent(JPanelFactory.of(jbCheckBox, new JBLabel(tip)), jbTextField, 1, true); } diff --git a/src/main/java/io/github/linwancen/plugin/show/settings/AbstractSettingsConfigurable.java b/src/main/java/io/github/linwancen/plugin/show/settings/AbstractSettingsConfigurable.java index 1a6c8f1..2fa7ac3 100644 --- a/src/main/java/io/github/linwancen/plugin/show/settings/AbstractSettingsConfigurable.java +++ b/src/main/java/io/github/linwancen/plugin/show/settings/AbstractSettingsConfigurable.java @@ -1,10 +1,13 @@ package io.github.linwancen.plugin.show.settings; +import org.jetbrains.annotations.NotNull; + public class AbstractSettingsConfigurable { private AbstractSettingsConfigurable() {} - static boolean isModified(AbstractSettingsState settings, AbstractSettingsComponent component, boolean modified) { + static boolean isModified(@NotNull AbstractSettingsState settings, @NotNull AbstractSettingsComponent component, + boolean modified) { modified |= !component.getLineInclude().equals(settings.getLineInclude()); modified |= !component.getLineExclude().equals(settings.getLineExclude()); modified |= !component.getDocInclude().equals(settings.getDocInclude()); @@ -14,7 +17,7 @@ public class AbstractSettingsConfigurable { return modified; } - static void apply(AbstractSettingsState settings, AbstractSettingsComponent component) { + static void apply(@NotNull AbstractSettingsState settings, @NotNull AbstractSettingsComponent component) { settings.setLineInclude(component.getLineInclude()); settings.setLineExclude(component.getLineExclude()); settings.setDocInclude(component.getDocInclude()); @@ -23,7 +26,7 @@ public class AbstractSettingsConfigurable { settings.setDocGet(component.getDocGet()); } - static void reset(AbstractSettingsState settings, AbstractSettingsComponent component) { + static void reset(@NotNull AbstractSettingsState settings, @NotNull AbstractSettingsComponent component) { component.setLineInclude(settings.getLineInclude()); component.setLineExclude(settings.getLineExclude()); component.setDocInclude(settings.getDocInclude()); diff --git a/src/main/java/io/github/linwancen/plugin/show/settings/AbstractSettingsState.java b/src/main/java/io/github/linwancen/plugin/show/settings/AbstractSettingsState.java index 12f713f..25c4650 100644 --- a/src/main/java/io/github/linwancen/plugin/show/settings/AbstractSettingsState.java +++ b/src/main/java/io/github/linwancen/plugin/show/settings/AbstractSettingsState.java @@ -1,21 +1,28 @@ package io.github.linwancen.plugin.show.settings; +import org.jetbrains.annotations.NotNull; + import java.util.regex.Pattern; public abstract class AbstractSettingsState { + @NotNull public transient Pattern lineInclude = Pattern.compile(""); + @NotNull public transient Pattern lineExclude = Pattern.compile("^java"); + @NotNull public transient Pattern docInclude = Pattern.compile(""); + @NotNull public transient Pattern docExclude = Pattern.compile(""); public transient boolean docGetEffect = false; + @NotNull public transient Pattern docGet = Pattern.compile(".+?(?:[。\\r\\n]|\\. )"); public String getLineInclude() { return lineInclude.pattern(); } - public void setLineInclude(String lineInclude) { + public void setLineInclude(@NotNull String lineInclude) { this.lineInclude = Pattern.compile(lineInclude); } @@ -23,7 +30,7 @@ public abstract class AbstractSettingsState { return lineExclude.pattern(); } - public void setLineExclude(String lineExclude) { + public void setLineExclude(@NotNull String lineExclude) { this.lineExclude = Pattern.compile(lineExclude); } @@ -32,7 +39,7 @@ public abstract class AbstractSettingsState { return docInclude.pattern(); } - public void setDocInclude(String docInclude) { + public void setDocInclude(@NotNull String docInclude) { this.docInclude = Pattern.compile(docInclude); } @@ -40,7 +47,7 @@ public abstract class AbstractSettingsState { return docExclude.pattern(); } - public void setDocExclude(String docExclude) { + public void setDocExclude(@NotNull String docExclude) { this.docExclude = Pattern.compile(docExclude); } @@ -49,7 +56,7 @@ public abstract class AbstractSettingsState { return docGet.pattern(); } - public void setDocGet(String docExclude) { + public void setDocGet(@NotNull String docExclude) { this.docGet = Pattern.compile(docExclude); } } diff --git a/src/main/java/io/github/linwancen/plugin/show/settings/AppSettingsComponent.java b/src/main/java/io/github/linwancen/plugin/show/settings/AppSettingsComponent.java index 750ab68..811d8e0 100644 --- a/src/main/java/io/github/linwancen/plugin/show/settings/AppSettingsComponent.java +++ b/src/main/java/io/github/linwancen/plugin/show/settings/AppSettingsComponent.java @@ -7,6 +7,7 @@ import com.intellij.ui.components.JBLabel; import com.intellij.ui.components.JBTextField; import com.intellij.util.ui.FormBuilder; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; @@ -69,15 +70,13 @@ public class AppSettingsComponent extends AbstractSettingsComponent { @NotNull protected JPanel lineEndFilterPanel() { - JPanel text = JPanelFactory.of( + @NotNull JPanel text = JPanelFactory.of( 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, skipBlank), 1) .addComponent(JPanelFactory.of(fromNew, fromParam, getToSet, skipAnnotation, skipAscii, skipBlank), 1) .addSeparator() .addComponent(text) @@ -89,6 +88,7 @@ public class AppSettingsComponent extends AbstractSettingsComponent { return myMainPanel; } + @NotNull public JComponent getPreferredFocusedComponent() { return showTreeComment; } @@ -248,6 +248,7 @@ public class AppSettingsComponent extends AbstractSettingsComponent { skipBlank.setSelected(newStatus); } + @Nullable public Color getLineEndColor() { return lineEndColor.getSelectedColor(); } @@ -256,6 +257,7 @@ public class AppSettingsComponent extends AbstractSettingsComponent { lineEndColor.setSelectedColor(color); } + @Nullable public Color getLineEndJsonColor() { return lineEndJsonColor.getSelectedColor(); } diff --git a/src/main/java/io/github/linwancen/plugin/show/settings/AppSettingsConfigurable.java b/src/main/java/io/github/linwancen/plugin/show/settings/AppSettingsConfigurable.java index 83039f4..2e33452 100644 --- a/src/main/java/io/github/linwancen/plugin/show/settings/AppSettingsConfigurable.java +++ b/src/main/java/io/github/linwancen/plugin/show/settings/AppSettingsConfigurable.java @@ -2,19 +2,24 @@ package io.github.linwancen.plugin.show.settings; import com.google.common.base.Splitter; import com.intellij.openapi.options.Configurable; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; public class AppSettingsConfigurable implements Configurable { + @SuppressWarnings("NotNullFieldNotInitialized") + @NotNull private AppSettingsComponent mySettingsComponent; + @NotNull @Override public String getDisplayName() { return "Show Comment Global."; } + @NotNull @Override public JComponent getPreferredFocusedComponent() { return mySettingsComponent.getPreferredFocusedComponent(); @@ -29,7 +34,7 @@ public class AppSettingsConfigurable implements Configurable { @Override public boolean isModified() { - AppSettingsState settings = AppSettingsState.getInstance(); + @NotNull AppSettingsState settings = AppSettingsState.getInstance(); boolean modified = mySettingsComponent.getShowTreeComment() != settings.showTreeComment; modified |= mySettingsComponent.getCompact() != settings.compact; @@ -47,8 +52,8 @@ public class AppSettingsConfigurable implements Configurable { modified |= !mySettingsComponent.getLineTags().equals(String.join("|", settings.lineTags)); modified |= !mySettingsComponent.getLineEndCount().equals(String.valueOf(settings.lineEndCount)); - modified |= !mySettingsComponent.getLineEndColor().equals(settings.lineEndTextAttr.getForegroundColor()); - modified |= !mySettingsComponent.getLineEndJsonColor().equals(settings.lineEndJsonTextAttr.getForegroundColor()); + modified |= !settings.lineEndTextAttr.getForegroundColor().equals(mySettingsComponent.getLineEndColor()); + modified |= !settings.lineEndJsonTextAttr.getForegroundColor().equals(mySettingsComponent.getLineEndJsonColor()); modified |= !mySettingsComponent.getLineEndPrefix().equals(settings.lineEndPrefix); modified |= mySettingsComponent.getGetToSet() != settings.getToSet; @@ -65,7 +70,7 @@ public class AppSettingsConfigurable implements Configurable { @Override public void apply() { - AppSettingsState settings = AppSettingsState.getInstance(); + @NotNull AppSettingsState settings = AppSettingsState.getInstance(); settings.showTreeComment = mySettingsComponent.getShowTreeComment(); settings.compact = mySettingsComponent.getCompact(); @@ -103,7 +108,7 @@ public class AppSettingsConfigurable implements Configurable { @Override public void reset() { - AppSettingsState settings = AppSettingsState.getInstance(); + @NotNull AppSettingsState settings = AppSettingsState.getInstance(); mySettingsComponent.setShowTreeComment(settings.showTreeComment); mySettingsComponent.setCompact(settings.compact); @@ -137,6 +142,7 @@ public class AppSettingsConfigurable implements Configurable { @Override public void disposeUIResources() { + //noinspection ConstantConditions mySettingsComponent = null; } diff --git a/src/main/java/io/github/linwancen/plugin/show/settings/AppSettingsState.java b/src/main/java/io/github/linwancen/plugin/show/settings/AppSettingsState.java index 8aa08ed..309a70f 100644 --- a/src/main/java/io/github/linwancen/plugin/show/settings/AppSettingsState.java +++ b/src/main/java/io/github/linwancen/plugin/show/settings/AppSettingsState.java @@ -34,7 +34,9 @@ public class AppSettingsState extends AbstractSettingsState implements Persisten public boolean showLineEndCommentGo = true; public boolean showLineEndCommentKotlin = true; + @NotNull public String[] treeTags = {"author"}; + @NotNull public String[] lineTags = {}; public final TextAttributes lineEndTextAttr = new TextAttributes( @@ -43,6 +45,7 @@ public class AppSettingsState extends AbstractSettingsState implements Persisten public final TextAttributes lineEndJsonTextAttr = new TextAttributes(new JBColor(Gray._140, Gray._140), null, null, null, Font.ITALIC); + @NotNull public String lineEndPrefix = " // "; public int lineEndCount = 2; public int lineEndLen = 0; @@ -53,6 +56,7 @@ public class AppSettingsState extends AbstractSettingsState implements Persisten public boolean skipAscii = !"en".equals(Locale.getDefault().getLanguage()); public boolean skipBlank = true; + @NotNull public static AppSettingsState getInstance() { AppSettingsState service = ApplicationManager.getApplication().getService(AppSettingsState.class); if (service == null) { @@ -72,20 +76,22 @@ public class AppSettingsState extends AbstractSettingsState implements Persisten XmlSerializerUtil.copyBean(state, this); } + @NotNull public String getLineEndColor() { return Integer.toHexString(lineEndTextAttr.getForegroundColor().getRGB()).toUpperCase(); } - public void setLineEndColor(String s) { + public void setLineEndColor(@NotNull String s) { int rgb = new BigInteger(s, 16).intValue(); lineEndTextAttr.setForegroundColor(new JBColor(new Color(rgb), new Color(rgb))); } + @NotNull public String getLineEndJsonColor() { return Integer.toHexString(lineEndJsonTextAttr.getForegroundColor().getRGB()).toUpperCase(); } - public void setLineEndJsonColor(String s) { + public void setLineEndJsonColor(@NotNull String s) { int rgb = new BigInteger(s, 16).intValue(); lineEndJsonTextAttr.setForegroundColor(new JBColor(new Color(rgb), new Color(rgb))); } diff --git a/src/main/java/io/github/linwancen/plugin/show/settings/JPanelFactory.java b/src/main/java/io/github/linwancen/plugin/show/settings/JPanelFactory.java index 026e9ad..18b794c 100644 --- a/src/main/java/io/github/linwancen/plugin/show/settings/JPanelFactory.java +++ b/src/main/java/io/github/linwancen/plugin/show/settings/JPanelFactory.java @@ -1,5 +1,8 @@ package io.github.linwancen.plugin.show.settings; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + import javax.swing.*; import java.awt.*; @@ -7,9 +10,10 @@ public class JPanelFactory { private JPanelFactory() {} - public static JPanel of(Component... components) { - JPanel jPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); - for (Component component : components) { + @NotNull + public static JPanel of(@NotNull Component... components) { + @NotNull JPanel jPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + for (@Nullable Component component : components) { if (component != null) { jPanel.add(component); } diff --git a/src/main/java/io/github/linwancen/plugin/show/settings/ProjectSettingsComponent.java b/src/main/java/io/github/linwancen/plugin/show/settings/ProjectSettingsComponent.java index 76be6b1..4e6b626 100644 --- a/src/main/java/io/github/linwancen/plugin/show/settings/ProjectSettingsComponent.java +++ b/src/main/java/io/github/linwancen/plugin/show/settings/ProjectSettingsComponent.java @@ -32,6 +32,7 @@ public class ProjectSettingsComponent extends AbstractSettingsComponent { return myMainPanel; } + @NotNull public JComponent getPreferredFocusedComponent() { return projectFilterEffective; } diff --git a/src/main/java/io/github/linwancen/plugin/show/settings/ProjectSettingsConfigurable.java b/src/main/java/io/github/linwancen/plugin/show/settings/ProjectSettingsConfigurable.java index 64bba5a..8e8e6e0 100644 --- a/src/main/java/io/github/linwancen/plugin/show/settings/ProjectSettingsConfigurable.java +++ b/src/main/java/io/github/linwancen/plugin/show/settings/ProjectSettingsConfigurable.java @@ -16,17 +16,21 @@ public class ProjectSettingsConfigurable extends ModuleAwareProjectConfigurable< @NotNull @Override - protected ProjectSettingsConfigurable createModuleConfigurable(Module module) { + protected ProjectSettingsConfigurable createModuleConfigurable(@NotNull Module module) { return new ProjectSettingsConfigurable(module.getProject()); } + @SuppressWarnings("NotNullFieldNotInitialized") + @NotNull private ProjectSettingsComponent mySettingsComponent; + @NotNull @Override public String getDisplayName() { return "Show Comment Project."; } + @NotNull @Override public JComponent getPreferredFocusedComponent() { return mySettingsComponent.getPreferredFocusedComponent(); @@ -41,7 +45,7 @@ public class ProjectSettingsConfigurable extends ModuleAwareProjectConfigurable< @Override public boolean isModified() { - ProjectSettingsState settings = ProjectSettingsState.getInstance(getProject()); + @NotNull ProjectSettingsState settings = ProjectSettingsState.getInstance(getProject()); boolean modified = mySettingsComponent.getGlobalFilterEffective() != settings.globalFilterEffective; modified |= mySettingsComponent.getProjectFilterEffective() != settings.projectFilterEffective; modified = AbstractSettingsConfigurable.isModified(settings, mySettingsComponent, modified); @@ -50,7 +54,7 @@ public class ProjectSettingsConfigurable extends ModuleAwareProjectConfigurable< @Override public void apply() { - ProjectSettingsState settings = ProjectSettingsState.getInstance(getProject()); + @NotNull ProjectSettingsState settings = ProjectSettingsState.getInstance(getProject()); settings.globalFilterEffective = mySettingsComponent.getGlobalFilterEffective(); settings.projectFilterEffective = mySettingsComponent.getProjectFilterEffective(); AbstractSettingsConfigurable.apply(settings, mySettingsComponent); @@ -58,7 +62,7 @@ public class ProjectSettingsConfigurable extends ModuleAwareProjectConfigurable< @Override public void reset() { - ProjectSettingsState settings = ProjectSettingsState.getInstance(getProject()); + @NotNull ProjectSettingsState settings = ProjectSettingsState.getInstance(getProject()); mySettingsComponent.setGlobalFilterEffective(settings.globalFilterEffective); mySettingsComponent.setProjectFilterEffective(settings.projectFilterEffective); AbstractSettingsConfigurable.reset(settings, mySettingsComponent); @@ -66,6 +70,7 @@ public class ProjectSettingsConfigurable extends ModuleAwareProjectConfigurable< @Override public void disposeUIResources() { + //noinspection ConstantConditions mySettingsComponent = null; } diff --git a/src/main/java/io/github/linwancen/plugin/show/settings/ProjectSettingsState.java b/src/main/java/io/github/linwancen/plugin/show/settings/ProjectSettingsState.java index aacc772..7386f69 100644 --- a/src/main/java/io/github/linwancen/plugin/show/settings/ProjectSettingsState.java +++ b/src/main/java/io/github/linwancen/plugin/show/settings/ProjectSettingsState.java @@ -12,11 +12,12 @@ import org.jetbrains.annotations.Nullable; name = "io.github.linwancen.plugin.show.settings.ProjectSettingsState", storages = @Storage("ShowCommentProject.xml") ) -public class ProjectSettingsState extends AbstractSettingsState implements PersistentStateComponent { +public class ProjectSettingsState extends AbstractSettingsState implements PersistentStateComponent { public boolean globalFilterEffective = true; public boolean projectFilterEffective = false; + @NotNull public static ProjectSettingsState getInstance(@NotNull Project project) { ProjectSettingsState service = project.getService(ProjectSettingsState.class); if (service == null) { diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 4dc832a..a7c6d90 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -1,9 +1,9 @@ - io.github.linwancen.show-comment - Show Comment - 林万程 + io.github.linwancen.show-comment + Show Comment + 林万程 -
  • "xx-ClassNameOrSimpleName.json" and jump to field @@ -53,79 +53,79 @@ Show doc comment at the Project view Tree, line End, json etc. 主页一个 Start,您的支持是项目前进的动力。 ]]> - - com.intellij.modules.java - com.intellij.database - JavaScript - com.intellij.modules.python - org.jetbrains.plugins.go - org.jetbrains.kotlin - - + + com.intellij.modules.java + com.intellij.database + JavaScript + com.intellij.modules.python + org.jetbrains.plugins.go + org.jetbrains.kotlin + + - - - - + + + + - - - + + + - - - - - + + + + + - - - - - + + + + + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/liveTemplates/show-comment-doc.xml b/src/main/resources/liveTemplates/show-comment-doc.xml index ad25ff4..45267ee 100644 --- a/src/main/resources/liveTemplates/show-comment-doc.xml +++ b/src/main/resources/liveTemplates/show-comment-doc.xml @@ -1,254 +1,263 @@ -