Skip to content

Commit

Permalink
#264 | Added new Flexible Search inspection rules
Browse files Browse the repository at this point in the history
  • Loading branch information
mlytvyn authored Mar 6, 2023
1 parent 0ee9c14 commit 09a3d20
Show file tree
Hide file tree
Showing 23 changed files with 228 additions and 45 deletions.
22 changes: 15 additions & 7 deletions resources/META-INF/plugin-inspections.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,32 +43,40 @@
shortName="CngContextParentIsNotValid" level="ERROR"
implementationClass="com.intellij.idea.plugin.hybris.codeInspection.rule.cockpitng.CngContextParentIsNotValid"/>

<!-- Flexible Search -->
<localInspection groupPath="hybris" shortName="FxsUnknownTypeNameInspection" displayName="[y] Unknown type"
groupName="[y] Flexible Search" level="ERROR" language="FlexibleSearch" enabledByDefault="true"
implementationClass="com.intellij.idea.plugin.hybris.codeInspection.rule.flexibleSearch.FxsUnknownTypeNameInspection"/>
<localInspection groupPath="hybris" shortName="FxsUnknownTypeAttributeInspection" displayName="[y] Unknown attribute"
groupName="[y] Flexible Search" level="ERROR" language="FlexibleSearch" enabledByDefault="true"
implementationClass="com.intellij.idea.plugin.hybris.codeInspection.rule.flexibleSearch.FxsUnknownTypeAttributeInspection"/>

<!-- Impex -->
<localInspection groupPath="hybris" shortName="NoUniqueValueInspection" displayName="[y] No unique value in column"
<localInspection groupPath="hybris" shortName="ImpexNoUniqueValueInspection" displayName="[y] No unique value in column"
groupName="[y] Impex" level="WARNING" language="Impex" enabledByDefault="true"
implementationClass="com.intellij.idea.plugin.hybris.codeInspection.rule.impex.ImpexNoUniqueValueInspection"/>

<localInspection groupPath="hybris" shortName="UnknownConfigPropertyInspection" displayName="[y] Unknown configuration property"
<localInspection groupPath="hybris" shortName="ImpexUnknownConfigPropertyInspection" displayName="[y] Unknown configuration property"
groupName="[y] Impex" level="ERROR" language="Impex" enabledByDefault="true"
implementationClass="com.intellij.idea.plugin.hybris.codeInspection.rule.impex.ImpexUnknownConfigPropertyInspection"/>

<localInspection groupPath="hybris" shortName="UnknownMacrosInspection" displayName="[y] Unknown macros"
<localInspection groupPath="hybris" shortName="ImpexUnknownMacrosInspection" displayName="[y] Unknown macros"
groupName="[y] Impex" level="ERROR" language="Impex" enabledByDefault="true"
implementationClass="com.intellij.idea.plugin.hybris.codeInspection.rule.impex.ImpexUnknownMacrosInspection"/>

<localInspection groupPath="hybris" shortName="UnknownTypeAttributeInspection" displayName="[y] Unknown attribute"
<localInspection groupPath="hybris" shortName="ImpexUnknownTypeAttributeInspection" displayName="[y] Unknown attribute"
groupName="[y] Impex" level="ERROR" language="Impex" enabledByDefault="true"
implementationClass="com.intellij.idea.plugin.hybris.codeInspection.rule.impex.ImpexUnknownTypeAttributeInspection"/>

<localInspection groupPath="hybris" shortName="ConfigProcessorInspection" displayName="[y] Incorrect use of $config macros"
<localInspection groupPath="hybris" shortName="ImpexConfigProcessorInspection" displayName="[y] Incorrect use of $config macros"
groupName="[y] Impex" level="WARNING" language="Impex" enabledByDefault="true"
implementationClass="com.intellij.idea.plugin.hybris.codeInspection.rule.impex.ImpexConfigProcessorInspection"/>

<localInspection groupPath="hybris" shortName="UniqueAttributeWithoutIndex" displayName="[y] Unique attribute without an index"
<localInspection groupPath="hybris" shortName="ImpexUniqueAttributeWithoutIndex" displayName="[y] Unique attribute without an index"
groupName="[y] Impex" level="WARNING" language="Impex" enabledByDefault="true"
implementationClass="com.intellij.idea.plugin.hybris.codeInspection.rule.impex.ImpexUniqueAttributeWithoutIndexInspection"/>

