Handle modifiers correctly in "val to object" #KT-18919 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
0b5b5d8e89
commit
8e59d3e379
@@ -41,14 +41,13 @@ class ValToObjectIntention : SelfTargetingIntention<KtProperty>(KtProperty::clas
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun applyTo(element: KtProperty, editor: Editor?) {
|
override fun applyTo(element: KtProperty, editor: Editor?) {
|
||||||
val modifier = element.visibilityModifier()
|
|
||||||
val name = element.name ?: return
|
val name = element.name ?: return
|
||||||
val objectLiteral = element.initializer as? KtObjectLiteralExpression ?: return
|
val objectLiteral = element.initializer as? KtObjectLiteralExpression ?: return
|
||||||
val declaration = objectLiteral.objectDeclaration
|
val declaration = objectLiteral.objectDeclaration
|
||||||
val superTypeList = declaration.getSuperTypeList()
|
val superTypeList = declaration.getSuperTypeList()
|
||||||
val body = declaration.getBody() ?: return
|
val body = declaration.getBody() ?: return
|
||||||
|
|
||||||
val prefix = modifier?.text?.plus(" ") ?: ""
|
val prefix = element.modifierList?.text?.plus(" ") ?: ""
|
||||||
val superTypesText = superTypeList?.text?.plus(" ") ?: ""
|
val superTypesText = superTypeList?.text?.plus(" ") ?: ""
|
||||||
|
|
||||||
val replacementText = "${prefix}object $name: $superTypesText${body.text}"
|
val replacementText = "${prefix}object $name: $superTypesText${body.text}"
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// SKIP_ERRORS_BEFORE
|
||||||
|
// SKIP_ERRORS_AFTER
|
||||||
|
|
||||||
|
expect interface EmptyInterface
|
||||||
|
|
||||||
|
expect val <caret>ofInterface = object : EmptyInterface{}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// SKIP_ERRORS_BEFORE
|
||||||
|
// SKIP_ERRORS_AFTER
|
||||||
|
|
||||||
|
expect interface EmptyInterface
|
||||||
|
|
||||||
|
expect object ofInterface : EmptyInterface {}
|
||||||
@@ -16214,6 +16214,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("expected.kt")
|
||||||
|
public void testExpected() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/valToObject/expected.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("getter.kt")
|
@TestMetadata("getter.kt")
|
||||||
public void testGetter() throws Exception {
|
public void testGetter() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/valToObject/getter.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/valToObject/getter.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user