diff --git a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/FirJavaFacade.kt b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/FirJavaFacade.kt index 29934c5cf9f..2595aec5d3f 100644 --- a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/FirJavaFacade.kt +++ b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/FirJavaFacade.kt @@ -239,6 +239,9 @@ abstract class FirJavaFacade( return buildJavaClass { resolvePhase = FirResolvePhase.BODY_RESOLVE javaAnnotations += javaClass.annotations + if (javaClass.isDeprecatedInJavaDoc && javaAnnotations.none { it.isJavaDeprecatedAnnotation() }) { + javaAnnotations += DeprecatedInJavaDocAnnotation + } source = javaClass.toSourceElement() this.moduleData = moduleData symbol = classSymbol diff --git a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/javaAnnotationsMapping.kt b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/javaAnnotationsMapping.kt index 28f7e141511..43ab24cf40e 100644 --- a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/javaAnnotationsMapping.kt +++ b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/javaAnnotationsMapping.kt @@ -53,7 +53,24 @@ internal fun Iterable.convertAnnotationsToFir( internal fun JavaAnnotationOwner.convertAnnotationsToFir( session: FirSession, -): List = annotations.convertAnnotationsToFir(session) +): List = buildList { + var isDeprecated = false + + annotations.mapTo(this) { + if (it.isJavaDeprecatedAnnotation()) isDeprecated = true + it.toFirAnnotationCall(session) + } + + if (!isDeprecated && isDeprecatedInJavaDoc) { + add(DeprecatedInJavaDocAnnotation.toFirAnnotationCall(session)) + } +} + +internal object DeprecatedInJavaDocAnnotation : JavaAnnotation { + override val arguments: Collection get() = emptyList() + override val classId: ClassId get() = StandardClassIds.Annotations.Java.Deprecated + override fun resolve(): JavaClass? = null +} internal fun FirAnnotationContainer.setAnnotationsFromJava( session: FirSession, @@ -225,6 +242,10 @@ private fun fillAnnotationArgumentMapping( } } +internal fun JavaAnnotation.isJavaDeprecatedAnnotation(): Boolean { + return classId == StandardClassIds.Annotations.Java.Deprecated +} + private fun JavaAnnotation.toFirAnnotationCall(session: FirSession): FirAnnotation = buildAnnotation { val lookupTag = when (classId) { StandardClassIds.Annotations.Java.Target -> StandardClassIds.Annotations.Target diff --git a/compiler/testData/diagnostics/tests/deprecated/javaDocDeprecated.fir.kt b/compiler/testData/diagnostics/tests/deprecated/javaDocDeprecated.fir.kt index 35b7aa0977a..7fe15f4c3d2 100644 --- a/compiler/testData/diagnostics/tests/deprecated/javaDocDeprecated.fir.kt +++ b/compiler/testData/diagnostics/tests/deprecated/javaDocDeprecated.fir.kt @@ -15,6 +15,6 @@ public class A { // FILE: B.kt -class B(private val foo: String) : A() { - override fun getFoo(text: String): String = super.getFoo(text + foo) +class B(private val foo: String) : A() { + override fun getFoo(text: String): String = super.getFoo(text + foo) } diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/Deprecated.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/Deprecated.fir.kt index 19314b425cd..208bc7abaec 100644 --- a/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/Deprecated.fir.kt +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/Deprecated.fir.kt @@ -14,9 +14,9 @@ fun foo(javaClass: JavaClass) { javaClass.something4 = 1 javaClass.something4++ - javaClass.something5 - javaClass.something5 = 1 - javaClass.something5++ + javaClass.something5 + javaClass.something5 = 1 + javaClass.something5++ } // FILE: JavaClass.java diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/Deprecated.fir.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/Deprecated.fir.kt deleted file mode 100644 index 50732e329ec..00000000000 --- a/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/Deprecated.fir.kt +++ /dev/null @@ -1,22 +0,0 @@ -// FILE: KotlinFile.kt -public interface I { - public fun doIt() -} - -fun foo(javaClass: JavaClass) { - javaClass.doSomething1 { bar() } - javaClass.doSomething2 { bar() } -} - -fun bar(){} - -// FILE: JavaClass.java -public class JavaClass { - @Deprecated - public void doSomething1(Runnable runnable) { runnable.run(); } - - /** - * @deprecated - */ - public void doSomething2(Runnable runnable) { runnable.run(); } -} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/Deprecated.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/Deprecated.kt index cec871b4954..68f81276c67 100644 --- a/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/Deprecated.kt +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/Deprecated.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // FILE: KotlinFile.kt public interface I { public fun doIt() diff --git a/compiler/testData/loadJava/compiledJava/annotations/JavaDocDeprecated.fir.txt b/compiler/testData/loadJava/compiledJava/annotations/JavaDocDeprecated.fir.txt index c7a99507f3b..e2666b9dc53 100644 --- a/compiler/testData/loadJava/compiledJava/annotations/JavaDocDeprecated.fir.txt +++ b/compiler/testData/loadJava/compiledJava/annotations/JavaDocDeprecated.fir.txt @@ -1,5 +1,5 @@ -public open class JavaDocDeprecated : R|kotlin/Any| { - public open fun getFoo(text: R|kotlin/String!|): R|kotlin/String!| +@R|kotlin/Deprecated|(message = String(Deprecated in Java)) public open class JavaDocDeprecated : R|kotlin/Any| { + @R|kotlin/Deprecated|(message = String(Deprecated in Java)) public open fun getFoo(text: R|kotlin/String!|): R|kotlin/String!| public constructor(): R|test/JavaDocDeprecated|