@@ -487,15 +487,42 @@ open class KotlinFileExtractor(
487
487
extractDeclInitializers(c.declarations, false ) { Pair (blockId, obinitId) }
488
488
}
489
489
490
- private fun extractAnnotations (annotations : List <IrConstructorCall >, parent : Label <out DbExprparent >, extractEnumTypeAccesses : Boolean ) {
491
- val groupedAnnotations = metaAnnotationSupport.groupRepeatableAnnotations(annotations)
490
+ private val javaLangDeprecated by lazy { referenceExternalClass(" java.lang.Deprecated" ) }
491
+
492
+ private val javaLangDeprecatedConstructor by lazy { javaLangDeprecated?.constructors?.singleOrNull() }
493
+
494
+ private fun replaceKotlinDeprecatedAnnotation (annotations : List <IrConstructorCall >): List <IrConstructorCall > {
495
+ val shouldReplace =
496
+ annotations.any { (it.type as ? IrSimpleType )?.classFqName?.asString() == " kotlin.Deprecated" } &&
497
+ annotations.none { (it.type as ? IrSimpleType )?.classFqName?.asString() == " java.lang.Deprecated" }
498
+ val jldConstructor = javaLangDeprecatedConstructor
499
+ if (! shouldReplace || jldConstructor == null )
500
+ return annotations
501
+ return annotations.filter { (it.type as ? IrSimpleType )?.classFqName?.asString() != " kotlin.Deprecated" } +
502
+ // Note we lose any arguments to @java.lang.Deprecated that were written in source.
503
+ IrConstructorCallImpl .fromSymbolOwner(
504
+ UNDEFINED_OFFSET , UNDEFINED_OFFSET , jldConstructor.returnType, jldConstructor.symbol, 0
505
+ )
506
+ }
507
+
508
+ private fun extractAnnotations (c : IrAnnotationContainer , annotations : List <IrConstructorCall >, parent : Label <out DbExprparent >, extractEnumTypeAccesses : Boolean ) {
509
+ val origin = when (c) {
510
+ is IrDeclaration -> c.origin
511
+ else -> null
512
+ }
513
+ val replacedAnnotations =
514
+ if (origin == IrDeclarationOrigin .IR_EXTERNAL_JAVA_DECLARATION_STUB )
515
+ replaceKotlinDeprecatedAnnotation(annotations)
516
+ else
517
+ annotations
518
+ val groupedAnnotations = metaAnnotationSupport.groupRepeatableAnnotations(replacedAnnotations)
492
519
for ((idx, constructorCall: IrConstructorCall ) in groupedAnnotations.sortedBy { v -> v.type.classFqName?.asString() }.withIndex()) {
493
520
extractAnnotation(constructorCall, parent, idx, extractEnumTypeAccesses)
494
521
}
495
522
}
496
523
497
524
private fun extractAnnotations (c : IrAnnotationContainer , parent : Label <out DbExprparent >, extractEnumTypeAccesses : Boolean ) {
498
- extractAnnotations(c.annotations, parent, extractEnumTypeAccesses)
525
+ extractAnnotations(c, c .annotations, parent, extractEnumTypeAccesses)
499
526
}
500
527
501
528
private fun extractAnnotation (
@@ -505,19 +532,8 @@ open class KotlinFileExtractor(
505
532
extractEnumTypeAccesses : Boolean ,
506
533
contextLabel : String? = null
507
534
): Label <out DbExpr > {
508
- val isConvertedJavaDeprecatedAnnotation = (constructorCall.type as ? IrSimpleType )?.classFqName?.asString() == " kotlin.Deprecated" &&
509
- constructorCall.source is JavaSourceElement
510
-
511
- val extractType =
512
- (
513
- if (isConvertedJavaDeprecatedAnnotation)
514
- pluginContext.referenceClass(FqName (" java.lang.Deprecated" ))?.defaultType
515
- else
516
- null
517
- ) ? : erase(constructorCall.type)
518
-
519
535
// Erase the type here because the JVM lowering erases the annotation type, and so the Java extractor will see it in erased form.
520
- val t = useType(extractType )
536
+ val t = useType(erase(constructorCall.type) )
521
537
val annotationContextLabel = contextLabel ? : " {${t.javaResult.id} }"
522
538
val id = tw.getLabelFor<DbDeclannotation >(" @\" annotation;{$parent };$annotationContextLabel \" " )
523
539
tw.writeExprs_declannotation(id, t.javaResult.id, parent, idx)
@@ -526,11 +542,7 @@ open class KotlinFileExtractor(
526
542
val locId = tw.getLocation(constructorCall)
527
543
tw.writeHasLocation(id, locId)
528
544
529
- // If this is `java.lang.Deprecated`, extract an annotation without parameters -- whatever the original source
530
- // may have supplied has been lost.
531
- val paramCount = if (isConvertedJavaDeprecatedAnnotation) 0 else constructorCall.valueArgumentsCount
532
-
533
- for (i in 0 until paramCount) {
545
+ for (i in 0 until constructorCall.valueArgumentsCount) {
534
546
val param = constructorCall.symbol.owner.valueParameters[i]
535
547
val prop = constructorCall.symbol.owner.parentAsClass.declarations
536
548
.filterIsInstance<IrProperty >()
@@ -702,7 +714,7 @@ open class KotlinFileExtractor(
702
714
else
703
715
listOf ()
704
716
705
- extractAnnotations(c.annotations + additionalAnnotations, id, extractFunctionBodies)
717
+ extractAnnotations(c, c .annotations + additionalAnnotations, id, extractFunctionBodies)
706
718
707
719
if (extractFunctionBodies && ! c.isAnonymousObject && ! c.isLocal)
708
720
externalClassExtractor.writeStubTrapFile(c)
@@ -900,7 +912,7 @@ open class KotlinFileExtractor(
900
912
else -> null
901
913
}
902
914
val extraAnnotations = listOfNotNull(getNullabilityAnnotation(vp.type, vp.origin, vp.annotations, javaParameter?.annotations))
903
- extractAnnotations(vp.annotations + extraAnnotations, id, extractTypeAccess)
915
+ extractAnnotations(vp, vp .annotations + extraAnnotations, id, extractTypeAccess)
904
916
return extractValueParameter(id, substitutedType, vp.name.asString(), location, parent, idx, useValueParameter(vp, parentSourceDeclaration), syntheticParameterNames, vp.isVararg, vp.isNoinline, vp.isCrossinline)
905
917
}
906
918
}
@@ -1468,7 +1480,7 @@ open class KotlinFileExtractor(
1468
1480
1469
1481
if (extractAnnotations) {
1470
1482
val extraAnnotations = listOfNotNull(getNullabilityAnnotation(f.returnType, f.origin, f.annotations, getJavaCallable(f)?.annotations))
1471
- extractAnnotations(f.annotations + extraAnnotations, id, extractMethodAndParameterTypeAccesses)
1483
+ extractAnnotations(f, f .annotations + extraAnnotations, id, extractMethodAndParameterTypeAccesses)
1472
1484
}
1473
1485
1474
1486
return id
0 commit comments