From e25c4b96ad536b66c8625b3b65191f51a9fd5031 Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Mon, 14 Nov 2016 14:25:15 +0300 Subject: [PATCH] Add test for specify type explicitly when it can be inferred from getter #KT-14794 In Progress --- .../idea/intentions/SpecifyTypeExplicitlyIntention.kt | 6 +----- .../specifyTypeExplicitly/propertyTypeFromGetter.kt | 1 + .../specifyTypeExplicitly/propertyTypeFromGetter.kt.after | 1 + .../kotlin/idea/intentions/IntentionTestGenerated.java | 6 ++++++ 4 files changed, 9 insertions(+), 5 deletions(-) create mode 100644 idea/testData/intentions/specifyTypeExplicitly/propertyTypeFromGetter.kt create mode 100644 idea/testData/intentions/specifyTypeExplicitly/propertyTypeFromGetter.kt.after diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/SpecifyTypeExplicitlyIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/SpecifyTypeExplicitlyIntention.kt index 82d08f81ab2..bab74a3ec1c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/SpecifyTypeExplicitlyIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/SpecifyTypeExplicitlyIntention.kt @@ -76,10 +76,6 @@ class SpecifyTypeExplicitlyIntention : } companion object { - - private val PropertyDescriptor.getterType: KotlinType? - get() = getter?.returnType?.let { if (it.isError) null else it } - private val PropertyDescriptor.setterType: KotlinType? get() = setter?.valueParameters?.firstOrNull()?.type?.let { if (it.isError) null else it } @@ -110,7 +106,7 @@ class SpecifyTypeExplicitlyIntention : val descriptor = declaration.analyze()[BindingContext.DECLARATION_TO_DESCRIPTOR, declaration] val type = (descriptor as? CallableDescriptor)?.returnType if (type != null && type.isError && descriptor is PropertyDescriptor) { - return descriptor.getterType ?: descriptor.setterType ?: ErrorUtils.createErrorType("null type") + return descriptor.setterType ?: ErrorUtils.createErrorType("null type") } return type ?: ErrorUtils.createErrorType("null type") } diff --git a/idea/testData/intentions/specifyTypeExplicitly/propertyTypeFromGetter.kt b/idea/testData/intentions/specifyTypeExplicitly/propertyTypeFromGetter.kt new file mode 100644 index 00000000000..0d7991639f2 --- /dev/null +++ b/idea/testData/intentions/specifyTypeExplicitly/propertyTypeFromGetter.kt @@ -0,0 +1 @@ +val x get() = 1 diff --git a/idea/testData/intentions/specifyTypeExplicitly/propertyTypeFromGetter.kt.after b/idea/testData/intentions/specifyTypeExplicitly/propertyTypeFromGetter.kt.after new file mode 100644 index 00000000000..cf8fae8a629 --- /dev/null +++ b/idea/testData/intentions/specifyTypeExplicitly/propertyTypeFromGetter.kt.after @@ -0,0 +1 @@ +val x: Int get() = 1 diff --git a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java index ca17ef95796..8438426dbe2 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -12916,6 +12916,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest { doTest(fileName); } + @TestMetadata("propertyTypeFromGetter.kt") + public void testPropertyTypeFromGetter() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/specifyTypeExplicitly/propertyTypeFromGetter.kt"); + doTest(fileName); + } + @TestMetadata("publicMember.kt") public void testPublicMember() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/specifyTypeExplicitly/publicMember.kt");