Rename: Disable Java member rename by reference to import alias

#KT-18076 Fixed
This commit is contained in:
Alexey Sedunov
2017-06-01 15:01:13 +03:00
parent 9c11c42ec2
commit 566e701131
7 changed files with 29 additions and 0 deletions
@@ -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()
}
@@ -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");