Search in sources :

Example 1 with ApiService

use of io.github.kings1990.plugin.fastrequest.model.ApiService in project fast-request by dromara.

the class AllApisNavToolWindow method refreshFilterModule.

public void refreshFilterModule(List<String> selectModule, List<String> selectMethodType) {
    DumbService.getInstance(myProject).smartInvokeLater(() -> {
        Task.Backgroundable task = new Task.Backgroundable(myProject, "Reload apis...") {

            @Override
            public void run(@NotNull ProgressIndicator indicator) {
                indicator.setIndeterminate(false);
                ApplicationManager.getApplication().runReadAction(() -> {
                    if (allApiList == null) {
                        return;
                    }
                    List<ApiService> filterList = allApiList.stream().filter(q -> selectModule.contains(q.getModuleName())).collect(Collectors.toList());
                    indicator.setText("Rendering");
                    List<ApiService.ApiMethod> filterMethodList = new ArrayList<>();
                    filterList.stream().map(ApiService::getApiMethodList).filter(CollectionUtil::isNotEmpty).forEach(filterMethodList::addAll);
                    long count = filterMethodList.stream().filter(q -> selectMethodType.contains(q.getMethodType())).count();
                    RootNode root = new RootNode(count + " apis") {
                    };
                    NodeUtil.convertToRoot(root, NodeUtil.convertToMap(filterList.stream().filter(q -> CollectionUtil.isNotEmpty(q.getApiMethodList())).filter(q -> q.getApiMethodList().stream().anyMatch(p -> selectMethodType.contains(p.getMethodType()))).collect(Collectors.toList())), selectMethodType);
                    apiTree.setModel(new DefaultTreeModel(root));
                });
            }
        };
        ProgressManager.getInstance().runProcessWithProgressAsynchronously(task, new BackgroundableProcessIndicator(task));
    });
}
Also used : java.util(java.util) AllIcons(com.intellij.icons.AllIcons) MessageType(com.intellij.openapi.ui.MessageType) ModuleManager(com.intellij.openapi.module.ModuleManager) ApiService(io.github.kings1990.plugin.fastrequest.model.ApiService) KeyAdapter(java.awt.event.KeyAdapter) Border(javax.swing.border.Border) Query(com.intellij.util.Query) PsiClass(com.intellij.psi.PsiClass) PersistentSearchEverywhereContributorFilter(com.intellij.ide.actions.searcheverywhere.PersistentSearchEverywhereContributorFilter) ModuleUtil(com.intellij.openapi.module.ModuleUtil) Task(com.intellij.openapi.progress.Task) MethodType(io.github.kings1990.plugin.fastrequest.model.MethodType) Disposer(com.intellij.openapi.util.Disposer) MouseAdapter(java.awt.event.MouseAdapter) Project(com.intellij.openapi.project.Project) SpeedSearchUtil(com.intellij.ui.speedSearch.SpeedSearchUtil) AllClassesSearch(com.intellij.psi.search.searches.AllClassesSearch) PsiNavigateUtil(com.intellij.util.PsiNavigateUtil) Module(com.intellij.openapi.module.Module) CommonActionsManager(com.intellij.ide.CommonActionsManager) BackgroundableProcessIndicator(com.intellij.openapi.progress.impl.BackgroundableProcessIndicator) io.github.kings1990.plugin.fastrequest.view.component.tree(io.github.kings1990.plugin.fastrequest.view.component.tree) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) ProgressManager(com.intellij.openapi.progress.ProgressManager) DumbService(com.intellij.openapi.project.DumbService) CollectionUtil(cn.hutool.core.collection.CollectionUtil) NotificationGroupManager(com.intellij.notification.NotificationGroupManager) ToolWindow(com.intellij.openapi.wm.ToolWindow) PsiMethod(com.intellij.psi.PsiMethod) FastRequestSearchEverywhereConfiguration(io.github.kings1990.plugin.fastrequest.configurable.FastRequestSearchEverywhereConfiguration) CheckBoxFilterAction(io.github.kings1990.plugin.fastrequest.action.CheckBoxFilterAction) KeyEvent(java.awt.event.KeyEvent) com.intellij.ui(com.intellij.ui) Collectors(java.util.stream.Collectors) Disposable(com.intellij.openapi.Disposable) MouseEvent(java.awt.event.MouseEvent) java.awt(java.awt) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) SimpleToolWindowPanel(com.intellij.openapi.ui.SimpleToolWindowPanel) List(java.util.List) Constant(io.github.kings1990.plugin.fastrequest.config.Constant) ApplicationManager(com.intellij.openapi.application.ApplicationManager) ProjectScope(com.intellij.psi.search.ProjectScope) NotNull(org.jetbrains.annotations.NotNull) javax.swing(javax.swing) Task(com.intellij.openapi.progress.Task) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) NotNull(org.jetbrains.annotations.NotNull) ApiService(io.github.kings1990.plugin.fastrequest.model.ApiService) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) BackgroundableProcessIndicator(com.intellij.openapi.progress.impl.BackgroundableProcessIndicator)

