File tree Expand file tree Collapse file tree 5 files changed +13
-8
lines changed
workflow-ui/core-common/src
main/java/com/squareup/workflow1/ui
test/java/com/squareup/workflow1/ui Expand file tree Collapse file tree 5 files changed +13
-8
lines changed Original file line number Diff line number Diff line change @@ -36,14 +36,19 @@ public interface Compatible {
3636
3737 public companion object {
3838 /* *
39- * Calculates a suitable [Compatible.compatibilityKey] for a given [value] and [name].
39+ * Calculates a suitable [Compatible.compatibilityKey] for a given [value], incorporating
40+ * [name] if that is not blank. Includes the [compatibilityKey] for [value] if it
41+ * implements [Compatible], to support recursion from wrapping.
42+ *
43+ * Style note: [name] is given more prominence than the key generate
4044 */
4145 public fun keyFor (
4246 value : Any ,
4347 name : String = ""
4448 ): String {
45- return ((value as ? Compatible )?.compatibilityKey ? : value::class .java.name) +
46- if (name.isEmpty()) " " else " +$name "
49+ val key = (value as ? Compatible )?.compatibilityKey ? : value::class .java.name
50+
51+ return name.takeIf { it.isNotEmpty() }?.let { " $name ($key )" } ? : key
4752 }
4853 }
4954}
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ public data class Named<W : Any>(
1515 require(name.isNotBlank()) { " name must not be blank." }
1616 }
1717
18- override val compatibilityKey: String = Compatible .keyFor(wrapped, " Named( $name ) " )
18+ override val compatibilityKey: String = Compatible .keyFor(wrapped, " Named: $name " )
1919
2020 override fun toString (): String {
2121 return " ${super .toString()} : $compatibilityKey "
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ public data class NamedScreen<C : Screen>(
1616 require(name.isNotBlank()) { " name must not be blank." }
1717 }
1818
19- override val compatibilityKey: String = Compatible .keyFor(content, " NamedScreen( $name ) " )
19+ override val compatibilityKey: String = Compatible .keyFor(content, " NamedScreen: $name " )
2020
2121 @Deprecated(" Use content" , ReplaceWith (" content" ))
2222 public val wrapped: C = content
Original file line number Diff line number Diff line change @@ -57,7 +57,7 @@ internal class NamedScreenTest {
5757
5858 @Test fun `recursive keys are legible` () {
5959 assertThat(NamedScreen (NamedScreen (Hey , " one" ), " ho" ).compatibilityKey)
60- .isEqualTo(" com.squareup.workflow1.ui.NamedScreenTest\$ Hey+NamedScreen(one)+NamedScreen(ho )" )
60+ .isEqualTo(" NamedScreen:ho(NamedScreen:one( com.squareup.workflow1.ui.NamedScreenTest\$ Hey) )" )
6161 }
6262
6363 private class Foo (override val compatibilityKey : String ) : Compatible, Screen
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ import org.junit.Test
55
66// If you try to replace isTrue() with isTrue compilation fails.
77@OptIn(WorkflowUiExperimentalApi ::class )
8- @Suppress(" UsePropertyAccessSyntax " , " DEPRECATION" )
8+ @Suppress(" DEPRECATION" )
99internal class NamedTest {
1010 object Whut
1111 object Hey
@@ -58,7 +58,7 @@ internal class NamedTest {
5858
5959 @Test fun `recursive keys are legible` () {
6060 assertThat(Named (Named (Hey , " one" ), " ho" ).compatibilityKey)
61- .isEqualTo(" com.squareup.workflow1.ui.NamedTest\$ Hey+Named(one)+Named(ho )" )
61+ .isEqualTo(" Named:ho(Named:one( com.squareup.workflow1.ui.NamedTest\$ Hey) )" )
6262 }
6363
6464 private class Foo (override val compatibilityKey : String ) : Compatible
You can’t perform that action at this time.
0 commit comments