From 9d53e4633f26ab95217cfd4047feec65d8d78e50 Mon Sep 17 00:00:00 2001 From: Mykhailo Lytvyn Date: Sun, 3 Nov 2024 18:41:45 +0100 Subject: [PATCH] Added possibility to search through Bean System via Search Everywhere --- CHANGELOG.md | 1 + .../system/type/searcheverywhere/SystemRef.kt | 24 +++++++++--- .../TypeSearchEverywhereContributor.kt | 39 ++++++++++++++++--- 3 files changed, 52 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eca402e7a..60332c5d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### `Search Everywhere` enhancements - Introduced possibility to search through Type System via _Search Everywhere_ [#1267](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/1267) - Added scope and preview for Type System Search Everywhere [#1269](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/1269) +- Added possibility to search through Bean System via _Search Everywhere_ [#1270](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/1270) ### `ImpEx` enhancements - Added **CronExp** language injection for **Trigger** type into String literal [#1256](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/1256) diff --git a/src/com/intellij/idea/plugin/hybris/system/type/searcheverywhere/SystemRef.kt b/src/com/intellij/idea/plugin/hybris/system/type/searcheverywhere/SystemRef.kt index cb6bad3d1..7aff9a198 100644 --- a/src/com/intellij/idea/plugin/hybris/system/type/searcheverywhere/SystemRef.kt +++ b/src/com/intellij/idea/plugin/hybris/system/type/searcheverywhere/SystemRef.kt @@ -19,24 +19,36 @@ package com.intellij.idea.plugin.hybris.system.type.searcheverywhere import com.intellij.idea.plugin.hybris.common.utils.HybrisIcons +import com.intellij.idea.plugin.hybris.system.bean.BSDomFileDescription +import com.intellij.idea.plugin.hybris.system.type.file.TSDomFileDescription import com.intellij.navigation.NavigationItem import com.intellij.psi.PsiElement +import com.intellij.psi.xml.XmlFile +import com.intellij.util.xml.DomManager import javax.swing.Icon data class SystemRef(val id: String, val displayName: String, val icon: Icon?) { companion object { private val typeSystem = SystemRef("type", "Type System", HybrisIcons.TypeSystem.FILE) -// private val beanSystem = SystemRef("bean", "Bean System", HybrisIcons.BeanSystem.FILE) + private val beanSystem = SystemRef("bean", "Bean System", HybrisIcons.BeanSystem.FILE) fun forNavigationItem(item: NavigationItem): SystemRef? = when (item) { - is PsiElement -> typeSystem + is PsiElement -> { + val file = item.containingFile as? XmlFile + ?: return null + + when (DomManager.getDomManager(item.project).getDomFileDescription(file)) { + is TSDomFileDescription -> typeSystem + is BSDomFileDescription -> beanSystem + else -> null + } + + } + else -> null } - fun forAllSystems(): List { -// return listOf(typeSystem, beanSystem) - return listOf(typeSystem) - } + fun forAllSystems() = listOf(typeSystem, beanSystem) } } diff --git a/src/com/intellij/idea/plugin/hybris/system/type/searcheverywhere/TypeSearchEverywhereContributor.kt b/src/com/intellij/idea/plugin/hybris/system/type/searcheverywhere/TypeSearchEverywhereContributor.kt index b9204ca0d..af0d490c4 100644 --- a/src/com/intellij/idea/plugin/hybris/system/type/searcheverywhere/TypeSearchEverywhereContributor.kt +++ b/src/com/intellij/idea/plugin/hybris/system/type/searcheverywhere/TypeSearchEverywhereContributor.kt @@ -21,6 +21,8 @@ import com.intellij.ide.actions.SearchEverywherePsiRenderer import com.intellij.ide.actions.searcheverywhere.* import com.intellij.ide.util.gotoByName.FilteringGotoByModel import com.intellij.idea.plugin.hybris.common.utils.HybrisIcons +import com.intellij.idea.plugin.hybris.system.bean.meta.BSMetaModelAccess +import com.intellij.idea.plugin.hybris.system.bean.model.Beans import com.intellij.idea.plugin.hybris.system.type.meta.TSMetaModelAccess import com.intellij.idea.plugin.hybris.system.type.model.* import com.intellij.navigation.ChooseByNameContributor @@ -59,6 +61,10 @@ class TypeSearchEverywhereContributor(event: AnActionEvent) : AbstractGotoSECont EnumTypes.ENUMTYPE -> HybrisIcons.TypeSystem.Types.ENUM Relations.RELATION -> HybrisIcons.TypeSystem.Types.RELATION MapTypes.MAPTYPE -> HybrisIcons.TypeSystem.Types.MAP + + Beans.BEAN -> HybrisIcons.BeanSystem.BEAN + Beans.ENUM -> HybrisIcons.BeanSystem.ENUM + else -> null } @@ -86,18 +92,23 @@ class TypeSearchEverywhereContributor(event: AnActionEvent) : AbstractGotoSECont private class TypeChooseByNameContributor : ChooseByNameContributor { override fun getNames(project: Project?, includeNonProjectItems: Boolean): Array { if (project == null) return emptyArray() - return TSMetaModelAccess.getInstance(project).getAll() + val types = TSMetaModelAccess.getInstance(project).getAll() + .mapNotNull { it.name } + .toTypedArray() + val beans = BSMetaModelAccess.getInstance(project).getAllBeans() .mapNotNull { it.name } .toTypedArray() + val enums = BSMetaModelAccess.getInstance(project).getAllEnums() + .mapNotNull { it.name } + .toTypedArray() + return types + beans + enums } override fun getItemsByName(name: String?, pattern: String?, project: Project?, includeNonProjectItems: Boolean): Array { - if (project == null) return emptyArray() - if (name == null) return emptyArray() - if (pattern == null) return emptyArray() + if (project == null || name == null || pattern == null) return emptyArray() - return TSMetaModelAccess.getInstance(project).getAll() - .filter { it.name?.lowercase()?.contains(pattern.lowercase()) ?: false } + val types = TSMetaModelAccess.getInstance(project).getAll() + .filter { it.name?.lowercase()?.contains(pattern.lowercase()) == true } .flatMap { it.retrieveAllDoms() } .mapNotNull { when (it) { @@ -111,6 +122,22 @@ class TypeSearchEverywhereContributor(event: AnActionEvent) : AbstractGotoSECont } .mapNotNull { it as? NavigationItem } .toTypedArray() + + val beans = BSMetaModelAccess.getInstance(project).getAllBeans() + .filter { it.name?.lowercase()?.contains(pattern.lowercase()) == true } + .flatMap { it.retrieveAllDoms() } + .mapNotNull { it.clazz.xmlAttributeValue } + .mapNotNull { it as? NavigationItem } + .toTypedArray() + + val enums = BSMetaModelAccess.getInstance(project).getAllEnums() + .filter { it.name?.lowercase()?.contains(pattern.lowercase()) == true } + .flatMap { it.retrieveAllDoms() } + .mapNotNull { it.clazz.xmlAttributeValue } + .mapNotNull { it as? NavigationItem } + .toTypedArray() + + return types + beans + enums } } }