Example 2 with ApiService

use of io.github.kings1990.plugin.fastrequest.model.ApiService in project fast-request by dromara.

the class NodeUtil method getAllApiList.

public static List<ApiService> getAllApiList(Collection<PsiClass> controller) {
    SpringMethodUrlGenerator springMethodUrlGenerator = ApplicationManager.getApplication().getService(SpringMethodUrlGenerator.class);
    JaxRsGenerator jaxRsGenerator = ApplicationManager.getApplication().getService(JaxRsGenerator.class);
    List<ApiService> apiServiceList = new ArrayList<>();
    for (PsiClass psiClass : controller) {
        Module module = ModuleUtil.findModuleForPsiElement(psiClass);
        if (module == null) {
            continue;
        }
        String moduleName = module.getName();
        String className = psiClass.getName();
        PsiMethod[] methods = psiClass.getMethods();
        List<ApiService.ApiMethod> apiMethodList = new ArrayList<>();
        for (PsiMethod method : methods) {
            Constant.FrameworkType frameworkType = FrPsiUtil.calcFrameworkType(method);
            if (frameworkType.equals(Constant.FrameworkType.SPRING)) {
                for (Constant.SpringMappingConfig value : Constant.SpringMappingConfig.values()) {
                    if (method.getAnnotation(value.getCode()) != null) {
                        String methodDescription = springMethodUrlGenerator.getMethodDescription(method);
                        String name = method.getName();
                        String methodUrl = springMethodUrlGenerator.getMethodRequestMappingUrl(method);
                        String classUrl = springMethodUrlGenerator.getClassRequestMappingUrl(method);
                        String originUrl = classUrl + "/" + methodUrl;
                        originUrl = (originUrl.startsWith("/") ? "" : "/") + originUrl.replace("//", "/");
                        String methodType = springMethodUrlGenerator.getMethodType(method);
                        ApiService.ApiMethod apiMethod = new ApiService.ApiMethod(method, originUrl, methodDescription, name, methodType);
                        apiMethodList.add(apiMethod);
                        break;
                    }
                }
            } else {
                for (Constant.JaxRsMappingConfig value : Constant.JaxRsMappingConfig.values()) {
                    if (method.getAnnotation(value.getCode()) != null) {
                        String methodDescription = jaxRsGenerator.getMethodDescription(method);
                        String name = method.getName();
                        String methodUrl = jaxRsGenerator.getMethodRequestMappingUrl(method);
                        String classUrl = jaxRsGenerator.getClassRequestMappingUrl(method);
                        String originUrl = classUrl + "/" + methodUrl;
                        originUrl = (originUrl.startsWith("/") ? "" : "/") + originUrl.replace("//", "/");
                        String methodType = jaxRsGenerator.getMethodType(method);
                        ApiService.ApiMethod apiMethod = new ApiService.ApiMethod(method, originUrl, methodDescription, name, methodType);
                        apiMethodList.add(apiMethod);
                        break;
                    }
                }
            }
        }
        String packageName = getPackageName(psiClass);
        if (packageName == null) {
            packageName = "";
        }
        ApiService apiService = new ApiService(moduleName, packageName, className, apiMethodList);
        apiServiceList.add(apiService);
    }
    return apiServiceList;
}
Also used : JaxRsGenerator(io.github.kings1990.plugin.fastrequest.generator.impl.JaxRsGenerator) PsiMethod(com.intellij.psi.PsiMethod) Constant(io.github.kings1990.plugin.fastrequest.config.Constant) PsiClass(com.intellij.psi.PsiClass) ApiService(io.github.kings1990.plugin.fastrequest.model.ApiService) SpringMethodUrlGenerator(io.github.kings1990.plugin.fastrequest.generator.impl.SpringMethodUrlGenerator) Module(com.intellij.openapi.module.Module)

