Skip to content

Commit

Permalink
#257 | Improved performance of the Global Meta Model and TS LineMarker
Browse files Browse the repository at this point in the history
  • Loading branch information
mlytvyn authored Mar 2, 2023
1 parent e823733 commit d10dda0
Show file tree
Hide file tree
Showing 44 changed files with 468 additions and 486 deletions.
6 changes: 5 additions & 1 deletion resources/META-INF/plugin-release-info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<li><a href="https://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/setting_up_environment.html">How to Configure Project Environment For Plugin Developers</a></li>
<li>We are working with <a href="https://help.github.com/articles/about-pull-requests/">Pull Requests</a>. You need to fork this repository, implement a feature in a separate branch, then send us a pull request.</li>
<li>Be sure to include into your pull request and all commit messages the following line: "Signed-off-by: Your Real Name [email protected]" otherwise it can not be accepted. Use your real name.</li>
<li>For additional questions you can send an <a href="mailto:[email protected]">email</a></li>§
<li>For additional questions you can send an <a href="mailto:[email protected]">email</a></li>
</ul>
<h3>Contributors and Developers</h3>
Expand Down Expand Up @@ -91,6 +91,10 @@

<change-notes>
<![CDATA[
<h3>2023.1.2</h3>
<ul>
<li><i>Feature:</i> Improved performance of the Global Meta Model and TS LineMarker (<a href="https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/257" target="_blank" rel="nofollow">#257</a>)</li>
</ul>
<h3>2023.1.1</h3>
<ul>
<li><i>Feature:</i> Added possibility to import CCv2 folders as modules (<a href="https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/238" target="_blank" rel="nofollow">#238</a>)</li>
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* 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.codeInsight.daemon

import com.intellij.codeInsight.daemon.RelatedItemLineMarkerInfo
import com.intellij.idea.plugin.hybris.common.utils.HybrisI18NBundleUtils.message
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.meta.model.TSMetaRelation.RelationEnd
import com.intellij.idea.plugin.hybris.system.type.utils.ModelsUtils
import com.intellij.psi.PsiClass
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiIdentifier
import com.intellij.psi.xml.XmlElement
import javax.swing.Icon

abstract class AbstractTSAttributeLineMarkerProvider<T : PsiElement> : AbstractTSItemLineMarkerProvider<T>() {

override fun getTooltipText() = message("hybris.editor.gutter.item.attribute.tooltip.navigate.declaration")
override fun getPopupTitle() = message("hybris.editor.gutter.bean.attribute.navigate.choose.class.title")
override fun getEmptyPopupText() = message("hybris.editor.gutter.navigate.no.matching.attributes")

override fun collectDeclarations(psi: T): RelatedItemLineMarkerInfo<PsiElement>? {
val psiClass = psi.parent
if (psiClass !is PsiClass || !ModelsUtils.isModelFile(psiClass)) return null

return TSMetaModelAccess.getInstance(psi.project).findMetaItemByName(cleanSearchName(psiClass.name))
?.let { collect(it, psi) }
}

protected abstract fun collect(meta: TSGlobalMetaItem, psi: T): RelatedItemLineMarkerInfo<PsiElement>?

protected open fun getPsiElementRelatedItemLineMarkerInfo(
meta: TSGlobalMetaItem, name: String, nameIdentifier: PsiIdentifier
) = with(getAttributeElements(meta, name)) {
if (this.isEmpty()) {
val groupedRelElements = getRelations(meta, name)
return@with getRelationMarkers(groupedRelElements, RelationEnd.SOURCE, HybrisIcons.TS_RELATION_SOURCE, nameIdentifier)
?: getRelationMarkers(groupedRelElements, RelationEnd.TARGET, HybrisIcons.TS_RELATION_TARGET, nameIdentifier)
} else {
return@with createTargetsWithGutterIcon(nameIdentifier, this, HybrisIcons.TS_ATTRIBUTE)
}
}

open fun getAttributeElements(meta: TSGlobalMetaItem, name: String) = meta.allAttributes
.filter { it.name == name }
.flatMap { it.declarations }
.map { it.domAnchor }
.mapNotNull { it.retrieveDomElement() }
.mapNotNull { it.xmlElement }

open fun getRelations(meta: TSGlobalMetaItem, name: String) = meta.allRelationEnds
.filter { it.qualifier == name }
.filter { it.isNavigable }
.filter { it.domAnchor.retrieveDomElement()?.xmlElement != null }
.groupBy({ it.end }, { it.domAnchor.retrieveDomElement()!!.xmlElement!! })

open fun getRelationMarkers(
groupedRelElements: Map<RelationEnd, List<XmlElement?>>,
target: RelationEnd,
icon: Icon,
nameIdentifier: PsiIdentifier
) = groupedRelElements[target]
?.let { createTargetsWithGutterIcon(nameIdentifier, it, icon) }

}
Loading

0 comments on commit d10dda0

Please sign in to comment.