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

Switch to multiplatform Parcelize annotation #337

Merged
merged 10 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 5 additions & 1 deletion detekt-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@
<ID>MagicNumber:UUID7.kt$0x80L</ID>
<ID>MagicNumber:UUID7.kt$12</ID>
<ID>MagicNumber:UUID7.kt$16</ID>
<ID>MatchingDeclarationName:Parcelable.android.kt$Parcelable : Parcelable</ID>
<ID>MatchingDeclarationName:CommonParcelable.apple.kt$CommonParcelable</ID>
<ID>MatchingDeclarationName:CommonParcelable.js.kt$CommonParcelable</ID>
<ID>MatchingDeclarationName:CommonParcelable.jvm.kt$CommonParcelable</ID>
<ID>MatchingDeclarationName:CommonParcelable.linux.kt$CommonParcelable</ID>
<ID>MatchingDeclarationName:CommonParcelable.ming.kt$CommonParcelable</ID>
<ID>TooManyFunctions:SHA1.kt$SHA1</ID>
<ID>VariableNaming:UUID7.kt$val rand_a = random.nextBits(12).toLong()</ID>
</CurrentIssues>
Expand Down
1 change: 1 addition & 0 deletions gradle/build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugins {
dependencies {
implementation(libs.plugins.kotlin.jvm.toDep())
implementation(libs.plugins.kotlin.serialization.toDep())
implementation(libs.plugins.kotlin.parcelize.toDep())
implementation(libs.plugins.android.toDep())
implementation(libs.plugins.binary.toDep())
implementation(libs.plugins.publish.toDep())
Expand Down
2 changes: 2 additions & 0 deletions gradle/build-logic/src/main/kotlin/publish.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,6 @@ tasks.withType<AbstractPublishToMaven>().configureEach {
tasks.withType<AbstractArchiveTask>().configureEach {
isPreserveFileTimestamps = false
isReproducibleFileOrder = true
filePermissions {}
dirPermissions {}
}
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ sqldelight-runtime = { module = "app.cash.sqldelight:runtime", version = "2.0.2"
[plugins]
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
kotlin-parcelize = { id = "org.jetbrains.kotlin.plugin.parcelize", version.ref = "kotlin" }
android = { id = "com.android.application", version = "8.5.0" }
binary = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version = "0.14.0" }
publish = { id = "io.github.gradle-nexus.publish-plugin", version = "2.0.0" }
Expand Down
22 changes: 11 additions & 11 deletions kotlinx-uuid-core/api/android/kotlinx-uuid-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public final class kotlinx/uuid/Serializer$WrappedCurlyBrackets : kotlinx/uuid/S
public static final field INSTANCE Lkotlinx/uuid/Serializer$WrappedCurlyBrackets;
}

public final class kotlinx/uuid/UUID : kotlinx/uuid/internal/Parcelable, java/lang/Comparable {
public final class kotlinx/uuid/UUID : android/os/Parcelable, java/lang/Comparable {
public static final field CREATOR Landroid/os/Parcelable$Creator;
public static final field Companion Lkotlinx/uuid/UUID$Companion;
public fun <init> ()V
Expand All @@ -73,6 +73,7 @@ public final class kotlinx/uuid/UUID : kotlinx/uuid/internal/Parcelable, java/la
public synthetic fun <init> (Lkotlinx/uuid/UUID$Version;JIJIILkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun compareTo (Ljava/lang/Object;)I
public fun compareTo (Lkotlinx/uuid/UUID;)I
public final fun describeContents ()I
public fun equals (Ljava/lang/Object;)Z
public final fun getClockSequence ()I
public final fun getNode ()J
Expand All @@ -84,6 +85,7 @@ public final class kotlinx/uuid/UUID : kotlinx/uuid/internal/Parcelable, java/la
public final fun isRfcVariant ()Z
public fun toString ()Ljava/lang/String;
public final fun toString (Z)Ljava/lang/String;
public final fun writeToParcel (Landroid/os/Parcel;I)V
}

public final class kotlinx/uuid/UUID$Companion {
Expand All @@ -92,6 +94,14 @@ public final class kotlinx/uuid/UUID$Companion {
public final fun serializer ()Lkotlinx/serialization/KSerializer;
}

public final class kotlinx/uuid/UUID$Creator : android/os/Parcelable$Creator {
public fun <init> ()V
public synthetic fun createFromParcel (Landroid/os/Parcel;)Ljava/lang/Object;
public final fun createFromParcel (Landroid/os/Parcel;)Lkotlinx/uuid/UUID;
public synthetic fun newArray (I)[Ljava/lang/Object;
public final fun newArray (I)[Lkotlinx/uuid/UUID;
}

public final class kotlinx/uuid/UUID$Version : java/lang/Enum {
public static final field DCE_SECURITY Lkotlinx/uuid/UUID$Version;
public static final field NAME_BASED_MD5 Lkotlinx/uuid/UUID$Version;
Expand All @@ -118,13 +128,3 @@ public final class kotlinx/uuid/UUIDKt {
public static final fun toUUIDOrNull (Ljava/lang/String;)Lkotlinx/uuid/UUID;
}

public abstract class kotlinx/uuid/internal/Parcelable : android/os/Parcelable {
public fun <init> (JJ)V
public fun describeContents ()I
public fun writeToParcel (Landroid/os/Parcel;I)V
}

public final class kotlinx/uuid/internal/Parcelable_androidKt {
public static final fun getCreator ()Landroid/os/Parcelable$Creator;
}

9 changes: 2 additions & 7 deletions kotlinx-uuid-core/api/jvm/kotlinx-uuid-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ public final class kotlinx/uuid/Serializer$WrappedCurlyBrackets : kotlinx/uuid/S
public static final field INSTANCE Lkotlinx/uuid/Serializer$WrappedCurlyBrackets;
}

public final class kotlinx/uuid/UUID : kotlinx/uuid/internal/Parcelable, java/lang/Comparable {
public static final field CREATOR Lkotlinx/uuid/internal/ParcelableCreator;
public final class kotlinx/uuid/UUID : java/lang/Comparable, kotlinx/uuid/internal/CommonParcelable {
public static final field Companion Lkotlinx/uuid/UUID$Companion;
public fun <init> ()V
public fun <init> (IJIJI)V
Expand Down Expand Up @@ -123,10 +122,6 @@ public final class kotlinx/uuid/UUIDKt {
public static final fun toUUIDOrNull (Ljava/lang/String;)Lkotlinx/uuid/UUID;
}

public abstract class kotlinx/uuid/internal/Parcelable {
public fun <init> (JJ)V
}

public abstract interface class kotlinx/uuid/internal/ParcelableCreator {
public abstract interface class kotlinx/uuid/internal/CommonParcelable {
}

9 changes: 7 additions & 2 deletions kotlinx-uuid-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ plugins {
id("dokkaLicensee")
id("kover")
id("com.android.library")
kotlin("plugin.parcelize")
}

kotlin {
applyDefaultHierarchyTemplate {
common {
group("linuxDerivat") {
withAndroidNative()
withLinux()
group("androidNative")
group("linux")
}
}
}
Expand Down Expand Up @@ -80,4 +81,8 @@ kotlin {
}
}
}
compilerOptions.freeCompilerArgs.addAll(
"-P",
"plugin:org.jetbrains.kotlin.parcelize:additionalAnnotation=kotlinx.uuid.internal.CommonParcelize",
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package kotlinx.uuid.internal

import android.os.Parcel
import androidx.test.ext.junit.runners.*
import kotlinx.parcelize.parcelableCreator
import kotlinx.uuid.*
import org.junit.runner.*
import kotlin.test.*
Expand All @@ -14,6 +15,6 @@ class ParcelableTest {
val uuid = UUID(SOME_UUID_STRING)
uuid.writeToParcel(parcel, uuid.describeContents())
parcel.setDataPosition(0)
assertEquals(uuid, UUID.CREATOR.createFromParcel(parcel))
assertEquals(uuid, parcelableCreator<UUID>().createFromParcel(parcel))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package kotlinx.uuid.internal

import android.os.*

public actual typealias CommonParcelable = Parcelable

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package kotlinx.uuid.internal

public actual interface CommonParcelable

This file was deleted.

8 changes: 3 additions & 5 deletions kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/UUID.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import kotlin.jvm.*
* This type represents a UUID as per RFC
* See: https://tools.ietf.org/html/rfc4122
*/
@CommonParcelize
@Serializable(with = Serializer.Default::class)
public class UUID internal constructor(
internal val timeStampAndVersionRaw: Long,
internal val clockSequenceVariantAndNodeRaw: Long,
) : Parcelable(timeStampAndVersionRaw, clockSequenceVariantAndNodeRaw), Comparable<UUID> {
) : CommonParcelable, Comparable<UUID> {
private constructor(
helper: UUID
) : this(
Expand All @@ -26,7 +27,7 @@ public class UUID internal constructor(

/**
* Creates an instance by the string [uuid] representation.
* An input string should consist of five hexademical parts
* An input string should consist of five hexadecimal parts
* separated with the minus character, and optionally surrounded with curly brackets.
* The space and tab characters are ignored at the end and at the beginning
* and surrounding brackets and minus characters.
Expand Down Expand Up @@ -206,9 +207,6 @@ public class UUID internal constructor(
}

private fun versionFor(id: Int): Version? = Version.entries.firstOrNull { it.id == id }

@JvmField
public val CREATOR: ParcelableCreator<UUID> = creator
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
package kotlinx.uuid.internal

import kotlinx.uuid.*
@Target(AnnotationTarget.CLASS)
internal annotation class CommonParcelize

@Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING")
public expect abstract class Parcelable(
timeStampAndVersionRaw: Long,
clockSequenceVariantAndNodeRaw: Long
)

public expect interface ParcelableCreator<T : Any>

internal expect val creator: ParcelableCreator<UUID>
public expect interface CommonParcelable
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package kotlinx.uuid.internal

public actual interface CommonParcelable

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package kotlinx.uuid.internal

public actual interface CommonParcelable

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package kotlinx.uuid.internal

public actual interface CommonParcelable

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package kotlinx.uuid.internal

public actual interface CommonParcelable

This file was deleted.

Loading