Example 3 with ApiService

use of io.github.kings1990.plugin.fastrequest.model.ApiService in project fast-request by dromara.

the class NodeUtil method convertToRoot.

public static void convertToRoot(DefaultMutableTreeNode root, LinkedHashMap<String, LinkedHashMap<String, LinkedHashMap<String, List<ApiService>>>> dataMap, List<String> selectMethodType) {
    List<ModuleNode> moduleNodeList = new ArrayList<>();
    for (Map.Entry<String, LinkedHashMap<String, LinkedHashMap<String, List<ApiService>>>> moduleEntry : dataMap.entrySet()) {
        String moduleName = moduleEntry.getKey();
        ModuleNode moduleNode = new ModuleNode(moduleName);
        LinkedHashMap<String, LinkedHashMap<String, List<ApiService>>> packageMap = moduleEntry.getValue();
        Map<String, PackageNode> packageNodeMap = new LinkedHashMap<>();
        for (Map.Entry<String, LinkedHashMap<String, List<ApiService>>> packageEntry : packageMap.entrySet()) {
            String packageName = packageEntry.getKey();
            LinkedHashMap<String, List<ApiService>> classMap = packageEntry.getValue();
            for (Map.Entry<String, List<ApiService>> classEntry : classMap.entrySet()) {
                String className = classEntry.getKey();
                ClassNode classNode = new ClassNode(className);
                for (ApiService apiService : classEntry.getValue()) {
                    List<ApiService.ApiMethod> apiMethodList = apiService.getApiMethodList();
                    List<ApiService.ApiMethod> filterMethodList = apiMethodList.stream().filter(q -> selectMethodType.contains(q.getMethodType())).collect(Collectors.toList());
                    filterMethodList.forEach(apiMethod -> classNode.add(new MethodNode(apiMethod)));
                }
                customPending(packageNodeMap, packageName).add(classNode);
            }
        }
        List<PackageNode> nodes = new ArrayList<>();
        packageNodeMap.forEach((key, rootNode) -> {
            if ("".equals(key)) {
                return;
            }
            while (true) {
                List<PackageNode> list = findChildren(rootNode);
                if (list.size() == 1) {
                    PackageNode newEle = list.get(0);
                    rootNode.remove(newEle);
                    String value = rootNode.getSource() + "." + newEle.getSource();
                    newEle.setSource(value);
                    newEle.setUserObject(value);
                    rootNode = newEle;
                } else {
                    break;
                }
            }
            sortChildNode(rootNode);
            nodes.add(rootNode);
        });
        nodes.forEach(moduleNode::add);
        PackageNode noPackageNode = packageNodeMap.get("");
        if (noPackageNode != null) {
            ArrayList<ClassNode> nodeList = (ArrayList<ClassNode>) IteratorUtils.toList(noPackageNode.children().asIterator());
            nodeList.sort(Comparator.comparing(ClassNode::toString));
            nodeList.forEach(moduleNode::add);
        }
        moduleNodeList.add(moduleNode);
    }
    moduleNodeList.sort(Comparator.comparing(ModuleNode::toString));
    moduleNodeList.forEach(root::add);
}
Also used : java.util(java.util) PsiMethod(com.intellij.psi.PsiMethod) TreeNode(javax.swing.tree.TreeNode) FrPsiUtil(io.github.kings1990.plugin.fastrequest.util.FrPsiUtil) ApiService(io.github.kings1990.plugin.fastrequest.model.ApiService) Collectors(java.util.stream.Collectors) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) SpringMethodUrlGenerator(io.github.kings1990.plugin.fastrequest.generator.impl.SpringMethodUrlGenerator) PsiClass(com.intellij.psi.PsiClass) ModuleUtil(com.intellij.openapi.module.ModuleUtil) JaxRsGenerator(io.github.kings1990.plugin.fastrequest.generator.impl.JaxRsGenerator) Constant(io.github.kings1990.plugin.fastrequest.config.Constant) IteratorUtils(org.apache.commons.collections.IteratorUtils) ApplicationManager(com.intellij.openapi.application.ApplicationManager) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull) ApiService(io.github.kings1990.plugin.fastrequest.model.ApiService)

