From ea39a4a02fe12b9d6fb5283a7be1bcf4eb3d03b7 Mon Sep 17 00:00:00 2001 From: Mykhailo Lytvyn Date: Sun, 15 Jan 2023 20:52:17 +0100 Subject: [PATCH] #168 | Added navigation to 'items.xml' Relation declaration from generated classes --- resources/META-INF/plugin-release-info.xml | 1 + .../TSAttributeFieldLineMarkerProvider.kt | 25 +++++++++++++++---- ...EnumerationChildrenRendererInfoProvider.kt | 4 +-- .../references/ColumnReferenceMixin.kt | 3 ++- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/resources/META-INF/plugin-release-info.xml b/resources/META-INF/plugin-release-info.xml index 79f27eba2..50d23d259 100644 --- a/resources/META-INF/plugin-release-info.xml +++ b/resources/META-INF/plugin-release-info.xml @@ -126,6 +126,7 @@ (#120, #71)
  • Feature: Enabled [y] plugin settings sharing through Settings Sync (#163)
  • +
  • Feature: Added navigation to items.xml Relation declaration from generated classes (#168)
  • Feature: Added navigation to items.xml Enum values declaration from generated classes (#115)
  • Feature: Added navigation to beans.xml Enum values declaration from generated classes (#111)
  • Feature: Added navigation to beans.xml Bean property declaration from generated classes (#112)
  • diff --git a/src/com/intellij/idea/plugin/hybris/codeInsight/daemon/TSAttributeFieldLineMarkerProvider.kt b/src/com/intellij/idea/plugin/hybris/codeInsight/daemon/TSAttributeFieldLineMarkerProvider.kt index 1085a3e72..ae664d4d3 100644 --- a/src/com/intellij/idea/plugin/hybris/codeInsight/daemon/TSAttributeFieldLineMarkerProvider.kt +++ b/src/com/intellij/idea/plugin/hybris/codeInsight/daemon/TSAttributeFieldLineMarkerProvider.kt @@ -19,13 +19,13 @@ package com.intellij.idea.plugin.hybris.codeInsight.daemon import com.intellij.codeInsight.daemon.RelatedItemLineMarkerInfo +import com.intellij.idea.plugin.hybris.common.utils.HybrisIcons +import com.intellij.idea.plugin.hybris.system.type.meta.TSMetaModelAccess import com.intellij.idea.plugin.hybris.system.type.meta.model.TSGlobalMetaItem -import com.intellij.idea.plugin.hybris.system.type.model.Attribute import com.intellij.psi.PsiElement import com.intellij.psi.PsiField -import com.intellij.psi.PsiJavaCodeReferenceElement +import com.intellij.psi.PsiIdentifier import com.intellij.psi.PsiLiteralExpression -import com.intellij.psi.PsiMethod import com.intellij.psi.impl.source.PsiClassReferenceType import com.intellij.psi.util.childrenOfType import java.util.* @@ -39,7 +39,22 @@ class TSAttributeFieldLineMarkerProvider : AbstractTSAttributeLineMarkerProvider if ((psi.type as PsiClassReferenceType).name != String::class.java.simpleName) return Optional.empty() return psi.childrenOfType() - .map { getPsiElementRelatedItemLineMarkerInfo(meta, it.value.toString(), psi.nameIdentifier) } - .firstOrNull() ?: Optional.empty() + .map { + val name = it.value.toString() + val nameIdentifier = psi.nameIdentifier + getPsiElementRelatedItemLineMarkerInfo(meta, name, nameIdentifier) + .or { getPsiElementRelatedRelationLineMarkerInfo(name, nameIdentifier) } + } + .firstOrNull() + ?: Optional.empty() + } + + private fun getPsiElementRelatedRelationLineMarkerInfo(name: String, nameIdentifier: PsiIdentifier): Optional> { + val dom = TSMetaModelAccess.getInstance(nameIdentifier.project).findMetaRelationByName(name) + ?.retrieveDom() + ?.xmlElement + ?: return Optional.empty>() + + return Optional.of(createTargetsWithGutterIcon(nameIdentifier, listOf(dom), HybrisIcons.RELATION)) } } \ No newline at end of file diff --git a/src/com/intellij/idea/plugin/hybris/debugger/ui/tree/render/ModelEnumerationChildrenRendererInfoProvider.kt b/src/com/intellij/idea/plugin/hybris/debugger/ui/tree/render/ModelEnumerationChildrenRendererInfoProvider.kt index 84e875518..9a7eee343 100644 --- a/src/com/intellij/idea/plugin/hybris/debugger/ui/tree/render/ModelEnumerationChildrenRendererInfoProvider.kt +++ b/src/com/intellij/idea/plugin/hybris/debugger/ui/tree/render/ModelEnumerationChildrenRendererInfoProvider.kt @@ -55,7 +55,7 @@ object ModelEnumerationChildrenRendererInfoProvider { meta.allAttributes .find { attr -> attr.name == computedConstantValue } - ?.let { attribute -> return@mapNotNull getChildInfo(attribute, computedConstantValue, it.name, metaAccess, debuggerUtils) } + ?.let { attribute -> return@mapNotNull createChildInfo(attribute, computedConstantValue, it.name, metaAccess, debuggerUtils) } meta.allRelationEnds .find { relation -> relation.name == computedConstantValue } ?.let { relation -> return@mapNotNull createChildInfo(computedConstantValue, relation, it.name, debuggerUtils) } @@ -79,7 +79,7 @@ object ModelEnumerationChildrenRendererInfoProvider { true ) - private fun getChildInfo( + private fun createChildInfo( attribute: TSGlobalMetaItem.TSGlobalMetaItemAttribute, attributeName: String, fieldName: String, diff --git a/src/com/intellij/idea/plugin/hybris/flexibleSearch/references/ColumnReferenceMixin.kt b/src/com/intellij/idea/plugin/hybris/flexibleSearch/references/ColumnReferenceMixin.kt index 57b1ec8b7..6523619f6 100644 --- a/src/com/intellij/idea/plugin/hybris/flexibleSearch/references/ColumnReferenceMixin.kt +++ b/src/com/intellij/idea/plugin/hybris/flexibleSearch/references/ColumnReferenceMixin.kt @@ -1,5 +1,6 @@ package com.intellij.idea.plugin.hybris.flexibleSearch.references +import com.intellij.codeInsight.highlighting.HighlightedReference import com.intellij.extapi.psi.ASTWrapperPsiElement import com.intellij.idea.plugin.hybris.flexibleSearch.psi.* import com.intellij.idea.plugin.hybris.psi.reference.TSReferenceBase @@ -37,7 +38,7 @@ abstract class ColumnReferenceMixin(node: ASTNode) : ASTWrapperPsiElement(node), } -internal class TSAttributeReference(owner: FlexibleSearchColumnReference) : TSReferenceBase(owner) { +internal class TSAttributeReference(owner: FlexibleSearchColumnReference) : TSReferenceBase(owner), HighlightedReference { override fun multiResolve(incompleteCode: Boolean): Array { val featureName = element.text.replace("!", "")