[Analysis API FIR] preserve type annotations on asPsiType conversion
^KT-66603 Fixed
This commit is contained in:
committed by
Space Team
parent
3c8a95e623
commit
96575a0bdb
+4
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2024 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.
|
||||
*/
|
||||
|
||||
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.light.classes.symbol.annotations
|
||||
|
||||
import com.intellij.psi.*
|
||||
import com.intellij.psi.impl.light.LightReferenceListBuilder
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisNonPublicApi
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.*
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.KtKClassAnnotationValue.KtNonLocalKClassAnnotationValue
|
||||
@@ -161,7 +162,8 @@ internal fun KtAnnotatedSymbol.computeThrowsList(
|
||||
}
|
||||
|
||||
context(KtAnalysisSession)
|
||||
internal fun annotateByKtType(
|
||||
@KtAnalysisNonPublicApi
|
||||
fun annotateByKtType(
|
||||
psiType: PsiType,
|
||||
ktType: KtType,
|
||||
psiContext: PsiTypeElement,
|
||||
|
||||
+3
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2024 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.
|
||||
*/
|
||||
|
||||
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.light.classes.symbol.methods
|
||||
import com.intellij.psi.*
|
||||
import kotlinx.collections.immutable.PersistentMap
|
||||
import kotlinx.collections.immutable.mutate
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisNonPublicApi
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.hasAnnotation
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtFunctionSymbol
|
||||
@@ -236,6 +237,7 @@ internal class SymbolLightSimpleMethod(
|
||||
this@SymbolLightSimpleMethod.containingClass.isAnnotationType,
|
||||
suppressWildcards = suppressWildcards(),
|
||||
)?.let {
|
||||
@OptIn(KtAnalysisNonPublicApi::class)
|
||||
annotateByKtType(it.type, ktType, it, modifierList)
|
||||
}
|
||||
} ?: nonExistentType()
|
||||
|
||||
+2
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.light.classes.symbol.parameters
|
||||
|
||||
import com.intellij.psi.*
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisNonPublicApi
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtValueParameterSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||
@@ -84,6 +85,7 @@ internal abstract class SymbolLightParameterCommon(
|
||||
ktType.typeMappingMode(),
|
||||
suppressWildcards = parameterSymbol.suppressWildcardMode(),
|
||||
)?.let {
|
||||
@OptIn(KtAnalysisNonPublicApi::class)
|
||||
annotateByKtType(it.type, ktType, it, modifierList)
|
||||
}
|
||||
} ?: nonExistentType()
|
||||
|
||||
+4
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2024 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.
|
||||
*/
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.intellij.psi.PsiIdentifier
|
||||
import com.intellij.psi.PsiModifierList
|
||||
import com.intellij.psi.PsiType
|
||||
import com.intellij.psi.util.TypeConversionUtil
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisNonPublicApi
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtCallableSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtReceiverParameterSymbol
|
||||
@@ -93,8 +94,10 @@ internal class SymbolLightParameterForReceiver private constructor(
|
||||
ktType.typeMappingMode(),
|
||||
suppressWildcards = receiver.suppressWildcard() ?: method.suppressWildcards(),
|
||||
)?.let {
|
||||
@OptIn(KtAnalysisNonPublicApi::class)
|
||||
annotateByKtType(it.type, ktType, it, modifierList)
|
||||
}
|
||||
|
||||
if (method is SymbolLightAnnotationsMethod) {
|
||||
val erased = TypeConversionUtil.erasure(psiType)
|
||||
val name = erased.canonicalText
|
||||
|
||||
+4
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2024 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.
|
||||
*/
|
||||
|
||||
@@ -51,14 +51,13 @@ internal fun KtAnalysisSession.mapType(
|
||||
psiContext: PsiElement,
|
||||
mode: KtTypeMappingMode
|
||||
): PsiClassType? {
|
||||
val psiTypeElement = type.asPsiTypeElement(
|
||||
val psiType = type.asPsiType(
|
||||
psiContext,
|
||||
allowErrorTypes = true,
|
||||
mode,
|
||||
)
|
||||
return (psiTypeElement?.type as? PsiClassType)?.let {
|
||||
annotateByKtType(it, type, psiTypeElement, modifierListAsParent = null) as? PsiClassType
|
||||
}
|
||||
|
||||
return psiType as? PsiClassType
|
||||
}
|
||||
|
||||
internal enum class NullabilityType {
|
||||
|
||||
Reference in New Issue
Block a user