Forbid suggesting "iterate over" on expression with Nothing type

#KT-14555 Fixed
This commit is contained in:
Mikhail Glukhikh
2018-11-08 14:56:27 +03:00
parent 1e0746ebcd
commit 503f061c8c
3 changed files with 13 additions and 0 deletions
@@ -21,6 +21,7 @@ import com.intellij.codeInsight.intention.HighPriorityAction
import com.intellij.codeInsight.template.TemplateBuilderImpl
import com.intellij.codeInsight.template.impl.ConstantNode
import com.intellij.openapi.editor.Editor
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
import org.jetbrains.kotlin.idea.core.*
@@ -51,6 +52,7 @@ class IterateExpressionIntention : SelfTargetingIntention<KtExpression>(KtExpres
val resolutionFacade = expression.getResolutionFacade()
val bindingContext = resolutionFacade.analyze(expression, BodyResolveMode.PARTIAL)
val type = bindingContext.getType(expression) ?: return null
if (KotlinBuiltIns.isNothing(type)) return null
val scope = expression.getResolutionScope(bindingContext, resolutionFacade)
val detector = resolutionFacade.ideService<IterableTypesDetection>().createDetector(scope)
val elementType = detector.elementType(type)?.type ?: return null
+6
View File
@@ -0,0 +1,6 @@
// JS
// IS_APPLICABLE: false
fun foo(): String {
<caret>return "hello"
}
@@ -9673,6 +9673,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
runTest("idea/testData/intentions/iterateExpression/nonOperatotExtensionIterator.kt");
}
@TestMetadata("nothing.kt")
public void testNothing() throws Exception {
runTest("idea/testData/intentions/iterateExpression/nothing.kt");
}
@TestMetadata("simple.kt")
public void testSimple() throws Exception {
runTest("idea/testData/intentions/iterateExpression/simple.kt");