Fix WrapWithSafeLetCallFix ignore extension method
Related to KT-17726
This commit is contained in:
committed by
Mikhail Glukhikh
parent
bd73916d99
commit
c8e58ce9ab
@@ -21,12 +21,14 @@ import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||
import org.jetbrains.kotlin.diagnostics.Errors
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.idea.core.KotlinNameSuggester
|
||||
import org.jetbrains.kotlin.idea.core.NewDeclarationNameValidator
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.createSmartPointer
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getLastParentOfTypeInRow
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
||||
import org.jetbrains.kotlin.types.typeUtil.isNullabilityMismatch
|
||||
|
||||
class WrapWithSafeLetCallFix(
|
||||
@@ -57,6 +59,12 @@ class WrapWithSafeLetCallFix(
|
||||
object UnsafeFactory : KotlinSingleIntentionActionFactory() {
|
||||
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
||||
val element = diagnostic.psiElement
|
||||
|
||||
if (element is KtNameReferenceExpression) {
|
||||
val resolvedCall = element.getResolvedCall(element.analyze())
|
||||
if (resolvedCall?.call?.callType != Call.CallType.INVOKE) return null
|
||||
}
|
||||
|
||||
val expression = element.getParentOfType<KtExpression>(true) ?: return null
|
||||
|
||||
val parent = element.parent
|
||||
|
||||
-1
@@ -2,7 +2,6 @@
|
||||
// ACTION: Add non-null asserted (!!) call
|
||||
// ACTION: Convert to expression body
|
||||
// ACTION: Replace with safe (this?.) call
|
||||
// ACTION: Wrap with '?.let { ... }' call
|
||||
// ERROR: Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type A?
|
||||
|
||||
class A {
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
// "Wrap with '?.let { ... }' call" "false"
|
||||
// WITH_RUNTIME
|
||||
// ACTION: Add non-null asserted (!!) call
|
||||
// ACTION: Introduce local variable
|
||||
// ACTION: Replace with safe (this?.) call
|
||||
// ERROR: Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type String?
|
||||
|
||||
fun String?.foo() {
|
||||
toLowerCase<caret>()
|
||||
}
|
||||
@@ -11243,6 +11243,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("extensionMethod.kt")
|
||||
public void testExtensionMethod() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/wrapWithSafeLetCall/extensionMethod.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("insideLet.kt")
|
||||
public void testInsideLet() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/wrapWithSafeLetCall/insideLet.kt");
|
||||
|
||||
Reference in New Issue
Block a user