Add ability to rename java methods with usages in Kotlin
This commit is contained in:
+7
-6
@@ -45,7 +45,7 @@ public class RenameKotlinFunctionProcessor : RenamePsiElementProcessor() {
|
||||
}
|
||||
|
||||
override fun canProcessElement(element: PsiElement): Boolean {
|
||||
return element is JetNamedFunction || element is KotlinLightMethod
|
||||
return element is JetNamedFunction || (element is KotlinLightMethod && element.getOrigin() is JetNamedFunction)
|
||||
}
|
||||
|
||||
override fun substituteElementToRename(element: PsiElement?, editor: Editor?): PsiElement? {
|
||||
@@ -56,7 +56,12 @@ public class RenameKotlinFunctionProcessor : RenamePsiElementProcessor() {
|
||||
}
|
||||
|
||||
// Use java dialog to ask we should rename function with the base element
|
||||
return unwrapPsiMethod(javaMethodProcessorInstance.substituteElementToRename(wrappedMethod, editor))
|
||||
val subtitudedJavaElement = javaMethodProcessorInstance.substituteElementToRename(wrappedMethod, editor)
|
||||
|
||||
return when (subtitudedJavaElement) {
|
||||
is KotlinLightMethod -> subtitudedJavaElement.getOrigin() as? JetNamedFunction
|
||||
else -> subtitudedJavaElement
|
||||
}
|
||||
}
|
||||
|
||||
override fun prepareRenaming(element: PsiElement?, newName: String?, allRenames: MutableMap<PsiElement, String>, scope: SearchScope) {
|
||||
@@ -68,8 +73,4 @@ public class RenameKotlinFunctionProcessor : RenamePsiElementProcessor() {
|
||||
is JetNamedFunction -> ApplicationManager.getApplication()!!.runReadAction(Computable { LightClassUtil.getLightClassMethod(element) })
|
||||
else -> throw IllegalStateException("Can't be for element $element there because of canProcessElement()")
|
||||
}
|
||||
|
||||
private fun unwrapPsiMethod(element: PsiElement?): JetNamedFunction? {
|
||||
return (element as? KotlinLightMethod)?.getOrigin() as? JetNamedFunction
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package testing.kotlin
|
||||
|
||||
import testing.JavaClass
|
||||
|
||||
class KotlinClass: JavaClass() {
|
||||
override fun bar(): String = "Override"
|
||||
}
|
||||
|
||||
fun usages() {
|
||||
val a = JavaClass().bar()
|
||||
val b = KotlinClass().bar()
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package testing;
|
||||
|
||||
public class JavaClass {
|
||||
public String bar() {
|
||||
return "Test";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package testing.kotlin
|
||||
|
||||
import testing.JavaClass
|
||||
|
||||
class KotlinClass: JavaClass() {
|
||||
override fun foo(): String = "Override"
|
||||
}
|
||||
|
||||
fun usages() {
|
||||
val a = JavaClass().foo()
|
||||
val b = KotlinClass().foo()
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package testing;
|
||||
|
||||
public class JavaClass {
|
||||
public String foo() {
|
||||
return "Test";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
// RENAME: JAVA_METHOD->testing.JavaClass->String foo()->bar
|
||||
@@ -0,0 +1,2 @@
|
||||
// RENAME: KOTLIN_FUNCTION->testing.kotlin.KotlinClass.foo->bar
|
||||
// FILE: MethodUsages.kt
|
||||
@@ -46,6 +46,16 @@ public class RenameTestGenerated extends AbstractRenameTest {
|
||||
doTest("idea/testData/refactoring/rename/renameJavaInterface/renameJavaInterface.test");
|
||||
}
|
||||
|
||||
@TestMetadata("renameJavaMethod/javaBaseMethod.test")
|
||||
public void testRenameJavaMethod_JavaBaseMethod() throws Exception {
|
||||
doTest("idea/testData/refactoring/rename/renameJavaMethod/javaBaseMethod.test");
|
||||
}
|
||||
|
||||
@TestMetadata("renameJavaMethod/kotlinOverridenMethod.test")
|
||||
public void testRenameJavaMethod_KotlinOverridenMethod() throws Exception {
|
||||
doTest("idea/testData/refactoring/rename/renameJavaMethod/kotlinOverridenMethod.test");
|
||||
}
|
||||
|
||||
@TestMetadata("renameKotlinBaseMethod/javaWrapperForBaseFunction.test")
|
||||
public void testRenameKotlinBaseMethod_JavaWrapperForBaseFunction() throws Exception {
|
||||
doTest("idea/testData/refactoring/rename/renameKotlinBaseMethod/javaWrapperForBaseFunction.test");
|
||||
|
||||
Reference in New Issue
Block a user