Example 4 with ApiService

use of io.github.kings1990.plugin.fastrequest.model.ApiService in project fast-request by dromara.

the class AllApisNavToolWindow method rendingTree.

private void rendingTree(List<String> moduleNameList) {
    Task.Backgroundable task = new Task.Backgroundable(myProject, "Reload apis...") {

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            indicator.setIndeterminate(false);
            ApplicationManager.getApplication().runReadAction(() -> {
                Query<PsiClass> query = AllClassesSearch.search(ProjectScope.getContentScope(myProject), myProject);
                Collection<PsiClass> controller = query.filtering(cls -> cls.getAnnotation("org.springframework.web.bind.annotation.RestController") != null || cls.getAnnotation("org.springframework.stereotype.Controller") != null || cls.getAnnotation("org.springframework.web.bind.annotation.RequestMapping") != null || cls.getAnnotation("javax.ws.rs.Path") != null).filtering(cls -> {
                    if (moduleNameList == null) {
                        return true;
                    }
                    Module module = ModuleUtil.findModuleForFile(cls.getContainingFile());
                    if (module == null) {
                        return false;
                    }
                    return moduleNameList.contains(module.getName());
                }).allowParallelProcessing().findAll();
                allApiList = NodeUtil.getAllApiList(controller);
                indicator.setText("Rendering");
                List<String> selectMethodType = methodTypeFilter.getSelectedElementList();
                List<ApiService.ApiMethod> filterMethodList = new ArrayList<>();
                allApiList.stream().map(ApiService::getApiMethodList).forEach(filterMethodList::addAll);
                long count = filterMethodList.stream().filter(q -> selectMethodType.contains(q.getMethodType())).count();
                RootNode root = new RootNode(count + " apis");
                NodeUtil.convertToRoot(root, NodeUtil.convertToMap(allApiList.stream().filter(q -> CollectionUtil.isNotEmpty(q.getApiMethodList())).collect(Collectors.toList())), methodTypeFilter.getSelectedElementList());
                apiTree.setModel(new DefaultTreeModel(root));
                NotificationGroupManager.getInstance().getNotificationGroup("toolWindowNotificationGroup").createNotification("Reload apis complete", MessageType.INFO).notify(myProject);
            });
        }
    };
    ProgressManager.getInstance().runProcessWithProgressAsynchronously(task, new BackgroundableProcessIndicator(task));
}
Also used : java.util(java.util) AllIcons(com.intellij.icons.AllIcons) MessageType(com.intellij.openapi.ui.MessageType) ModuleManager(com.intellij.openapi.module.ModuleManager) ApiService(io.github.kings1990.plugin.fastrequest.model.ApiService) KeyAdapter(java.awt.event.KeyAdapter) Border(javax.swing.border.Border) Query(com.intellij.util.Query) PsiClass(com.intellij.psi.PsiClass) PersistentSearchEverywhereContributorFilter(com.intellij.ide.actions.searcheverywhere.PersistentSearchEverywhereContributorFilter) ModuleUtil(com.intellij.openapi.module.ModuleUtil) Task(com.intellij.openapi.progress.Task) MethodType(io.github.kings1990.plugin.fastrequest.model.MethodType) Disposer(com.intellij.openapi.util.Disposer) MouseAdapter(java.awt.event.MouseAdapter) Project(com.intellij.openapi.project.Project) SpeedSearchUtil(com.intellij.ui.speedSearch.SpeedSearchUtil) AllClassesSearch(com.intellij.psi.search.searches.AllClassesSearch) PsiNavigateUtil(com.intellij.util.PsiNavigateUtil) Module(com.intellij.openapi.module.Module) CommonActionsManager(com.intellij.ide.CommonActionsManager) BackgroundableProcessIndicator(com.intellij.openapi.progress.impl.BackgroundableProcessIndicator) io.github.kings1990.plugin.fastrequest.view.component.tree(io.github.kings1990.plugin.fastrequest.view.component.tree) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) ProgressManager(com.intellij.openapi.progress.ProgressManager) DumbService(com.intellij.openapi.project.DumbService) CollectionUtil(cn.hutool.core.collection.CollectionUtil) NotificationGroupManager(com.intellij.notification.NotificationGroupManager) ToolWindow(com.intellij.openapi.wm.ToolWindow) PsiMethod(com.intellij.psi.PsiMethod) FastRequestSearchEverywhereConfiguration(io.github.kings1990.plugin.fastrequest.configurable.FastRequestSearchEverywhereConfiguration) CheckBoxFilterAction(io.github.kings1990.plugin.fastrequest.action.CheckBoxFilterAction) KeyEvent(java.awt.event.KeyEvent) com.intellij.ui(com.intellij.ui) Collectors(java.util.stream.Collectors) Disposable(com.intellij.openapi.Disposable) MouseEvent(java.awt.event.MouseEvent) java.awt(java.awt) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) SimpleToolWindowPanel(com.intellij.openapi.ui.SimpleToolWindowPanel) List(java.util.List) Constant(io.github.kings1990.plugin.fastrequest.config.Constant) ApplicationManager(com.intellij.openapi.application.ApplicationManager) ProjectScope(com.intellij.psi.search.ProjectScope) NotNull(org.jetbrains.annotations.NotNull) javax.swing(javax.swing) Task(com.intellij.openapi.progress.Task) PsiClass(com.intellij.psi.PsiClass) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) NotNull(org.jetbrains.annotations.NotNull) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) BackgroundableProcessIndicator(com.intellij.openapi.progress.impl.BackgroundableProcessIndicator) Module(com.intellij.openapi.module.Module)

