Skip to content

Commit

Permalink
#772 | Improved detailed message for `TSDeploymentTableMustNotBeRedec…
Browse files Browse the repository at this point in the history
…laredInChildTypes`
  • Loading branch information
mlytvyn authored Oct 27, 2023
1 parent 5656fb4 commit c80ad46
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
- Do not register SAP javadocs for custom extensions [#763](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/763)
- Use custom library names for all custom libraries [#764](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/764)

### `items.xml` inspection rules
- Improved detailed message for `TSDeploymentTableMustNotBeRedeclaredInChildTypes` [#772](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/772)

### `ImpEx` enhancements
- Use single space after Header Mode [#761](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/761)

Expand Down
1 change: 1 addition & 0 deletions resources/i18n/HybrisBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ hybris.inspections.ts.DeploymentTypeCodeMustBeUnique.key=[y] Deployment type cod
hybris.inspections.ts.DeploymentTableMustBeUnique.key=[y] Deployment table must be unique
hybris.inspections.ts.DeploymentTableMustExistForItemExtendingGenericItem.key=[y] A deployment table must be defined for all Items extending GenericItem
hybris.inspections.ts.DeploymentTableMustNotBeRedeclaredInChildTypes.key=[y] Deployment table must be declared only once per Model and not redeclared in child declarations
hybris.inspections.ts.DeploymentTableMustNotBeRedeclaredInChildTypes.problem.key=[y] Deployment table must be declared only once per Model and not redeclared in child declarations. [{0} : {1}] extends [{2} : {3}]
hybris.inspections.ts.DeploymentTypeCodeMustBeGreaterThanTenThousand.key=[y] Type codes between 1 and 10000 are reserved for SAP Commerce
hybris.inspections.ts.JaloClassIsNotAllowedWhenAddingFieldsToExistingClass.key=[y] The jaloclass attribute is not allowed when autocreate='false' and generate='false'
hybris.inspections.ts.DeploymentTableMustExistForManyToManyRelation.key=[y] A deployment table must be defined for all many-to-many relations
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of "SAP Commerce Developers Toolset" plugin for Intellij IDEA.
* Copyright (C) 2019 EPAM Systems <[email protected]>
* Copyright (C) 2019-2023 EPAM Systems <[email protected]> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
Expand All @@ -19,6 +19,7 @@
package com.intellij.idea.plugin.hybris.codeInspection.rule.typeSystem

import com.intellij.idea.plugin.hybris.codeInspection.fix.xml.XmlDeleteSubTagQuickFix
import com.intellij.idea.plugin.hybris.common.utils.HybrisI18NBundleUtils.message
import com.intellij.idea.plugin.hybris.system.type.meta.TSMetaModelAccess
import com.intellij.idea.plugin.hybris.system.type.model.ItemType
import com.intellij.idea.plugin.hybris.system.type.model.Items
Expand All @@ -27,7 +28,6 @@ import com.intellij.lang.annotation.HighlightSeverity
import com.intellij.openapi.project.Project
import com.intellij.util.xml.highlighting.DomElementAnnotationHolder
import com.intellij.util.xml.highlighting.DomHighlightingHelper
import org.apache.commons.lang3.StringUtils

class TSDeploymentTableMustNotBeRedeclaredInChildTypes : AbstractTSInspection() {

Expand All @@ -51,19 +51,26 @@ class TSDeploymentTableMustNotBeRedeclaredInChildTypes : AbstractTSInspection()
?: return

val currentMetaTypeCode = metaItem.deployment?.typeCode
?.takeIf { it.isNotBlank() }
?: return

if (StringUtils.isBlank(currentMetaTypeCode)) return

val countDeploymentTablesInParents = metaItem.allExtends
val metaItemParent = metaItem.allExtends
.flatMap { it.declarations }
.count { StringUtils.isNotBlank(it.deployment?.typeCode) }
.firstOrNull { it.deployment?.typeCode?.isNotBlank() ?: false }
?: return

if (countDeploymentTablesInParents == 0) return
val message = message(
"hybris.inspections.ts.DeploymentTableMustNotBeRedeclaredInChildTypes.problem.key",
metaItem.name ?: "?",
currentMetaTypeCode,
metaItemParent.name ?: "?",
metaItemParent.deployment?.typeCode ?: "?"
)

holder.createProblem(
dom,
severity,
displayName,
message,
getTextRange(dom),
XmlDeleteSubTagQuickFix(ItemType.DEPLOYMENT)
)
Expand Down

0 comments on commit c80ad46

Please sign in to comment.