Shorten References: Allow import insertion when function and property have the same name

#KT-22745 Fixed
This commit is contained in:
Alexey Sedunov
2018-02-27 19:15:14 +03:00
parent df4cd14161
commit df4c80f43a
8 changed files with 40 additions and 4 deletions
@@ -514,13 +514,20 @@ class ShortenReferences(val options: (KtElement) -> Options = { Options.DEFAULT
}
return when {
targetsMatch || resolvedCallsMatch -> AnalyzeQualifiedElementResult.ShortenNow
targetsMatch || resolvedCallsMatch ->
AnalyzeQualifiedElementResult.ShortenNow
// it makes no sense to insert import when there is a conflict with function, property etc
targetsWhenShort.any { it !is ClassifierDescriptorWithTypeParameters && it !is PackageViewDescriptor } -> AnalyzeQualifiedElementResult.Skip
// Function doesn't conflict with property
targets.all { it is FunctionDescriptor } && targetsWhenShort.all { it is PropertyDescriptor } ->
AnalyzeQualifiedElementResult.ImportDescriptors(targets)
// In other cases it makes no sense to insert import when there is a conflict with function, property etc
targetsWhenShort.any { it !is ClassifierDescriptorWithTypeParameters && it !is PackageViewDescriptor } ->
AnalyzeQualifiedElementResult.Skip
else -> AnalyzeQualifiedElementResult.ImportDescriptors(targets)
else ->
AnalyzeQualifiedElementResult.ImportDescriptors(targets)
}
}
@@ -0,0 +1,8 @@
import foo.name
val name = ""
fun main(args: Array<String>) {
name
name()
}
@@ -0,0 +1,7 @@
val name = ""
fun <caret>name() {}
fun main(args: Array<String>) {
name
name()
}
@@ -0,0 +1,5 @@
{
"mainFile": "test.kt",
"type": "MOVE_KOTLIN_TOP_LEVEL_DECLARATIONS",
"targetPackage": "foo"
}
@@ -613,6 +613,12 @@ public class MoveTestGenerated extends AbstractMoveTest {
doTest(fileName);
}
@TestMetadata("kotlin/moveTopLevelDeclarations/misc/functionAndPropertyWithSameName/functionAndPropertyWithSameName.test")
public void testKotlin_moveTopLevelDeclarations_misc_functionAndPropertyWithSameName_FunctionAndPropertyWithSameName() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/functionAndPropertyWithSameName/functionAndPropertyWithSameName.test");
doTest(fileName);
}
@TestMetadata("kotlin/moveTopLevelDeclarations/misc/internalReferences/internalReferences.test")
public void testKotlin_moveTopLevelDeclarations_misc_internalReferences_InternalReferences() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/internalReferences/internalReferences.test");