[kotlin] fix "Add annotation" quickfix in K2 mode (KTIJ-31459)

In regular cases 'annotationTarget' is null, so the empty prefix should be used instead of silently exiting. 'addAnnotationEntry' in K1 works this way.

GitOrigin-RevId: 0ee53829a2575b6d57b6c14f927e80b4c482af3c
This commit is contained in:
Nikolay Chashnikov
2024-10-01 13:12:04 +02:00
committed by intellij-monorepo-bot
parent c656bfdf25
commit f7eeedb6a1

View File

@@ -204,14 +204,11 @@ object K2CreatePropertyFromUsageBuilder {
request: AnnotationRequest,
annotationTarget: AnnotationUseSiteTarget?
): KtAnnotationEntry? {
if (annotationTarget == null) return null
val declaration = target as? KtDeclaration ?: return null
val classId = ClassId.topLevel(FqName(request.qualifiedName))
val annotationUseSiteTargetPrefix =
if (isApplicableTargetSet(declaration, classId, fieldAnnotationTargetCallableId)) {
if (annotationTarget == null || isApplicableTargetSet(declaration, classId, fieldAnnotationTargetCallableId)) {
""
} else {
"${annotationTarget.renderName}:"