mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:10:43 +07:00
[kotlin] Adapt new code to changes in Analysis API on 'kt-master' merge
GitOrigin-RevId: e2eba9d30707d326e91287763d04a6a14fa653b5
This commit is contained in:
committed by
intellij-monorepo-bot
parent
95c2bd5349
commit
78a2d2117a
@@ -1,6 +1,7 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.kotlin.idea.k2.codeinsight.fixes
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KaExperimentalApi
|
||||
import org.jetbrains.kotlin.analysis.api.KaSession
|
||||
import org.jetbrains.kotlin.analysis.api.fir.diagnostics.KaFirDiagnostic
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.types.impl.KaTypeRendererForSource
|
||||
@@ -11,6 +12,7 @@ import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
internal object ReplacePrimitiveCastWithNumberConversionFixFactory {
|
||||
|
||||
@OptIn(KaExperimentalApi::class)
|
||||
val replacePrimitiveCastWithNumberConversionFixFactory =
|
||||
KotlinQuickFixFactory.ModCommandBased { diagnostic: KaFirDiagnostic.CastNeverSucceeds ->
|
||||
val binaryExpression = diagnostic.psi
|
||||
|
||||
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.analysis.api.base.KaConstantValue
|
||||
import org.jetbrains.kotlin.analysis.api.fir.diagnostics.KaFirDiagnostic
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KaDeclarationSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KaFunctionSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KaNamedFunctionSymbol
|
||||
import org.jetbrains.kotlin.builtins.StandardNames
|
||||
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
|
||||
import org.jetbrains.kotlin.idea.codeinsight.api.applicators.fixes.KotlinQuickFixFactory.IntentionBased
|
||||
@@ -66,7 +67,7 @@ object DeprecationFixFactory {
|
||||
else -> null
|
||||
} ?: return emptyList()
|
||||
val expression = (referenceExpression.parent as? KtCallExpression)?.takeIf {
|
||||
(kaSymbol as? KaFunctionSymbol)?.isOperator == true && referenceExpression.mainReference.resolve() is KtValVarKeywordOwner
|
||||
(kaSymbol as? KaNamedFunctionSymbol)?.isOperator == true && referenceExpression.mainReference.resolve() is KtValVarKeywordOwner
|
||||
} ?: referenceExpression
|
||||
val replaceWithData =
|
||||
fetchReplaceWithPattern(kaSymbol) ?: return emptyList()
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.intellij.codeInsight.intention.HighPriorityAction
|
||||
import com.intellij.modcommand.ActionContext
|
||||
import com.intellij.modcommand.ModPsiUpdater
|
||||
import com.intellij.modcommand.Presentation
|
||||
import org.jetbrains.kotlin.analysis.api.KaIdeApi
|
||||
import org.jetbrains.kotlin.analysis.api.KaSession
|
||||
import org.jetbrains.kotlin.analysis.api.components.ShortenCommand
|
||||
import org.jetbrains.kotlin.analysis.api.components.ShortenStrategy
|
||||
@@ -19,6 +20,7 @@ import org.jetbrains.kotlin.psi.KtNameReferenceExpression
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getQualifiedElement
|
||||
import org.jetbrains.kotlin.psi.psiUtil.isInImportDirective
|
||||
|
||||
@OptIn(KaIdeApi::class)
|
||||
internal class ImportMemberIntention :
|
||||
KotlinApplicableModCommandAction<KtNameReferenceExpression, ImportMemberIntention.Context>(KtNameReferenceExpression::class),
|
||||
HighPriorityAction {
|
||||
@@ -61,6 +63,7 @@ internal class ImportMemberIntention :
|
||||
}
|
||||
|
||||
context(KaSession)
|
||||
@OptIn(KaIdeApi::class)
|
||||
private fun computeContext(psi: KtNameReferenceExpression, symbol: KtSymbol): ImportMemberIntention.Context? {
|
||||
return when (symbol) {
|
||||
is KaConstructorSymbol,
|
||||
@@ -90,7 +93,7 @@ private fun computeContext(psi: KtNameReferenceExpression, symbol: KtSymbol): Im
|
||||
is KaCallableSymbol -> {
|
||||
val callableId = symbol.callableId ?: return null
|
||||
if (callableId.callableName.isSpecial) return null
|
||||
if (symbol.getImportableName() == null) return null
|
||||
if (symbol.importableFqName == null) return null
|
||||
val shortenCommand = collectPossibleReferenceShortenings(
|
||||
psi.containingKtFile,
|
||||
classShortenStrategy = { ShortenStrategy.DO_NOT_SHORTEN },
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.jetbrains.kotlin.idea.k2.codeinsight.copyPaste
|
||||
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import com.intellij.psi.util.parentsOfType
|
||||
import org.jetbrains.kotlin.analysis.api.KaIdeApi
|
||||
import org.jetbrains.kotlin.analysis.api.KaSession
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KaCallableSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KaSymbol
|
||||
@@ -31,8 +32,9 @@ internal fun <T> Collection<T>.toSortedStringSet(): Set<String> = map { it.toStr
|
||||
* In the resulting map symbols that cannot be imported (e.g., local symbols) are associated with `null` key.
|
||||
*/
|
||||
context(KaSession)
|
||||
@OptIn(KaIdeApi::class)
|
||||
internal fun KtReference.getResolvedSymbolsGroupedByImportableFqName(): Map<FqName?, List<KaSymbol>> = resolveToImportableSymbols()
|
||||
.groupBy { symbol -> symbol.getImportableName() }
|
||||
.groupBy { symbol -> symbol.importableFqName }
|
||||
|
||||
context(KaSession)
|
||||
private fun KtReference.resolveToImportableSymbols(): Collection<KaSymbol> =
|
||||
|
||||
@@ -4,6 +4,7 @@ package org.jetbrains.kotlin.idea.k2.codeinsight.copyPaste
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import com.intellij.psi.createSmartPointer
|
||||
import org.jetbrains.kotlin.analysis.api.KaAnalysisApiInternals
|
||||
import org.jetbrains.kotlin.analysis.api.KaImplementationDetail
|
||||
import org.jetbrains.kotlin.analysis.api.KaSession
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.resolution.KaSymbolBasedReference
|
||||
@@ -30,6 +31,7 @@ import org.jetbrains.kotlin.utils.exceptions.errorWithAttachment
|
||||
import kotlin.collections.flatMap
|
||||
|
||||
internal object KotlinReferenceRestoringHelper {
|
||||
@OptIn(KaImplementationDetail::class)
|
||||
fun collectSourceReferenceInfos(sourceFile: KtFile, startOffsets: IntArray, endOffsets: IntArray): List<KotlinSourceReferenceInfo> {
|
||||
var currentStartOffsetInPastedText = 0
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ fun KtReference.resolveCompanionObjectShortReferenceToContainingClassSymbol(): K
|
||||
// class name reference resolves to companion
|
||||
if (expression.name == symbol.name?.asString()) return null
|
||||
|
||||
val containingSymbol = symbol.getContainingSymbol() as? KaNamedClassOrObjectSymbol
|
||||
val containingSymbol = symbol.containingSymbol as? KaNamedClassOrObjectSymbol
|
||||
return containingSymbol?.takeIf { it.companionObject == symbol }
|
||||
}
|
||||
|
||||
|
||||
@@ -320,7 +320,7 @@ class CodeInliner(
|
||||
return Argument(expression, expression.getKtType(), isNamed = single.isNamed())
|
||||
}
|
||||
val parameterType = parameter.getReturnKtType()
|
||||
val elementType = parameterType.getArrayElementType() ?: return null
|
||||
val elementType = parameterType.arrayElementType ?: return null
|
||||
val expression = psiFactory.buildExpression {
|
||||
appendFixedText(arrayOfFunctionName(elementType))
|
||||
appendFixedText("(")
|
||||
|
||||
@@ -151,7 +151,7 @@ object InlinePostProcessor: AbstractInlinePostProcessor() {
|
||||
for ((argument, param) in arguments.asReversed()) {
|
||||
idx--
|
||||
val defaultValue = param.symbol.defaultValue
|
||||
?: callableSymbol.getAllOverriddenSymbols()
|
||||
?: callableSymbol.allOverriddenSymbols
|
||||
.mapNotNull {
|
||||
val params = (it as? KtFunctionLikeSymbol)?.valueParameters
|
||||
params?.getOrNull(idx)?.defaultValue
|
||||
|
||||
Reference in New Issue
Block a user