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 and navigation for Cockpitng 'list-view -> qualifier' #175

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
3 changes: 2 additions & 1 deletion resources/META-INF/optional-lang-dependencies.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@
<dom.fileMetaData rootTagName="editor-definition" stubVersion="2"
implementation="com.intellij.idea.plugin.hybris.system.cockpitng.CngEditorDefinitionDomFileDescription"/>

<completion.contributor language="XML" implementationClass="com.intellij.idea.plugin.hybris.codeInsight.completion.CockpitngCompletionContributor"/>
<completion.contributor language="XML" implementationClass="com.intellij.idea.plugin.hybris.system.cockpitng.codeInsight.completion.CngCompletionContributor"/>
<applicationService serviceImplementation="com.intellij.idea.plugin.hybris.system.cockpitng.codeInsight.completion.provider.CngItemAttributeCodeCompletionProvider"/>

<projectService serviceInterface="com.intellij.idea.plugin.hybris.system.cockpitng.meta.CngMetaModelAccess"
serviceImplementation="com.intellij.idea.plugin.hybris.system.cockpitng.meta.impl.CngMetaModelAccessImpl"/>
Expand Down
5 changes: 3 additions & 2 deletions resources/META-INF/plugin-internal.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
<applicationService serviceImplementation="com.intellij.idea.plugin.hybris.psi.reference.provider.HybrisEnumItemReferenceProvider"/>
<applicationService serviceImplementation="com.intellij.idea.plugin.hybris.psi.reference.provider.HybrisEnumLiteralItemReferenceProvider"/>
<applicationService serviceImplementation="com.intellij.idea.plugin.hybris.psi.reference.provider.HybrisModelItemReferenceProvider"/>
<applicationService serviceImplementation="com.intellij.idea.plugin.hybris.psi.reference.provider.TSItemReferenceProvider"/>
<applicationService serviceImplementation="com.intellij.idea.plugin.hybris.system.cockpitng.psi.provider.TSItemReferenceProvider"/>
<applicationService serviceImplementation="com.intellij.idea.plugin.hybris.system.cockpitng.psi.provider.TSAttributeReferenceProvider"/>
<psi.referenceContributor language="XML" implementation="com.intellij.idea.plugin.hybris.system.cockpitng.psi.contributor.CngReferenceContributor"/>
<psi.referenceContributor language="XML" implementation="com.intellij.idea.plugin.hybris.psi.reference.contributor.HybrisItemsXmlReferenceContributor"/>
<psi.referenceContributor language="XML" implementation="com.intellij.idea.plugin.hybris.psi.reference.contributor.HybrisCockpitngReferenceContributor"/>