<localInspection groupPath="hybris" shortName="UniqueDocumentId" displayName="[y] Unique document Id in column"
<localInspection groupPath="hybris" shortName="ImpexUniqueDocumentId" displayName="[y] Unique document Id in column"
groupName="[y] Impex" level="ERROR" language="Impex" enabledByDefault="true"
implementationClass="com.intellij.idea.plugin.hybris.codeInspection.rule.impex.ImpexUniqueDocumentIdInspection"/>

Expand Down
6 changes: 6 additions & 0 deletions resources/META-INF/plugin-release-info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@
<li><i>Feature:</i> Improved performance of the Global Meta Model and TS LineMarker (<a href="https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/257" target="_blank" rel="nofollow">#257</a>)</li>
<li><i>Feature:</i> IDEA modules by default will be stored in the <code>/.idea/idea-modules</code> (<a href="https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/259" target="_blank" rel="nofollow">#259</a>)</li>
<li><i>Feature:</i> Added collapse/expand all actions for TS and BS views (<a href="https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/262" target="_blank" rel="nofollow">#262</a>)</li>
<li><i>Feature:</i> Added new <strong>Flexible Search</strong> inspection rules (<a href="https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/264" target="_blank" rel="nofollow">#264</a>)
<ul>
<li>Item Type is not defined</li>
<li>Attribute is not defined</li>
</ul>
</li>
<li><i>Bug Fix:</i> Console is not releasing Document on Project dispose (<a href="https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/260" target="_blank" rel="nofollow">#260</a>)</li>
<li><i>Bug Fix:</i> Fixed Ant targets registration after Project Refresh</li>
<li><i>Other:</i> Improved cleanup on Project dispose</li>
Expand Down
4 changes: 2 additions & 2 deletions resources/i18n/HybrisBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ hybris.inspections.bs.DuplicateEnumDefinition.key=[y] Enum definition is duplica
hybris.inspections.bs.DuplicateBeanPropertyDefinition.key=[y] Property is duplicated for the Bean
hybris.inspections.bs.DuplicateEnumValueDefinition.key=[y] Enum value is duplicated for the Enum

hybris.inspections.impex.ImpexUnknownTypeNameInspection.key=[y] Unknown type ''{0}''
hybris.inspections.impex.ImpexUnknownTypeAttributeInspection.key=[y] Unknown attribute ''{0}'' for type ''{1}''
hybris.inspections.UnknownTypeNameInspection.key=[y] Unknown type ''{0}''
hybris.inspections.UnknownTypeAttributeInspection.key=[y] Unknown attribute ''{0}'' for type ''{1}''

hybris.inspections.ei.EiUnknownExtensionDefinition.key=[y] Unknown extension
hybris.inspections.ei.EiDuplicateExtensionDefinition.key=[y] Dependency on extension is already declared
Expand Down
23 changes: 23 additions & 0 deletions resources/inspectionDescriptions/FxsUnknownTypeNameInspection.html
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 lang="en">
<body>
This type does not exist in Type System (items.xml).
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!--
~ 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 attribute does not exist in type system (items.xml).
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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.flexibleSearch

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.flexibleSearch.psi.FlexibleSearchColumnReference
import com.intellij.idea.plugin.hybris.flexibleSearch.psi.FlexibleSearchVisitor
import com.intellij.idea.plugin.hybris.flexibleSearch.references.FxsTSAttributeReference
import com.intellij.psi.PsiElementVisitor

class FxsUnknownTypeAttributeInspection : LocalInspectionTool() {
override fun getDefaultLevel(): HighlightDisplayLevel {
return HighlightDisplayLevel.ERROR
}

override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor = object : FlexibleSearchVisitor() {

override fun visitColumnReference(parameter: FlexibleSearchColumnReference) {
val references = parameter.references
if (references.isEmpty()) return

val firstReference = references.firstOrNull() ?: return
if (firstReference !is FxsTSAttributeReference) return

val result = firstReference.multiResolve(false)
if (result.isNotEmpty()) return
val itemType = firstReference.getType()
?: "unknown"

holder.registerProblem(
parameter,
HybrisI18NBundleUtils.message("hybris.inspections.UnknownTypeAttributeInspection.key", parameter.text, itemType),
ProblemHighlightType.ERROR
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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.flexibleSearch

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.flexibleSearch.psi.FlexibleSearchTableName
import com.intellij.idea.plugin.hybris.flexibleSearch.psi.FlexibleSearchVisitor
import com.intellij.idea.plugin.hybris.psi.reference.TSReferenceBase
import com.intellij.psi.PsiElementVisitor

class FxsUnknownTypeNameInspection : LocalInspectionTool() {
override fun getDefaultLevel(): HighlightDisplayLevel {
return HighlightDisplayLevel.ERROR
}

override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor = object : FlexibleSearchVisitor() {
override fun visitTableName(parameter: FlexibleSearchTableName) {
val references = parameter.references
if (references.isEmpty()) return

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

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

holder.registerProblem(
parameter,
HybrisI18NBundleUtils.message("hybris.inspections.UnknownTypeNameInspection.key", parameter.text),
ProblemHighlightType.ERROR
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,20 @@ private class ImpexHeaderLineVisitor(private val problemsHolder: ProblemsHolder)
override fun visitAnyHeaderParameterName(parameter: ImpexAnyHeaderParameterName) {
if (isNotMacros(parameter) && isNotDocumentId(parameter.firstChild)) {
val references = parameter.references
if (references.isNotEmpty()) {
val firstReference = references.first()
if (!firstReference.canonicalText.contains(".") && firstReference is TSReferenceBase<*>) {
val result = firstReference.multiResolve(false)
if (references.isEmpty()) return

if (result.isEmpty()) {
val typeName = findHeaderItemTypeName(parameter)
?.text
?: ""
problemsHolder.registerProblem(
parameter,
message("hybris.inspections.impex.ImpexUnknownTypeAttributeInspection.key", parameter.text, typeName),
ProblemHighlightType.ERROR)
}
val firstReference = references.first()
if (!firstReference.canonicalText.contains(".") && firstReference is TSReferenceBase<*>) {
val result = firstReference.multiResolve(false)

if (result.isEmpty()) {
val typeName = findHeaderItemTypeName(parameter)
?.text
?: ""
problemsHolder.registerProblem(
parameter,
message("hybris.inspections.UnknownTypeAttributeInspection.key", parameter.text, typeName),
ProblemHighlightType.ERROR)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private class ImpexHeaderTypeVisitor(private val problemsHolder: ProblemsHolder)

problemsHolder.registerProblem(
parameter,
HybrisI18NBundleUtils.message("hybris.inspections.impex.ImpexUnknownTypeNameInspection.key", parameter.text),
HybrisI18NBundleUtils.message("hybris.inspections.UnknownTypeNameInspection.key", parameter.text),
ProblemHighlightType.ERROR
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ import com.intellij.psi.PsiReference
* @author Nosov Aleksandr <[email protected]>
*/

abstract class TypeNameMixin(astNode: ASTNode) : ASTWrapperPsiElement(astNode),
FlexibleSearchTableName {
abstract class TypeNameMixin(astNode: ASTNode) : ASTWrapperPsiElement(astNode), FlexibleSearchTableName {

private var myReference: FxsTSItemReference? = null

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.intellij.idea.plugin.hybris.flexibleSearch.references

import com.intellij.codeInsight.highlighting.HighlightedReference
import com.intellij.idea.plugin.hybris.common.HybrisConstants
import com.intellij.idea.plugin.hybris.common.HybrisConstants.CODE_ATTRIBUTE_NAME
import com.intellij.idea.plugin.hybris.common.HybrisConstants.NAME_ATTRIBUTE_NAME
Expand All @@ -20,13 +19,23 @@ import com.intellij.psi.ResolveResult
import com.intellij.psi.impl.source.tree.LeafPsiElement
import com.intellij.psi.util.*

internal class FxsTSAttributeReference(owner: FlexibleSearchColumnReference) : TSReferenceBase<FlexibleSearchColumnReference>(owner),
HighlightedReference {
internal class FxsTSAttributeReference(owner: FlexibleSearchColumnReference) : TSReferenceBase<FlexibleSearchColumnReference>(owner) {

override fun multiResolve(incompleteCode: Boolean): Array<ResolveResult> = CachedValuesManager.getManager(project)
.getParameterizedCachedValue(element, CACHE_KEY, provider, false, this)
.let { PsiUtils.getValidResults(it) }

fun getType(): String? {
val itemType = if (hasPrefix(element)) {
deepSearchOfTypeReference(element, element.firstChild.text)
} else {
findItemTypeReference(element)
}
return itemType
?.text
?.replace("!", "")
}

companion object {
val CACHE_KEY = Key.create<ParameterizedCachedValue<Array<ResolveResult>, FxsTSAttributeReference>>("HYBRIS_TS_CACHED_REFERENCE")

Expand Down
Loading

0 comments on commit 09a3d20

Please sign in to comment.