Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relation qualifier and modifiers must not be declared for part with navigable false #307

Merged
6 changes: 6 additions & 0 deletions resources/META-INF/plugin-inspections.xml
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,12 @@
bundle="i18n.HybrisBundle" key="hybris.inspections.ts.TSDeploymentTableNameLengthShouldBeValid.key"
shortName="TSDeploymentTableNameLengthShouldBeValid" level="ERROR"
implementationClass="com.intellij.idea.plugin.hybris.codeInspection.rule.typeSystem.TSDeploymentTableNameLengthShouldBeValid"/>

<localInspection language="XML" enabledByDefault="true" groupPath="SAP Commerce" groupName="[y] Type System"
bundle="i18n.HybrisBundle" key="hybris.inspections.ts.TSQualifierAndModifiersMustNotBeDeclaredForNavigableFalse.key"
shortName="TSQualifierAndModifiersMustNotBeDeclaredForNavigableFalse" level="ERROR"
implementationClass="com.intellij.idea.plugin.hybris.codeInspection.rule.typeSystem.TSQualifierAndModifiersMustNotBeDeclaredForNavigableFalse"/>

</extensions>

</idea-plugin>
5 changes: 5 additions & 0 deletions resources/META-INF/plugin-release-info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@
<li><i>Feature:</i> Enabled Wizard-based Project Import from the Welcome Screen (<a href="https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/306" target="_blank" rel="nofollow">#306</a>)</li>
<li><i>Feature:</i> Improved support of the custom DOM files (<a href="https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/301" target="_blank" rel="nofollow">#301</a>)</li>
<li><i>Feature:</i> Enable selection of the CCv2 modules during Project import (<a href="https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/303" target="_blank" rel="nofollow">#303</a>)</li>
<li><i>Feature:</i> Added new inspection rules for <code>items.xml</code>
<ul>
<li>Relation qualifier and modifiers must not be declared for part with <code>navigable='false'</code>(<a href="https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/307" target="_blank" rel="nofollow">#307</a>)</li>
</ul>
</li>
<li><i>Other:</i> Added Project icon for Plugin repository (<a href="https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/302" target="_blank" rel="nofollow">#302</a>)</li>
<li><i>Other:</i> Replaced Caffeine cache with IDEA user data (<a href="https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/304" target="_blank" rel="nofollow">#304</a>)</li>
<li><i>Other:</i> Updated to Gradle plugin to 1.13.3</li>
Expand Down
1 change: 1 addition & 0 deletions resources/i18n/HybrisBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ hybris.inspections.ts.DefaultValueForEnumTypeMustBeAssignable.key=[y] Default va
hybris.inspections.ts.DeploymentTagMustNotBeDeclaredForO2MRelation.key=[y] Deployment tag must not be declared for one-to-many relation
hybris.inspections.ts.TSDeploymentTableNameLengthShouldBeValid.key=[y] Deployment table name must not exceed max allowed length
hybris.inspections.fix.ts.TSDeploymentTableNameLengthShouldBeValid.key=[y] Deployment table name ''{0}'' is length of ''{1}'' and must not exceed max allowed length of ''{2}''
hybris.inspections.ts.TSQualifierAndModifiersMustNotBeDeclaredForNavigableFalse.key=[y] Qualifier and modifiers must not be declared for navigable false

hybris.inspections.bs.DuplicateBeanDeclaration.key=[y] Bean declaration is duplicated within the same file
hybris.inspections.bs.DuplicateEnumDeclaration.key=[y] Enum declaration is duplicated within the same file
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!--
~ 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/>.
-->

<html>
<body>
Qualifier and modifiers must not be declared for navigable false in many-to-many relation
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package com.intellij.idea.plugin.hybris.codeInspection.rule.typeSystem
import com.intellij.idea.plugin.hybris.system.type.model.Cardinality
import com.intellij.idea.plugin.hybris.system.type.model.Items
import com.intellij.idea.plugin.hybris.system.type.model.Relation
import com.intellij.idea.plugin.hybris.system.type.model.cardinality
import com.intellij.lang.annotation.HighlightSeverity
import com.intellij.openapi.project.Project
import com.intellij.util.xml.highlighting.DomElementAnnotationHolder
Expand All @@ -42,8 +43,8 @@ class TSDeploymentTableMustExistForManyToManyRelation : AbstractTSInspection() {
holder: DomElementAnnotationHolder,
severity: HighlightSeverity
) {
val sourceCardinality = dom.sourceElement.cardinality.value ?: Cardinality.MANY
val targetCardinality = dom.targetElement.cardinality.value ?: Cardinality.MANY
val sourceCardinality = dom.sourceElement.cardinality
val targetCardinality = dom.targetElement.cardinality

if (sourceCardinality == Cardinality.MANY && targetCardinality == Cardinality.MANY && dom.deployment.typeCode.stringValue == null) {
holder.createProblem(dom.deployment.typeCode, severity, displayName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.intellij.idea.plugin.hybris.codeInspection.fix.XmlDeleteTagQuickFix
import com.intellij.idea.plugin.hybris.system.type.model.Cardinality
import com.intellij.idea.plugin.hybris.system.type.model.Items
import com.intellij.idea.plugin.hybris.system.type.model.Relation
import com.intellij.idea.plugin.hybris.system.type.model.cardinality
import com.intellij.lang.annotation.HighlightSeverity
import com.intellij.openapi.project.Project
import com.intellij.util.xml.highlighting.DomElementAnnotationHolder
Expand All @@ -46,8 +47,8 @@ class TSDeploymentTagMustNotBeDeclaredForO2MRelation : AbstractTSInspection() {
holder: DomElementAnnotationHolder,
severity: HighlightSeverity,
) {
if (relation.sourceElement.cardinality.value === Cardinality.ONE ||
relation.targetElement.cardinality.value === Cardinality.ONE) {
if (relation.sourceElement.cardinality === Cardinality.ONE ||
relation.targetElement.cardinality === Cardinality.ONE) {
holder.createProblem(
relation.deployment,
severity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,9 @@ class TSListsInRelationShouldBeAvoided : AbstractTSInspection() {
holder: DomElementAnnotationHolder,
severity: HighlightSeverity
) {
val cardinality = relation.cardinality.value ?: Cardinality.MANY
val collectionType = relation.collectionType.value ?: Type.COLLECTION
val xmlElement = relation.collectionType.xmlElement
if (xmlElement != null && cardinality == Cardinality.MANY && collectionType == Type.LIST) {
if (xmlElement != null && relation.cardinality == Cardinality.MANY && collectionType == Type.LIST) {
holder.createProblem(
relation.collectionType,
severity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@
package com.intellij.idea.plugin.hybris.codeInspection.rule.typeSystem

import com.intellij.idea.plugin.hybris.codeInspection.fix.XmlDeleteAttributeQuickFix
import com.intellij.idea.plugin.hybris.system.type.model.Cardinality
import com.intellij.idea.plugin.hybris.system.type.model.Items
import com.intellij.idea.plugin.hybris.system.type.model.RelationElement
import com.intellij.idea.plugin.hybris.system.type.model.elements
import com.intellij.idea.plugin.hybris.system.type.model.*
import com.intellij.lang.annotation.HighlightSeverity
import com.intellij.openapi.project.Project
import com.intellij.util.xml.highlighting.DomElementAnnotationHolder
Expand All @@ -45,7 +42,7 @@ class TSOrderingOfRelationShouldBeAvoided : AbstractTSInspection() {
holder: DomElementAnnotationHolder,
severity: HighlightSeverity
) {
val cardinality = relation.cardinality.value ?: Cardinality.MANY
val cardinality = relation.cardinality
val ordered = relation.ordered.value ?: false
if (relation.xmlElement != null && relation.ordered.xmlElement != null && cardinality == Cardinality.MANY && ordered) {
holder.createProblem(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* 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.codeInspection.rule.typeSystem

import com.intellij.idea.plugin.hybris.codeInspection.fix.XmlDeleteAttributeQuickFix
import com.intellij.idea.plugin.hybris.codeInspection.fix.XmlDeleteTagQuickFix
import com.intellij.idea.plugin.hybris.system.type.model.*
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

class TSQualifierAndModifiersMustNotBeDeclaredForNavigableFalse : AbstractTSInspection() {
override fun inspect(
project: Project,
dom: Items,
holder: DomElementAnnotationHolder,
helper: DomHighlightingHelper,
severity: HighlightSeverity
) {
dom.relations.relations
.filter { it.sourceElement.cardinality === Cardinality.MANY && it.targetElement.cardinality === Cardinality.MANY }
.filter { !it.sourceElement.navigable || !it.targetElement.navigable }
.forEach {
checkNonNavigable(it.sourceElement, holder, severity)
checkNonNavigable(it.targetElement, holder, severity)
}
}

private fun checkNonNavigable(
relationElement: RelationElement,
holder: DomElementAnnotationHolder,
severity: HighlightSeverity,
) {
if (relationElement.navigable) {
return
}

if (relationElement.qualifier.exists()) {
holder.createProblem(
relationElement.qualifier,
severity,
displayName,
XmlDeleteAttributeQuickFix(relationElement.qualifier.value)
)
}
if (relationElement.modifiers.exists()) {
holder.createProblem(
relationElement.modifiers,
severity,
displayName,
XmlDeleteTagQuickFix()
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class TSStructureTreeElement(
private fun resolveLocationString(dom: RelationElement) = listOfNotNull(
dom.type.stringValue,
dom.collectionType.stringValue ?: "collection",
dom.cardinality.stringValue,
dom.cardinality,
dom.ordered.stringValue?.let { "ordered($it)" }
).joinToString()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ import com.intellij.idea.plugin.hybris.system.type.meta.TSMetaHelper
import com.intellij.idea.plugin.hybris.system.type.meta.model.*
import com.intellij.idea.plugin.hybris.system.type.meta.model.TSMetaRelation.RelationEnd
import com.intellij.idea.plugin.hybris.system.type.meta.model.TSMetaRelation.TSMetaRelationElement
import com.intellij.idea.plugin.hybris.system.type.model.Cardinality
import com.intellij.idea.plugin.hybris.system.type.model.Relation
import com.intellij.idea.plugin.hybris.system.type.model.RelationElement
import com.intellij.idea.plugin.hybris.system.type.model.Type
import com.intellij.idea.plugin.hybris.system.type.model.*
import com.intellij.openapi.module.Module
import com.intellij.util.xml.DomAnchor
import com.intellij.util.xml.DomService
Expand Down Expand Up @@ -68,11 +65,11 @@ internal class TSMetaRelationImpl(
override val type = dom.type.stringValue ?: ""
override val qualifier = dom.qualifier.stringValue
override val name = qualifier
override val isNavigable = dom.navigable.value ?: true
override val isNavigable = dom.navigable
override val isOrdered = java.lang.Boolean.TRUE == dom.ordered.value
override val isDeprecated = TSMetaHelper.isDeprecated(dom.model, name)
override val collectionType = dom.collectionType.value ?: Type.COLLECTION
override val cardinality = dom.cardinality.value ?: Cardinality.MANY
override val cardinality = dom.cardinality
override val description = dom.description.stringValue
override val metaType = dom.metaType.stringValue
// type will be flattened after merge, we need to know exact type to expand it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,13 @@ val Relations.elements: List<RelationElement>
get() {
return relations.flatMap { listOf(it.sourceElement, it.targetElement) }
}

val RelationElement.cardinality: Cardinality
get() {
return cardinalityNoFallback.value ?: Cardinality.MANY
}

val RelationElement.navigable: Boolean
get() {
return navigableNoFallback.value ?: true
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public interface RelationElement extends DomElement {
*/
@NotNull
@com.intellij.util.xml.Attribute(CARDINALITY)
GenericAttributeValue<Cardinality> getCardinality();
GenericAttributeValue<Cardinality> getCardinalityNoFallback();


/**
Expand All @@ -116,7 +116,7 @@ public interface RelationElement extends DomElement {
*/
@NotNull
@com.intellij.util.xml.Attribute(NAVIGABLE)
GenericAttributeValue<Boolean> getNavigable();
GenericAttributeValue<Boolean> getNavigableNoFallback();


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private boolean isRelationOutOfDate(
@NotNull final Relation relation,
@NotNull final Map<String, PsiClass> filteredClasses
) {
final Boolean sourceNavigable = getBoolean(relation.getSourceElement().getNavigable());
final Boolean sourceNavigable = getBoolean(relation.getSourceElement().getNavigableNoFallback());

if (Boolean.TRUE.equals(sourceNavigable)) {
final Boolean isGenerate = getBoolean(relation.getSourceElement().getModel().getGenerate());
Expand All @@ -81,7 +81,7 @@ private boolean isRelationOutOfDate(
}
}

final Boolean targetNavigable = getBoolean(relation.getTargetElement().getNavigable());
final Boolean targetNavigable = getBoolean(relation.getTargetElement().getNavigableNoFallback());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use Kotlin compile class instead ModelExtensionsKt.getNavigable(relation.getTargetElement()), same for all java usages of the Kotlin extension functions/properties


if (Boolean.TRUE.equals(targetNavigable)) {
final Boolean isGenerate = getBoolean(relation.getTargetElement().getModel().getGenerate());
Expand Down