<internalFileTemplate name="FlexibleSearch File"/>
<internalFileTemplate name="Impex File"/>
Expand Down
1 change: 1 addition & 0 deletions resources/META-INF/plugin-release-info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
<li><code>context -> component</code> (<a href="https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/169" target="_blank" rel="nofollow">#169</a>)</li>
<li><code>actions -> action-id</code> (<a href="https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/172" target="_blank" rel="nofollow">#172</a>)</li>
<li><code>widgets -> widgetDefinitionId</code> (<a href="https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/173" target="_blank" rel="nofollow">#173</a>)</li>
<li><code>list-view -> qualifier</code> (<a href="https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/175" target="_blank" rel="nofollow">#175</a>)</li>
</ul>
</li>
<li><i>Bug Fix:</i> FlexibleSearch code completion should not be case-sensitive for attributes (<a href="https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/167" target="_blank" rel="nofollow">#167</a>)</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ package com.intellij.idea.plugin.hybris.system.cockpitng
import com.intellij.idea.plugin.hybris.common.HybrisConstants
import com.intellij.idea.plugin.hybris.common.utils.HybrisIcons
import com.intellij.idea.plugin.hybris.system.cockpitng.model.config.Config
import com.intellij.idea.plugin.hybris.system.cockpitng.psi.CngPatterns
import com.intellij.openapi.module.Module
import com.intellij.psi.xml.XmlFile
import com.intellij.util.xml.DomFileDescription
import javax.swing.Icon

class CngConfigDomFileDescription : DomFileDescription<Config>(Config::class.java, "config") {
class CngConfigDomFileDescription : DomFileDescription<Config>(Config::class.java, CngPatterns.ROOT) {

override fun getFileIcon(flags: Int): Icon = HybrisIcons.COCKPIT_NG_CONFIG

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,37 @@
* 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.codeInsight.completion
package com.intellij.idea.plugin.hybris.system.cockpitng.codeInsight.completion

import com.intellij.codeInsight.completion.CompletionContributor
import com.intellij.codeInsight.completion.CompletionType
import com.intellij.idea.plugin.hybris.codeInsight.completion.provider.ItemTypeCodeCompletionProvider
import com.intellij.idea.plugin.hybris.common.HybrisConstants
import com.intellij.idea.plugin.hybris.common.utils.PsiXmlUtils
import com.intellij.idea.plugin.hybris.system.cockpitng.codeInsight.completion.provider.CngItemAttributeCodeCompletionProvider
import com.intellij.idea.plugin.hybris.system.cockpitng.psi.CngPatterns
import com.intellij.patterns.PlatformPatterns
import com.intellij.patterns.StandardPatterns

class CockpitngCompletionContributor : CompletionContributor() {
class CngCompletionContributor : CompletionContributor() {

init {
extend(
CompletionType.BASIC,
PsiXmlUtils.tagAttributePattern("context", "type", null)
.inFile(
PlatformPatterns.psiFile()
.withName(StandardPatterns.string().endsWith(HybrisConstants.COCKPIT_NG_CONFIG_XML))
),
PlatformPatterns.psiElement().inside(CngPatterns.CONTEXT_TYPE),
ItemTypeCodeCompletionProvider.instance
)
extend(
CompletionType.BASIC,
PsiXmlUtils.tagAttributePattern("context", "parent", null)
.inFile(
PlatformPatterns.psiFile()
.withName(StandardPatterns.string().endsWith(HybrisConstants.COCKPIT_NG_CONFIG_XML))
),
PlatformPatterns.psiElement().inside(CngPatterns.FLOW_STEP_CONTENT_PROPERTY_TYPE),
ItemTypeCodeCompletionProvider.instance
)
extend(
CompletionType.BASIC,
PlatformPatterns.psiElement().inside(CngPatterns.CONTEXT_PARENT),
ItemTypeCodeCompletionProvider.instance
)
extend(
CompletionType.BASIC,
PlatformPatterns.psiElement().inside(CngPatterns.LIST_VIEW_COLUMN_QUALIFIER),
CngItemAttributeCodeCompletionProvider.instance
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* 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.codeInsight.lookup.LookupElementBuilder
import com.intellij.idea.plugin.hybris.common.utils.HybrisIcons
import com.intellij.idea.plugin.hybris.system.cockpitng.model.config.Context
import com.intellij.idea.plugin.hybris.system.type.meta.TSMetaModelAccess
import com.intellij.openapi.application.ApplicationManager
import com.intellij.psi.PsiElement
import com.intellij.psi.util.findParentOfType
import com.intellij.psi.xml.XmlTag
import com.intellij.util.ProcessingContext
import com.intellij.util.xml.DomManager

class CngItemAttributeCodeCompletionProvider : CompletionProvider<CompletionParameters>() {

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

val resultCaseInsensitive = result.caseInsensitive()

TSMetaModelAccess.getInstance(project).findMetaItemByName(type)
?.allAttributes
?.map {
LookupElementBuilder.create(it.name)
.withStrikeoutness(it.isDeprecated)
.withTypeText(it.flattenType, true)
.withIcon(HybrisIcons.ATTRIBUTE)
}
?.forEach { resultCaseInsensitive.addElement(it) }
}

private fun resolveContext(element: PsiElement): Context? {
var parent = element.findParentOfType<XmlTag>()

while (parent != null && parent.name != "context") {
parent = parent.findParentOfType()
}
return DomManager.getDomManager(element.project).getDomElement(parent) as? Context
}

companion object {
val instance: CompletionProvider<CompletionParameters> =
ApplicationManager.getApplication().getService(CngItemAttributeCodeCompletionProvider::class.java)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* 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.psi

import com.intellij.idea.plugin.hybris.common.HybrisConstants
import com.intellij.idea.plugin.hybris.common.utils.PsiXmlUtils
import com.intellij.patterns.PlatformPatterns
import com.intellij.patterns.StandardPatterns
import com.intellij.patterns.XmlPatterns
import com.intellij.psi.xml.XmlTag

object CngPatterns {
const val ROOT = "config"
private const val CONTEXT = "context"

private val cngFile = PlatformPatterns.psiFile()
.withName(StandardPatterns.string().endsWith(HybrisConstants.COCKPIT_NG_CONFIG_XML))

val LIST_VIEW_COLUMN_QUALIFIER = XmlPatterns.xmlAttributeValue()
.withParent(
XmlPatterns.xmlAttribute().withLocalName("qualifier")
.withParent(
XmlPatterns.xmlTag().withLocalName("column")
.withParent(XmlPatterns.xmlTag().withLocalName("list-view"))
)
)
.inside(
XmlPatterns.xmlTag().withLocalName(CONTEXT)
.andNot(XmlPatterns.xmlAttributeValue().withValue(StandardPatterns.string().oneOfIgnoreCase("."))),
)
.inFile(cngFile)

val CONTEXT_PARENT = PsiXmlUtils.tagAttributeValuePattern(ROOT, CONTEXT, "parent")
.andNot(XmlPatterns.xmlAttributeValue().withValue(StandardPatterns.string().oneOfIgnoreCase("auto", ".")))
.inFile(cngFile)

val CONTEXT_TYPE = PsiXmlUtils.tagAttributeValuePattern(ROOT, CONTEXT, "type")
.andNot(XmlPatterns.xmlAttributeValue().withValue(StandardPatterns.string().contains(".")))
.inFile(cngFile)

val FLOW_STEP_CONTENT_PROPERTY_TYPE = XmlPatterns.xmlAttributeValue()
.withParent(
XmlPatterns.xmlAttribute().withLocalName("type")
.withParent(
XmlPatterns.xmlTag().withLocalName("property")
.inside(
XmlPatterns.xmlTag()
.withNamespace("http://www.hybris.com/cockpitng/config/wizard-config")
.withLocalName("content")
)
)
)
.andNot(XmlPatterns.xmlAttributeValue().withValue(StandardPatterns.string().contains(".")))
.inside(XmlPatterns.xmlTag().withLocalName(CONTEXT))
.inFile(cngFile)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* 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.psi

import com.intellij.codeInsight.highlighting.HighlightedReference
import com.intellij.idea.plugin.hybris.common.HybrisConstants
import com.intellij.idea.plugin.hybris.impex.psi.references.result.AttributeResolveResult
import com.intellij.idea.plugin.hybris.psi.reference.TSReferenceBase
import com.intellij.idea.plugin.hybris.system.cockpitng.model.config.Context
import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiPolyVariantReference
import com.intellij.psi.ResolveResult
import com.intellij.psi.util.findParentOfType
import com.intellij.psi.xml.XmlTag
import com.intellij.util.xml.DomManager

class TSAttributeReference(element: PsiElement) : TSReferenceBase<PsiElement>(element), PsiPolyVariantReference, HighlightedReference {

override fun calculateDefaultRangeInElement() = TextRange.from(1, element.textLength - HybrisConstants.QUOTE_LENGTH)

override fun multiResolve(incompleteCode: Boolean): Array<ResolveResult> {
val type = resolveContext()
?.type
?.stringValue
?: return emptyArray()

val meta = metaModelAccess.findMetaItemByName(type) ?: return emptyArray()
return metaItemService.findAttributesByName(meta, value, true)
?.mapNotNull { it.retrieveDom() }
?.map { AttributeResolveResult(it) }
?.toTypedArray()
?: emptyArray()
}

private fun resolveContext(): Context? {
var parent = element.findParentOfType<XmlTag>()

while (parent != null && (parent.name != "context" || parent.getAttributeValue("type") == null)) {
parent = parent.findParentOfType()
}
return DomManager.getDomManager(element.project).getDomElement(parent) as? Context
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.intellij.idea.plugin.hybris.psi.reference
package com.intellij.idea.plugin.hybris.system.cockpitng.psi

import com.intellij.codeInsight.highlighting.HighlightedReference
import com.intellij.idea.plugin.hybris.common.HybrisConstants
import com.intellij.idea.plugin.hybris.impex.psi.references.result.EnumResolveResult
import com.intellij.idea.plugin.hybris.impex.psi.references.result.ItemResolveResult
import com.intellij.idea.plugin.hybris.impex.psi.references.result.RelationResolveResult
import com.intellij.idea.plugin.hybris.psi.reference.TSReferenceBase
import com.intellij.idea.plugin.hybris.system.type.meta.model.TSGlobalMetaEnum
import com.intellij.idea.plugin.hybris.system.type.meta.model.TSGlobalMetaItem
import com.intellij.idea.plugin.hybris.system.type.meta.model.TSGlobalMetaRelation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,33 @@
* 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.psi.reference.contributor
package com.intellij.idea.plugin.hybris.system.cockpitng.psi.contributor

import com.intellij.idea.plugin.hybris.common.HybrisConstants
import com.intellij.idea.plugin.hybris.common.utils.PsiXmlUtils
import com.intellij.idea.plugin.hybris.psi.reference.provider.TSItemReferenceProvider
import com.intellij.patterns.PlatformPatterns
import com.intellij.patterns.StandardPatterns
import com.intellij.patterns.XmlPatterns
import com.intellij.idea.plugin.hybris.system.cockpitng.psi.CngPatterns
import com.intellij.idea.plugin.hybris.system.cockpitng.psi.provider.TSAttributeReferenceProvider
import com.intellij.idea.plugin.hybris.system.cockpitng.psi.provider.TSItemReferenceProvider
import com.intellij.psi.PsiReferenceContributor
import com.intellij.psi.PsiReferenceRegistrar

class HybrisCockpitngReferenceContributor : PsiReferenceContributor() {
class CngReferenceContributor : PsiReferenceContributor() {

override fun registerReferenceProviders(registrar: PsiReferenceRegistrar) {
val cockpitngConfigFile = PlatformPatterns.psiFile()
.withName(StandardPatterns.string().endsWith(HybrisConstants.COCKPIT_NG_CONFIG_XML))

// classes resolved by JavaXmlClassListReferenceContributor
registrar.registerReferenceProvider(
PsiXmlUtils.tagAttributeValuePattern("context", "type")
.inFile(cockpitngConfigFile),
CngPatterns.CONTEXT_TYPE,
TSItemReferenceProvider.instance
)
registrar.registerReferenceProvider(
CngPatterns.FLOW_STEP_CONTENT_PROPERTY_TYPE,
TSItemReferenceProvider.instance
)
registrar.registerReferenceProvider(
PsiXmlUtils.tagAttributeValuePattern("config", "context", "parent")
.andNot(XmlPatterns.xmlAttributeValue().withValue(StandardPatterns.string().oneOfIgnoreCase("auto")))
.inFile(cockpitngConfigFile),
CngPatterns.CONTEXT_PARENT,
TSItemReferenceProvider.instance
)
registrar.registerReferenceProvider(
CngPatterns.LIST_VIEW_COLUMN_QUALIFIER,
TSAttributeReferenceProvider.instance
)
}
}
Loading