Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ dependencies {
implementation 'commons-codec:commons-codec:1.15'
implementation 'org.freemarker:freemarker:2.3.31'
implementation 'com.youbenzi:MDTool:1.2.4'
implementation 'org.projectlombok:lombok:1.18.2'
annotationProcessor 'org.projectlombok:lombok:1.18.2'
implementation 'org.projectlombok:lombok:1.18.20'
annotationProcessor 'org.projectlombok:lombok:1.18.20'
}

// See https://github.com/JetBrains/gradle-intellij-plugin/
Expand Down Expand Up @@ -50,4 +50,4 @@ publishPlugin {

tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
import cn.gudqs7.plugins.common.util.jetbrain.ExceptionUtil;
import cn.gudqs7.plugins.common.util.structure.PsiAnnotationUtil;
import cn.gudqs7.plugins.search.pojo.RequestMappingAnnotationInfo;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleUtil;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.psi.impl.java.stubs.index.JavaAnnotationIndex;
import com.intellij.psi.search.GlobalSearchScope;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -36,7 +39,7 @@ public static ApiResolverService getInstance(Project project) {
public List<ApiNavigationItem> getApiNavigationItemList() {
List<ApiNavigationItem> navigationItemList = new ArrayList<>();
String[] supportAnnotations = new String[]{"Controller", "RestController"};
Map<String, PsiClass> psiClassMap = new HashMap<>();
List<PsiClass> psiClassList = new ArrayList<>();
for (String supportAnnotation : supportAnnotations) {
Collection<PsiAnnotation> psiAnnotations = JavaAnnotationIndex.getInstance().get(supportAnnotation, project, GlobalSearchScope.projectScope(project));
for (PsiAnnotation psiAnnotation : psiAnnotations) {
Expand All @@ -46,10 +49,10 @@ public List<ApiNavigationItem> getApiNavigationItemList() {
continue;
}
PsiClass psiClass = (PsiClass) psiElement;
psiClassMap.put(psiClass.getQualifiedName(), psiClass);
psiClassList.add(psiClass);
}
}
for (PsiClass psiClass : psiClassMap.values()) {
for (PsiClass psiClass : psiClassList) {
try {
navigationItemList.addAll(getServiceItemList(psiClass));
} catch (Exception e) {
Expand Down Expand Up @@ -144,7 +147,8 @@ private List<MethodPathInfo> getMethodList0(@NotNull PsiMethod psiMethod, String
for (String methodPath : pathList) {
String psiClassName = psiClass.getName();
String psiMethodName = psiMethod.getName();
String location = psiClassName + "#" + psiMethodName;
String moduleName = getModuleName(psiClass);
String location = buildLocation(moduleName, psiClassName, psiMethodName);
AnnotationHolder psiMethodHolder = AnnotationHolder.getPsiMethodHolder(psiMethod);
CommentInfo commentInfo = psiMethodHolder.getCommentInfo();
String description = commentInfo.getValue("");
Expand All @@ -165,5 +169,17 @@ private List<String> getRequestMappingPath(PsiAnnotation requestMappingAnnotatio
return pathList;
}

@Nullable
private String getModuleName(@NotNull PsiClass psiClass) {
Module module = ModuleUtil.findModuleForPsiElement(psiClass);
return module != null ? module.getName() : null;
}

private String buildLocation(@Nullable String moduleName, @NotNull String className, @NotNull String methodName) {
if (StringUtils.isNotBlank(moduleName)) {
return "[" + moduleName + "] " + className + "#" + methodName;
}
return className + "#" + methodName;
}

}