Skip to content

Commit

Permalink
#168 | Added navigation to 'items.xml' Relation declaration from gene…
Browse files Browse the repository at this point in the history
…rated classes
  • Loading branch information
mlytvyn authored Jan 15, 2023
1 parent fcea802 commit ea39a4a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
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 @@ -126,6 +126,7 @@
(<a href="https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/120" target="_blank" rel="nofollow">#120</a>,
<a href="https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/71" target="_blank" rel="nofollow">#71</a>)</li>
<li><i>Feature:</i> Enabled [y] plugin settings sharing through <a href="https://www.jetbrains.com/help/idea/sharing-your-ide-settings.html#IDE_settings_sync">Settings Sync</a> (<a href="https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/163" target="_blank" rel="nofollow">#163</a>)</li>
<li><i>Feature:</i> Added navigation to <code>items.xml</code> Relation declaration from generated classes (<a href="https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/168" target="_blank" rel="nofollow">#168</a>)</li>
<li><i>Feature:</i> Added navigation to <code>items.xml</code> Enum values declaration from generated classes (<a href="https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/115" target="_blank" rel="nofollow">#115</a>)</li>
<li><i>Feature:</i> Added navigation to <code>beans.xml</code> Enum values declaration from generated classes (<a href="https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/111" target="_blank" rel="nofollow">#111</a>)</li>
<li><i>Feature:</i> Added navigation to <code>beans.xml</code> Bean property declaration from generated classes (<a href="https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/112" target="_blank" rel="nofollow">#112</a>)</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand All @@ -39,7 +39,22 @@ class TSAttributeFieldLineMarkerProvider : AbstractTSAttributeLineMarkerProvider
if ((psi.type as PsiClassReferenceType).name != String::class.java.simpleName) return Optional.empty()

return psi.childrenOfType<PsiLiteralExpression>()
.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<RelatedItemLineMarkerInfo<PsiElement>> {
val dom = TSMetaModelAccess.getInstance(nameIdentifier.project).findMetaRelationByName(name)
?.retrieveDom()
?.xmlElement
?: return Optional.empty<RelatedItemLineMarkerInfo<PsiElement>>()

return Optional.of(createTargetsWithGutterIcon(nameIdentifier, listOf(dom), HybrisIcons.RELATION))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand All @@ -79,7 +79,7 @@ object ModelEnumerationChildrenRendererInfoProvider {
true
)

private fun getChildInfo(
private fun createChildInfo(
attribute: TSGlobalMetaItem.TSGlobalMetaItemAttribute,
attributeName: String,
fieldName: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -37,7 +38,7 @@ abstract class ColumnReferenceMixin(node: ASTNode) : ASTWrapperPsiElement(node),

}

internal class TSAttributeReference(owner: FlexibleSearchColumnReference) : TSReferenceBase<FlexibleSearchColumnReference>(owner) {
internal class TSAttributeReference(owner: FlexibleSearchColumnReference) : TSReferenceBase<FlexibleSearchColumnReference>(owner), HighlightedReference {

override fun multiResolve(incompleteCode: Boolean): Array<ResolveResult> {
val featureName = element.text.replace("!", "")
Expand Down

0 comments on commit ea39a4a

Please sign in to comment.