Shorten References: Allow import insertion when function and property have the same name
#KT-22745 Fixed
This commit is contained in:
@@ -514,13 +514,20 @@ class ShortenReferences(val options: (KtElement) -> Options = { Options.DEFAULT
|
|||||||
}
|
}
|
||||||
|
|
||||||
return when {
|
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
|
// Function doesn't conflict with property
|
||||||
targetsWhenShort.any { it !is ClassifierDescriptorWithTypeParameters && it !is PackageViewDescriptor } -> AnalyzeQualifiedElementResult.Skip
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
package foo
|
||||||
|
|
||||||
|
fun name() {}
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
import foo.name
|
||||||
|
|
||||||
|
val name = ""
|
||||||
|
|
||||||
|
fun main(args: Array<String>) {
|
||||||
|
name
|
||||||
|
name()
|
||||||
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
val name = ""
|
||||||
|
fun <caret>name() {}
|
||||||
|
|
||||||
|
fun main(args: Array<String>) {
|
||||||
|
name
|
||||||
|
name()
|
||||||
|
}
|
||||||
+5
@@ -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);
|
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")
|
@TestMetadata("kotlin/moveTopLevelDeclarations/misc/internalReferences/internalReferences.test")
|
||||||
public void testKotlin_moveTopLevelDeclarations_misc_internalReferences_InternalReferences() throws Exception {
|
public void testKotlin_moveTopLevelDeclarations_misc_internalReferences_InternalReferences() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/internalReferences/internalReferences.test");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/internalReferences/internalReferences.test");
|
||||||
|
|||||||
Reference in New Issue
Block a user