Skip to content

Commit

Permalink
enhance: Compatible with 2024.3+
Browse files Browse the repository at this point in the history
  • Loading branch information
huangbaihua001 committed Dec 22, 2024
1 parent a37d572 commit b1ea1be
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 47 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -> https://plugins.jetbrains.com/docs/intellij/intellij-artifacts.html
pluginGroup=jiux.net.plugin.restfultoolkit
pluginName=RestfulToolkitX
pluginVersion=2.1.9
pluginVersion=2.1.10
# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
# for insight into build numbers and IntelliJ Platform versions.
pluginSinceBuild=202
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,36 @@

import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.psi.PsiAnnotation;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.PsiModifierList;
import com.intellij.psi.impl.java.stubs.index.JavaAnnotationIndex;
import com.intellij.psi.search.GlobalSearchScope;
import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import jiux.net.plugin.restful.annotations.PathMappingAnnotation;
import jiux.net.plugin.restful.annotations.SpringControllerAnnotation;
import jiux.net.plugin.restful.annotations.SpringRequestMethodAnnotation;
import jiux.net.plugin.restful.common.spring.RequestMappingAnnotationHelper;
import jiux.net.plugin.restful.method.RequestPath;
import jiux.net.plugin.restful.method.action.PropertiesHandler;
import jiux.net.plugin.restful.navigation.action.RestServiceItem;
import org.jetbrains.kotlin.idea.stubindex.KotlinAnnotationsIndex;
import org.jetbrains.kotlin.psi.*;
import org.jetbrains.kotlin.psi.KtAnnotationEntry;
import org.jetbrains.kotlin.psi.KtCallExpression;
import org.jetbrains.kotlin.psi.KtClass;
import org.jetbrains.kotlin.psi.KtCollectionLiteralExpression;
import org.jetbrains.kotlin.psi.KtDeclaration;
import org.jetbrains.kotlin.psi.KtExpression;
import org.jetbrains.kotlin.psi.KtModifierList;
import org.jetbrains.kotlin.psi.KtNamedFunction;
import org.jetbrains.kotlin.psi.KtValueArgument;
import org.jetbrains.kotlin.psi.KtValueArgumentList;
import org.jetbrains.kotlin.psi.KtValueArgumentName;

public class SpringResolver extends BaseServiceResolver {

Expand Down Expand Up @@ -135,31 +152,35 @@ public List<RestServiceItem> getRestServiceItemList(
List<RestServiceItem> serviceItemList = getServiceItemList(psiClass);
itemList.addAll(serviceItemList);
}
// kotlin:
Collection<KtAnnotationEntry> ktAnnotationEntries = KotlinAnnotationsIndex
.getInstance()
.get(controllerAnnotation.getShortName(), project, globalSearchScope);
for (KtAnnotationEntry ktAnnotationEntry : ktAnnotationEntries) {
KtClass ktClass = (KtClass) ktAnnotationEntry.getParent().getParent();

List<RequestPath> classRequestPaths = getRequestPaths(ktClass);

List<KtNamedFunction> ktNamedFunctions = getKtNamedFunctions(ktClass);
for (KtNamedFunction fun : ktNamedFunctions) {
List<RequestPath> requestPaths = getRequestPaths(fun);
// kotlin:
// Collection<KtAnnotationEntry> ktAnnotationEntries = KotlinAnnotationsIndex
// .getInstance()
// .get(controllerAnnotation.getShortName(), project, globalSearchScope);
// for (KtAnnotationEntry ktAnnotationEntry : ktAnnotationEntries) {
// KtClass ktClass = (KtClass) ktAnnotationEntry.getParent().getParent();
//
// List<RequestPath> classRequestPaths = getRequestPaths(ktClass);
//
// List<KtNamedFunction> ktNamedFunctions = getKtNamedFunctions(ktClass);
// for (KtNamedFunction fun : ktNamedFunctions) {
// List<RequestPath> requestPaths = getRequestPaths(fun);
//
// for (RequestPath classRequestPath : classRequestPaths) {
// for (RequestPath requestPath : requestPaths) {
// requestPath.concat(classRequestPath);
// itemList.add(createRestServiceItem(fun, "", requestPath));
// }
// }
// }
// }

for (RequestPath classRequestPath : classRequestPaths) {
for (RequestPath requestPath : requestPaths) {
requestPath.concat(classRequestPath);
itemList.add(createRestServiceItem(fun, "", requestPath));
}
}
}
}
}
return itemList;
}



protected List<RestServiceItem> getServiceItemList(PsiClass psiClass) {
PsiMethod[] psiMethods = psiClass.getMethods();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ public void projectOpened(@NotNull Project project) {
RestServicesNavigator restServicesNavigator = RestServicesNavigator.getInstance(
project
);

restServicesNavigator.listenForProjectsChanges();

ToolkitUtil.runWhenInitialized(
project,
() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,30 +104,40 @@ protected void paintComponent(Graphics g) {
}

public void initToolWindow() {



final ToolWindowManagerEx manager = ToolWindowManagerEx.getInstanceEx(project);
myToolWindow = (ToolWindowEx) manager.getToolWindow(TOOL_WINDOW_ID);
if (myToolWindow != null) {
return;
}

initTree();

myToolWindow =
(ToolWindowEx) manager.registerToolWindow(
TOOL_WINDOW_ID,
false,
ToolWindowAnchor.RIGHT,
project,
true
);
myToolWindow.setIcon(ToolkitIcons.SERVICE);

final JPanel panel = new RestServicesNavigatorPanel(project, myTree);
final ContentFactory contentFactory = ServiceManager.getService(ContentFactory.class);
final Content content = contentFactory.createContent(panel, "", false);
ContentManager contentManager = myToolWindow.getContentManager();
contentManager.addContent(content);
contentManager.setSelectedContent(content, false);
manager.invokeLater(() -> {

myToolWindow = (ToolWindowEx) manager.getToolWindow(TOOL_WINDOW_ID);
if (myToolWindow != null) {
return;
}

initTree();

myToolWindow =
(ToolWindowEx) manager.registerToolWindow(
TOOL_WINDOW_ID,
false,
ToolWindowAnchor.RIGHT,
project,
true
);
myToolWindow.setIcon(ToolkitIcons.SERVICE);

final JPanel panel = new RestServicesNavigatorPanel(project, myTree);
final ContentFactory contentFactory = ServiceManager.getService(ContentFactory.class);
final Content content = contentFactory.createContent(panel, "", false);
ContentManager contentManager = myToolWindow.getContentManager();
contentManager.addContent(content);
contentManager.setSelectedContent(content, false);

});


}

public void scheduleStructureUpdate() {
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/META-INF/kotlin.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<idea-plugin>
<extensions defaultExtensionNs="com.intellij">
<org.jetbrains.kotlin.supportsKotlinPluginMode version="2024.2.1"/>
</extensions>
</idea-plugin>
</idea-plugin>

0 comments on commit b1ea1be

Please sign in to comment.