Fix "unexpected error type" exception in initializer -> getter

So #KT-19674 Fixed
This commit is contained in:
Mikhail Glukhikh
2017-09-12 18:27:02 +03:00
committed by Mikhail Glukhikh
parent a9ece23e63
commit 13fc526695
4 changed files with 27 additions and 1 deletions
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.psi.KtProperty
import org.jetbrains.kotlin.psi.KtPsiFactory
import org.jetbrains.kotlin.psi.psiUtil.isExtensionDeclaration
import org.jetbrains.kotlin.types.isError
class ConvertPropertyInitializerToGetterIntention : SelfTargetingRangeIntention<KtProperty>(KtProperty::class.java, "Convert property initializer to getter") {
@@ -53,7 +54,9 @@ class ConvertPropertyInitializerToGetterIntention : SelfTargetingRangeIntention<
fun convertPropertyInitializerToGetter(property: KtProperty, editor: Editor?) {
val type = SpecifyTypeExplicitlyIntention.getTypeForDeclaration(property)
SpecifyTypeExplicitlyIntention.addTypeAnnotation(editor, property, type)
if (!type.isError) {
SpecifyTypeExplicitlyIntention.addTypeAnnotation(editor, property, type)
}
val initializer = property.initializer!!
val getter = KtPsiFactory(property).createPropertyGetter(initializer)
@@ -0,0 +1,8 @@
// SKIP_ERRORS_BEFORE
// SKIP_ERRORS_AFTER
class Some
class Other {
val x = Some<caret>
}
@@ -0,0 +1,9 @@
// SKIP_ERRORS_BEFORE
// SKIP_ERRORS_AFTER
class Some
class Other {
val x
get() = Some
}
@@ -5651,6 +5651,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/intentions/convertPropertyInitializerToGetter"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("errorType.kt")
public void testErrorType() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertPropertyInitializerToGetter/errorType.kt");
doTest(fileName);
}
@TestMetadata("inapplicableIfExtensionProperty.kt")
public void testInapplicableIfExtensionProperty() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertPropertyInitializerToGetter/inapplicableIfExtensionProperty.kt");