Fix CCE in ReplaceAddWithPlusAssignIntention #KT-20183 Fixed

This commit is contained in:
Mikhail Glukhikh
2017-10-10 16:16:43 +03:00
committed by Mikhail Glukhikh
parent fd95769780
commit c5cb45794a
3 changed files with 14 additions and 2 deletions
@@ -18,12 +18,12 @@ package org.jetbrains.kotlin.idea.intentions
import com.intellij.openapi.editor.Editor
import org.jetbrains.kotlin.builtins.DefaultBuiltIns
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.psi.KtDotQualifiedExpression
import org.jetbrains.kotlin.psi.KtPsiFactory
import org.jetbrains.kotlin.psi.createExpressionByPattern
import org.jetbrains.kotlin.resolve.BindingContextUtils
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.kotlin.resolve.calls.resolvedCallUtil.getExplicitReceiverValue
import org.jetbrains.kotlin.resolve.descriptorUtil.isSubclassOf
@@ -47,7 +47,8 @@ class ReplaceAddWithPlusAssignIntention : SelfTargetingOffsetIndependentIntentio
} ?: return false
val resolvedCall = element.getResolvedCall(context) ?: return false
val receiverClass = DescriptorUtils.getClassDescriptorForType(resolvedCall.getExplicitReceiverValue()?.type ?: return false)
val receiverType = resolvedCall.getExplicitReceiverValue()?.type ?: return false
val receiverClass = receiverType.constructor.declarationDescriptor as? ClassDescriptor ?: return false
return receiverClass.isSubclassOf(DefaultBuiltIns.Instance.mutableCollection)
}
@@ -0,0 +1,5 @@
// IS_APPLICABLE: false
fun <C : MutableCollection<Int>> foo(col: C) {
col.<caret>add(0)
}
@@ -13615,6 +13615,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
doTest(fileName);
}
@TestMetadata("addGeneric.kt")
public void testAddGeneric() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceAddWithPlusAssign/addGeneric.kt");
doTest(fileName);
}
@TestMetadata("addToVar.kt")
public void testAddToVar() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceAddWithPlusAssign/addToVar.kt");