[KLIB] API 4 ABI: Add information about backing field annotations

^KT-62259
This commit is contained in:
Dmitriy Dolovov
2023-11-14 12:30:41 +01:00
committed by Space Team
parent 01f072bb7d
commit d8eee222af
20 changed files with 151 additions and 12 deletions
@@ -170,6 +170,18 @@ data class AbiQualifiedName(val packageName: AbiCompoundName, val relativeName:
}
}
/**
* The common interface for entities that can have annotations.
*/
@ExperimentalLibraryAbiReader
interface AbiAnnotatedEntity {
/**
* Annotations are not a part of ABI. But sometimes it is useful to have the ability to check if some declaration
* has a specific annotation. See [AbiReadingFilter.NonPublicMarkerAnnotations] as an example.
*/
fun hasAnnotation(annotationClassName: AbiQualifiedName): Boolean
}
/**
* The common interface for all declarations.
*
@@ -177,15 +189,9 @@ data class AbiQualifiedName(val packageName: AbiCompoundName, val relativeName:
* @property signatures The set of signatures of the declaration.
*/
@ExperimentalLibraryAbiReader
sealed interface AbiDeclaration {
sealed interface AbiDeclaration : AbiAnnotatedEntity {
val qualifiedName: AbiQualifiedName
val signatures: AbiSignatures
/**
* Annotations are not a part of ABI. But sometimes it is useful to have the ability to check if some declaration
* has a specific annotation. See [AbiReadingFilter.NonPublicMarkerAnnotations] as an example.
*/
fun hasAnnotation(annotationClassName: AbiQualifiedName): Boolean
}
/**
@@ -302,16 +308,27 @@ interface AbiValueParameter {
* An [AbiDeclaration] that represents a property.
*
* @property kind The property kind.
* @property getter The getter accessor, fi any.
* @property setter The setter accessor, fi any.
* @property getter The getter accessor, if any.
* @property setter The setter accessor, if any.
* @property backingField The backing field, if any.
*/
@ExperimentalLibraryAbiReader
interface AbiProperty : AbiDeclarationWithModality {
val kind: AbiPropertyKind
val getter: AbiFunction?
val setter: AbiFunction?
val backingField: AbiField?
}
/**
* An entity that represents a field.
*
* Since fields are not a part of ABI, [AbiField] is not inherited from [AbiDeclaration]. And consequently don't have
* such attributes as [AbiDeclaration.qualifiedName] or [AbiDeclaration.signatures].
*/
@ExperimentalLibraryAbiReader
interface AbiField : AbiAnnotatedEntity
/** All known kinds of properties. */
@ExperimentalLibraryAbiReader
enum class AbiPropertyKind { VAL, CONST_VAL, VAR }
@@ -65,7 +65,11 @@ interface AbiReadingFilter {
override fun isDeclarationExcluded(declaration: AbiDeclaration): Boolean {
for (nonPublicMarkerName in nonPublicMarkerNames) {
if (declaration.hasAnnotation(nonPublicMarkerName)) return true
if (declaration.hasAnnotation(nonPublicMarkerName)
|| (declaration as? AbiProperty)?.backingField?.hasAnnotation(nonPublicMarkerName) == true
) {
return true
}
}
return false
}
@@ -190,7 +190,8 @@ internal class AbiPropertyImpl(
modality: AbiModality,
kind: AbiPropertyKind,
override val getter: AbiFunction?,
override val setter: AbiFunction?
override val setter: AbiFunction?,
override val backingField: AbiField?
) : AbiProperty {
private val flags = MODALITY.toFlags(modality) or PROPERTY_KIND.toFlags(kind)
@@ -204,6 +205,11 @@ internal class AbiPropertyImpl(
}
}
@ExperimentalLibraryAbiReader
internal class AbiFieldImpl(private val annotations: Set<AbiQualifiedName>) : AbiField {
override fun hasAnnotation(annotationClassName: AbiQualifiedName) = annotationClassName in annotations
}
@ExperimentalLibraryAbiReader
internal class AbiTypeParameterImpl(
override val tag: String,
@@ -423,6 +423,9 @@ private class LibraryDeserializer(
containingEntity = thisPropertyEntity,
parentTypeParameterResolver = typeParameterResolver
).discardIfExcluded()
},
backingField = proto.hasBackingField().ifTrue {
AbiFieldImpl(deserializeAnnotations(proto.backingField.base))
}
)
}
@@ -41,7 +41,7 @@ class LibraryAbiDumpHandler(testServices: TestServices) : BinaryArtifactHandler<
)
for ((abiSignatureVersion, dumper) in dumpers) {
LibraryAbiRenderer.render(libraryAbi, dumper.builderForModule(module), AbiRenderingSettings(abiSignatureVersion))
LibraryAbiRenderer.render(libraryAbi, dumper.builderForModule(module), AbiRenderingSettings(abiSignatureVersion))
}
}