KT-57468 Kotlin assignment plugin: operation name cannot be found
The problem results in broken import quick fix and import optimizer on the IDE side [1]. `AssignResolutionAltererExtension` introduced a possibility to override resolution of assignment statements. The inconsistency though is that `KtSimpleNameReference.getResolvesByNames` doesn't return a name for the overridden `=`. Kotlin as a language doesn't support this [2]. This commit eliminates the drawback above: 1. It fixes the name `assign` the `=` can be resolved to [3]. This eliminates the need to search for the name, bypassing the plugins. 2. `KtSimpleNameReference.getResolvesByNames` returns `assign` among other names in case it deals with binary `=` and assignment is resolved. 3. `KtCompilerPluginsProvider` was extended to check plugins' presence. K1 implementation added. ---------------------------------------------------------------- [1]: https://youtrack.jetbrains.com/issue/KTIJ-24390 [2]: OperatorConventions.getNameForOperationSymbol https://kotlinlang.org/docs/operator-overloading.html#augmented-assignments [3]: OperatorConventions#ASSIGN_METHOD + AssignmentPluginNames
This commit is contained in:
committed by
Space Team
parent
4c1a66b7d6
commit
1e0115aef8
+28
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.descriptors
|
||||
|
||||
import org.jetbrains.kotlin.analysis.project.structure.KtCompilerPluginsProvider
|
||||
import org.jetbrains.kotlin.analysis.project.structure.KtSourceModule
|
||||
import org.jetbrains.kotlin.extensions.ProjectExtensionDescriptor
|
||||
import org.jetbrains.kotlin.extensions.internal.InternalNonStableExtensionPoints
|
||||
import org.jetbrains.kotlin.resolve.extensions.AssignResolutionAltererExtension
|
||||
|
||||
@Suppress("unused")
|
||||
class KtFe10CompilerPluginsProvider : KtCompilerPluginsProvider() {
|
||||
override fun <T : Any> getRegisteredExtensions(module: KtSourceModule, extensionType: ProjectExtensionDescriptor<T>): List<T> {
|
||||
return extensionType.getInstances(module.project)
|
||||
}
|
||||
|
||||
@OptIn(InternalNonStableExtensionPoints::class)
|
||||
override fun isPluginOfTypeRegistered(module: KtSourceModule, pluginType: CompilerPluginType): Boolean {
|
||||
val extension = when (pluginType) {
|
||||
CompilerPluginType.ASSIGNMENT -> AssignResolutionAltererExtension
|
||||
else -> return false
|
||||
}
|
||||
return extension.getInstances(module.project).isNotEmpty()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user