mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[kotlin] Port SurroundWithNullCheckFix to K2
^KTIJ-29540 GitOrigin-RevId: 4c60378b27eb11ca86b9268487f77924a102f49f
This commit is contained in:
committed by
intellij-monorepo-bot
parent
f8b0d92b07
commit
5bbaa6b1ec
+13
@@ -347,6 +347,18 @@ class KotlinK2QuickFixRegistrar : KotlinQuickFixRegistrar() {
|
||||
registerFactory(ActualAnnotationsNotMatchExpectFixFactory.factory)
|
||||
}
|
||||
|
||||
private val surroundWithNullCheck = KtQuickFixesListBuilder.registerPsiQuickFix {
|
||||
registerFactory(SurroundWithNullCheckFixFactory.argumentTypeMismatchFactory)
|
||||
registerFactory(SurroundWithNullCheckFixFactory.assignmentTypeMismatchFactory)
|
||||
registerFactory(SurroundWithNullCheckFixFactory.iteratorOnNullableFactory)
|
||||
registerFactory(SurroundWithNullCheckFixFactory.nullabilityMismatchBasedOnJavaAnnotationsFactory)
|
||||
registerFactory(SurroundWithNullCheckFixFactory.receiverNullabilityMismatchBasedOnJavaAnnotationsFactory)
|
||||
registerFactory(SurroundWithNullCheckFixFactory.unsafeCallFactory)
|
||||
registerFactory(SurroundWithNullCheckFixFactory.unsafeImplicitInvokeCallFactory)
|
||||
registerFactory(SurroundWithNullCheckFixFactory.unsafeInfixCallFactory)
|
||||
registerFactory(SurroundWithNullCheckFixFactory.unsafeOperatorCallFactory)
|
||||
}
|
||||
|
||||
override val list: KotlinQuickFixesList = KotlinQuickFixesList.createCombined(
|
||||
keywords,
|
||||
addAbstract,
|
||||
@@ -361,6 +373,7 @@ class KotlinK2QuickFixRegistrar : KotlinQuickFixRegistrar() {
|
||||
typeMismatch,
|
||||
needExplicitType,
|
||||
superKeyword,
|
||||
surroundWithNullCheck,
|
||||
vararg,
|
||||
visibility,
|
||||
other,
|
||||
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.kotlin.idea.k2.codeinsight.fixes
|
||||
|
||||
import com.intellij.modcommand.ActionContext
|
||||
import com.intellij.modcommand.ModPsiUpdater
|
||||
import com.intellij.psi.SmartPsiElementPointer
|
||||
import com.intellij.psi.createSmartPointer
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.fir.diagnostics.KtFirDiagnostic
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtNamedSymbol
|
||||
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
|
||||
import org.jetbrains.kotlin.idea.codeinsight.api.applicable.intentions.KotlinPsiUpdateModCommandAction
|
||||
import org.jetbrains.kotlin.idea.codeinsight.api.applicators.fixes.KotlinQuickFixFactory
|
||||
import org.jetbrains.kotlin.idea.codeinsight.utils.SurroundWithNullCheckUtils
|
||||
import org.jetbrains.kotlin.idea.codeinsight.utils.SurroundWithNullCheckUtils.hasAcceptableParent
|
||||
import org.jetbrains.kotlin.idea.references.mainReference
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.psi.KtOperationReferenceExpression
|
||||
import org.jetbrains.kotlin.psi.KtReferenceExpression
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getParentOfTypesAndPredicate
|
||||
|
||||
internal object SurroundWithNullCheckFixFactory {
|
||||
|
||||
val argumentTypeMismatchFactory = KotlinQuickFixFactory.ModCommandBased { diagnostic: KtFirDiagnostic.ArgumentTypeMismatch ->
|
||||
if (!diagnostic.isMismatchDueToNullability) return@ModCommandBased emptyList()
|
||||
createQuickFixIfApplicableToTypeMismatch(diagnostic)
|
||||
}
|
||||
|
||||
val assignmentTypeMismatchFactory = KotlinQuickFixFactory.ModCommandBased { diagnostic: KtFirDiagnostic.AssignmentTypeMismatch ->
|
||||
if (!diagnostic.isMismatchDueToNullability) return@ModCommandBased emptyList()
|
||||
createQuickFixIfApplicableToTypeMismatch(diagnostic)
|
||||
}
|
||||
|
||||
val iteratorOnNullableFactory = KotlinQuickFixFactory.ModCommandBased { diagnostic: KtFirDiagnostic.IteratorOnNullable ->
|
||||
val nullableExpression = diagnostic.psi as? KtReferenceExpression ?: return@ModCommandBased emptyList()
|
||||
val forExpression = SurroundWithNullCheckUtils.getForExpressionIfApplicable(nullableExpression)
|
||||
?: return@ModCommandBased emptyList()
|
||||
val elementContext = ElementContext(nullableExpression.createSmartPointer())
|
||||
listOf(
|
||||
SurroundWithNullCheckFix(forExpression, elementContext)
|
||||
)
|
||||
}
|
||||
|
||||
val nullabilityMismatchBasedOnJavaAnnotationsFactory =
|
||||
KotlinQuickFixFactory.ModCommandBased { diagnostic: KtFirDiagnostic.NullabilityMismatchBasedOnJavaAnnotations ->
|
||||
createQuickFixIfApplicableToTypeMismatch(diagnostic)
|
||||
}
|
||||
|
||||
val receiverNullabilityMismatchBasedOnJavaAnnotationsFactory =
|
||||
KotlinQuickFixFactory.ModCommandBased { diagnostic: KtFirDiagnostic.ReceiverNullabilityMismatchBasedOnJavaAnnotations ->
|
||||
createQuickFixIfApplicableToUnsafeCall(diagnostic)
|
||||
}
|
||||
|
||||
val unsafeCallFactory = KotlinQuickFixFactory.ModCommandBased { diagnostic: KtFirDiagnostic.UnsafeCall ->
|
||||
createQuickFixIfApplicableToUnsafeCall(diagnostic)
|
||||
}
|
||||
|
||||
val unsafeImplicitInvokeCallFactory = KotlinQuickFixFactory.ModCommandBased { diagnostic: KtFirDiagnostic.UnsafeImplicitInvokeCall ->
|
||||
createQuickFixIfApplicableToUnsafeCall(diagnostic)
|
||||
}
|
||||
|
||||
val unsafeInfixCallFactory = KotlinQuickFixFactory.ModCommandBased { diagnostic: KtFirDiagnostic.UnsafeInfixCall ->
|
||||
createQuickFixIfApplicableToUnsafeCall(diagnostic)
|
||||
}
|
||||
|
||||
val unsafeOperatorCallFactory = KotlinQuickFixFactory.ModCommandBased { diagnostic: KtFirDiagnostic.UnsafeOperatorCall ->
|
||||
createQuickFixIfApplicableToUnsafeCall(diagnostic)
|
||||
}
|
||||
|
||||
context(KtAnalysisSession)
|
||||
private fun createQuickFixIfApplicableToUnsafeCall(diagnostic: KtFirDiagnostic<*>): List<SurroundWithNullCheckFix> {
|
||||
val element = when (diagnostic) {
|
||||
is KtFirDiagnostic.UnsafeCall -> diagnostic.receiverExpression
|
||||
else -> diagnostic.psi
|
||||
} ?: return emptyList()
|
||||
|
||||
val expressionParent = element.getParentOfType<KtExpression>(strict = element is KtOperationReferenceExpression)
|
||||
?: return emptyList()
|
||||
|
||||
val nullableExpression = SurroundWithNullCheckUtils.getNullableExpressionIfApplicable(element) ?: return emptyList()
|
||||
|
||||
val expressionTarget = expressionParent.getParentOfTypesAndPredicate(
|
||||
strict = false, parentClasses = arrayOf(KtExpression::class.java)
|
||||
) {
|
||||
!it.isUsedAsExpression() && it.hasAcceptableParent()
|
||||
} ?: return emptyList()
|
||||
// Surround declaration (even of local variable) with null check is generally a bad idea
|
||||
if (expressionTarget is KtDeclaration) return emptyList()
|
||||
|
||||
val referenceSymbol = nullableExpression.mainReference.resolveToSymbol() as? KtNamedSymbol ?: return emptyList()
|
||||
val file = expressionTarget.containingKtFile
|
||||
val scope = file.getScopeContextForPosition(expressionTarget).getCompositeScope()
|
||||
|
||||
val callableSymbol = scope.getCallableSymbols(referenceSymbol.name).firstOrNull() ?: return emptyList()
|
||||
if (referenceSymbol != callableSymbol) return emptyList()
|
||||
|
||||
val elementContext = ElementContext(nullableExpression.createSmartPointer())
|
||||
return listOf(
|
||||
SurroundWithNullCheckFix(expressionTarget, elementContext)
|
||||
)
|
||||
}
|
||||
|
||||
context(KtAnalysisSession)
|
||||
private fun createQuickFixIfApplicableToTypeMismatch(diagnostic: KtFirDiagnostic<*>): List<SurroundWithNullCheckFix> {
|
||||
val nullableExpression = diagnostic.psi as? KtReferenceExpression ?: return emptyList()
|
||||
val root = SurroundWithNullCheckUtils.getRootExpressionIfApplicable(nullableExpression) ?: return emptyList()
|
||||
val elementContext = ElementContext(nullableExpression.createSmartPointer())
|
||||
return listOf(
|
||||
SurroundWithNullCheckFix(root, elementContext)
|
||||
)
|
||||
}
|
||||
|
||||
private data class ElementContext(
|
||||
val nullableExpressionPointer: SmartPsiElementPointer<KtExpression>,
|
||||
)
|
||||
|
||||
private class SurroundWithNullCheckFix(
|
||||
element: KtExpression,
|
||||
elementContext: ElementContext,
|
||||
) : KotlinPsiUpdateModCommandAction.ElementBased<KtExpression, ElementContext>(element, elementContext) {
|
||||
|
||||
override fun invoke(
|
||||
actionContext: ActionContext,
|
||||
element: KtExpression,
|
||||
elementContext: ElementContext,
|
||||
updater: ModPsiUpdater,
|
||||
) {
|
||||
val nullableExpression = elementContext.nullableExpressionPointer.element?.let(updater::getWritable) ?: return
|
||||
SurroundWithNullCheckUtils.applyTo(actionContext.project, element, nullableExpression)
|
||||
}
|
||||
|
||||
override fun getFamilyName(): String {
|
||||
return KotlinBundle.message("surround.with.null.check")
|
||||
}
|
||||
}
|
||||
}
|
||||
+942
-916
File diff suppressed because it is too large
Load Diff
+126
@@ -5653,7 +5653,133 @@ public abstract class HighLevelQuickFixTestGenerated extends AbstractHighLevelQu
|
||||
|
||||
|
||||
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
@TestMetadata("../../../idea/tests/testData/quickfix/surroundWithNullCheck")
|
||||
public static class SurroundWithNullCheck extends AbstractHighLevelQuickFixTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||
}
|
||||
|
||||
@TestMetadata("argumentNullable.kt")
|
||||
public void testArgumentNullable() throws Exception {
|
||||
runTest("../../../idea/tests/testData/quickfix/surroundWithNullCheck/argumentNullable.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("assignment.kt")
|
||||
public void testAssignment() throws Exception {
|
||||
runTest("../../../idea/tests/testData/quickfix/surroundWithNullCheck/assignment.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("chainedUnsafeCall.kt")
|
||||
public void testChainedUnsafeCall() throws Exception {
|
||||
runTest("../../../idea/tests/testData/quickfix/surroundWithNullCheck/chainedUnsafeCall.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("expressionUnsafeCall.kt")
|
||||
public void testExpressionUnsafeCall() throws Exception {
|
||||
runTest("../../../idea/tests/testData/quickfix/surroundWithNullCheck/expressionUnsafeCall.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("in.kt")
|
||||
public void testIn() throws Exception {
|
||||
runTest("../../../idea/tests/testData/quickfix/surroundWithNullCheck/in.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inLambda.kt")
|
||||
public void testInLambda() throws Exception {
|
||||
runTest("../../../idea/tests/testData/quickfix/surroundWithNullCheck/inLambda.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inLambda2.kt")
|
||||
public void testInLambda2() throws Exception {
|
||||
runTest("../../../idea/tests/testData/quickfix/surroundWithNullCheck/inLambda2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inLambda3.kt")
|
||||
public void testInLambda3() throws Exception {
|
||||
runTest("../../../idea/tests/testData/quickfix/surroundWithNullCheck/inLambda3.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("infixUnsafeCall.kt")
|
||||
public void testInfixUnsafeCall() throws Exception {
|
||||
runTest("../../../idea/tests/testData/quickfix/surroundWithNullCheck/infixUnsafeCall.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("invokeFuncUnsafe.kt")
|
||||
public void testInvokeFuncUnsafe() throws Exception {
|
||||
runTest("../../../idea/tests/testData/quickfix/surroundWithNullCheck/invokeFuncUnsafe.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("invokeUnsafe.kt")
|
||||
public void testInvokeUnsafe() throws Exception {
|
||||
runTest("../../../idea/tests/testData/quickfix/surroundWithNullCheck/invokeUnsafe.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("iteratorUnsafe.kt")
|
||||
public void testIteratorUnsafe() throws Exception {
|
||||
runTest("../../../idea/tests/testData/quickfix/surroundWithNullCheck/iteratorUnsafe.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nullableInCondition.kt")
|
||||
public void testNullableInCondition() throws Exception {
|
||||
runTest("../../../idea/tests/testData/quickfix/surroundWithNullCheck/nullableInCondition.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("objectNestedQualifiers.kt")
|
||||
public void testObjectNestedQualifiers() throws Exception {
|
||||
runTest("../../../idea/tests/testData/quickfix/surroundWithNullCheck/objectNestedQualifiers.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("objectQualifier.kt")
|
||||
public void testObjectQualifier() throws Exception {
|
||||
runTest("../../../idea/tests/testData/quickfix/surroundWithNullCheck/objectQualifier.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("simpleUnsafeCall.kt")
|
||||
public void testSimpleUnsafeCall() throws Exception {
|
||||
runTest("../../../idea/tests/testData/quickfix/surroundWithNullCheck/simpleUnsafeCall.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("unsafeCallInBinary.kt")
|
||||
public void testUnsafeCallInBinary() throws Exception {
|
||||
runTest("../../../idea/tests/testData/quickfix/surroundWithNullCheck/unsafeCallInBinary.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("unsafeCallInDeclaration.kt")
|
||||
public void testUnsafeCallInDeclaration() throws Exception {
|
||||
runTest("../../../idea/tests/testData/quickfix/surroundWithNullCheck/unsafeCallInDeclaration.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("unsafeCallInGetter.kt")
|
||||
public void testUnsafeCallInGetter() throws Exception {
|
||||
runTest("../../../idea/tests/testData/quickfix/surroundWithNullCheck/unsafeCallInGetter.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("unsafeCallInsideAnonymous.kt")
|
||||
public void testUnsafeCallInsideAnonymous() throws Exception {
|
||||
runTest("../../../idea/tests/testData/quickfix/surroundWithNullCheck/unsafeCallInsideAnonymous.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("unsafeCallInsideIf.kt")
|
||||
public void testUnsafeCallInsideIf() throws Exception {
|
||||
runTest("../../../idea/tests/testData/quickfix/surroundWithNullCheck/unsafeCallInsideIf.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("unsafeCallInsideWhen.kt")
|
||||
public void testUnsafeCallInsideWhen() throws Exception {
|
||||
runTest("../../../idea/tests/testData/quickfix/surroundWithNullCheck/unsafeCallInsideWhen.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("unsafeCallInsideWhile.kt")
|
||||
public void testUnsafeCallInsideWhile() throws Exception {
|
||||
runTest("../../../idea/tests/testData/quickfix/surroundWithNullCheck/unsafeCallInsideWhile.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("unstableValue.kt")
|
||||
public void testUnstableValue() throws Exception {
|
||||
runTest("../../../idea/tests/testData/quickfix/surroundWithNullCheck/unstableValue.kt");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
+2
-1
@@ -5,4 +5,5 @@ fun foo(x: String?) {
|
||||
}
|
||||
|
||||
fun bar(s: String) = s.hashCode()
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.SurroundWithNullCheckFixFactory$SurroundWithNullCheckFix
|
||||
+2
-1
@@ -7,4 +7,5 @@ fun foo(x: String?) {
|
||||
}
|
||||
|
||||
fun bar(s: String) = s.hashCode()
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.SurroundWithNullCheckFixFactory$SurroundWithNullCheckFix
|
||||
@@ -4,4 +4,5 @@ fun foo(s: String?) {
|
||||
var ss: String = ""
|
||||
ss = <caret>s
|
||||
}
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.SurroundWithNullCheckFixFactory$SurroundWithNullCheckFix
|
||||
+2
-1
@@ -6,4 +6,5 @@ fun foo(s: String?) {
|
||||
ss = s
|
||||
}
|
||||
}
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.SurroundWithNullCheckFixFactory$SurroundWithNullCheckFix
|
||||
@@ -2,4 +2,5 @@
|
||||
fun test(a: String, b: List<String>?) {
|
||||
a <caret>in b
|
||||
}
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.SurroundWithNullCheckFixFactory$SurroundWithNullCheckFix
|
||||
@@ -4,4 +4,5 @@ fun test(a: String, b: List<String>?) {
|
||||
a in b
|
||||
}
|
||||
}
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.SurroundWithNullCheckFixFactory$SurroundWithNullCheckFix
|
||||
@@ -11,4 +11,5 @@ fun test() {
|
||||
it<caret>.foo()
|
||||
}
|
||||
}
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.SurroundWithNullCheckFixFactory$SurroundWithNullCheckFix
|
||||
@@ -13,4 +13,5 @@ fun test() {
|
||||
}
|
||||
}
|
||||
}
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.SurroundWithNullCheckFixFactory$SurroundWithNullCheckFix
|
||||
@@ -11,4 +11,5 @@ fun test(x: Foo?) {
|
||||
x<caret>.foo()
|
||||
}
|
||||
}
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.SurroundWithNullCheckFixFactory$SurroundWithNullCheckFix
|
||||
+2
-1
@@ -13,4 +13,5 @@ fun test(x: Foo?) {
|
||||
}
|
||||
}
|
||||
}
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.SurroundWithNullCheckFixFactory$SurroundWithNullCheckFix
|
||||
+2
-1
@@ -5,4 +5,5 @@ infix fun Int.op(arg: Int) = this
|
||||
fun foo(arg: Int?) {
|
||||
arg <caret>op 42
|
||||
}
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.SurroundWithNullCheckFixFactory$SurroundWithNullCheckFix
|
||||
+2
-1
@@ -7,4 +7,5 @@ fun foo(arg: Int?) {
|
||||
arg op 42
|
||||
}
|
||||
}
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.SurroundWithNullCheckFixFactory$SurroundWithNullCheckFix
|
||||
+2
-1
@@ -3,4 +3,5 @@
|
||||
fun foo(exec: (() -> Unit)?) {
|
||||
<caret>exec()
|
||||
}
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.SurroundWithNullCheckFixFactory$SurroundWithNullCheckFix
|
||||
+2
-1
@@ -5,4 +5,5 @@ fun foo(exec: (() -> Unit)?) {
|
||||
exec()
|
||||
}
|
||||
}
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.SurroundWithNullCheckFixFactory$SurroundWithNullCheckFix
|
||||
@@ -5,4 +5,5 @@ operator fun Int.invoke() = this
|
||||
fun foo(arg: Int?) {
|
||||
<caret>arg()
|
||||
}
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.SurroundWithNullCheckFixFactory$SurroundWithNullCheckFix
|
||||
+2
-1
@@ -7,4 +7,5 @@ fun foo(arg: Int?) {
|
||||
arg()
|
||||
}
|
||||
}
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.SurroundWithNullCheckFixFactory$SurroundWithNullCheckFix
|
||||
@@ -4,4 +4,5 @@
|
||||
fun foo(list: List<String>?) {
|
||||
for (element in <caret>list) {}
|
||||
}
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.SurroundWithNullCheckFixFactory$SurroundWithNullCheckFix
|
||||
+2
-1
@@ -6,4 +6,5 @@ fun foo(list: List<String>?) {
|
||||
for (element in list) {}
|
||||
}
|
||||
}
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.SurroundWithNullCheckFixFactory$SurroundWithNullCheckFix
|
||||
+2
-1
@@ -6,4 +6,5 @@ fun foz(arg: String?) {
|
||||
|
||||
}
|
||||
}
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.SurroundWithNullCheckFixFactory$SurroundWithNullCheckFix
|
||||
+2
-1
@@ -8,4 +8,5 @@ fun foz(arg: String?) {
|
||||
}
|
||||
}
|
||||
}
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.SurroundWithNullCheckFixFactory$SurroundWithNullCheckFix
|
||||
+2
-1
@@ -8,4 +8,5 @@ object Util {
|
||||
fun f1(o: Any, p: Int): Any = o
|
||||
fun f2(o: Any): Any = o
|
||||
}
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.SurroundWithNullCheckFixFactory$SurroundWithNullCheckFix
|
||||
+2
-1
@@ -10,4 +10,5 @@ object Util {
|
||||
fun f1(o: Any, p: Int): Any = o
|
||||
fun f2(o: Any): Any = o
|
||||
}
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.SurroundWithNullCheckFixFactory$SurroundWithNullCheckFix
|
||||
+2
-1
@@ -8,4 +8,5 @@ fun use(arg: Int?) {
|
||||
Obj.foo(<caret>arg)
|
||||
}
|
||||
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.SurroundWithNullCheckFixFactory$SurroundWithNullCheckFix
|
||||
+2
-1
@@ -10,4 +10,5 @@ fun use(arg: Int?) {
|
||||
}
|
||||
}
|
||||
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.SurroundWithNullCheckFixFactory$SurroundWithNullCheckFix
|
||||
+2
-1
@@ -3,4 +3,5 @@
|
||||
fun foo(arg: Int?) {
|
||||
arg<caret>.inc()
|
||||
}
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.SurroundWithNullCheckFixFactory$SurroundWithNullCheckFix
|
||||
+2
-1
@@ -5,4 +5,5 @@ fun foo(arg: Int?) {
|
||||
arg.inc()
|
||||
}
|
||||
}
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.SurroundWithNullCheckFixFactory$SurroundWithNullCheckFix
|
||||
+2
-1
@@ -3,4 +3,5 @@
|
||||
fun foo(arg: Int?) {
|
||||
42 + arg<caret>.inc() - 13
|
||||
}
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.SurroundWithNullCheckFixFactory$SurroundWithNullCheckFix
|
||||
+2
-1
@@ -5,4 +5,5 @@ fun foo(arg: Int?) {
|
||||
42 + arg.inc() - 13
|
||||
}
|
||||
}
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.SurroundWithNullCheckFixFactory$SurroundWithNullCheckFix
|
||||
+2
-1
@@ -6,4 +6,5 @@ fun Int.bar() = this
|
||||
fun foo(arg: Int?) {
|
||||
run(fun() = arg<caret>.bar())
|
||||
}
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.SurroundWithNullCheckFixFactory$SurroundWithNullCheckFix
|
||||
+2
-1
@@ -8,4 +8,5 @@ fun foo(arg: Int?) {
|
||||
run(fun() = arg.bar())
|
||||
}
|
||||
}
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.SurroundWithNullCheckFixFactory$SurroundWithNullCheckFix
|
||||
+2
-1
@@ -3,4 +3,5 @@
|
||||
fun foo(arg: Int?, flag: Boolean) {
|
||||
if (flag) arg<caret>.inc()
|
||||
}
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.SurroundWithNullCheckFixFactory$SurroundWithNullCheckFix
|
||||
+2
-1
@@ -5,4 +5,5 @@ fun foo(arg: Int?, flag: Boolean) {
|
||||
arg.inc()
|
||||
}
|
||||
}
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.SurroundWithNullCheckFixFactory$SurroundWithNullCheckFix
|
||||
+2
-1
@@ -6,4 +6,5 @@ fun foo(arg: Int?, flag: Boolean) {
|
||||
true -> arg<caret>.inc()
|
||||
}
|
||||
}
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.SurroundWithNullCheckFixFactory$SurroundWithNullCheckFix
|
||||
+2
-1
@@ -8,4 +8,5 @@ fun foo(arg: Int?, flag: Boolean) {
|
||||
}
|
||||
}
|
||||
}
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.SurroundWithNullCheckFixFactory$SurroundWithNullCheckFix
|
||||
+2
-1
@@ -3,4 +3,5 @@
|
||||
fun foo(arg: Int?, flag: Boolean) {
|
||||
while (flag) arg<caret>.inc()
|
||||
}
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.SurroundWithNullCheckFixFactory$SurroundWithNullCheckFix
|
||||
+2
-1
@@ -5,4 +5,5 @@ fun foo(arg: Int?, flag: Boolean) {
|
||||
arg.inc()
|
||||
}
|
||||
}
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SurroundWithNullCheckFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.SurroundWithNullCheckFixFactory$SurroundWithNullCheckFix
|
||||
+10
-3
@@ -188,7 +188,7 @@ internal fun MutableTWorkspace.generateK2FixTests() {
|
||||
model("$idea/quickfix/specifyTypeExplicitly", pattern = pattern, isIgnored = true)
|
||||
model("$idea/quickfix/superTypeIsExtensionType", pattern = pattern, isIgnored = true)
|
||||
model("$idea/quickfix/suppress", pattern = pattern, isIgnored = true)
|
||||
model("$idea/quickfix/surroundWithNullCheck", pattern = pattern, isIgnored = true)
|
||||
model("$idea/quickfix/surroundWithNullCheck", pattern = pattern)
|
||||
model("$idea/quickfix/suspiciousCollectionReassignment", pattern = pattern, isIgnored = true)
|
||||
model("$idea/quickfix/tooLongCharLiteralToString", pattern = pattern, isIgnored = true)
|
||||
model("$idea/quickfix/typeImports", pattern = pattern, isIgnored = true)
|
||||
@@ -209,10 +209,17 @@ internal fun MutableTWorkspace.generateK2FixTests() {
|
||||
}
|
||||
|
||||
testClass<AbstractHighLevelQuickFixMultiFileTest> {
|
||||
val pattern = Patterns.forRegex("""^(\w+)\.((before\.Main\.\w+)|(test))$""")
|
||||
val testMethodName = "doTestWithExtraFile"
|
||||
model(
|
||||
"$idea/quickfix/autoImports",
|
||||
pattern = Patterns.forRegex("""^(\w+)\.((before\.Main\.\w+)|(test))$"""),
|
||||
testMethodName = "doTestWithExtraFile"
|
||||
pattern = pattern,
|
||||
testMethodName = testMethodName,
|
||||
)
|
||||
model(
|
||||
"$idea/quickfix/surroundWithNullCheck",
|
||||
pattern = pattern,
|
||||
testMethodName = testMethodName,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user