Provide import alias suggestion for Companion
Fixed #EA-223797
This commit is contained in:
+8
-1
@@ -40,6 +40,7 @@ import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
|||||||
import org.jetbrains.kotlin.resolve.scopes.utils.findClassifier
|
import org.jetbrains.kotlin.resolve.scopes.utils.findClassifier
|
||||||
import org.jetbrains.kotlin.resolve.scopes.utils.findPackage
|
import org.jetbrains.kotlin.resolve.scopes.utils.findPackage
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||||
|
import org.jetbrains.kotlin.utils.checkWithAttachment
|
||||||
|
|
||||||
object KotlinIntroduceImportAliasHandler : RefactoringActionHandler {
|
object KotlinIntroduceImportAliasHandler : RefactoringActionHandler {
|
||||||
const val REFACTORING_NAME = "Introduce Import Alias"
|
const val REFACTORING_NAME = "Introduce Import Alias"
|
||||||
@@ -83,7 +84,13 @@ object KotlinIntroduceImportAliasHandler : RefactoringActionHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val suggestionsName = KotlinNameSuggester.suggestNamesByFqName(fqName, validator = validator)
|
val suggestionsName = KotlinNameSuggester.suggestNamesByFqName(
|
||||||
|
fqName,
|
||||||
|
validator = validator,
|
||||||
|
defaultName = { fqName.asString().replace('.', '_') })
|
||||||
|
checkWithAttachment(suggestionsName.isNotEmpty(), { "Unable to build any suggestion name for $fqName" }) {
|
||||||
|
it.withAttachment("file.kt", file.text)
|
||||||
|
}
|
||||||
val newName = suggestionsName.first()
|
val newName = suggestionsName.first()
|
||||||
suggestedImportAliasNames = suggestionsName
|
suggestedImportAliasNames = suggestionsName
|
||||||
val newDirective = ImportInsertHelperImpl.addImport(project, file, fqName, false, Name.identifier(newName))
|
val newDirective = ImportInsertHelperImpl.addImport(project, file, fqName, false, Name.identifier(newName))
|
||||||
|
|||||||
Reference in New Issue
Block a user