Forbid suggesting "iterate over" on expression with Nothing type
#KT-14555 Fixed
This commit is contained in:
@@ -21,6 +21,7 @@ import com.intellij.codeInsight.intention.HighPriorityAction
|
|||||||
import com.intellij.codeInsight.template.TemplateBuilderImpl
|
import com.intellij.codeInsight.template.TemplateBuilderImpl
|
||||||
import com.intellij.codeInsight.template.impl.ConstantNode
|
import com.intellij.codeInsight.template.impl.ConstantNode
|
||||||
import com.intellij.openapi.editor.Editor
|
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.analyze
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
||||||
import org.jetbrains.kotlin.idea.core.*
|
import org.jetbrains.kotlin.idea.core.*
|
||||||
@@ -51,6 +52,7 @@ class IterateExpressionIntention : SelfTargetingIntention<KtExpression>(KtExpres
|
|||||||
val resolutionFacade = expression.getResolutionFacade()
|
val resolutionFacade = expression.getResolutionFacade()
|
||||||
val bindingContext = resolutionFacade.analyze(expression, BodyResolveMode.PARTIAL)
|
val bindingContext = resolutionFacade.analyze(expression, BodyResolveMode.PARTIAL)
|
||||||
val type = bindingContext.getType(expression) ?: return null
|
val type = bindingContext.getType(expression) ?: return null
|
||||||
|
if (KotlinBuiltIns.isNothing(type)) return null
|
||||||
val scope = expression.getResolutionScope(bindingContext, resolutionFacade)
|
val scope = expression.getResolutionScope(bindingContext, resolutionFacade)
|
||||||
val detector = resolutionFacade.ideService<IterableTypesDetection>().createDetector(scope)
|
val detector = resolutionFacade.ideService<IterableTypesDetection>().createDetector(scope)
|
||||||
val elementType = detector.elementType(type)?.type ?: return null
|
val elementType = detector.elementType(type)?.type ?: return null
|
||||||
|
|||||||
@@ -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");
|
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")
|
@TestMetadata("simple.kt")
|
||||||
public void testSimple() throws Exception {
|
public void testSimple() throws Exception {
|
||||||
runTest("idea/testData/intentions/iterateExpression/simple.kt");
|
runTest("idea/testData/intentions/iterateExpression/simple.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user