KT-28471: "Add initializer" quickfix initializes non-null variable with null
This commit is contained in:
committed by
Dmitry Gridin
parent
c0f896c96a
commit
8f2a73b734
@@ -58,7 +58,7 @@ object InitializePropertyQuickFixFactory : KotlinIntentionActionsFactory() {
|
||||
override fun invoke(project: Project, editor: Editor?, file: KtFile) {
|
||||
val element = element ?: return
|
||||
val descriptor = element.resolveToDescriptorIfAny() as? PropertyDescriptor ?: return
|
||||
val initializerText = CodeInsightUtils.defaultInitializer(descriptor.type) ?: "null"
|
||||
val initializerText = CodeInsightUtils.defaultInitializer(descriptor.type) ?: "TODO()"
|
||||
val initializer = element.setInitializer(KtPsiFactory(project).createExpression(initializerText))!!
|
||||
if (editor != null) {
|
||||
PsiDocumentManager.getInstance(project).commitDocument(editor.document)
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
// "Add initializer" "true"
|
||||
// WITH_RUNTIME
|
||||
class A
|
||||
<caret>var label: A
|
||||
@@ -0,0 +1,4 @@
|
||||
// "Add initializer" "true"
|
||||
// WITH_RUNTIME
|
||||
class A
|
||||
var label: A = TODO()
|
||||
@@ -740,6 +740,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
||||
runTest("idea/testData/quickfix/addInitializer/topLevelProperty.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("topLevelPropertyVarClass.kt")
|
||||
public void testTopLevelPropertyVarClass() throws Exception {
|
||||
runTest("idea/testData/quickfix/addInitializer/topLevelPropertyVarClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("topLevelPropertyVarGetterOnly.kt")
|
||||
public void testTopLevelPropertyVarGetterOnly() throws Exception {
|
||||
runTest("idea/testData/quickfix/addInitializer/topLevelPropertyVarGetterOnly.kt");
|
||||
|
||||
Reference in New Issue
Block a user