-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Replace ArrayContentBased with Poko.ReadArrayContent This allows support for using this feature with a custom Poko annotation. Change ArrayContentBased to a deprecated typealias for compatibility. * Replace project usages of ArrayContentBased with ReadArrayContent
- Loading branch information
1 parent
1838bd6
commit 55ce748
Showing
16 changed files
with
108 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 6 additions & 24 deletions
30
poko-annotations/src/commonMain/kotlin/dev/drewhamilton/poko/ArrayContentBased.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,10 @@ | ||
package dev.drewhamilton.poko | ||
|
||
/** | ||
* Declares that a [Poko] class's generated functions will be based on this property's array | ||
* content. This differs from the Poko class (and data class) default of comparing arrays by | ||
* reference only. | ||
* | ||
* Poko class properties of type [Array], [BooleanArray], [CharArray], [ByteArray], [ShortArray], | ||
* [IntArray], [LongArray], [FloatArray], and [DoubleArray] are supported, including nested | ||
* [Array] types. | ||
* | ||
* Properties of a generic type or of type [Any] are also supported. For these properties, Poko will | ||
* generate a `when` statement that disambiguates the various array types at runtime and analyzes | ||
* content if the property is an array. (Note that with this logic, typed arrays will never be | ||
* considered equals to primitive arrays, even if they hold the same content. For example, | ||
* `arrayOf(1, 2)` will not be considered equals to `intArrayOf(1, 2)`.) | ||
* | ||
* Properties of a value class type that wraps an array are not supported. Tagging non-array | ||
* properties with this annotation is an error. | ||
* | ||
* Using array properties in data models is not generally recommended, because they are mutable. | ||
* Mutating an array marked with this annotation will cause the parent Poko class to produce | ||
* different `equals` and `hashCode` results at different times. This annotation should only be used | ||
* by consumers for whom performant code is more important than safe code. | ||
* Legacy name for [Poko.ReadArrayContent]. | ||
*/ | ||
@Retention(AnnotationRetention.SOURCE) | ||
@Target(AnnotationTarget.PROPERTY) | ||
public annotation class ArrayContentBased | ||
@Deprecated( | ||
message = "Moved to @Poko.ReadArrayContent for compatibility with custom Poko annotation", | ||
replaceWith = ReplaceWith("Poko.ReadArrayContent"), | ||
) | ||
public typealias ArrayContentBased = Poko.ReadArrayContent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 2 additions & 3 deletions
5
poko-tests-without-k2/src/commonMain/kotlin/poko/AnyArrayHolder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
package poko | ||
|
||
import dev.drewhamilton.poko.ArrayContentBased | ||
import dev.drewhamilton.poko.Poko | ||
|
||
@Suppress("Unused") | ||
@Poko class AnyArrayHolder( | ||
@ArrayContentBased val any: Any, | ||
@ArrayContentBased val nullableAny: Any?, | ||
@Poko.ReadArrayContent val any: Any, | ||
@Poko.ReadArrayContent val nullableAny: Any?, | ||
val trailingProperty: String, | ||
) |
41 changes: 20 additions & 21 deletions
41
poko-tests-without-k2/src/commonMain/kotlin/poko/ArrayHolder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,27 @@ | ||
package poko | ||
|
||
import dev.drewhamilton.poko.ArrayContentBased | ||
import dev.drewhamilton.poko.Poko | ||
|
||
@Suppress("Unused") | ||
@Poko class ArrayHolder( | ||
@ArrayContentBased val stringArray: Array<String>, | ||
@ArrayContentBased val nullableStringArray: Array<String>?, | ||
@ArrayContentBased val booleanArray: BooleanArray, | ||
@ArrayContentBased val nullableBooleanArray: BooleanArray?, | ||
@ArrayContentBased val byteArray: ByteArray, | ||
@ArrayContentBased val nullableByteArray: ByteArray?, | ||
@ArrayContentBased val charArray: CharArray, | ||
@ArrayContentBased val nullableCharArray: CharArray?, | ||
@ArrayContentBased val shortArray: ShortArray, | ||
@ArrayContentBased val nullableShortArray: ShortArray?, | ||
@ArrayContentBased val intArray: IntArray, | ||
@ArrayContentBased val nullableIntArray: IntArray?, | ||
@ArrayContentBased val longArray: LongArray, | ||
@ArrayContentBased val nullableLongArray: LongArray?, | ||
@ArrayContentBased val floatArray: FloatArray, | ||
@ArrayContentBased val nullableFloatArray: FloatArray?, | ||
@ArrayContentBased val doubleArray: DoubleArray, | ||
@ArrayContentBased val nullableDoubleArray: DoubleArray?, | ||
@ArrayContentBased val nestedStringArray: Array<Array<String>>, | ||
@ArrayContentBased val nestedIntArray: Array<IntArray>, | ||
@Poko.ReadArrayContent val stringArray: Array<String>, | ||
@Poko.ReadArrayContent val nullableStringArray: Array<String>?, | ||
@Poko.ReadArrayContent val booleanArray: BooleanArray, | ||
@Poko.ReadArrayContent val nullableBooleanArray: BooleanArray?, | ||
@Poko.ReadArrayContent val byteArray: ByteArray, | ||
@Poko.ReadArrayContent val nullableByteArray: ByteArray?, | ||
@Poko.ReadArrayContent val charArray: CharArray, | ||
@Poko.ReadArrayContent val nullableCharArray: CharArray?, | ||
@Poko.ReadArrayContent val shortArray: ShortArray, | ||
@Poko.ReadArrayContent val nullableShortArray: ShortArray?, | ||
@Poko.ReadArrayContent val intArray: IntArray, | ||
@Poko.ReadArrayContent val nullableIntArray: IntArray?, | ||
@Poko.ReadArrayContent val longArray: LongArray, | ||
@Poko.ReadArrayContent val nullableLongArray: LongArray?, | ||
@Poko.ReadArrayContent val floatArray: FloatArray, | ||
@Poko.ReadArrayContent val nullableFloatArray: FloatArray?, | ||
@Poko.ReadArrayContent val doubleArray: DoubleArray, | ||
@Poko.ReadArrayContent val nullableDoubleArray: DoubleArray?, | ||
@Poko.ReadArrayContent val nestedStringArray: Array<Array<String>>, | ||
@Poko.ReadArrayContent val nestedIntArray: Array<IntArray>, | ||
) |
3 changes: 1 addition & 2 deletions
3
poko-tests-without-k2/src/commonMain/kotlin/poko/ComplexGenericArrayHolder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
package poko | ||
|
||
import dev.drewhamilton.poko.ArrayContentBased | ||
import dev.drewhamilton.poko.Poko | ||
|
||
@Suppress("Unused") | ||
@Poko class ComplexGenericArrayHolder<A : Any, G : A>( | ||
@ArrayContentBased val generic: G, | ||
@Poko.ReadArrayContent val generic: G, | ||
) |
3 changes: 1 addition & 2 deletions
3
poko-tests-without-k2/src/commonMain/kotlin/poko/GenericArrayHolder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
package poko | ||
|
||
import dev.drewhamilton.poko.ArrayContentBased | ||
import dev.drewhamilton.poko.Poko | ||
|
||
@Suppress("Unused") | ||
@Poko class GenericArrayHolder<G>( | ||
@ArrayContentBased val generic: G, | ||
@Poko.ReadArrayContent val generic: G, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
package poko | ||
|
||
import dev.drewhamilton.poko.ArrayContentBased | ||
import dev.drewhamilton.poko.Poko | ||
|
||
@Suppress("Unused") | ||
@Poko class AnyArrayHolder( | ||
@ArrayContentBased val any: Any, | ||
@ArrayContentBased val nullableAny: Any?, | ||
@Poko.ReadArrayContent val any: Any, | ||
@Poko.ReadArrayContent val nullableAny: Any?, | ||
val trailingProperty: String, | ||
) |
Oops, something went wrong.