Fix caret after "Introduce import alias" if invoke in import directive
#KT-30833 Fixed
This commit is contained in:
+6
-3
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveImportReference
|
||||
import org.jetbrains.kotlin.idea.codeInsight.CodeInsightUtils
|
||||
import org.jetbrains.kotlin.idea.core.KotlinNameSuggester
|
||||
import org.jetbrains.kotlin.idea.core.moveCaret
|
||||
import org.jetbrains.kotlin.idea.imports.importableFqName
|
||||
import org.jetbrains.kotlin.idea.refactoring.selectElement
|
||||
import org.jetbrains.kotlin.idea.references.KtSimpleNameReference
|
||||
@@ -44,9 +45,7 @@ import org.jetbrains.kotlin.psi.KtCallExpression
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.KtNameReferenceExpression
|
||||
import org.jetbrains.kotlin.psi.KtUserType
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getQualifiedElement
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getQualifiedElementSelector
|
||||
import org.jetbrains.kotlin.psi.psiUtil.siblings
|
||||
import org.jetbrains.kotlin.psi.psiUtil.*
|
||||
import org.jetbrains.kotlin.resolve.PropertyImportedFromObject
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.isExtension
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
@@ -74,6 +73,8 @@ object KotlinIntroduceImportAliasHandler : RefactoringActionHandler {
|
||||
}
|
||||
}
|
||||
|
||||
val elementInImportDirective = element.isInImportDirective()
|
||||
|
||||
val oldName = element.mainReference.value
|
||||
val scopes = usages.mapNotNull {
|
||||
val expression = it.reference.element
|
||||
@@ -99,6 +100,8 @@ object KotlinIntroduceImportAliasHandler : RefactoringActionHandler {
|
||||
replaceUsages(usages, newName)
|
||||
cleanImport(file, fqName)
|
||||
|
||||
if (elementInImportDirective) editor.moveCaret(newDirective.alias?.nameIdentifier?.textOffset ?: newDirective.endOffset)
|
||||
|
||||
if (!ApplicationManager.getApplication().isUnitTestMode) {
|
||||
invokeRename(project, editor, newDirective.alias, suggestionsName)
|
||||
}
|
||||
|
||||
@@ -9,6 +9,6 @@ class Outer {
|
||||
|
||||
class Test() {
|
||||
fun test() {
|
||||
val i = Middle1.Inner()
|
||||
val i = Middle<caret>1.Inner()
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,6 @@ class Outer {
|
||||
class Test() {
|
||||
fun test() {
|
||||
val foo = 1
|
||||
foo1()
|
||||
foo<caret>1()
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ class Outer {
|
||||
|
||||
class Test() {
|
||||
fun test() {
|
||||
val i = foo1()
|
||||
val i = foo<caret>1()
|
||||
}
|
||||
|
||||
fun test2() {
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package test
|
||||
|
||||
import test.Foo<caret>
|
||||
|
||||
class Foo
|
||||
|
||||
fun main() {
|
||||
Foo()
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package test
|
||||
|
||||
import test.Foo as <caret>Foo1
|
||||
|
||||
class Foo
|
||||
|
||||
fun main() {
|
||||
Foo1()
|
||||
}
|
||||
@@ -10143,6 +10143,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
runTest("idea/testData/intentions/introduceImportAlias/function.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inImport.kt")
|
||||
public void testInImport() throws Exception {
|
||||
runTest("idea/testData/intentions/introduceImportAlias/inImport.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("middleImport.kt")
|
||||
public void testMiddleImport() throws Exception {
|
||||
runTest("idea/testData/intentions/introduceImportAlias/middleImport.kt");
|
||||
|
||||
Reference in New Issue
Block a user