Fix let implement quickfix label for object expressions
Fixes #KT-11782
This commit is contained in:
committed by
Mikhail Glukhikh
parent
cdab9d5103
commit
da5c963a43
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.idea.util.ShortenReferences
|
|||||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||||
import org.jetbrains.kotlin.psi.KtFile
|
import org.jetbrains.kotlin.psi.KtFile
|
||||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||||
|
import org.jetbrains.kotlin.psi.psiUtil.isObjectLiteral
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import org.jetbrains.kotlin.types.TypeUtils
|
import org.jetbrains.kotlin.types.TypeUtils
|
||||||
import org.jetbrains.kotlin.types.typeUtil.isInterface
|
import org.jetbrains.kotlin.types.typeUtil.isInterface
|
||||||
@@ -52,7 +53,8 @@ class LetImplementInterfaceFix(
|
|||||||
expectedTypeNameSourceCode = IdeDescriptorRenderers.SOURCE_CODE.renderType(expectedTypeNotNullable)
|
expectedTypeNameSourceCode = IdeDescriptorRenderers.SOURCE_CODE.renderType(expectedTypeNotNullable)
|
||||||
|
|
||||||
val verb = if (expressionType.isInterface()) "extend" else "implement"
|
val verb = if (expressionType.isInterface()) "extend" else "implement"
|
||||||
prefix = "Let '${expressionType.renderShort()}' $verb"
|
val typeDescription = if (element.isObjectLiteral()) "the anonymous object" else "'${expressionType.renderShort()}'"
|
||||||
|
prefix = "Let $typeDescription $verb"
|
||||||
|
|
||||||
validExpectedType = with (expectedType) {
|
validExpectedType = with (expectedType) {
|
||||||
isInterface() &&
|
isInterface() &&
|
||||||
@@ -72,4 +74,4 @@ class LetImplementInterfaceFix(
|
|||||||
val entryElement = element.addSuperTypeListEntry(superTypeEntry)
|
val entryElement = element.addSuperTypeListEntry(superTypeEntry)
|
||||||
ShortenReferences.DEFAULT.process(entryElement)
|
ShortenReferences.DEFAULT.process(entryElement)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
// "Let the anonymous object implement interface 'A'" "true"
|
||||||
|
package let.implement
|
||||||
|
|
||||||
|
fun bar() {
|
||||||
|
foo(<caret>object {})
|
||||||
|
}
|
||||||
|
|
||||||
|
fun foo(a: A) {
|
||||||
|
}
|
||||||
|
|
||||||
|
interface A
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
// "Let the anonymous object implement interface 'A'" "true"
|
||||||
|
package let.implement
|
||||||
|
|
||||||
|
fun bar() {
|
||||||
|
foo(<caret>object : A {})
|
||||||
|
}
|
||||||
|
|
||||||
|
fun foo(a: A) {
|
||||||
|
}
|
||||||
|
|
||||||
|
interface A
|
||||||
@@ -7405,6 +7405,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("letObjectImplementAdditionalInterface.kt")
|
||||||
|
public void testLetObjectImplementAdditionalInterface() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/typeMismatch/letObjectImplementAdditionalInterface.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("letStringImplementInterface.kt")
|
@TestMetadata("letStringImplementInterface.kt")
|
||||||
public void testLetStringImplementInterface() throws Exception {
|
public void testLetStringImplementInterface() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/typeMismatch/letStringImplementInterface.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/typeMismatch/letStringImplementInterface.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user