package doc from parent and other project or jar | 在父包和其他项目中获取包注释
This commit is contained in:
@@ -35,7 +35,7 @@ public class Tree implements ProjectViewNodeDecorator {
|
||||
return;
|
||||
}
|
||||
|
||||
PsiDocComment docComment = psiDocCommentOf(node, project);
|
||||
PsiDocComment docComment = nodeDoc(node, project);
|
||||
if (docComment == null) {
|
||||
return;
|
||||
}
|
||||
@@ -52,14 +52,14 @@ public class Tree implements ProjectViewNodeDecorator {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private PsiDocComment psiDocCommentOf(ProjectViewNode<?> node, Project project) {
|
||||
private PsiDocComment nodeDoc(ProjectViewNode<?> node, Project project) {
|
||||
if (node instanceof PsiFileNode) {
|
||||
PsiFile psiFile = ((PsiFileNode) node).getValue();
|
||||
return DocUtils.fileDoc(psiFile);
|
||||
}
|
||||
if (node instanceof PsiDirectoryNode) {
|
||||
PsiDirectory psiDirectory = ((PsiDirectoryNode) node).getValue();
|
||||
return DocUtils.dirDoc(psiDirectory);
|
||||
return dirDoc(psiDirectory);
|
||||
}
|
||||
|
||||
if (node instanceof PsiMethodNode) {
|
||||
@@ -81,7 +81,7 @@ public class Tree implements ProjectViewNodeDecorator {
|
||||
if (node instanceof PackageElementNode) {
|
||||
// On Packages View
|
||||
PsiPackage psiPackage = ((PackageElementNode) node).getValue().getPackage();
|
||||
return DocUtils.packageDoc(psiPackage);
|
||||
return packageDoc(psiPackage);
|
||||
}
|
||||
|
||||
// On Packages View, Project Files View
|
||||
@@ -93,7 +93,43 @@ public class Tree implements ProjectViewNodeDecorator {
|
||||
if (psiDirectory == null) {
|
||||
return null;
|
||||
}
|
||||
return DocUtils.dirDoc(psiDirectory);
|
||||
return dirDoc(psiDirectory);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private PsiDocComment dirDoc(PsiDirectory child) {
|
||||
while (true) {
|
||||
PsiDocComment docComment = DocUtils.dirDoc(child);
|
||||
if (docComment != null) {
|
||||
return docComment;
|
||||
}
|
||||
PsiDirectory parent = child.getParent();
|
||||
if (parent == null) {
|
||||
return null;
|
||||
}
|
||||
if (parent.getChildren().length != 1) {
|
||||
return null;
|
||||
}
|
||||
child = parent;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private PsiDocComment packageDoc(PsiPackage child) {
|
||||
while (true) {
|
||||
PsiDocComment docComment = DocUtils.packageDoc(child);
|
||||
if (docComment != null) {
|
||||
return docComment;
|
||||
}
|
||||
PsiPackage parent = child.getParentPackage();
|
||||
if (parent == null) {
|
||||
return null;
|
||||
}
|
||||
if (parent.getChildren().length != 1) {
|
||||
return null;
|
||||
}
|
||||
child = parent;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,10 +23,18 @@ public class DocUtils {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PsiDocComment packageDoc(PsiPackage psiPackage) {
|
||||
public static PsiDocComment packageDoc(@Nullable PsiPackage psiPackage) {
|
||||
if (psiPackage == null) {
|
||||
return null;
|
||||
}
|
||||
String name = psiPackage.getName();
|
||||
if (name == null || name.length() == 0) {
|
||||
return null;
|
||||
}
|
||||
PsiDirectory[] psiDirectories = psiPackage.getDirectories();
|
||||
for (PsiDirectory psiDirectory : psiDirectories) {
|
||||
PsiDocComment psiDocComment = dirDoc(psiDirectory);
|
||||
PsiFile file = psiDirectory.findFile(PsiPackage.PACKAGE_INFO_FILE);
|
||||
PsiDocComment psiDocComment = PackageDocUtils.fromPackageInfoFile(file);
|
||||
if (psiDocComment != null) {
|
||||
return psiDocComment;
|
||||
}
|
||||
@@ -67,7 +75,7 @@ public class DocUtils {
|
||||
|
||||
@Nullable
|
||||
public static PsiDocComment dirDoc(PsiDirectory psiDirectory) {
|
||||
PsiFile file = psiDirectory.findFile(PsiPackage.PACKAGE_INFO_FILE);
|
||||
return PackageDocUtils.fromPackageInfoFile(file);
|
||||
PsiPackage psiPackage = JavaDirectoryService.getInstance().getPackage(psiDirectory);
|
||||
return packageDoc(psiPackage);
|
||||
}
|
||||
}
|
||||
|
||||
4
src/test/java/io/github/linwancen/package-info.java
Normal file
4
src/test/java/io/github/linwancen/package-info.java
Normal file
@@ -0,0 +1,4 @@
|
||||
/**
|
||||
* should show in main even if Compact Middle Packages
|
||||
*/
|
||||
package io.github.linwancen;
|
||||
Reference in New Issue
Block a user