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 code completion for list-view:column:class #1028

Merged
merged 3 commits into from
Feb 25, 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 @@ -4,6 +4,7 @@
- Added code completion for various `merge-mode` attributes [#1022](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/1022)
- Ignore case of the `merge-mode` attribute [#1023](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/1023)
- Improved xsd mapping for `ea:attribute` [#1024](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/1024)
- Added code completion for `list-view:column`:`class` [#1028](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/1028)

## [2024.1.0]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ object HybrisConstants {
const val CLASS_FQN_IMPEX_SPECIAL_TRANSLATOR = "de.hybris.platform.impex.jalo.translators.SpecialValueTranslator"
const val CLASS_FQN_IMPEX_HEADER_TRANSLATOR = "de.hybris.platform.impex.jalo.translators.HeaderCellTranslator"
const val CLASS_FQN_IMPEX_CELL_DECORATOR = "de.hybris.platform.util.CSVCellDecorator"
const val CLASS_FQN_CNG_WIDGET_COMPONENT_RENDERER = "com.hybris.cockpitng.widgets.common.WidgetComponentRenderer"
const val CLASS_FQN_FLEXIBLE_SEARCH_QUERY = "de.hybris.platform.servicelayer.search.FlexibleSearchQuery"
const val CLASS_FQN_CODE_GENERATOR = "de.hybris.bootstrap.codegenerator.CodeGenerator"
const val CLASS_NAME_FLEXIBLE_SEARCH_QUERY = "FlexibleSearchQuery"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

package com.intellij.idea.plugin.hybris.impex.codeInsight.lookup

import com.intellij.codeInsight.completion.JavaLookupElementBuilder
import com.intellij.codeInsight.lookup.LookupElementBuilder
import com.intellij.idea.plugin.hybris.codeInsight.completion.AutoPopupInsertHandler
import com.intellij.idea.plugin.hybris.common.utils.HybrisIcons
Expand All @@ -27,7 +26,6 @@ import com.intellij.idea.plugin.hybris.impex.constants.modifier.TypeModifier
import com.intellij.idea.plugin.hybris.impex.psi.ImpexAttribute
import com.intellij.idea.plugin.hybris.impex.psi.ImpexTypes
import com.intellij.idea.plugin.hybris.impex.settings.ImpexCompletionSettings
import com.intellij.psi.PsiClass
import com.intellij.psi.PsiElement
import com.intellij.psi.impl.source.tree.LeafPsiElement
import com.intellij.psi.util.childrenOfType
Expand All @@ -39,10 +37,8 @@ object ImpExLookupElementFactory {

fun build(element: PsiElement, modifier: AttributeModifier, completionSettings: ImpexCompletionSettings) = build(element, modifier.modifierName, completionSettings)

fun buildJavaClass(psiClass: PsiClass, presentableText: String) = JavaLookupElementBuilder.forClass(psiClass, psiClass.qualifiedName, true)
.withPresentableText(presentableText)

fun buildModifierValue(lookupElement: String) = LookupElementBuilder.create(lookupElement)

fun buildModifierValue(lookupElement: String, typeText: String, presentableText: String = lookupElement) = LookupElementBuilder.create(lookupElement)
.withPresentableText(presentableText)
.withTypeText(typeText, true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ package com.intellij.idea.plugin.hybris.impex.constants.modifier
import com.intellij.codeInsight.lookup.LookupElement
import com.intellij.idea.plugin.hybris.common.HybrisConstants
import com.intellij.idea.plugin.hybris.impex.codeInsight.lookup.ImpExLookupElementFactory
import com.intellij.idea.plugin.hybris.impex.completion.ImpexImplementationClassCompletionContributor
import com.intellij.idea.plugin.hybris.impex.psi.ImpexAnyAttributeName
import com.intellij.idea.plugin.hybris.impex.psi.ImpexAnyAttributeValue
import com.intellij.idea.plugin.hybris.java.completion.JavaClassCompletionService
import com.intellij.openapi.project.Project

/**
Expand Down Expand Up @@ -60,11 +60,11 @@ enum class AttributeModifier(
PATH_DELIMITER("path-delimiter"),
POS("pos"),
CELL_DECORATOR("cellDecorator") {
override fun getLookupElements(project: Project) = ImpexImplementationClassCompletionContributor.getInstance(project)
override fun getLookupElements(project: Project) = JavaClassCompletionService.getInstance(project)
.getImplementationsForClasses(HybrisConstants.CLASS_FQN_IMPEX_CELL_DECORATOR)
},
TRANSLATOR("translator") {
override fun getLookupElements(project: Project) = ImpexImplementationClassCompletionContributor.getInstance(project)
override fun getLookupElements(project: Project) = JavaClassCompletionService.getInstance(project)
.getImplementationsForClasses(*HybrisConstants.CLASS_FQN_IMPEX_TRANSLATORS)
},
EXPR("expr"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ package com.intellij.idea.plugin.hybris.impex.constants.modifier
import com.intellij.codeInsight.lookup.LookupElement
import com.intellij.idea.plugin.hybris.common.HybrisConstants
import com.intellij.idea.plugin.hybris.impex.codeInsight.lookup.ImpExLookupElementFactory
import com.intellij.idea.plugin.hybris.impex.completion.ImpexImplementationClassCompletionContributor
import com.intellij.idea.plugin.hybris.impex.constants.InterceptorType
import com.intellij.idea.plugin.hybris.impex.psi.ImpexAnyAttributeName
import com.intellij.idea.plugin.hybris.impex.psi.ImpexAnyAttributeValue
import com.intellij.idea.plugin.hybris.java.completion.JavaClassCompletionService
import com.intellij.idea.plugin.hybris.project.utils.PluginCommon
import com.intellij.idea.plugin.hybris.system.type.codeInsight.completion.TSCompletionService
import com.intellij.idea.plugin.hybris.system.type.meta.model.TSMetaType
Expand Down Expand Up @@ -76,7 +76,7 @@ enum class TypeModifier(
CACHE_UNIQUE("cacheUnique", HybrisConstants.IMPEX_MODIFIER_BOOLEAN_VALUES),
IMPEX_LEGACY_MODE("impex.legacy.mode", HybrisConstants.IMPEX_MODIFIER_BOOLEAN_VALUES),
PROCESSOR("processor") {
override fun getLookupElements(project: Project) = ImpexImplementationClassCompletionContributor.getInstance(project)
override fun getLookupElements(project: Project) = JavaClassCompletionService.getInstance(project)
.getImplementationsForClasses(HybrisConstants.CLASS_FQN_IMPEX_PROCESSOR)
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.intellij.idea.plugin.hybris.impex.completion
package com.intellij.idea.plugin.hybris.java.completion

import com.intellij.codeInsight.completion.JavaLookupElementBuilder
import com.intellij.codeInsight.lookup.LookupElement
import com.intellij.idea.plugin.hybris.impex.codeInsight.lookup.ImpExLookupElementFactory
import com.intellij.openapi.components.Service
import com.intellij.openapi.project.Project
import com.intellij.psi.JavaPsiFacade
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.psi.search.searches.ClassInheritorsSearch

@Service(Service.Level.PROJECT)
class ImpexImplementationClassCompletionContributor(val myProject: Project) {
class JavaClassCompletionService(val myProject: Project) {

fun getImplementationsForClasses(vararg qualifiedNames: String): Set<LookupElement> {
val psiFacade = JavaPsiFacade.getInstance(myProject)
Expand All @@ -41,13 +41,15 @@ class ImpexImplementationClassCompletionContributor(val myProject: Project) {
.filterNot { it.isInterface }
.mapNotNull {
val presentableText = it.name ?: return@mapNotNull null
ImpExLookupElementFactory.buildJavaClass(it, presentableText)
val lookupString = it.qualifiedName ?: return@mapNotNull null
JavaLookupElementBuilder.forClass(it, lookupString, true)
.withPresentableText(presentableText)
}
.toSet()
}

companion object {
fun getInstance(project: Project): ImpexImplementationClassCompletionContributor = project.getService(ImpexImplementationClassCompletionContributor::class.java)
fun getInstance(project: Project): JavaClassCompletionService = project.getService(JavaClassCompletionService::class.java)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,10 @@ class CngCompletionContributor : CompletionContributor() {
PlatformPatterns.psiElement().inside(CngPatterns.WIDGET_SETTING),
CngWidgetSettingCompletionProvider.instance
)
extend(
CompletionType.BASIC,
PlatformPatterns.psiElement().inside(CngPatterns.WIDGET_COMPONENT_RENDERER_CLASS),
CngWidgetComponentRendererClassCompletionProvider.instance
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* This file is part of "SAP Commerce Developers Toolset" plugin for Intellij IDEA.
* Copyright (C) 2019 EPAM Systems <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.intellij.idea.plugin.hybris.system.cockpitng.codeInsight.completion.provider

import com.intellij.codeInsight.completion.CompletionParameters
import com.intellij.codeInsight.completion.CompletionProvider
import com.intellij.codeInsight.completion.CompletionResultSet
import com.intellij.idea.plugin.hybris.common.HybrisConstants
import com.intellij.idea.plugin.hybris.java.completion.JavaClassCompletionService
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.Service
import com.intellij.util.ProcessingContext

@Service(Service.Level.APP)
class CngWidgetComponentRendererClassCompletionProvider : CompletionProvider<CompletionParameters>() {

public override fun addCompletions(
parameters: CompletionParameters,
context: ProcessingContext,
result: CompletionResultSet
) {
val project = parameters.editor.project ?: return

val elements = JavaClassCompletionService.getInstance(project).getImplementationsForClasses(
HybrisConstants.CLASS_FQN_CNG_WIDGET_COMPONENT_RENDERER
)
result.addAllElements(elements)
}

companion object {
val instance: CompletionProvider<CompletionParameters> = ApplicationManager.getApplication().getService(CngWidgetComponentRendererClassCompletionProvider::class.java)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ object CngPatterns {
.inside(XmlPatterns.xmlTag().withLocalName(CONFIG_CONTEXT))
.inFile(cngConfigFile)

val WIDGET_COMPONENT_RENDERER_CLASS = XmlPatterns.or(
attributeValue(
"class",
"column",
"list-view",
CngConfigDomFileDescription.NAMESPACE_COCKPIT_NG_COMPONENT_LIST_VIEW
)
.inside(XmlPatterns.xmlTag().withLocalName(CONFIG_CONTEXT))
.inFile(cngConfigFile)

)

val EDITOR_DEFINITION = XmlPatterns.or(
attributeValue(
"editor",
Expand Down
Loading