[FIR] Report DEPRECATION when Java declaration is deprecated in javadoc
#KT-60682
This commit is contained in:
committed by
Space Team
parent
99307f97e9
commit
4e041494be
@@ -239,6 +239,9 @@ abstract class FirJavaFacade(
|
|||||||
return buildJavaClass {
|
return buildJavaClass {
|
||||||
resolvePhase = FirResolvePhase.BODY_RESOLVE
|
resolvePhase = FirResolvePhase.BODY_RESOLVE
|
||||||
javaAnnotations += javaClass.annotations
|
javaAnnotations += javaClass.annotations
|
||||||
|
if (javaClass.isDeprecatedInJavaDoc && javaAnnotations.none { it.isJavaDeprecatedAnnotation() }) {
|
||||||
|
javaAnnotations += DeprecatedInJavaDocAnnotation
|
||||||
|
}
|
||||||
source = javaClass.toSourceElement()
|
source = javaClass.toSourceElement()
|
||||||
this.moduleData = moduleData
|
this.moduleData = moduleData
|
||||||
symbol = classSymbol
|
symbol = classSymbol
|
||||||
|
|||||||
@@ -53,7 +53,24 @@ internal fun Iterable<JavaAnnotation>.convertAnnotationsToFir(
|
|||||||
|
|
||||||
internal fun JavaAnnotationOwner.convertAnnotationsToFir(
|
internal fun JavaAnnotationOwner.convertAnnotationsToFir(
|
||||||
session: FirSession,
|
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(
|
internal fun FirAnnotationContainer.setAnnotationsFromJava(
|
||||||
session: FirSession,
|
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 {
|
private fun JavaAnnotation.toFirAnnotationCall(session: FirSession): FirAnnotation = buildAnnotation {
|
||||||
val lookupTag = when (classId) {
|
val lookupTag = when (classId) {
|
||||||
StandardClassIds.Annotations.Java.Target -> StandardClassIds.Annotations.Target
|
StandardClassIds.Annotations.Java.Target -> StandardClassIds.Annotations.Target
|
||||||
|
|||||||
@@ -15,6 +15,6 @@ public class A {
|
|||||||
|
|
||||||
// FILE: B.kt
|
// FILE: B.kt
|
||||||
|
|
||||||
class B(private val foo: String) : A() {
|
class B(private val foo: String) : <!DEPRECATION!>A<!>() {
|
||||||
override fun getFoo(text: String): String = super.getFoo(text + foo)
|
override fun <!OVERRIDE_DEPRECATION!>getFoo<!>(text: String): String = super.<!DEPRECATION!>getFoo<!>(text + foo)
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -14,9 +14,9 @@ fun foo(javaClass: JavaClass) {
|
|||||||
javaClass.<!DEPRECATION!>something4<!> = 1
|
javaClass.<!DEPRECATION!>something4<!> = 1
|
||||||
javaClass.<!DEPRECATION, DEPRECATION!>something4<!>++
|
javaClass.<!DEPRECATION, DEPRECATION!>something4<!>++
|
||||||
|
|
||||||
javaClass.something5
|
javaClass.<!DEPRECATION!>something5<!>
|
||||||
javaClass.something5 = 1
|
javaClass.<!DEPRECATION!>something5<!> = 1
|
||||||
javaClass.something5++
|
javaClass.<!DEPRECATION, DEPRECATION!>something5<!>++
|
||||||
}
|
}
|
||||||
|
|
||||||
// FILE: JavaClass.java
|
// FILE: JavaClass.java
|
||||||
|
|||||||
-22
@@ -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
@@ -1,3 +1,4 @@
|
|||||||
|
// FIR_IDENTICAL
|
||||||
// FILE: KotlinFile.kt
|
// FILE: KotlinFile.kt
|
||||||
public interface I {
|
public interface I {
|
||||||
public fun doIt()
|
public fun doIt()
|
||||||
|
|||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
public open class JavaDocDeprecated : R|kotlin/Any| {
|
@R|kotlin/Deprecated|(message = String(Deprecated in Java)) 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 fun getFoo(text: R|kotlin/String!|): R|kotlin/String!|
|
||||||
|
|
||||||
public constructor(): R|test/JavaDocDeprecated|
|
public constructor(): R|test/JavaDocDeprecated|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user