diff --git a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/JavaSymbolProvider.kt b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/JavaSymbolProvider.kt index cbeb0969e5a..78fb7b74872 100644 --- a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/JavaSymbolProvider.kt +++ b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/JavaSymbolProvider.kt @@ -309,7 +309,12 @@ class JavaSymbolProvider( } if (classIsAnnotation) { 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) { val parameterForAnnotationConstructor = buildJavaValueParameter { + source = (javaMethod as? JavaElementImpl<*>)?.psi?.toFirPsiSourceElement(FirFakeSourceElementKind.ImplicitJavaAnnotationConstructor) session = this@JavaSymbolProvider.session returnTypeRef = firJavaMethod.returnTypeRef name = methodName @@ -505,11 +511,13 @@ class JavaSymbolProvider( } private fun buildConstructorForAnnotationClass( + classSource: FirSourceElement?, constructorId: CallableId, ownerClassBuilder: FirJavaClassBuilder, valueParametersForAnnotationConstructor: ValueParametersForAnnotationConstructor ): FirJavaConstructor { return buildJavaConstructor { + source = classSource session = this@JavaSymbolProvider.session symbol = FirConstructorSymbol(constructorId) status = FirResolvedDeclarationStatusImpl(Visibilities.Public, Modality.FINAL) diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirSourceElement.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirSourceElement.kt index bab6e154260..e24d42d4043 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirSourceElement.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirSourceElement.kt @@ -161,6 +161,14 @@ sealed class FirFakeSourceElementKind : FirSourceElementKind() { // { it + 1} --> { it -> it + 1 } // where `it` parameter declaration has fake source 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 { diff --git a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/references/FirReferenceResolveHelper.kt b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/references/FirReferenceResolveHelper.kt index c0928b8f1d6..85621f74508 100644 --- a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/references/FirReferenceResolveHelper.kt +++ b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/references/FirReferenceResolveHelper.kt @@ -186,14 +186,14 @@ internal object FirReferenceResolveHelper { val ktValueArgumentName = expression.parent as? KtValueArgumentName ?: return emptyList() val ktValueArgument = ktValueArgumentName.parent as? KtValueArgument ?: 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(analysisSession.firResolveState) ?: return emptyList() + val firCall = ktCallExpression.getOrBuildFirSafe(analysisSession.firResolveState) ?: return emptyList() val parameter = firCall.findCorrespondingParameter(ktValueArgument) ?: return emptyList() return listOfNotNull(parameter.buildSymbol(symbolBuilder)) } - private fun FirFunctionCall.findCorrespondingParameter(ktValueArgument: KtValueArgument): FirValueParameter? = + private fun FirCall.findCorrespondingParameter(ktValueArgument: KtValueArgument): FirValueParameter? = argumentMapping?.entries?.firstNotNullResult { (firArgument, firParameter) -> if (firArgument.psi == ktValueArgument) firParameter else null diff --git a/idea/testData/resolve/references/JavaAnnotationParameter.kt b/idea/testData/resolve/references/JavaAnnotationParameter.kt index 741ac0bb37f..48a99222f5d 100644 --- a/idea/testData/resolve/references/JavaAnnotationParameter.kt +++ b/idea/testData/resolve/references/JavaAnnotationParameter.kt @@ -1,6 +1,5 @@ -// IGNORE_FIR - -@java.lang.annotation.Retention(value = java.lang.annotation.RetentionPolicy.RUNTIME) +@java.lang.annotation.Retention(value = java.lang.annotation.RetentionPolicy.RUNTIME) annotation class Anno() -// REF: (in java.lang.annotation.Retention).value() \ No newline at end of file +// REF1: (java.lang.annotation).Retention +// REF2: (in java.lang.annotation.Retention).value() \ No newline at end of file