Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added possibility to search through Bean System via Search Everywhere #1270

Merged
merged 1 commit into from
Nov 3, 2024
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<SystemRef> {
// return listOf(typeSystem, beanSystem)
return listOf(typeSystem)
}
fun forAllSystems() = listOf(typeSystem, beanSystem)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -86,18 +92,23 @@ class TypeSearchEverywhereContributor(event: AnActionEvent) : AbstractGotoSECont
private class TypeChooseByNameContributor : ChooseByNameContributor {
override fun getNames(project: Project?, includeNonProjectItems: Boolean): Array<String> {
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<NavigationItem> {
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) {
Expand All @@ -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
}
}
}
Loading