[Commonizer] Don't commonize deprecated functions
1. All functions marked with @Deprecated from Kotlin/Native platform libraries have DeprecationLevel.ERROR, and therefore practically can not be used by a developer in their code. So, it does not make sence to keep such declarations in commonized libraries. 2. Commonization of such functions would also require commonization of annotations with nested annotations as const values (ex: @Deprecated(level = DeprecationLevel.ERROR), where both @Deprecated and DeprecationLevel are annotation classes). This is not implemented yet.
This commit is contained in:
+7
-1
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.core.Commonizer
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.fqNameWithTypeParameters
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.isBlacklistedDarwinFunction
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.isDeprecated
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.isKniBridgeFunction
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
@@ -53,8 +54,13 @@ internal inline fun PropertyCollector(
|
||||
internal inline fun FunctionCollector(
|
||||
crossinline typedCollector: (SimpleFunctionDescriptor) -> Unit
|
||||
): (DeclarationDescriptor) -> Boolean = Collector<SimpleFunctionDescriptor> { candidate ->
|
||||
if (candidate.kind.isReal && !candidate.isKniBridgeFunction() && !candidate.isBlacklistedDarwinFunction())
|
||||
if (candidate.kind.isReal
|
||||
&& !candidate.isKniBridgeFunction()
|
||||
&& !candidate.isDeprecated()
|
||||
&& !candidate.isBlacklistedDarwinFunction()
|
||||
) {
|
||||
typedCollector(candidate)
|
||||
}
|
||||
}
|
||||
|
||||
/** Used for approximation of [PropertyDescriptor]s before running concrete [Commonizer]s */
|
||||
|
||||
+3
-3
@@ -15,6 +15,9 @@ private val DEPRECATED_ANNOTATION_FQN = FqName(Deprecated::class.java.name)
|
||||
internal fun SimpleFunctionDescriptor.isKniBridgeFunction() =
|
||||
name.asString().startsWith("kniBridge")
|
||||
|
||||
internal fun SimpleFunctionDescriptor.isDeprecated() =
|
||||
annotations.hasAnnotation(DEPRECATED_ANNOTATION_FQN)
|
||||
|
||||
// the following logic determines Kotlin functions with conflicting overloads in Darwin library:
|
||||
internal fun SimpleFunctionDescriptor.isBlacklistedDarwinFunction(): Boolean {
|
||||
if ((containingDeclaration as? PackageFragmentDescriptor)?.fqName?.isUnderDarwinPackage != true)
|
||||
@@ -24,9 +27,6 @@ internal fun SimpleFunctionDescriptor.isBlacklistedDarwinFunction(): Boolean {
|
||||
if (!name.startsWith("simd_") && !name.startsWith("__"))
|
||||
return false
|
||||
|
||||
if (annotations.hasAnnotation(DEPRECATED_ANNOTATION_FQN))
|
||||
return true
|
||||
|
||||
return valueParameters.any { parameter ->
|
||||
val type = parameter.type
|
||||
val abbreviationType = type.getAbbreviation()
|
||||
|
||||
+5
@@ -17,3 +17,8 @@ external fun externalFunction2()
|
||||
|
||||
inline fun inlineFunction1() {}
|
||||
inline fun inlineFunction2() {}
|
||||
|
||||
@Deprecated
|
||||
fun deprecatedFunction1() {}
|
||||
@Deprecated
|
||||
fun deprecatedFunction2() {}
|
||||
|
||||
+5
@@ -17,3 +17,8 @@ fun externalFunction2() {}
|
||||
|
||||
inline fun inlineFunction1() {}
|
||||
fun inlineFunction2() {}
|
||||
|
||||
@Deprecated
|
||||
fun deprecatedFunction1() {}
|
||||
@Deprecated
|
||||
fun deprecatedFunction3() {}
|
||||
|
||||
Reference in New Issue
Block a user