Rename: Disable Java member rename by reference to import alias
#KT-18076 Fixed
This commit is contained in:
+2
@@ -26,6 +26,7 @@ import com.intellij.refactoring.rename.inplace.MemberInplaceRenameHandler
|
||||
import com.intellij.refactoring.rename.inplace.MemberInplaceRenamer
|
||||
import org.jetbrains.kotlin.asJava.unwrapped
|
||||
import org.jetbrains.kotlin.idea.references.SyntheticPropertyAccessorReference
|
||||
import org.jetbrains.kotlin.idea.references.mainReference
|
||||
import org.jetbrains.kotlin.psi.KtPsiUtil
|
||||
import org.jetbrains.kotlin.psi.KtSimpleNameExpression
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
|
||||
@@ -46,6 +47,7 @@ class JavaMemberByKotlinReferenceInplaceRenameHandler : MemberInplaceRenameHandl
|
||||
if (element?.unwrapped !is PsiMember) return false
|
||||
val refExpr = file.findElementAt(editor.caretModel.offset)?.getNonStrictParentOfType<KtSimpleNameExpression>() ?: return false
|
||||
if (refExpr.references.any { (it as? SyntheticPropertyAccessorReference)?.resolve() != null }) return false
|
||||
if (refExpr.mainReference.getImportAlias() != null) return false
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
class Foo {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import Foo as Baz
|
||||
|
||||
fun test() {
|
||||
val bar: Baz = Baz()
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
class Foo {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import Foo as Bar
|
||||
|
||||
fun test() {
|
||||
val bar: /*rename*/Bar = Bar()
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"type": "AUTO_DETECT",
|
||||
"mainFile": "test.kt",
|
||||
"newName": "Baz"
|
||||
}
|
||||
@@ -216,6 +216,12 @@ public class RenameTestGenerated extends AbstractRenameTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("javaClassImportAliasByRef/javaClassImportAliasByRef.test")
|
||||
public void testJavaClassImportAliasByRef_JavaClassImportAliasByRef() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/javaClassImportAliasByRef/javaClassImportAliasByRef.test");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("labeledAnonymousFunByLabel/labeledLambdaByLabel.test")
|
||||
public void testLabeledAnonymousFunByLabel_LabeledLambdaByLabel() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/labeledAnonymousFunByLabel/labeledLambdaByLabel.test");
|
||||
|
||||
Reference in New Issue
Block a user