Aggregations

Module (com.intellij.openapi.module.Module)4 PsiClass (com.intellij.psi.PsiClass)4 PsiMethod (com.intellij.psi.PsiMethod)4 Constant (io.github.kings1990.plugin.fastrequest.config.Constant)4 ApiService (io.github.kings1990.plugin.fastrequest.model.ApiService)4 ApplicationManager (com.intellij.openapi.application.ApplicationManager)3 ModuleUtil (com.intellij.openapi.module.ModuleUtil)3 CollectionUtil (cn.hutool.core.collection.CollectionUtil)2 AllIcons (com.intellij.icons.AllIcons)2 CommonActionsManager (com.intellij.ide.CommonActionsManager)2 PersistentSearchEverywhereContributorFilter (com.intellij.ide.actions.searcheverywhere.PersistentSearchEverywhereContributorFilter)2 NotificationGroupManager (com.intellij.notification.NotificationGroupManager)2 Disposable (com.intellij.openapi.Disposable)2 com.intellij.openapi.actionSystem (com.intellij.openapi.actionSystem)2 ModuleManager (com.intellij.openapi.module.ModuleManager)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 ProgressManager (com.intellij.openapi.progress.ProgressManager)2 Task (com.intellij.openapi.progress.Task)2 BackgroundableProcessIndicator (com.intellij.openapi.progress.impl.BackgroundableProcessIndicator)2 DumbService (com.intellij.openapi.project.DumbService)2