Add function to supertype immediately removes redundant modifiers #KT-12297 Fixed
This commit is contained in:
@@ -35,9 +35,12 @@ import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
||||
import org.jetbrains.kotlin.idea.core.ShortenReferences
|
||||
import org.jetbrains.kotlin.idea.core.TemplateKind
|
||||
import org.jetbrains.kotlin.idea.core.getFunctionBodyTextFromTemplate
|
||||
import org.jetbrains.kotlin.idea.core.implicitModality
|
||||
import org.jetbrains.kotlin.idea.imports.importableFqName
|
||||
import org.jetbrains.kotlin.idea.util.application.executeWriteCommand
|
||||
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.modalityModifier
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||
import org.jetbrains.kotlin.types.typeUtil.supertypes
|
||||
@@ -87,6 +90,11 @@ class AddFunctionToSupertypeFix private constructor(
|
||||
val insertedFunctionElement = classBody.addBefore(functionElement, classBody.rBrace) as KtNamedFunction
|
||||
|
||||
ShortenReferences.DEFAULT.process(insertedFunctionElement)
|
||||
val modifierToken = insertedFunctionElement.modalityModifier()?.node?.elementType as? KtModifierKeywordToken
|
||||
?: return@executeWriteCommand
|
||||
if (insertedFunctionElement.implicitModality() == modifierToken) {
|
||||
RemoveModifierFix(insertedFunctionElement, modifierToken, true).invoke()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,7 +188,7 @@ class AddFunctionToSupertypeFix private constructor(
|
||||
private fun generateFunctionSignatureForType(functionDescriptor: FunctionDescriptor, typeDescriptor: ClassDescriptor): FunctionDescriptor {
|
||||
// TODO: support for generics.
|
||||
|
||||
val modality = if (typeDescriptor.kind == ClassKind.INTERFACE) Modality.OPEN else typeDescriptor.modality
|
||||
val modality = if (typeDescriptor.kind == ClassKind.INTERFACE) Modality.ABSTRACT else typeDescriptor.modality
|
||||
|
||||
return functionDescriptor.copy(
|
||||
typeDescriptor,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// "Add 'open fun f()' to 'A'" "true"
|
||||
// "Add 'abstract fun f()' to 'A'" "true"
|
||||
interface A
|
||||
class B : A {
|
||||
<caret>override fun f() {}
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
// "Add 'open fun f()' to 'A'" "true"
|
||||
// "Add 'abstract fun f()' to 'A'" "true"
|
||||
interface A {
|
||||
open fun f()
|
||||
fun f()
|
||||
}
|
||||
|
||||
class B : A {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// "Add 'open fun f()' to 'A'" "true"
|
||||
// "Add 'abstract fun f()' to 'A'" "true"
|
||||
interface A {
|
||||
}
|
||||
class B : A {
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
// "Add 'open fun f()' to 'A'" "true"
|
||||
// "Add 'abstract fun f()' to 'A'" "true"
|
||||
interface A {
|
||||
open fun f()
|
||||
fun f()
|
||||
}
|
||||
class B : A {
|
||||
<caret>override fun f() {}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
// "Add function to supertype..." "true"
|
||||
interface A {
|
||||
open fun foo()
|
||||
fun foo()
|
||||
}
|
||||
interface B {}
|
||||
class C: A, B {
|
||||
|
||||
Reference in New Issue
Block a user