mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[kotlin] mpp: do not suggest "Make not-nullable" fix for expect/actual declarations
^KTIJ-18743 Fixed GitOrigin-RevId: fb8ba1f8eb11e96177cc433602c3b730752bf81c
This commit is contained in:
committed by
intellij-monorepo-bot
parent
c3eb4cab5e
commit
eaa5126132
+5
-1
@@ -19,6 +19,8 @@ import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.core.isOverridable
|
||||
import org.jetbrains.kotlin.idea.project.languageVersionSettings
|
||||
import org.jetbrains.kotlin.idea.resolve.frontendService
|
||||
import org.jetbrains.kotlin.idea.util.isEffectivelyActual
|
||||
import org.jetbrains.kotlin.idea.util.isExpectDeclaration
|
||||
import org.jetbrains.kotlin.idea.util.textRangeIn
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.collectDescendantsOfType
|
||||
@@ -46,13 +48,14 @@ class RedundantNullableReturnTypeInspection : AbstractKotlinInspection() {
|
||||
if (typeElement.innerType == null) return
|
||||
val questionMark = typeElement.questionMarkNode as? LeafPsiElement ?: return
|
||||
|
||||
if (declaration.isOverridable()) return
|
||||
if (declaration.isOverridable() || declaration.isExpectDeclaration() || declaration.isEffectivelyActual()) return
|
||||
|
||||
val (body, targetDeclaration) = when (declaration) {
|
||||
is KtNamedFunction -> {
|
||||
val body = declaration.bodyExpression
|
||||
if (body != null) body to declaration else null
|
||||
}
|
||||
|
||||
is KtProperty -> {
|
||||
val initializer = declaration.initializer
|
||||
val getter = declaration.accessors.singleOrNull { it.isGetter }
|
||||
@@ -63,6 +66,7 @@ class RedundantNullableReturnTypeInspection : AbstractKotlinInspection() {
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
else -> null
|
||||
} ?: return
|
||||
val context = body.analyze()
|
||||
|
||||
+38
@@ -1191,4 +1191,42 @@ public abstract class QuickFixMultiModuleTestGenerated extends AbstractQuickFixM
|
||||
runTest("testData/multiModuleQuickFix/other/safeDeleteUsedInAnotherPlatform/");
|
||||
}
|
||||
}
|
||||
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
@TestMetadata("testData/multiModuleQuickFix/redundantNullableReturnType")
|
||||
public static class RedundantNullableReturnType extends AbstractQuickFixMultiModuleTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||
}
|
||||
|
||||
@TestMetadata("actualMethod")
|
||||
public void testActualMethod() throws Exception {
|
||||
runTest("testData/multiModuleQuickFix/redundantNullableReturnType/actualMethod/");
|
||||
}
|
||||
|
||||
@TestMetadata("actualTopLevelFunction")
|
||||
public void testActualTopLevelFunction() throws Exception {
|
||||
runTest("testData/multiModuleQuickFix/redundantNullableReturnType/actualTopLevelFunction/");
|
||||
}
|
||||
|
||||
@TestMetadata("actualTopLevelProperty")
|
||||
public void testActualTopLevelProperty() throws Exception {
|
||||
runTest("testData/multiModuleQuickFix/redundantNullableReturnType/actualTopLevelProperty/");
|
||||
}
|
||||
|
||||
@TestMetadata("expectMemberProperty")
|
||||
public void testExpectMemberProperty() throws Exception {
|
||||
runTest("testData/multiModuleQuickFix/redundantNullableReturnType/expectMemberProperty/");
|
||||
}
|
||||
|
||||
@TestMetadata("expectTopLevelFunction")
|
||||
public void testExpectTopLevelFunction() throws Exception {
|
||||
runTest("testData/multiModuleQuickFix/redundantNullableReturnType/expectTopLevelFunction/");
|
||||
}
|
||||
|
||||
@TestMetadata("expectTopLevelProperty")
|
||||
public void testExpectTopLevelProperty() throws Exception {
|
||||
runTest("testData/multiModuleQuickFix/redundantNullableReturnType/expectTopLevelProperty/");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
expect class MyClass {
|
||||
fun runAction(block: () -> Unit): Any?
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Make not-nullable" "false"
|
||||
// TOOL: org.jetbrains.kotlin.idea.inspections.RedundantNullableReturnTypeInspection
|
||||
// ACTION: Convert to block body
|
||||
// ACTION: Remove explicit type specification
|
||||
|
||||
actual class MyClass {
|
||||
actual fun runAction(block: () -> Unit): Any?<caret> = block()
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
expect fun runAction(block: () -> Unit): Any?
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// "Make not-nullable" "false"
|
||||
// TOOL: org.jetbrains.kotlin.idea.inspections.RedundantNullableReturnTypeInspection
|
||||
// ACTION: Convert to block body
|
||||
// ACTION: Remove explicit type specification
|
||||
|
||||
actual fun runAction(block: () -> Unit): Any?<caret> = block()
|
||||
+1
@@ -0,0 +1 @@
|
||||
expect val prop: Any?
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// "Make not-nullable" "false"
|
||||
// TOOL: org.jetbrains.kotlin.idea.inspections.RedundantNullableReturnTypeInspection
|
||||
// ACTION: Convert property initializer to getter
|
||||
// ACTION: Convert to lazy property
|
||||
// ACTION: Remove explicit type specification
|
||||
|
||||
actual val prop: Any?<caret> = 42
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// "Make not-nullable" "false"
|
||||
// TOOL: org.jetbrains.kotlin.idea.inspections.RedundantNullableReturnTypeInspection
|
||||
|
||||
expect class MyClass {
|
||||
actual val prop: Any?<caret>
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
actual class MyClass {
|
||||
actual val prop: Any? = 42
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// "Make not-nullable" "false"
|
||||
// TOOL: org.jetbrains.kotlin.idea.inspections.RedundantNullableReturnTypeInspection
|
||||
|
||||
expect fun runAction(block: () -> Unit): Any?<caret>
|
||||
+1
@@ -0,0 +1 @@
|
||||
actual fun runAction(block: () -> Unit): Any? = block()
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// "Make not-nullable" "false"
|
||||
// TOOL: org.jetbrains.kotlin.idea.inspections.RedundantNullableReturnTypeInspection
|
||||
|
||||
expect val prop: Any?<caret>
|
||||
+1
@@ -0,0 +1 @@
|
||||
actual val prop: Any? = 42
|
||||
Reference in New Issue
Block a user