Add test for specify type explicitly when it can be inferred from getter

#KT-14794 In Progress
This commit is contained in:
Denis Zharkov
2016-11-14 14:25:15 +03:00
parent 6fca46a452
commit e25c4b96ad
4 changed files with 9 additions and 5 deletions
@@ -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")
}
@@ -0,0 +1 @@
val x<caret> get() = 1
@@ -0,0 +1 @@
val x: Int get() = 1
@@ -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");