[FIR IDE] Fix annotation value parameter and ctor resolve
This commit is contained in:
@@ -309,7 +309,12 @@ class JavaSymbolProvider(
|
|||||||
}
|
}
|
||||||
if (classIsAnnotation) {
|
if (classIsAnnotation) {
|
||||||
declarations +=
|
declarations +=
|
||||||
buildConstructorForAnnotationClass(constructorId, this, valueParametersForAnnotationConstructor)
|
buildConstructorForAnnotationClass(
|
||||||
|
classSource = (javaClass as? JavaElementImpl<*>)?.psi?.toFirPsiSourceElement(FirFakeSourceElementKind.ImplicitConstructor),
|
||||||
|
constructorId = constructorId,
|
||||||
|
ownerClassBuilder = this,
|
||||||
|
valueParametersForAnnotationConstructor = valueParametersForAnnotationConstructor
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -438,6 +443,7 @@ class JavaSymbolProvider(
|
|||||||
}
|
}
|
||||||
if (classIsAnnotation) {
|
if (classIsAnnotation) {
|
||||||
val parameterForAnnotationConstructor = buildJavaValueParameter {
|
val parameterForAnnotationConstructor = buildJavaValueParameter {
|
||||||
|
source = (javaMethod as? JavaElementImpl<*>)?.psi?.toFirPsiSourceElement(FirFakeSourceElementKind.ImplicitJavaAnnotationConstructor)
|
||||||
session = this@JavaSymbolProvider.session
|
session = this@JavaSymbolProvider.session
|
||||||
returnTypeRef = firJavaMethod.returnTypeRef
|
returnTypeRef = firJavaMethod.returnTypeRef
|
||||||
name = methodName
|
name = methodName
|
||||||
@@ -505,11 +511,13 @@ class JavaSymbolProvider(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun buildConstructorForAnnotationClass(
|
private fun buildConstructorForAnnotationClass(
|
||||||
|
classSource: FirSourceElement?,
|
||||||
constructorId: CallableId,
|
constructorId: CallableId,
|
||||||
ownerClassBuilder: FirJavaClassBuilder,
|
ownerClassBuilder: FirJavaClassBuilder,
|
||||||
valueParametersForAnnotationConstructor: ValueParametersForAnnotationConstructor
|
valueParametersForAnnotationConstructor: ValueParametersForAnnotationConstructor
|
||||||
): FirJavaConstructor {
|
): FirJavaConstructor {
|
||||||
return buildJavaConstructor {
|
return buildJavaConstructor {
|
||||||
|
source = classSource
|
||||||
session = this@JavaSymbolProvider.session
|
session = this@JavaSymbolProvider.session
|
||||||
symbol = FirConstructorSymbol(constructorId)
|
symbol = FirConstructorSymbol(constructorId)
|
||||||
status = FirResolvedDeclarationStatusImpl(Visibilities.Public, Modality.FINAL)
|
status = FirResolvedDeclarationStatusImpl(Visibilities.Public, Modality.FINAL)
|
||||||
|
|||||||
@@ -161,6 +161,14 @@ sealed class FirFakeSourceElementKind : FirSourceElementKind() {
|
|||||||
// { it + 1} --> { it -> it + 1 }
|
// { it + 1} --> { it -> it + 1 }
|
||||||
// where `it` parameter declaration has fake source
|
// where `it` parameter declaration has fake source
|
||||||
object ItLambdaParameter : FirFakeSourceElementKind()
|
object ItLambdaParameter : FirFakeSourceElementKind()
|
||||||
|
|
||||||
|
// for java annotations implicit constructor is generated
|
||||||
|
// with a fake source which refers to containing class
|
||||||
|
object ImplicitJavaAnnotationConstructor : FirFakeSourceElementKind()
|
||||||
|
|
||||||
|
// for java annotations constructor implicit parameters are generated
|
||||||
|
// with a fake source which refers to declared annotation methods
|
||||||
|
object ImplicitAnnotationAnnotationConstructorParameter : FirFakeSourceElementKind()
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed class FirSourceElement {
|
sealed class FirSourceElement {
|
||||||
|
|||||||
+3
-3
@@ -186,14 +186,14 @@ internal object FirReferenceResolveHelper {
|
|||||||
val ktValueArgumentName = expression.parent as? KtValueArgumentName ?: return emptyList()
|
val ktValueArgumentName = expression.parent as? KtValueArgumentName ?: return emptyList()
|
||||||
val ktValueArgument = ktValueArgumentName.parent as? KtValueArgument ?: return emptyList()
|
val ktValueArgument = ktValueArgumentName.parent as? KtValueArgument ?: return emptyList()
|
||||||
val ktValueArgumentList = ktValueArgument.parent as? KtValueArgumentList ?: return emptyList()
|
val ktValueArgumentList = ktValueArgument.parent as? KtValueArgumentList ?: return emptyList()
|
||||||
val ktCallExpression = ktValueArgumentList.parent as? KtCallExpression ?: return emptyList()
|
val ktCallExpression = ktValueArgumentList.parent as? KtCallElement ?: return emptyList()
|
||||||
|
|
||||||
val firCall = ktCallExpression.getOrBuildFirSafe<FirFunctionCall>(analysisSession.firResolveState) ?: return emptyList()
|
val firCall = ktCallExpression.getOrBuildFirSafe<FirCall>(analysisSession.firResolveState) ?: return emptyList()
|
||||||
val parameter = firCall.findCorrespondingParameter(ktValueArgument) ?: return emptyList()
|
val parameter = firCall.findCorrespondingParameter(ktValueArgument) ?: return emptyList()
|
||||||
return listOfNotNull(parameter.buildSymbol(symbolBuilder))
|
return listOfNotNull(parameter.buildSymbol(symbolBuilder))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun FirFunctionCall.findCorrespondingParameter(ktValueArgument: KtValueArgument): FirValueParameter? =
|
private fun FirCall.findCorrespondingParameter(ktValueArgument: KtValueArgument): FirValueParameter? =
|
||||||
argumentMapping?.entries?.firstNotNullResult { (firArgument, firParameter) ->
|
argumentMapping?.entries?.firstNotNullResult { (firArgument, firParameter) ->
|
||||||
if (firArgument.psi == ktValueArgument) firParameter
|
if (firArgument.psi == ktValueArgument) firParameter
|
||||||
else null
|
else null
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// IGNORE_FIR
|
@java.lang.annotation.Re<caret>tention(va<caret>lue = java.lang.annotation.RetentionPolicy.RUNTIME)
|
||||||
|
|
||||||
@java.lang.annotation.Retention(va<caret>lue = java.lang.annotation.RetentionPolicy.RUNTIME)
|
|
||||||
annotation class Anno()
|
annotation class Anno()
|
||||||
|
|
||||||
// REF: (in java.lang.annotation.Retention).value()
|
// REF1: (java.lang.annotation).Retention
|
||||||
|
// REF2: (in java.lang.annotation.Retention).value()
|
||||||
Reference in New Issue
Block a user