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 {
36
36
37
37
public companion object {
38
38
/* *
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
40
44
*/
41
45
public fun keyFor (
42
46
value : Any ,
43
47
name : String = ""
44
48
): 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
47
52
}
48
53
}
49
54
}
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ public data class Named<W : Any>(
15
15
require(name.isNotBlank()) { " name must not be blank." }
16
16
}
17
17
18
- override val compatibilityKey: String = Compatible .keyFor(wrapped, " Named( $name ) " )
18
+ override val compatibilityKey: String = Compatible .keyFor(wrapped, " Named: $name " )
19
19
20
20
override fun toString (): String {
21
21
return " ${super .toString()} : $compatibilityKey "
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ public data class NamedScreen<C : Screen>(
16
16
require(name.isNotBlank()) { " name must not be blank." }
17
17
}
18
18
19
- override val compatibilityKey: String = Compatible .keyFor(content, " NamedScreen( $name ) " )
19
+ override val compatibilityKey: String = Compatible .keyFor(content, " NamedScreen: $name " )
20
20
21
21
@Deprecated(" Use content" , ReplaceWith (" content" ))
22
22
public val wrapped: C = content
Original file line number Diff line number Diff line change @@ -57,7 +57,7 @@ internal class NamedScreenTest {
57
57
58
58
@Test fun `recursive keys are legible` () {
59
59
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) )" )
61
61
}
62
62
63
63
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
5
5
6
6
// If you try to replace isTrue() with isTrue compilation fails.
7
7
@OptIn(WorkflowUiExperimentalApi ::class )
8
- @Suppress(" UsePropertyAccessSyntax " , " DEPRECATION" )
8
+ @Suppress(" DEPRECATION" )
9
9
internal class NamedTest {
10
10
object Whut
11
11
object Hey
@@ -58,7 +58,7 @@ internal class NamedTest {
58
58
59
59
@Test fun `recursive keys are legible` () {
60
60
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) )" )
62
62
}
63
63
64
64
private class Foo (override val compatibilityKey : String ) : Compatible
You can’t perform that action at this time.
0 commit comments