"Create abstract function" quick fix: don't suggest it if super classes are not writable
#KT-40215 Fixed
This commit is contained in:
committed by
Roman Golyshev
parent
0c832e30bf
commit
80e4e7939d
+9
-1
@@ -148,7 +148,10 @@ sealed class CreateCallableFromCallActionFactory<E : KtExpression>(
|
||||
receiverTypeInfo = TypeInfo(receiverType, Variance.IN_VARIANCE).ofThis()
|
||||
}
|
||||
|
||||
if (!receiverType.isAbstract() && TypeUtils.getAllSupertypes(receiverType).all { !it.isAbstract() }) return null
|
||||
val project = originalExpression.project
|
||||
if (!receiverType.isAbstract() && TypeUtils.getAllSupertypes(receiverType).none { it.isAbstract() && it.canRefactor(project) }) {
|
||||
return null
|
||||
}
|
||||
|
||||
return mainCallable.copy(
|
||||
receiverTypeInfo = receiverTypeInfo,
|
||||
@@ -157,6 +160,11 @@ sealed class CreateCallableFromCallActionFactory<E : KtExpression>(
|
||||
)
|
||||
}
|
||||
|
||||
private fun KotlinType.canRefactor(project: Project): Boolean {
|
||||
val declarationDescriptor = constructor.declarationDescriptor ?: return false
|
||||
return DescriptorToSourceUtilsIde.getAnyDeclaration(project, declarationDescriptor)?.canRefactor() == true
|
||||
}
|
||||
|
||||
protected fun getCallableWithReceiverInsideExtension(
|
||||
mainCallable: CallableInfo,
|
||||
originalExpression: KtExpression,
|
||||
|
||||
idea/testData/quickfix/createFromUsage/createFunction/call/abstract/notWritableAbstractSuperclass.kt
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
// "Create abstract function 'bar'" "false"
|
||||
// ACTION: Create function 'bar'
|
||||
// ACTION: Rename reference
|
||||
// ERROR: Unresolved reference: bar
|
||||
class Foo : Runnable {
|
||||
override fun run() {
|
||||
<caret>bar()
|
||||
}
|
||||
}
|
||||
@@ -4478,6 +4478,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
||||
runTest("idea/testData/quickfix/createFromUsage/createFunction/call/abstract/notAbstractClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("notWritableAbstractSuperclass.kt")
|
||||
public void testNotWritableAbstractSuperclass() throws Exception {
|
||||
runTest("idea/testData/quickfix/createFromUsage/createFunction/call/abstract/notWritableAbstractSuperclass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("otherExplicitReceiver.kt")
|
||||
public void testOtherExplicitReceiver() throws Exception {
|
||||
runTest("idea/testData/quickfix/createFromUsage/createFunction/call/abstract/otherExplicitReceiver.kt");
|
||||
|
||||
Reference in New Issue
Block a user