[AA FIR] correctly restore declaration with annotation with argument inside some type from symbol pointer
ConeAttributes can have some non-stable info, so we shouldn't render it Also reduce resolve from IMPLICIT_TYPES_BODY_RESOLVE to TYPES where it is possible ^KT-58141 Fixed
This commit is contained in:
committed by
Space Team
parent
866e8a26c7
commit
6b3e49e824
+6
@@ -118,6 +118,12 @@ public class Fe10IdeNormalAnalysisSourceModuleSingleSymbolByPsiGenerated extends
|
||||
runTest("analysis/analysis-api/testData/symbols/singleSymbolByPsi/setterWithAnnotations.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("typeAnnotationWithArgument.kt")
|
||||
public void testTypeAnnotationWithArgument() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/symbols/singleSymbolByPsi/typeAnnotationWithArgument.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("typeAnnotationsOnFunctionParameterType.kt")
|
||||
public void testTypeAnnotationsOnFunctionParameterType() throws Exception {
|
||||
|
||||
+12
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
@@ -8,11 +8,13 @@ package org.jetbrains.kotlin.analysis.api.fir.symbols.pointers
|
||||
import org.jetbrains.kotlin.fir.declarations.FirCallableDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.FirFunction
|
||||
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||
import org.jetbrains.kotlin.fir.renderer.ConeAttributeRenderer
|
||||
import org.jetbrains.kotlin.fir.renderer.ConeIdFullRenderer
|
||||
import org.jetbrains.kotlin.fir.renderer.ConeTypeRenderer
|
||||
import org.jetbrains.kotlin.fir.renderer.FirRenderer
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.lazyResolveToPhase
|
||||
import org.jetbrains.kotlin.fir.types.ConeAttributes
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||
|
||||
/**
|
||||
@@ -76,7 +78,7 @@ internal class FirCallableSignature private constructor(
|
||||
fun createSignature(callableSymbol: FirCallableSymbol<*>): FirCallableSignature = createSignature(callableSymbol.fir)
|
||||
|
||||
fun createSignature(callableDeclaration: FirCallableDeclaration): FirCallableSignature {
|
||||
callableDeclaration.lazyResolveToPhase(FirResolvePhase.IMPLICIT_TYPES_BODY_RESOLVE)
|
||||
callableDeclaration.lazyResolveToPhase(FirResolvePhase.TYPES)
|
||||
|
||||
return FirCallableSignature(
|
||||
receiverType = callableDeclaration.receiverParameter?.typeRef?.renderType(),
|
||||
@@ -87,13 +89,14 @@ internal class FirCallableSignature private constructor(
|
||||
null
|
||||
},
|
||||
typeParametersCount = callableDeclaration.typeParameters.size,
|
||||
returnType = callableDeclaration.returnTypeRef.renderType(),
|
||||
returnType = callableDeclaration.symbol.resolvedReturnTypeRef.renderType(),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun FirTypeRef.renderType(): String = FirRenderer(
|
||||
private fun FirTypeRef.renderType(builder: StringBuilder = StringBuilder()): String = FirRenderer(
|
||||
builder = builder,
|
||||
annotationRenderer = null,
|
||||
bodyRenderer = null,
|
||||
callArgumentsRenderer = null,
|
||||
@@ -105,7 +108,11 @@ private fun FirTypeRef.renderType(): String = FirRenderer(
|
||||
packageDirectiveRenderer = null,
|
||||
propertyAccessorRenderer = null,
|
||||
resolvePhaseRenderer = null,
|
||||
typeRenderer = ConeTypeRenderer(),
|
||||
typeRenderer = ConeTypeRenderer().apply { attributeRenderer = EmptyConeTypeAttributeRenderer },
|
||||
valueParameterRenderer = null,
|
||||
errorExpressionRenderer = null,
|
||||
).renderElementAsString(this)
|
||||
|
||||
private object EmptyConeTypeAttributeRenderer : ConeAttributeRenderer() {
|
||||
override fun render(attributes: ConeAttributes): String = ""
|
||||
}
|
||||
|
||||
+6
@@ -118,6 +118,12 @@ public class FirIdeNormalAnalysisSourceModuleSingleSymbolByPsiGenerated extends
|
||||
runTest("analysis/analysis-api/testData/symbols/singleSymbolByPsi/setterWithAnnotations.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("typeAnnotationWithArgument.kt")
|
||||
public void testTypeAnnotationWithArgument() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/symbols/singleSymbolByPsi/typeAnnotationWithArgument.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("typeAnnotationsOnFunctionParameterType.kt")
|
||||
public void testTypeAnnotationsOnFunctionParameterType() throws Exception {
|
||||
|
||||
+6
@@ -118,6 +118,12 @@ public class FirStandaloneNormalAnalysisSourceModuleSingleSymbolByPsiGenerated e
|
||||
runTest("analysis/analysis-api/testData/symbols/singleSymbolByPsi/setterWithAnnotations.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("typeAnnotationWithArgument.kt")
|
||||
public void testTypeAnnotationWithArgument() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/symbols/singleSymbolByPsi/typeAnnotationWithArgument.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("typeAnnotationsOnFunctionParameterType.kt")
|
||||
public void testTypeAnnotationsOnFunctionParameterType() throws Exception {
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE_K1
|
||||
@Target(AnnotationTarget.TYPE)
|
||||
annotation class Anno5(val s: String)
|
||||
|
||||
fun f<caret>oo(): List<@Anno5("1") Int>? = null
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
fun foo(): kotlin.collections.List<@Anno5(s = "1") kotlin.Int>?
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
KtFunctionSymbol:
|
||||
annotationsList: []
|
||||
callableIdIfNonLocal: /foo
|
||||
contextReceivers: []
|
||||
contractEffects: []
|
||||
hasStableParameterNames: true
|
||||
isBuiltinFunctionInvoke: false
|
||||
isExtension: false
|
||||
isExternal: false
|
||||
isInfix: false
|
||||
isInline: false
|
||||
isOperator: false
|
||||
isOverride: false
|
||||
isStatic: false
|
||||
isSuspend: false
|
||||
modality: FINAL
|
||||
name: foo
|
||||
origin: SOURCE
|
||||
receiverParameter: null
|
||||
returnType: KtUsualClassType:
|
||||
annotationsList: []
|
||||
ownTypeArguments: [
|
||||
KtUsualClassType:
|
||||
annotationsList: [
|
||||
Anno5(s = "1")
|
||||
psi: KtAnnotationEntry
|
||||
]
|
||||
ownTypeArguments: []
|
||||
type: @R|Anno5|(s = String(1)) kotlin/Int
|
||||
]
|
||||
type: kotlin/collections/List<@R|Anno5|(s = String(1)) kotlin/Int>?
|
||||
symbolKind: TOP_LEVEL
|
||||
typeParameters: []
|
||||
valueParameters: []
|
||||
visibility: Public
|
||||
getContainingModule: KtSourceModule "Sources of main"
|
||||
deprecationStatus: null
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* 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.fir.renderer
|
||||
|
||||
import org.jetbrains.kotlin.fir.types.ConeAttributes
|
||||
|
||||
abstract class ConeAttributeRenderer {
|
||||
abstract fun render(attributes: ConeAttributes): String
|
||||
|
||||
object ToString : ConeAttributeRenderer() {
|
||||
override fun render(attributes: ConeAttributes): String = attributes.joinToString(separator = " ", postfix = " ") { it.toString() }
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
@@ -12,6 +12,7 @@ open class ConeTypeRenderer {
|
||||
|
||||
lateinit var builder: StringBuilder
|
||||
lateinit var idRenderer: ConeIdRenderer
|
||||
var attributeRenderer: ConeAttributeRenderer = ConeAttributeRenderer.ToString
|
||||
|
||||
open fun renderAsPossibleFunctionType(
|
||||
type: ConeKotlinType,
|
||||
@@ -180,7 +181,7 @@ open class ConeTypeRenderer {
|
||||
|
||||
private fun ConeKotlinType.renderAttributes() {
|
||||
if (!attributes.any()) return
|
||||
builder.append(attributes.joinToString(" ", postfix = " ") { it.toString() })
|
||||
builder.append(attributeRenderer.render(attributes))
|
||||
}
|
||||
|
||||
private fun ConeTypeProjection.render() {
|
||||
|
||||
Reference in New Issue
Block a user