forked from unshare/hybris-integration-intellij-idea-plugin
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#338 | Impex type attribute validation for complex header
- Loading branch information
Showing
2 changed files
with
22 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 <[email protected]> | ||
|
@@ -41,16 +39,29 @@ 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 | ||
|
||
if (firstReference.canonicalText.contains(".")) return | ||
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 | ||
} | ||
} |