[FIR] Report DEPRECATION when Java declaration is deprecated in javadoc

#KT-60682
This commit is contained in:
Kirill Rakhman
2023-08-24 12:16:43 +02:00
committed by Space Team
parent 99307f97e9
commit 4e041494be
7 changed files with 33 additions and 30 deletions
@@ -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
@@ -53,7 +53,24 @@ internal fun Iterable<JavaAnnotation>.convertAnnotationsToFir(
internal fun JavaAnnotationOwner.convertAnnotationsToFir(
session: FirSession,
): List<FirAnnotation> = annotations.convertAnnotationsToFir(session)
): List<FirAnnotation> = 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<JavaAnnotationArgument> 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
@@ -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) : <!DEPRECATION!>A<!>() {
override fun <!OVERRIDE_DEPRECATION!>getFoo<!>(text: String): String = super.<!DEPRECATION!>getFoo<!>(text + foo)
}
@@ -14,9 +14,9 @@ fun foo(javaClass: JavaClass) {
javaClass.<!DEPRECATION!>something4<!> = 1
javaClass.<!DEPRECATION, DEPRECATION!>something4<!>++
javaClass.something5
javaClass.something5 = 1
javaClass.something5++
javaClass.<!DEPRECATION!>something5<!>
javaClass.<!DEPRECATION!>something5<!> = 1
javaClass.<!DEPRECATION, DEPRECATION!>something5<!>++
}
// FILE: JavaClass.java
@@ -1,22 +0,0 @@
// FILE: KotlinFile.kt
public interface I {
public fun doIt()
}
fun foo(javaClass: JavaClass) {
javaClass.<!DEPRECATION!>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(); }
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// FILE: KotlinFile.kt
public interface I {
public fun doIt()
@@ -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|