-
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.
Add ability to skip properties (#446)
* Introduce Poko.Skip annotation * Add SkipSupport opt-in annotation * Implement warning for consumers of custom Skip annotation * Use custom annotation in sample:jvm module, ensuring compilation works if no custom Skip annotation is provided
- Loading branch information
1 parent
0867931
commit 18b3b4b
Showing
15 changed files
with
196 additions
and
16 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
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
7 changes: 7 additions & 0 deletions
7
.../drewhamilton/poko/ArrayContentSupport.kt → ...dev/drewhamilton/poko/optInAnnotations.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
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
11 changes: 11 additions & 0 deletions
11
poko-tests-without-k2/src/commonMain/kotlin/poko/SkippedProperty.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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package poko | ||
|
||
import dev.drewhamilton.poko.Poko | ||
import dev.drewhamilton.poko.SkipSupport | ||
|
||
@OptIn(SkipSupport::class) | ||
@Suppress("Unused") | ||
@Poko class SkippedProperty( | ||
val id: String, | ||
@Poko.Skip val callback: () -> Unit, | ||
) |
28 changes: 28 additions & 0 deletions
28
poko-tests-without-k2/src/commonTest/kotlin/SkippedPropertyTest.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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
import assertk.assertAll | ||
import assertk.assertThat | ||
import assertk.assertions.isEqualTo | ||
import kotlin.test.Test | ||
import poko.SkippedProperty | ||
|
||
class SkippedPropertyTest { | ||
|
||
@Test fun skipped_property_omitted_from_all_generated_functions() { | ||
val a = SkippedProperty( | ||
id = "id", | ||
callback = { println("Callback <a> invoked") }, | ||
) | ||
val b = SkippedProperty( | ||
id = "id", | ||
callback = { println("Callback <b> invoked") }, | ||
) | ||
|
||
assertAll { | ||
assertThat(a).isEqualTo(b) | ||
assertThat(b).isEqualTo(a) | ||
assertThat(a.hashCode()).isEqualTo(b.hashCode()) | ||
assertThat(a.toString()).isEqualTo(b.toString()) | ||
assertThat(a.toString()).isEqualTo("SkippedProperty(id=id)") | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package poko | ||
|
||
import dev.drewhamilton.poko.Poko | ||
import dev.drewhamilton.poko.SkipSupport | ||
|
||
@OptIn(SkipSupport::class) | ||
@Suppress("Unused") | ||
@Poko class SkippedProperty( | ||
val id: String, | ||
@Poko.Skip val callback: () -> Unit, | ||
) |
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
import assertk.assertAll | ||
import assertk.assertThat | ||
import assertk.assertions.isEqualTo | ||
import kotlin.test.Test | ||
import poko.SkippedProperty | ||
|
||
class SkippedPropertyTest { | ||
|
||
@Test fun skipped_property_omitted_from_all_generated_functions() { | ||
val a = SkippedProperty( | ||
id = "id", | ||
callback = { println("Callback <a> invoked") }, | ||
) | ||
val b = SkippedProperty( | ||
id = "id", | ||
callback = { println("Callback <b> invoked") }, | ||
) | ||
|
||
assertAll { | ||
assertThat(a).isEqualTo(b) | ||
assertThat(b).isEqualTo(a) | ||
assertThat(a.hashCode()).isEqualTo(b.hashCode()) | ||
assertThat(a.toString()).isEqualTo(b.toString()) | ||
assertThat(a.toString()).isEqualTo("SkippedProperty(id=id)") | ||
} | ||
} | ||
} |
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
8 changes: 8 additions & 0 deletions
8
sample/jvm/src/main/kotlin/dev/drewhamilton/poko/sample/jvm/MyData.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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package dev.drewhamilton.poko.sample.jvm | ||
|
||
/** | ||
* Local replacement for default Poko annotation. | ||
*/ | ||
@Retention(AnnotationRetention.SOURCE) | ||
@Target(AnnotationTarget.CLASS) | ||
annotation class MyData |
4 changes: 1 addition & 3 deletions
4
sample/jvm/src/main/kotlin/dev/drewhamilton/poko/sample/jvm/Sample.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