Skip to content

Commit

Permalink
#242 | Added completion and navigation for items.xml - metatype attri…
Browse files Browse the repository at this point in the history
…bute
  • Loading branch information
mlytvyn authored Feb 23, 2023
1 parent c16f6d7 commit e00b07e
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 19 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 @@ -96,6 +96,7 @@
<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>
<li><i>Feature:</i> Added more custom icons (<a href="https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/237" target="_blank" rel="nofollow">#237</a>)</li>
<li><i>Feature:</i> Added custom icons for CCv2 project tree modules (<a href="https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/239" target="_blank" rel="nofollow">#239</a>)</li>
<li><i>Feature:</i> Added completion and navigation for <code>items.xml</code> - <code>metatype</code> attribute (<a href="https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/242" target="_blank" rel="nofollow">#242</a>)</li>
</ul>
<h3>2023.1.0</h3>
<ul>
Expand Down
1 change: 1 addition & 0 deletions resources/i18n/HybrisBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ hybris.inspections.ts.QualifierMustStartWithLowercaseLetter.key=[y] Qualifier mu
hybris.inspections.ts.TypeNameMustStartWithUppercaseLetter.key=[y] Type Names (including EnumTypes and Relations) must start with an uppercase letter
hybris.inspections.ts.TypeNameMustNotStartWithGenerated.key=[y] Type Names (including EnumTypes and Relations) must not start with the string Generated
hybris.inspections.ts.TypeNameMustPointToExistingType.key=[y] Type Name must point to existing Type
hybris.inspections.ts.TSMetaTypeNameMustPointToExistingMetaType.key=[y] MetaType Name must point to existing MetaType
hybris.inspections.ts.OrderingOfRelationShouldBeAvoided.key=[y] Any side of a relation that has cardinality='many' should not have ordered='true' unless absolutely necessary
hybris.inspections.ts.ListsInRelationShouldBeAvoided.key=[y] Any side of a relation that has cardinality='many' should have collectiontype='set' unless absolutely necessary
hybris.inspections.ts.UseOfUnoptimizedAttributesIsNotRecommended.key=[y] Use of unoptimized attributes is not recommended
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private HybrisIcons() {

public static final Icon IMPEX_FILE = getIcon("/icons/fileTypes/impexFile.svg");
public static final Icon FS_FILE = getIcon("/icons/fileTypes/flexibleSearchFileIcon.svg");
public static final Icon BEAN_FILE = getIcon("/icons/beanIcon.svg");
public static final Icon BEAN_FILE = getIcon("/icons/beanSystem/beanIcon.svg");

public static final Icon IMPEX = getIcon("/icons/impex.svg");
public static final Icon FLEXIBLE_SEARCH = getIcon("/icons/flexibleSearch.svg");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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.type.file

import com.intellij.idea.plugin.hybris.common.HybrisConstants
import com.intellij.idea.plugin.hybris.system.type.meta.TSMetaHelper
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.TSMetaType
import com.intellij.util.xml.ConvertContext

class ItemMetaTypeConverter : ItemTypeConverter() {

override fun searchForName(name: String, context: ConvertContext, meta: TSMetaModelAccess) = meta.findMetaItemByName(name)
?.takeIf { TSMetaHelper.isAttributeDescriptor(it) }
?.retrieveDom()

override fun searchAll(context: ConvertContext, meta: TSMetaModelAccess) = meta.getAll<TSGlobalMetaItem>(TSMetaType.META_ITEM)
.filter { TSMetaHelper.isAttributeDescriptor(it) }
.mapNotNull { it.retrieveDom() }

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import com.intellij.idea.plugin.hybris.system.type.model.ItemType
import com.intellij.psi.PsiElement
import com.intellij.util.xml.ConvertContext

class ItemTypeConverter : TSConverterBase<ItemType>(ItemType::class.java) {
open class ItemTypeConverter : TSConverterBase<ItemType>(ItemType::class.java) {

override fun searchForName(name: String, context: ConvertContext, meta: TSMetaModelAccess) = meta.findMetaItemByName(name)
?.retrieveDom()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class TSMetaHelper {

companion object {
private fun escapeType(type: String?) = type
?.replace(HybrisConstants.TS_JAVA_LANG_PREFIX, "")
?.replace(HybrisConstants.TS_JAVA_LANG_PREFIX, "")

private fun flattenType(type: Type, elementType: String?) = when (type) {
Type.COLLECTION -> "Collection<${elementType ?: '?'}>"
Expand Down Expand Up @@ -68,41 +68,41 @@ class TSMetaHelper {
fun flattenType(meta: TSGlobalMetaCollection) = flattenType(meta.type, escapeType(meta.elementType))
fun flattenType(meta: TSGlobalMetaMap) = "Map<${escapeType(meta.argumentType) ?: '?'}, ${escapeType(meta.returnType) ?: '?'}>"
fun flattenType(meta: TSGlobalMetaRelation) =
escapeType(meta.source.type) + " [${mapCardinality(meta.source)}:${mapCardinality(meta.target)}] " + escapeType(meta.target.type)
escapeType(meta.source.type) + " [${mapCardinality(meta.source)}:${mapCardinality(meta.target)}] " + escapeType(meta.target.type)

fun flattenType(meta: TSGlobalMetaAtomic) = meta.name
fun flattenType(meta: TSGlobalMetaItem) = meta.name
fun flattenType(meta: TSGlobalMetaEnum) = meta.name

fun isDeprecated(dom: AttributeModel, name: String) = dom.setters
.any { name == it.name.stringValue && java.lang.Boolean.TRUE == it.deprecated.value }
.any { name == it.name.stringValue && java.lang.Boolean.TRUE == it.deprecated.value }

fun isLocalized(type: String?) = type?.startsWith(HybrisConstants.TS_ATTRIBUTE_LOCALIZED_PREFIX, true)
?: false
?: false

fun isDynamic(persistence: TSMetaPersistence) = PersistenceType.DYNAMIC == persistence.type

fun isCatalogAware(dom: CustomProperties) = getProperty(dom, HybrisConstants.TS_CATALOG_ITEM_TYPE)
?.let { parseBooleanValue(it) }
?: false
?.let { parseBooleanValue(it) }
?: false

fun getProperty(dom: CustomProperties, name: String) = dom.properties
.firstOrNull { name.equals(it.name.stringValue, true) }
.firstOrNull { name.equals(it.name.stringValue, true) }

fun parseStringValue(customProperty: CustomProperty) = customProperty.value.rawText?.replace("\"", "")

fun parseBooleanValue(customProperty: CustomProperty) =
"java.lang.Boolean.TRUE" == customProperty.value.rawText
|| "Boolean.TRUE" == customProperty.value.rawText
"java.lang.Boolean.TRUE" == customProperty.value.rawText
|| "Boolean.TRUE" == customProperty.value.rawText

fun parseIntValue(customProperty: CustomProperty) = customProperty.value.rawText
?.replace("Integer.valueOf(", "")
?.replace(")", "")
?.toIntOrNull()
?.replace("Integer.valueOf(", "")
?.replace(")", "")
?.toIntOrNull()

fun parseCommaSeparatedStringValue(customProperty: CustomProperty) = parseStringValue(customProperty)
?.split(",")
?.map { it.trim() }
?.split(",")
?.map { it.trim() }

fun getAllExtends(metaModel: TSGlobalMetaModel, meta: TSGlobalMetaItem): Set<TSGlobalMetaItem> {
val tempParents = LinkedHashSet<TSGlobalMetaItem>()
Expand All @@ -116,15 +116,19 @@ class TSMetaHelper {
}

fun getAllRelationEnds(
metaModel: TSGlobalMetaModel,
meta: TSGlobalMetaItem,
extends: Set<TSGlobalMetaItem>
metaModel: TSGlobalMetaModel,
meta: TSGlobalMetaItem,
extends: Set<TSGlobalMetaItem>
): Collection<TSMetaRelation.TSMetaRelationElement> {
val currentMetaRelationEnds = getMetaRelationEnds(metaModel, meta)
val extendsMetaRelationEnds = extends.flatMap { metaExtend -> getMetaRelationEnds(metaModel, metaExtend) }
return currentMetaRelationEnds + extendsMetaRelationEnds
}

fun isAttributeDescriptor(it: TSGlobalMetaItem) = (HybrisConstants.TS_META_TYPE_ATTRIBUTE_DESCRIPTOR == it.name
|| it.allExtends.any { extends -> HybrisConstants.TS_META_TYPE_ATTRIBUTE_DESCRIPTOR == extends.name })


private fun getMetaItem(metaModel: TSGlobalMetaModel, meta: TSGlobalMetaItem): TSGlobalMetaItem? {
val realExtendedMetaItemName = meta.extendedMetaItemName ?: HybrisConstants.TS_TYPE_GENERIC_ITEM

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import com.intellij.idea.plugin.hybris.system.type.converter.AttributeReferenceConverter;
import com.intellij.idea.plugin.hybris.system.type.file.CompositeConverter;
import com.intellij.idea.plugin.hybris.system.type.file.ItemMetaTypeConverter;
import com.intellij.util.xml.Convert;
import com.intellij.util.xml.DomElement;
import com.intellij.util.xml.GenericAttributeValue;
Expand Down Expand Up @@ -111,6 +112,7 @@ public interface Attribute extends DomElement {
*/
@NotNull
@com.intellij.util.xml.Attribute(META_TYPE)
@Convert(value = ItemMetaTypeConverter.class)
GenericAttributeValue<String> getMetaType();


Expand Down

0 comments on commit e00b07e

Please sign in to comment.