allow renaming functions which are members of anonymous objects
#KT-5857 Fixed
This commit is contained in:
+5
-3
@@ -44,8 +44,7 @@ public class RenameKotlinFunctionProcessor : RenameKotlinPsiProcessor() {
|
||||
override fun substituteElementToRename(element: PsiElement?, editor: Editor?): PsiElement? {
|
||||
val wrappedMethod = wrapPsiMethod(element)
|
||||
if (wrappedMethod == null) {
|
||||
// Cancel rename
|
||||
return null
|
||||
return element
|
||||
}
|
||||
|
||||
// Use java dialog to ask we should rename function with the base element
|
||||
@@ -58,7 +57,10 @@ public class RenameKotlinFunctionProcessor : RenameKotlinPsiProcessor() {
|
||||
}
|
||||
|
||||
override fun prepareRenaming(element: PsiElement?, newName: String?, allRenames: MutableMap<PsiElement, String>, scope: SearchScope) {
|
||||
javaMethodProcessorInstance.prepareRenaming(wrapPsiMethod(element), newName, allRenames, scope)
|
||||
val psiMethod = wrapPsiMethod(element)
|
||||
if (psiMethod?.getContainingClass() != null) {
|
||||
javaMethodProcessorInstance.prepareRenaming(psiMethod, newName, allRenames, scope)
|
||||
}
|
||||
}
|
||||
|
||||
private fun wrapPsiMethod(element: PsiElement?): PsiMethod? = when (element) {
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
class X {
|
||||
fun fn() : Iterator<String> = object : Iterator<String> {
|
||||
override fun next(): String {
|
||||
dddd()
|
||||
return ""
|
||||
}
|
||||
|
||||
override fun hasNext(): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
fun dd<caret>dd() { // try renaming this function
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
class X {
|
||||
fun fn() : Iterator<String> = object : Iterator<String> {
|
||||
override fun next(): String {
|
||||
xyzzy()
|
||||
return ""
|
||||
}
|
||||
|
||||
override fun hasNext(): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
fun xyzzy() { // try renaming this function
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
@@ -47,6 +47,10 @@ public class SimpleNameReferenceRenameTest extends LightCodeInsightTestCase {
|
||||
doTest("anotherRenamed");
|
||||
}
|
||||
|
||||
public void testLocalFunction() throws Exception {
|
||||
doTest("xyzzy");
|
||||
}
|
||||
|
||||
private void doTest(String newName) throws Exception {
|
||||
configureByFile(getTestName(true) + ".kt");
|
||||
PsiElement element = TargetElementUtilBase
|
||||
|
||||
Reference in New Issue
Block a user