Fix "unexpected error type" exception in initializer -> getter
So #KT-19674 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
a9ece23e63
commit
13fc526695
+4
-1
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.psi.KtDeclaration
|
|||||||
import org.jetbrains.kotlin.psi.KtProperty
|
import org.jetbrains.kotlin.psi.KtProperty
|
||||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.isExtensionDeclaration
|
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") {
|
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?) {
|
fun convertPropertyInitializerToGetter(property: KtProperty, editor: Editor?) {
|
||||||
val type = SpecifyTypeExplicitlyIntention.getTypeForDeclaration(property)
|
val type = SpecifyTypeExplicitlyIntention.getTypeForDeclaration(property)
|
||||||
SpecifyTypeExplicitlyIntention.addTypeAnnotation(editor, property, type)
|
if (!type.isError) {
|
||||||
|
SpecifyTypeExplicitlyIntention.addTypeAnnotation(editor, property, type)
|
||||||
|
}
|
||||||
|
|
||||||
val initializer = property.initializer!!
|
val initializer = property.initializer!!
|
||||||
val getter = KtPsiFactory(property).createPropertyGetter(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>
|
||||||
|
}
|
||||||
+9
@@ -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);
|
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")
|
@TestMetadata("inapplicableIfExtensionProperty.kt")
|
||||||
public void testInapplicableIfExtensionProperty() throws Exception {
|
public void testInapplicableIfExtensionProperty() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertPropertyInitializerToGetter/inapplicableIfExtensionProperty.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertPropertyInitializerToGetter/inapplicableIfExtensionProperty.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user