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

Impex Inspection rule - Type modifier is unknown #291

Merged
merged 1 commit into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions resources/META-INF/plugin-inspections.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@
groupName="[y] Impex" level="ERROR" language="Impex" enabledByDefault="true"
implementationClass="com.intellij.idea.plugin.hybris.codeInspection.rule.impex.ImpexUnknownTypeNameInspection"/>

<localInspection groupPath="SAP Commerce" shortName="ImpexUnknownTypeModifierInspection" displayName="[y] Unknown type modifier"
groupName="[y] Impex" level="ERROR" language="Impex" enabledByDefault="true"
implementationClass="com.intellij.idea.plugin.hybris.codeInspection.rule.impex.ImpexUnknownTypeModifierInspection"/>

<!-- <localInspection groupPath="SAP Commerce" shortName="ImpexUnknownAttributeModifierInspection" displayName="[y] Unknown attribute modifier"-->
<!-- groupName="[y] Impex" level="ERROR" language="Impex" enabledByDefault="true"-->
<!-- implementationClass="com.intellij.idea.plugin.hybris.codeInspection.rule.impex.ImpexUnknownAttributeModifierInspection"/>-->

<!-- Extension Info -->
<localInspection language="XML" enabledByDefault="true" groupPath="SAP Commerce" groupName="[y] Extension Info"
bundle="i18n.HybrisBundle" key="hybris.inspections.ei.EiUnknownExtensionDefinition.key"
Expand Down
7 changes: 6 additions & 1 deletion resources/META-INF/plugin-release-info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,12 @@
<li>Attribute is not defined</li>
</ul>
</li>
<li><i>Feature:</i> Added new inspection rule for <code>items.xml</code>
<li><i>Feature:</i> Added new <strong>Impex</strong> inspection rules
<ul>
<li>Type modifier is unknown (<a href="https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/291" target="_blank" rel="nofollow">#291</a>)</li>
</ul>
</li>
<li><i>Feature:</i> Added new inspection rules for <code>items.xml</code>
<ul>
<li>Deployment tag must not be declared for one-to-many relation (<a href="https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/289" target="_blank" rel="nofollow">#289</a>)</li>
</ul>
Expand Down
2 changes: 2 additions & 0 deletions resources/i18n/HybrisBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ hybris.inspections.impex.ImpexConfigProcessorInspection.key=[y] Incorrect use of
hybris.inspections.impex.ImpexUnknownConfigPropertyInspection.param.key=[y] Unknown config property ''{0}''
hybris.inspections.impex.ImpexUnknownConfigPropertyInspection.key=[y] Unknown config property ''{0}''
hybris.inspections.impex.ImpexUnknownMacrosInspection.key=[y] Unknown macro ''{0}''
hybris.inspections.impex.ImpexUnknownAttributeModifierInspection.key=[y] Unknown Attribute modifier ''{0}''
hybris.inspections.impex.ImpexUnknownTypeModifierInspection.key=[y] Unknown Type modifier ''{0}''

hybris.inspections.ts.AttributeHandlerMustBeSetForDynamicAttribute.key=[y] Attribute handler must be defined for Dynamic Attribute
hybris.inspections.ts.DeploymentTypeCodeMustBeUnique.key=[y] Deployment type code must be unique
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!--
~ This file is part of "hybris integration" plugin for Intellij IDEA.
~ Copyright (C) 2014-2019 Alexander Bartash <[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>
This modifier is not supported by Impex files.

see: <a href="https://help.sap.com/docs/SAP_COMMERCE/d0224eca81e249cb821f2cdf45a82ace/1c8f5bebdc6e434782ff0cfdb0ca1847.html?locale=en-US">help.sap.com</a>
SLD: <a href="https://help.sap.com/docs/SAP_COMMERCE/d0224eca81e249cb821f2cdf45a82ace/ccf4dd14636b4f7eac2416846ffd5a70.html?locale=en-US">SLD</a>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,28 @@ import com.intellij.psi.impl.source.tree.LeafPsiElement
class ImpexUnknownTypeAttributeInspection : LocalInspectionTool() {
override fun getDefaultLevel(): HighlightDisplayLevel = HighlightDisplayLevel.ERROR
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor = ImpexHeaderLineVisitor(holder)
}

private class ImpexHeaderLineVisitor(private val problemsHolder: ProblemsHolder) : ImpexVisitor() {
override fun visitAnyHeaderParameterName(parameter: ImpexAnyHeaderParameterName) {
if (!isNotMacros(parameter) || !isNotDocumentId(parameter.firstChild)) return
private class ImpexHeaderLineVisitor(private val problemsHolder: ProblemsHolder) : ImpexVisitor() {
override fun visitAnyHeaderParameterName(parameter: ImpexAnyHeaderParameterName) {
if (!isNotMacros(parameter) || !isNotDocumentId(parameter.firstChild)) return

val firstReference = parameter.references.firstOrNull() ?: return
val firstReference = parameter.references.firstOrNull() ?: return

if (firstReference.canonicalText.contains(".")) return
if (firstReference !is TSReferenceBase<*>) return
if (firstReference.multiResolve(false).isNotEmpty()) return
if (firstReference.canonicalText.contains(".")) return
if (firstReference !is TSReferenceBase<*>) return
if (firstReference.multiResolve(false).isNotEmpty()) return

val typeName = findHeaderItemTypeName(parameter)
?.text
?: "?"
problemsHolder.registerProblem(
parameter,
message("hybris.inspections.UnknownTypeAttributeInspection.key", parameter.text, typeName),
ProblemHighlightType.ERROR)
}
val typeName = findHeaderItemTypeName(parameter)
?.text
?: "?"
problemsHolder.registerProblem(
parameter,
message("hybris.inspections.UnknownTypeAttributeInspection.key", parameter.text, typeName),
ProblemHighlightType.ERROR)
}

private fun isNotMacros(parameter: ImpexAnyHeaderParameterName) = parameter.firstChild !is ImpexMacroUsageDec
private fun isNotMacros(parameter: ImpexAnyHeaderParameterName) = parameter.firstChild !is ImpexMacroUsageDec

private fun isNotDocumentId(element: PsiElement) = (element as LeafPsiElement).elementType != DOCUMENT_ID
private fun isNotDocumentId(element: PsiElement) = (element as LeafPsiElement).elementType != DOCUMENT_ID
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* 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.impex

import com.intellij.codeHighlighting.HighlightDisplayLevel
import com.intellij.codeInspection.LocalInspectionTool
import com.intellij.codeInspection.ProblemHighlightType
import com.intellij.codeInspection.ProblemsHolder
import com.intellij.idea.plugin.hybris.common.utils.HybrisI18NBundleUtils
import com.intellij.idea.plugin.hybris.impex.constants.modifier.TypeModifier
import com.intellij.idea.plugin.hybris.impex.psi.ImpexAnyAttributeName
import com.intellij.idea.plugin.hybris.impex.psi.ImpexFullHeaderType
import com.intellij.idea.plugin.hybris.impex.psi.ImpexVisitor
import com.intellij.psi.PsiElementVisitor
import com.intellij.psi.util.PsiTreeUtil

class ImpexUnknownTypeModifierInspection : LocalInspectionTool() {
override fun getDefaultLevel(): HighlightDisplayLevel = HighlightDisplayLevel.ERROR
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor = ImpexTypeModifierVisitor(holder)

private class ImpexTypeModifierVisitor(private val problemsHolder: ProblemsHolder) : ImpexVisitor() {

override fun visitAnyAttributeName(attribute: ImpexAnyAttributeName) {
PsiTreeUtil.getParentOfType(attribute, ImpexFullHeaderType::class.java) ?: return

if (TypeModifier.getByModifierName(attribute.text) == null) {
problemsHolder.registerProblem(
attribute,
HybrisI18NBundleUtils.message("hybris.inspections.impex.ImpexUnknownTypeModifierInspection.key", attribute.text),
ProblemHighlightType.ERROR
)
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,25 @@ import com.intellij.psi.impl.source.tree.LeafPsiElement
class ImpexUnknownTypeNameInspection : LocalInspectionTool() {
override fun getDefaultLevel(): HighlightDisplayLevel = HighlightDisplayLevel.ERROR
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor = ImpexHeaderTypeVisitor(holder)
}

private class ImpexHeaderTypeVisitor(private val problemsHolder: ProblemsHolder) : ImpexVisitor() {
private class ImpexHeaderTypeVisitor(private val problemsHolder: ProblemsHolder) : ImpexVisitor() {

override fun visitHeaderTypeName(parameter: ImpexHeaderTypeName) {
if (isDocumentId(parameter.firstChild)) return
override fun visitHeaderTypeName(parameter: ImpexHeaderTypeName) {
if (isDocumentId(parameter.firstChild)) return

val firstReference = parameter.references.firstOrNull() ?: return
if (firstReference !is TSReferenceBase<*>) return
val firstReference = parameter.references.firstOrNull() ?: return
if (firstReference !is TSReferenceBase<*>) return

val result = firstReference.multiResolve(false)
if (result.isNotEmpty()) return
val result = firstReference.multiResolve(false)
if (result.isNotEmpty()) return

problemsHolder.registerProblem(
parameter,
HybrisI18NBundleUtils.message("hybris.inspections.UnknownTypeNameInspection.key", parameter.text),
ProblemHighlightType.ERROR
)
}
problemsHolder.registerProblem(
parameter,
HybrisI18NBundleUtils.message("hybris.inspections.UnknownTypeNameInspection.key", parameter.text),
ProblemHighlightType.ERROR
)
}

private fun isDocumentId(element: PsiElement) = (element as LeafPsiElement).elementType == ImpexTypes.DOCUMENT_ID
private fun isDocumentId(element: PsiElement) = (element as LeafPsiElement).elementType == ImpexTypes.DOCUMENT_ID
}
}