[devkit] IncorrectParentDisposableInspection: link to SDK docs

GitOrigin-RevId: c0328cd2b50ca02bcd153733a456ea408c74a0ac
This commit is contained in:
Yann Cébron
2020-06-16 22:53:17 +03:00
committed by intellij-monorepo-bot
parent 8624927524
commit cfb368a902
2 changed files with 5 additions and 3 deletions
@@ -1,6 +1,6 @@
<html>
<body>
This inspection detects passing Application or Project as a parent disposable in plugin code. Such usage will lead to plugins not being
unloaded correctly.
unloaded correctly. Please see <a href="https://www.jetbrains.org/intellij/sdk/docs/basics/disposers.html#choosing-a-disposable-parent">Choosing a Disposable Parent</a> in SDK Docs.
</body>
</html>
@@ -32,6 +32,8 @@ class IncorrectParentDisposableInspection : DevKitUastInspectionBase(UCallExpres
return "/platform/" in file.virtualFile.path // TODO expand this check
}
private val sdkLink = "(<a href=\"https://www.jetbrains.org/intellij/sdk/docs/basics/disposers.html#choosing-a-disposable-parent\">Choosing a Disposable Parent</a>)"
private fun checkCallExpression(node: UCallExpression, holder: ProblemsHolder) {
val psiMethod = node.resolve() ?: return
psiMethod.parameters.forEachIndexed { index, parameter ->
@@ -41,10 +43,10 @@ class IncorrectParentDisposableInspection : DevKitUastInspectionBase(UCallExpres
val argumentSourcePsi = argumentForParameter.sourcePsi ?: return@forEachIndexed
val argumentType = (argumentForParameter.getExpressionType() as? PsiClassType)?.resolve() ?: return@forEachIndexed
if (argumentType.qualifiedName == Project::class.java.name) {
holder.registerProblem(argumentSourcePsi, "Don't use Project as disposable in plugin code")
holder.registerProblem(argumentSourcePsi, "<html>Don't use Project as disposable in plugin code $sdkLink</html>")
}
else if (argumentType.qualifiedName == Application::class.java.name) {
holder.registerProblem(argumentSourcePsi, "Don't use Application as disposable in plugin code")
holder.registerProblem(argumentSourcePsi, "<html>Don't use Application as disposable in plugin code $sdkLink</html>")
}
}
}