Don't run analysis in SpecifyTypeExplicitlyIntention.isAvailable()

If type is invalid, show error hint when action is invoked
This commit is contained in:
Dmitry Jemerov
2018-03-29 16:12:44 +02:00
parent 6d9457853e
commit a495c2e5ea
9 changed files with 50 additions and 16 deletions
@@ -16,6 +16,7 @@
package org.jetbrains.kotlin.idea.intentions
import com.intellij.codeInsight.hint.HintManager
import com.intellij.codeInsight.intention.LowPriorityAction
import com.intellij.codeInsight.template.*
import com.intellij.openapi.application.ApplicationManager
@@ -53,8 +54,6 @@ class SpecifyTypeExplicitlyIntention :
if (element is KtConstructor<*>) return null
if (element.typeReference != null) return null
if (getTypeForDeclaration(element).isError) return null
if (element is KtNamedFunction && element.hasBlockBody()) return null
text = if (element is KtFunction) "Specify return type explicitly" else "Specify type explicitly"
@@ -70,6 +69,13 @@ class SpecifyTypeExplicitlyIntention :
override fun applyTo(element: KtCallableDeclaration, editor: Editor?) {
val type = getTypeForDeclaration(element)
if (type.isError) {
if (editor != null) {
HintManager.getInstance().showErrorHint(editor, "Cannot infer type for this declaration")
}
return
}
addTypeAnnotation(editor, element, type)
}