mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-02-04 23:39:07 +07:00
[kotlin] use KtFile::hasImportAlias there it is possible
^KTIJ-26688 GitOrigin-RevId: bde9d5583526757416568fd19cfe8769fa05c3c9
This commit is contained in:
committed by
intellij-monorepo-bot
parent
d71101f6d0
commit
b8a44f941a
@@ -135,7 +135,7 @@ object SourceNavigationHelper {
|
||||
private fun Collection<GlobalSearchScope>.union(): List<GlobalSearchScope> =
|
||||
if (this.isNotEmpty()) listOf(GlobalSearchScope.union(this)) else emptyList()
|
||||
|
||||
private fun haveRenamesInImports(files: Collection<KtFile>) = files.any { file -> file.importDirectives.any { it.aliasName != null } }
|
||||
private fun haveRenamesInImports(files: Collection<KtFile>) = files.any(KtFile::hasImportAlias)
|
||||
|
||||
private fun findSpecialProperty(memberName: Name, containingClass: KtClass): KtNamedDeclaration? {
|
||||
// property constructor parameters
|
||||
|
||||
@@ -23,6 +23,8 @@ import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
object KotlinPsiHeuristics {
|
||||
@JvmStatic
|
||||
fun unwrapImportAlias(file: KtFile, aliasName: String): Collection<String> {
|
||||
if (!file.hasImportAlias()) return emptyList()
|
||||
|
||||
return file.aliasImportMap[aliasName]
|
||||
}
|
||||
|
||||
@@ -34,6 +36,8 @@ object KotlinPsiHeuristics {
|
||||
|
||||
@JvmStatic
|
||||
fun getImportAliases(file: KtFile, names: Set<String>): Set<String> {
|
||||
if (!file.hasImportAlias()) return emptySet()
|
||||
|
||||
val result = LinkedHashSet<String>()
|
||||
for ((aliasName, name) in file.aliasImportMap.entries()) {
|
||||
if (name in names) {
|
||||
@@ -71,6 +75,7 @@ object KotlinPsiHeuristics {
|
||||
val file = type.containingKotlinFileStub?.psi as? KtFile ?: return false
|
||||
|
||||
// TODO: support type aliases
|
||||
if (!file.hasImportAlias()) return false
|
||||
return file.aliasImportMap[referencedName].contains("Nothing")
|
||||
}
|
||||
|
||||
|
||||
@@ -97,11 +97,15 @@ class KotlinImportOptimizer : ImportOptimizer {
|
||||
|
||||
private class CollectUsedDescriptorsVisitor(file: KtFile) : KtVisitorVoid() {
|
||||
private val currentPackageName = file.packageFqName
|
||||
private val aliases: Map<FqName, List<Name>> = file.importDirectives
|
||||
.asSequence()
|
||||
.filter { !it.isAllUnder && it.alias != null }
|
||||
.mapNotNull { it.importPath }
|
||||
.groupBy(keySelector = { it.fqName }, valueTransform = { it.importedName as Name })
|
||||
private val aliases: Map<FqName, List<Name>> = if (file.hasImportAlias()) {
|
||||
file.importDirectives
|
||||
.asSequence()
|
||||
.filter { !it.isAllUnder && it.alias != null }
|
||||
.mapNotNull { it.importPath }
|
||||
.groupBy(keySelector = { it.fqName }, valueTransform = { it.importedName as Name })
|
||||
} else {
|
||||
emptyMap()
|
||||
}
|
||||
|
||||
private val descriptorsToImport = hashSetOf<OptimizedImportsBuilder.ImportableDescriptor>()
|
||||
private val namesToImport = hashMapOf<FqName, MutableSet<Name>>()
|
||||
|
||||
@@ -35,7 +35,10 @@ class ReplaceWithImportAliasInspection : AbstractKotlinInspection() {
|
||||
|
||||
private fun KtNameReferenceExpression.aliasNameIdentifier(): PsiElement? {
|
||||
val name = getIdentifier()?.text ?: return null
|
||||
val imports = containingKtFile.importDirectives.filter {
|
||||
val ktFile = containingKtFile
|
||||
if (!ktFile.hasImportAlias()) return null
|
||||
|
||||
val imports = ktFile.importDirectives.filter {
|
||||
!it.isAllUnder && it.alias != null && it.importedFqName?.shortName()?.asString() == name
|
||||
}.ifEmpty { return null }
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ class AddFullQualifierIntention : SelfTargetingIntention<KtNameReferenceExpressi
|
||||
val file = referenceExpression.containingKtFile
|
||||
val identifier = referenceExpression.getIdentifier()?.text
|
||||
val fqName = resultDescriptor.importableFqName
|
||||
return !file.importDirectives.any { it.aliasName == identifier && it.importedFqName == fqName }
|
||||
return !file.hasImportAlias() || file.importDirectives.none { it.aliasName == identifier && it.importedFqName == fqName }
|
||||
}
|
||||
|
||||
fun applyTo(referenceExpression: KtNameReferenceExpression, fqName: FqName): KtElement {
|
||||
|
||||
Reference in New Issue
Block a user