KT-11955 Copy/Paste inserts FQ-name
#KT-11955 Fixed
This commit is contained in:
@@ -46,6 +46,7 @@ import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ImplicitReceiver
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.findClassifier
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.findPackage
|
||||
import org.jetbrains.kotlin.utils.singletonOrEmptyList
|
||||
import java.util.*
|
||||
|
||||
class ShortenReferences(val options: (KtElement) -> Options = { Options.DEFAULT }) {
|
||||
@@ -210,12 +211,12 @@ class ShortenReferences(val options: (KtElement) -> Options = { Options.DEFAULT
|
||||
protected fun analyze(element: KtElement)
|
||||
= resolutionFacade.analyze(element, BodyResolveMode.PARTIAL)
|
||||
|
||||
protected fun processQualifiedElement(element: T, target: DeclarationDescriptor?, canShortenNow: Boolean) {
|
||||
protected fun processQualifiedElement(element: T, targets: Collection<DeclarationDescriptor>, canShortenNow: Boolean) {
|
||||
if (canShortenNow) {
|
||||
addElementToShorten(element)
|
||||
}
|
||||
else if (target != null && target !in failedToImportDescriptors && mayImport(target, file)) {
|
||||
descriptorsToImport.add(target)
|
||||
else if (targets.isNotEmpty() && targets.none { it in failedToImportDescriptors } && targets.all { mayImport(it, file) }) {
|
||||
descriptorsToImport.addAll(targets)
|
||||
}
|
||||
else {
|
||||
qualifier(element).accept(this)
|
||||
@@ -283,14 +284,14 @@ class ShortenReferences(val options: (KtElement) -> Options = { Options.DEFAULT
|
||||
val target = referenceExpression.targets(bindingContext).singleOrNull() ?: return
|
||||
|
||||
val scope = type.getResolutionScope(bindingContext, resolutionFacade)
|
||||
val name = target.getName()
|
||||
val name = target.name
|
||||
val targetByName = if (target is ClassifierDescriptor)
|
||||
scope.findClassifier(name, NoLookupLocation.FROM_IDE)
|
||||
else
|
||||
scope.findPackage(name)
|
||||
val canShortenNow = targetByName?.asString() == target.asString()
|
||||
|
||||
processQualifiedElement(type, target, canShortenNow)
|
||||
processQualifiedElement(type, target.singletonOrEmptyList(), canShortenNow)
|
||||
}
|
||||
|
||||
override fun qualifier(element: KtUserType) = element.qualifier!!
|
||||
@@ -378,7 +379,7 @@ class ShortenReferences(val options: (KtElement) -> Options = { Options.DEFAULT
|
||||
return false
|
||||
}
|
||||
|
||||
processQualifiedElement(qualifiedExpression, targets.singleOrNull(), targetsMatch)
|
||||
processQualifiedElement(qualifiedExpression, targets, targetsMatch)
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
package a.b.c.d
|
||||
|
||||
fun foo(p: Int) {}
|
||||
fun foo(p: String) {}
|
||||
@@ -0,0 +1,6 @@
|
||||
// ERROR: Unresolved reference: p
|
||||
import a.b.c.d.foo
|
||||
|
||||
fun g() {
|
||||
foo(p)
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
a.b.c.d.foo
|
||||
@@ -0,0 +1,5 @@
|
||||
import a.b.c.d.foo
|
||||
|
||||
fun f(p: Int) {
|
||||
<selection>foo(p)</selection>
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fun g() {
|
||||
<caret>
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package a.b.c
|
||||
|
||||
class Foo(p: Int)
|
||||
|
||||
fun Foo(s: String){}
|
||||
fun Foo(c: Char){}
|
||||
@@ -0,0 +1,3 @@
|
||||
fun foo() {
|
||||
<selection>a.b.c.Foo(1.0)</selection>
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import a.b.c.Foo
|
||||
|
||||
fun foo() {
|
||||
Foo(1.0)
|
||||
}
|
||||
+12
@@ -378,6 +378,12 @@ public class InsertImportOnPasteTestGenerated extends AbstractInsertImportOnPast
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/copyPaste/imports/TypeParameter.kt");
|
||||
doTestCopy(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("UnresolvedOverload.kt")
|
||||
public void testUnresolvedOverload() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/copyPaste/imports/UnresolvedOverload.kt");
|
||||
doTestCopy(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/copyPaste/imports")
|
||||
@@ -729,5 +735,11 @@ public class InsertImportOnPasteTestGenerated extends AbstractInsertImportOnPast
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/copyPaste/imports/TypeParameter.kt");
|
||||
doTestCut(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("UnresolvedOverload.kt")
|
||||
public void testUnresolvedOverload() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/copyPaste/imports/UnresolvedOverload.kt");
|
||||
doTestCut(fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,6 +101,12 @@ public class ShortenRefsTestGenerated extends AbstractShortenRefsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("UnresolvedOverload.kt")
|
||||
public void testUnresolvedOverload() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/shortenRefs/UnresolvedOverload.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/shortenRefs/constructor")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
Reference in New Issue
Block a user