Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Kotlin Metadata to version 0.9.0 #1830

Merged
merged 5 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ Change Log
* Fix: Fix extension function imports (#1814).
* Fix: Omit implicit modifiers on FileSpec.scriptBuilder (#1813).
* Fix: Fix trailing newline in PropertySpec (#1827).
Change: kotlinx-metadata 0.9.0. This is a breaking change for users of the
Egorand marked this conversation as resolved.
Show resolved Hide resolved
:kotlinpoet-metadata module, as `read` is deprecated in 0.9.0 and the
replacement `readStrict` was introduced in 0.9.0 (#1830).
sgjesse marked this conversation as resolved.
Show resolved Hide resolved

## Version 1.16.0

Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ kotlin-compilerEmbeddable = { module = "org.jetbrains.kotlin:kotlin-compiler-emb
kotlin-annotationProcessingEmbeddable = { module = "org.jetbrains.kotlin:kotlin-annotation-processing-embeddable", version.ref = "kotlin" }
kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin" }
kotlin-junit = { module = "org.jetbrains.kotlin:kotlin-test-junit", version.ref = "kotlin" }
kotlin-metadata = { module = "org.jetbrains.kotlinx:kotlinx-metadata-jvm", version = "0.8.0" }
kotlin-metadata = { module = "org.jetbrains.kotlinx:kotlinx-metadata-jvm", version = "0.9.0" }

ksp = { module = "com.google.devtools.ksp:symbol-processing", version.ref = "ksp" }
ksp-api = { module = "com.google.devtools.ksp:symbol-processing-api", version.ref = "ksp" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public inline fun <reified T : KotlinClassMetadata> Metadata.toKotlinClassMetada
*/
@KotlinPoetMetadataPreview
public fun Metadata.readKotlinClassMetadata(): KotlinClassMetadata {
val metadata = KotlinClassMetadata.read(asClassHeader())
val metadata = KotlinClassMetadata.readStrict(asClassHeader())
checkNotNull(metadata) {
"Could not parse metadata! Try bumping kotlinpoet and/or kotlinx-metadata version."
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ import kotlinx.metadata.Modality
import kotlinx.metadata.Visibility
import kotlinx.metadata.declaresDefaultValue
import kotlinx.metadata.hasAnnotations
import kotlinx.metadata.hasGetter
import kotlinx.metadata.hasSetter
import kotlinx.metadata.isConst
import kotlinx.metadata.isCrossinline
import kotlinx.metadata.isData
Expand Down Expand Up @@ -648,33 +646,31 @@ private fun KmProperty.toPropertySpec(
val returnTypeName = returnType.toTypeName(typeParamResolver)
val mutableAnnotations = mutableListOf<AnnotationSpec>()
if (containerData != null && propertyData != null) {
if (hasGetter) {
Egorand marked this conversation as resolved.
Show resolved Hide resolved
getterSignature?.let { getterSignature ->
if (!containerData.isInterface &&
modality != Modality.OPEN && modality != Modality.ABSTRACT
getterSignature?.let { getterSignature ->
if (!containerData.isInterface &&
modality != Modality.OPEN && modality != Modality.ABSTRACT
) {
// Infer if JvmName was used
// We skip interface types or open/abstract properties because they can't have @JvmName.
// For annotation properties, kotlinc puts JvmName annotations by default in
// bytecode but they're implicit in source, so we expect the simple name for
// annotation types.
val expectedMetadataName = if (containerData is ClassData &&
containerData.declarationContainer.isAnnotation
) {
// Infer if JvmName was used
// We skip interface types or open/abstract properties because they can't have @JvmName.
// For annotation properties, kotlinc puts JvmName annotations by default in
// bytecode but they're implicit in source, so we expect the simple name for
// annotation types.
val expectedMetadataName = if (containerData is ClassData &&
containerData.declarationContainer.isAnnotation
) {
name
} else {
"get${name.safeCapitalize(Locale.US)}"
}
getterSignature.jvmNameAnnotation(
metadataName = expectedMetadataName,
useSiteTarget = UseSiteTarget.GET,
)?.let { jvmNameAnnotation ->
mutableAnnotations += jvmNameAnnotation
}
name
} else {
"get${name.safeCapitalize(Locale.US)}"
}
getterSignature.jvmNameAnnotation(
metadataName = expectedMetadataName,
useSiteTarget = UseSiteTarget.GET,
)?.let { jvmNameAnnotation ->
mutableAnnotations += jvmNameAnnotation
}
}
}
if (hasSetter) {
if (setter != null) {
setterSignature?.let { setterSignature ->
Egorand marked this conversation as resolved.
Show resolved Hide resolved
if (containerData is ClassData &&
!containerData.declarationContainer.isAnnotation &&
Expand Down Expand Up @@ -777,16 +773,16 @@ private fun KmProperty.toPropertySpec(
// since the delegate handles it
// vals with initialized constants have a getter in bytecode but not a body in kotlin source
val modifierSet = modifiers.toSet()
if (hasGetter && !isDelegated && modality != Modality.ABSTRACT) {
JakeWharton marked this conversation as resolved.
Show resolved Hide resolved
if (!isDelegated && modality != Modality.ABSTRACT) {
propertyAccessor(
modifierSet,
getter,
this@toPropertySpec.getter,
FunSpec.getterBuilder().addStatement(NOT_IMPLEMENTED),
isOverride,
)?.let(::getter)
}
if (hasSetter && !isDelegated && modality != Modality.ABSTRACT) {
propertyAccessor(modifierSet, setter!!, FunSpec.setterBuilder(), isOverride)?.let(::setter)
if (setter != null && !isDelegated && modality != Modality.ABSTRACT) {
propertyAccessor(modifierSet, this@toPropertySpec.setter!!, FunSpec.setterBuilder(), isOverride)?.let(::setter)
}
}
.tag(this)
Expand Down