Fix exception of rename readonly overridden methods
This commit is contained in:
+4
-1
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.idea.caches.lightClasses.KtFakeLightClass
|
||||
import org.jetbrains.kotlin.idea.caches.lightClasses.KtFakeLightMethod
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.unsafeResolveToDescriptor
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
|
||||
import org.jetbrains.kotlin.idea.core.getDeepestSuperDeclarations
|
||||
import org.jetbrains.kotlin.idea.core.isOverridable
|
||||
import org.jetbrains.kotlin.idea.search.allScope
|
||||
@@ -206,7 +207,9 @@ fun findDeepestSuperMethodsNoWrapping(method: PsiElement): List<PsiElement> {
|
||||
is PsiMethod -> element.findDeepestSuperMethods().toList()
|
||||
is KtCallableDeclaration -> {
|
||||
val descriptor = element.resolveToDescriptorIfAny() as? CallableMemberDescriptor ?: return emptyList()
|
||||
descriptor.getDeepestSuperDeclarations(false).mapNotNull { it.source.getPsi() }
|
||||
descriptor.getDeepestSuperDeclarations(false).mapNotNull {
|
||||
it.source.getPsi() ?: DescriptorToSourceUtilsIde.getAnyDeclaration(element.project, it)
|
||||
}
|
||||
}
|
||||
else -> emptyList()
|
||||
}
|
||||
|
||||
@@ -41,10 +41,10 @@ import com.intellij.refactoring.BaseRefactoringProcessor.ConflictsInTestsExcepti
|
||||
import com.intellij.refactoring.changeSignature.ChangeSignatureUtil
|
||||
import com.intellij.refactoring.listeners.RefactoringEventData
|
||||
import com.intellij.refactoring.listeners.RefactoringEventListener
|
||||
import com.intellij.refactoring.rename.PsiElementRenameHandler
|
||||
import com.intellij.refactoring.ui.ConflictsDialog
|
||||
import com.intellij.refactoring.util.ConflictsUtil
|
||||
import com.intellij.refactoring.util.RefactoringUIUtil
|
||||
import com.intellij.refactoring.rename.PsiElementRenameHandler
|
||||
import com.intellij.ui.components.JBList
|
||||
import com.intellij.usageView.UsageViewTypeLocation
|
||||
import com.intellij.util.VisibilityUtil
|
||||
|
||||
+9
-5
@@ -11,10 +11,8 @@ import com.intellij.openapi.util.Pass
|
||||
import com.intellij.psi.*
|
||||
import com.intellij.psi.search.SearchScope
|
||||
import com.intellij.refactoring.listeners.RefactoringElementListener
|
||||
import com.intellij.refactoring.rename.RenameDialog
|
||||
import com.intellij.refactoring.rename.RenameJavaMethodProcessor
|
||||
import com.intellij.refactoring.rename.RenameProcessor
|
||||
import com.intellij.refactoring.rename.RenameUtil
|
||||
import com.intellij.refactoring.rename.*
|
||||
import com.intellij.refactoring.util.CommonRefactoringUtil
|
||||
import com.intellij.refactoring.util.RefactoringUtil
|
||||
import com.intellij.usageView.UsageInfo
|
||||
import com.intellij.util.SmartList
|
||||
@@ -122,7 +120,13 @@ class RenameKotlinFunctionProcessor : RenameKotlinPsiProcessor() {
|
||||
return substitutedJavaElement.kotlinOrigin as? KtNamedFunction
|
||||
}
|
||||
|
||||
return substitutedJavaElement
|
||||
val canRename = try {
|
||||
PsiElementRenameHandler.canRename(element.project, editor, substitutedJavaElement)
|
||||
} catch (e: CommonRefactoringUtil.RefactoringErrorHintException) {
|
||||
false
|
||||
}
|
||||
|
||||
return if (canRename) substitutedJavaElement else element
|
||||
}
|
||||
|
||||
override fun substituteElementToRename(element: PsiElement, editor: Editor, renameCallback: Pass<PsiElement>) {
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package testing.rename
|
||||
|
||||
interface A : Runnable {
|
||||
override fun run() {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
}
|
||||
|
||||
public open class B: A {
|
||||
fun lol() {
|
||||
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package testing.rename
|
||||
|
||||
interface A : Runnable {
|
||||
override fun run() {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
}
|
||||
|
||||
public open class B: A {
|
||||
override fun run() {
|
||||
|
||||
}
|
||||
}
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "KOTLIN_FUNCTION",
|
||||
"classId": "testing/rename/B",
|
||||
"oldName": "run",
|
||||
"newName": "lol",
|
||||
"comment": "Rename method with binary function overridden"
|
||||
}
|
||||
+5
@@ -698,6 +698,11 @@ public class RenameTestGenerated extends AbstractRenameTest {
|
||||
runTest("idea/testData/refactoring/rename/renameKotlinBaseMethod/kotlinBaseFunction.test");
|
||||
}
|
||||
|
||||
@TestMetadata("renameKotlinBaseMethodWithBinaryBase/kotlinBaseFunction.test")
|
||||
public void testRenameKotlinBaseMethodWithBinaryBase_KotlinBaseFunction() throws Exception {
|
||||
runTest("idea/testData/refactoring/rename/renameKotlinBaseMethodWithBinaryBase/kotlinBaseFunction.test");
|
||||
}
|
||||
|
||||
@TestMetadata("renameKotlinClass/javaWrapperForKotlinClass.test")
|
||||
public void testRenameKotlinClass_JavaWrapperForKotlinClass() throws Exception {
|
||||
runTest("idea/testData/refactoring/rename/renameKotlinClass/javaWrapperForKotlinClass.test");
|
||||
|
||||
Reference in New Issue
Block a user