Native: add ExperimentalForeignApi to generated cinterop declarations
cinterop tool should add ExperimentalForeignApi to all generated declarations by default. This commit implements adding the annotation. Nested declarations don't get the annotation, because they inherit the opt-in requirement from the enclosing classes implicitly. The annotation is not added to platform libraries, as intended. See previous commits. ^KT-58362
This commit is contained in:
committed by
Space Team
parent
3280d3ef80
commit
3f3f6eb5a8
+47
@@ -350,6 +350,9 @@ class StubIrBuilder(private val context: StubIrContext) {
|
||||
typealiases.toList(),
|
||||
containers.toList()
|
||||
)
|
||||
|
||||
stubs.addExperimentalAnnotations()
|
||||
|
||||
return StubIrBuilderResult(
|
||||
stubs,
|
||||
buildingContext.declarationMapper,
|
||||
@@ -358,6 +361,50 @@ class StubIrBuilder(private val context: StubIrContext) {
|
||||
)
|
||||
}
|
||||
|
||||
private fun StubContainer.addExperimentalAnnotations() {
|
||||
fun MutableList<AnnotationStub>.addExperimentalIfNecessary() {
|
||||
if (!configuration.disableExperimentalAnnotation)
|
||||
this.add(AnnotationStub.ExperimentalForeignApi)
|
||||
}
|
||||
|
||||
this.accept(object : StubIrVisitor<Unit, Unit> {
|
||||
override fun visitSimpleStubContainer(simpleStubContainer: SimpleStubContainer, data: Unit) {
|
||||
simpleStubContainer.children.forEach { it.accept(this, data) }
|
||||
simpleStubContainer.simpleContainers.forEach { visitSimpleStubContainer(it, data) }
|
||||
}
|
||||
|
||||
override fun visitClass(element: ClassStub, data: Unit) {
|
||||
val annotations = when (element) {
|
||||
is ClassStub.Companion -> return // Nested, see below.
|
||||
is ClassStub.Enum -> element.annotations
|
||||
is ClassStub.Simple -> element.annotations
|
||||
}
|
||||
annotations.addExperimentalIfNecessary()
|
||||
// Not visiting nested declarations intentionally -- they inherit opt-in requirement from the enclosing
|
||||
// class.
|
||||
}
|
||||
|
||||
override fun visitTypealias(element: TypealiasStub, data: Unit) {
|
||||
element.annotations.addExperimentalIfNecessary()
|
||||
}
|
||||
|
||||
override fun visitFunction(element: FunctionStub, data: Unit) {
|
||||
element.annotations.addExperimentalIfNecessary()
|
||||
}
|
||||
|
||||
override fun visitProperty(element: PropertyStub, data: Unit) {
|
||||
element.annotations.addExperimentalIfNecessary()
|
||||
}
|
||||
|
||||
// Not visiting nested declarations intentionally -- they inherit opt-in requirement from the enclosing
|
||||
// class.
|
||||
override fun visitConstructor(constructorStub: ConstructorStub, data: Unit) {}
|
||||
|
||||
// Property accessors inherit opt-in requirements from the property.
|
||||
override fun visitPropertyAccessor(propertyAccessor: PropertyAccessor, data: Unit) {}
|
||||
}, Unit)
|
||||
}
|
||||
|
||||
private fun generateStubsForWrappedMacro(macro: WrappedMacroDef) {
|
||||
try {
|
||||
generateStubsForGlobal(GlobalDecl(macro.name, macro.type, isConst = true))
|
||||
|
||||
Reference in New Issue
Block a user