From a7f6fb7ba9926c2ba88cb33082a2357705fa2ee8 Mon Sep 17 00:00:00 2001
From: Mykhailo Lytvyn <>
Date: Sat, 15 Apr 2023 21:36:46 +0200
Subject: [PATCH] Impex type attribute validation for complex header
---
resources/META-INF/plugin-release-info.xml | 5 ++++
.../ImpexUnknownTypeAttributeInspection.kt | 26 ++++++++++++-------
2 files changed, 22 insertions(+), 9 deletions(-)
diff --git a/resources/META-INF/plugin-release-info.xml b/resources/META-INF/plugin-release-info.xml
index 60515f7b2..8284dc1e6 100644
--- a/resources/META-INF/plugin-release-info.xml
+++ b/resources/META-INF/plugin-release-info.xml
@@ -93,6 +93,11 @@
2023.1.5
+ - Feature: Added new Impex inspection rules
+
+ - Type attribute validation for complex header (#338)
+
+
- Feature: Added generate Diagram run line marker for
- Business Process (#331)
diff --git a/src/com/intellij/idea/plugin/hybris/codeInspection/rule/impex/ImpexUnknownTypeAttributeInspection.kt b/src/com/intellij/idea/plugin/hybris/codeInspection/rule/impex/ImpexUnknownTypeAttributeInspection.kt
index 7894f16e9..600ddd1fd 100644
--- a/src/com/intellij/idea/plugin/hybris/codeInspection/rule/impex/ImpexUnknownTypeAttributeInspection.kt
+++ b/src/com/intellij/idea/plugin/hybris/codeInspection/rule/impex/ImpexUnknownTypeAttributeInspection.kt
@@ -23,15 +23,13 @@ import com.intellij.codeInspection.LocalInspectionTool
import com.intellij.codeInspection.ProblemHighlightType
import com.intellij.codeInspection.ProblemsHolder
import com.intellij.idea.plugin.hybris.common.utils.HybrisI18NBundleUtils.message
-import com.intellij.idea.plugin.hybris.impex.psi.ImpexAnyHeaderParameterName
-import com.intellij.idea.plugin.hybris.impex.psi.ImpexMacroUsageDec
+import com.intellij.idea.plugin.hybris.impex.psi.*
import com.intellij.idea.plugin.hybris.impex.psi.ImpexTypes.DOCUMENT_ID
-import com.intellij.idea.plugin.hybris.impex.psi.ImpexVisitor
-import com.intellij.idea.plugin.hybris.impex.utils.ImpexPsiUtils.findHeaderItemTypeName
import com.intellij.idea.plugin.hybris.psi.reference.TSReferenceBase
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiElementVisitor
import com.intellij.psi.impl.source.tree.LeafPsiElement
+import com.intellij.psi.util.PsiTreeUtil
/**
* @author Nosov Aleksandr
@@ -41,8 +39,17 @@ class ImpexUnknownTypeAttributeInspection : LocalInspectionTool() {
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor = ImpexHeaderLineVisitor(holder)
private class ImpexHeaderLineVisitor(private val problemsHolder: ProblemsHolder) : ImpexVisitor() {
+
+ override fun visitParameter(parameter: ImpexParameter) {
+ inspect(parameter)
+ }
+
override fun visitAnyHeaderParameterName(parameter: ImpexAnyHeaderParameterName) {
- if (!isNotMacros(parameter) || !isNotDocumentId(parameter.firstChild)) return
+ inspect(parameter)
+ }
+
+ private fun inspect(parameter: PsiElement) {
+ if (parameter.firstChild is ImpexMacroUsageDec || (parameter.firstChild as? LeafPsiElement)?.elementType == DOCUMENT_ID) return
val firstReference = parameter.references.firstOrNull() ?: return
@@ -50,7 +57,11 @@ class ImpexUnknownTypeAttributeInspection : LocalInspectionTool() {
if (firstReference !is TSReferenceBase<*>) return
if (firstReference.multiResolve(false).isNotEmpty()) return
- val typeName = findHeaderItemTypeName(parameter)
+ val typeName = (
+ PsiTreeUtil.getParentOfType(parameter, ImpexParameter::class.java)
+ ?: PsiTreeUtil.getParentOfType(parameter, ImpexFullHeaderParameter::class.java)
+ ?.anyHeaderParameterName
+ )
?.text
?: "?"
problemsHolder.registerProblem(
@@ -59,8 +70,5 @@ class ImpexUnknownTypeAttributeInspection : LocalInspectionTool() {
ProblemHighlightType.ERROR)
}
- private fun isNotMacros(parameter: ImpexAnyHeaderParameterName) = parameter.firstChild !is ImpexMacroUsageDec
-
- private fun isNotDocumentId(element: PsiElement) = (element as LeafPsiElement).elementType != DOCUMENT_ID
}
}
\ No newline at end of file