Skip to content

Commit ffeceff

Browse files
committed
Fix reflection in annotated strings
1 parent da8756a commit ffeceff

8 files changed

Lines changed: 93 additions & 53 deletions

File tree

core/src/androidHostTest/kotlin/com/orange/ouds/core/component/common/text/OudsAnnotatedStringTest.kt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,11 @@ class OudsAnnotatedStringTest {
720720
//endregion
721721
}
722722

723-
private class TestAnnotatedString(private val annotatedString: AnnotatedString) : OudsAnnotatedString<TestAnnotatedString>(annotatedString) {
723+
private class TestAnnotatedString(annotatedString: AnnotatedString) : OudsAnnotatedString<TestAnnotatedString>(annotatedString) {
724+
725+
override fun transform(transform: (AnnotatedString) -> AnnotatedString): TestAnnotatedString {
726+
return TestAnnotatedString(transform(annotatedString))
727+
}
724728

725729
val spanStyles: List<AnnotatedString.Range<SpanStyle>> = annotatedString.spanStyles
726730

@@ -730,7 +734,7 @@ private class TestAnnotatedString(private val annotatedString: AnnotatedString)
730734

731735
fun getStrongAnnotations(): List<AnnotatedString.Range<String>> = getStringAnnotations().filter { it.item == StrongAnnotation }
732736

733-
class Builder(capacity: Int = 16) : OudsAnnotatedString.Builder<TestAnnotatedString>(capacity, TestAnnotatedString::class.java), StrongBuilder,
737+
class Builder(capacity: Int = 16) : OudsAnnotatedString.Builder<TestAnnotatedString>(capacity), StrongBuilder,
734738
LinkBuilder {
735739

736740
constructor(text: String) : this() {
@@ -741,6 +745,10 @@ private class TestAnnotatedString(private val annotatedString: AnnotatedString)
741745
append(text)
742746
}
743747

748+
override fun toAnnotatedString(): TestAnnotatedString {
749+
return TestAnnotatedString(builder.toAnnotatedString())
750+
}
751+
744752
override fun addStrong(start: Int, end: Int) = addStrongImpl(start, end)
745753

746754
override fun pushStrong(): Int = pushStrongImpl()
@@ -754,5 +762,5 @@ private class TestAnnotatedString(private val annotatedString: AnnotatedString)
754762
}
755763

756764
private fun buildTestAnnotatedString(builder: (TestAnnotatedString.Builder).() -> Unit): TestAnnotatedString {
757-
return buildOudsAnnotatedString<TestAnnotatedString, TestAnnotatedString.Builder>(builder)
765+
return buildOudsAnnotatedString({ TestAnnotatedString.Builder() }, builder)
758766
}

core/src/commonMain/kotlin/com/orange/ouds/core/component/InteractionValuesIndicationNodeFactory.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import kotlinx.coroutines.async
3333
import kotlinx.coroutines.awaitAll
3434
import kotlinx.coroutines.flow.collectLatest
3535
import kotlinx.coroutines.launch
36+
import kotlin.jvm.JvmName
3637

3738
internal fun interactionValuesIndication(vararg interactionValues: InteractionValue<*, *>): IndicationNodeFactory =
3839
InteractionValuesIndicationNodeFactory(values = interactionValues.toList())

core/src/commonMain/kotlin/com/orange/ouds/core/component/common/text/OudsAnnotatedAlertMessageBulletListLabel.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ import androidx.compose.ui.text.AnnotatedString
4444
class OudsAnnotatedAlertMessageBulletListLabel internal constructor(annotatedString: AnnotatedString) :
4545
OudsAnnotatedString<OudsAnnotatedAlertMessageBulletListLabel>(annotatedString) {
4646

47+
override fun transform(transform: (AnnotatedString) -> AnnotatedString): OudsAnnotatedAlertMessageBulletListLabel {
48+
return OudsAnnotatedAlertMessageBulletListLabel(transform(annotatedString))
49+
}
50+
4751
/**
4852
* Builder for creating [OudsAnnotatedAlertMessageBulletListLabel] with strong text and link formatting.
4953
*
@@ -54,7 +58,7 @@ class OudsAnnotatedAlertMessageBulletListLabel internal constructor(annotatedStr
5458
* @param capacity Initial capacity for the underlying string builder. Defaults to 16.
5559
*/
5660
class Builder(capacity: Int = 16) :
57-
OudsAnnotatedString.Builder<OudsAnnotatedAlertMessageBulletListLabel>(capacity, OudsAnnotatedAlertMessageBulletListLabel::class.java),
61+
OudsAnnotatedString.Builder<OudsAnnotatedAlertMessageBulletListLabel>(capacity),
5862
StrongBuilder, LinkBuilder {
5963

6064
/**
@@ -84,6 +88,10 @@ class OudsAnnotatedAlertMessageBulletListLabel internal constructor(annotatedStr
8488
append(text)
8589
}
8690

91+
override fun toAnnotatedString(): OudsAnnotatedAlertMessageBulletListLabel {
92+
return OudsAnnotatedAlertMessageBulletListLabel(builder.toAnnotatedString())
93+
}
94+
8795
override fun addStrong(start: Int, end: Int) = addStrongImpl(start, end)
8896

8997
override fun pushStrong(): Int = pushStrongImpl()
@@ -111,5 +119,5 @@ class OudsAnnotatedAlertMessageBulletListLabel internal constructor(annotatedStr
111119
* @return The constructed annotated alert message bullet list label.
112120
*/
113121
fun buildOudsAnnotatedAlertMessageBulletListLabel(builder: (OudsAnnotatedAlertMessageBulletListLabel.Builder).() -> Unit): OudsAnnotatedAlertMessageBulletListLabel {
114-
return buildOudsAnnotatedString<OudsAnnotatedAlertMessageBulletListLabel, OudsAnnotatedAlertMessageBulletListLabel.Builder>(builder)
122+
return buildOudsAnnotatedString({ OudsAnnotatedAlertMessageBulletListLabel.Builder() }, builder)
115123
}

core/src/commonMain/kotlin/com/orange/ouds/core/component/common/text/OudsAnnotatedAlertMessageDescription.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ import androidx.compose.ui.text.AnnotatedString
4141
class OudsAnnotatedAlertMessageDescription internal constructor(annotatedString: AnnotatedString) :
4242
OudsAnnotatedString<OudsAnnotatedAlertMessageDescription>(annotatedString) {
4343

44+
override fun transform(transform: (AnnotatedString) -> AnnotatedString): OudsAnnotatedAlertMessageDescription {
45+
return OudsAnnotatedAlertMessageDescription(transform(annotatedString))
46+
}
47+
4448
/**
4549
* Builder for creating [OudsAnnotatedAlertMessageDescription] with strong text and link formatting.
4650
*
@@ -51,7 +55,7 @@ class OudsAnnotatedAlertMessageDescription internal constructor(annotatedString:
5155
* @param capacity Initial capacity for the underlying string builder. Defaults to 16.
5256
*/
5357
class Builder(capacity: Int = 16) :
54-
OudsAnnotatedString.Builder<OudsAnnotatedAlertMessageDescription>(capacity, OudsAnnotatedAlertMessageDescription::class.java),
58+
OudsAnnotatedString.Builder<OudsAnnotatedAlertMessageDescription>(capacity),
5559
StrongBuilder, LinkBuilder {
5660

5761
/**
@@ -81,6 +85,10 @@ class OudsAnnotatedAlertMessageDescription internal constructor(annotatedString:
8185
append(text)
8286
}
8387

88+
override fun toAnnotatedString(): OudsAnnotatedAlertMessageDescription {
89+
return OudsAnnotatedAlertMessageDescription(builder.toAnnotatedString())
90+
}
91+
8492
override fun addStrong(start: Int, end: Int) = addStrongImpl(start, end)
8593

8694
override fun pushStrong(): Int = pushStrongImpl()
@@ -112,5 +120,5 @@ class OudsAnnotatedAlertMessageDescription internal constructor(annotatedString:
112120
* @return The constructed annotated alert message description.
113121
*/
114122
fun buildOudsAnnotatedAlertMessageDescription(builder: (OudsAnnotatedAlertMessageDescription.Builder).() -> Unit): OudsAnnotatedAlertMessageDescription {
115-
return buildOudsAnnotatedString<OudsAnnotatedAlertMessageDescription, OudsAnnotatedAlertMessageDescription.Builder>(builder)
123+
return buildOudsAnnotatedString({ OudsAnnotatedAlertMessageDescription.Builder() }, builder)
116124
}

core/src/commonMain/kotlin/com/orange/ouds/core/component/common/text/OudsAnnotatedBulletListLabel.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ import androidx.compose.ui.text.AnnotatedString
3939
class OudsAnnotatedBulletListLabel internal constructor(annotatedString: AnnotatedString) :
4040
OudsAnnotatedString<OudsAnnotatedBulletListLabel>(annotatedString) {
4141

42+
override fun transform(transform: (AnnotatedString) -> AnnotatedString): OudsAnnotatedBulletListLabel {
43+
return OudsAnnotatedBulletListLabel(transform(annotatedString))
44+
}
45+
4246
/**
4347
* Builder for creating [OudsAnnotatedBulletListLabel] with strong text and link formatting.
4448
*
@@ -49,7 +53,7 @@ class OudsAnnotatedBulletListLabel internal constructor(annotatedString: Annotat
4953
* @param capacity Initial capacity for the underlying string builder. Defaults to 16.
5054
*/
5155
class Builder(capacity: Int = 16) :
52-
OudsAnnotatedString.Builder<OudsAnnotatedBulletListLabel>(capacity, OudsAnnotatedBulletListLabel::class.java),
56+
OudsAnnotatedString.Builder<OudsAnnotatedBulletListLabel>(capacity),
5357
StrongBuilder, LinkBuilder {
5458

5559
/**
@@ -79,6 +83,10 @@ class OudsAnnotatedBulletListLabel internal constructor(annotatedString: Annotat
7983
append(text)
8084
}
8185

86+
override fun toAnnotatedString(): OudsAnnotatedBulletListLabel {
87+
return OudsAnnotatedBulletListLabel(builder.toAnnotatedString())
88+
}
89+
8290
override fun addStrong(start: Int, end: Int) = addStrongImpl(start, end)
8391

8492
override fun pushStrong(): Int = pushStrongImpl()
@@ -108,5 +116,5 @@ class OudsAnnotatedBulletListLabel internal constructor(annotatedString: Annotat
108116
* @return The constructed annotated bullet list label.
109117
*/
110118
fun buildOudsAnnotatedBulletListLabel(builder: (OudsAnnotatedBulletListLabel.Builder).() -> Unit): OudsAnnotatedBulletListLabel {
111-
return buildOudsAnnotatedString<OudsAnnotatedBulletListLabel, OudsAnnotatedBulletListLabel.Builder>(builder)
119+
return buildOudsAnnotatedString({ OudsAnnotatedBulletListLabel.Builder() }, builder)
112120
}

core/src/commonMain/kotlin/com/orange/ouds/core/component/common/text/OudsAnnotatedErrorMessage.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ import androidx.compose.ui.text.AnnotatedString
4040
*/
4141
class OudsAnnotatedErrorMessage internal constructor(annotatedString: AnnotatedString) : OudsAnnotatedString<OudsAnnotatedErrorMessage>(annotatedString) {
4242

43+
override fun transform(transform: (AnnotatedString) -> AnnotatedString): OudsAnnotatedErrorMessage {
44+
return OudsAnnotatedErrorMessage(transform(annotatedString))
45+
}
46+
4347
/**
4448
* Builder for creating [OudsAnnotatedErrorMessage] with strong text formatting.
4549
*
@@ -48,7 +52,7 @@ class OudsAnnotatedErrorMessage internal constructor(annotatedString: AnnotatedS
4852
*
4953
* @param capacity Initial capacity for the underlying string builder. Defaults to 16.
5054
*/
51-
class Builder(capacity: Int = 16) : OudsAnnotatedString.Builder<OudsAnnotatedErrorMessage>(capacity, OudsAnnotatedErrorMessage::class.java),
55+
class Builder(capacity: Int = 16) : OudsAnnotatedString.Builder<OudsAnnotatedErrorMessage>(capacity),
5256
StrongBuilder {
5357

5458
/**
@@ -78,6 +82,10 @@ class OudsAnnotatedErrorMessage internal constructor(annotatedString: AnnotatedS
7882
append(text)
7983
}
8084

85+
override fun toAnnotatedString(): OudsAnnotatedErrorMessage {
86+
return OudsAnnotatedErrorMessage(builder.toAnnotatedString())
87+
}
88+
8189
override fun addStrong(start: Int, end: Int) = addStrongImpl(start, end)
8290

8391
override fun pushStrong(): Int = pushStrongImpl()
@@ -99,5 +107,5 @@ class OudsAnnotatedErrorMessage internal constructor(annotatedString: AnnotatedS
99107
* @return The constructed annotated error message.
100108
*/
101109
fun buildOudsAnnotatedErrorMessage(builder: (OudsAnnotatedErrorMessage.Builder).() -> Unit): OudsAnnotatedErrorMessage {
102-
return buildOudsAnnotatedString<OudsAnnotatedErrorMessage, OudsAnnotatedErrorMessage.Builder>(builder)
110+
return buildOudsAnnotatedString({ OudsAnnotatedErrorMessage.Builder() }, builder)
103111
}

core/src/commonMain/kotlin/com/orange/ouds/core/component/common/text/OudsAnnotatedHelperText.kt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ import androidx.compose.ui.text.AnnotatedString
3838
*/
3939
class OudsAnnotatedHelperText internal constructor(annotatedString: AnnotatedString) : OudsAnnotatedString<OudsAnnotatedHelperText>(annotatedString) {
4040

41+
override fun transform(transform: (AnnotatedString) -> AnnotatedString): OudsAnnotatedHelperText {
42+
return OudsAnnotatedHelperText(transform(annotatedString))
43+
}
44+
4145
/**
4246
* Builder for creating [OudsAnnotatedHelperText] with strong text formatting.
4347
*
@@ -46,7 +50,7 @@ class OudsAnnotatedHelperText internal constructor(annotatedString: AnnotatedStr
4650
*
4751
* @param capacity Initial capacity for the underlying string builder. Defaults to 16.
4852
*/
49-
class Builder(capacity: Int = 16) : OudsAnnotatedString.Builder<OudsAnnotatedHelperText>(capacity, OudsAnnotatedHelperText::class.java), StrongBuilder {
53+
class Builder(capacity: Int = 16) : OudsAnnotatedString.Builder<OudsAnnotatedHelperText>(capacity), StrongBuilder {
5054

5155
/**
5256
* Creates a builder initialized with plain text.
@@ -74,7 +78,11 @@ class OudsAnnotatedHelperText internal constructor(annotatedString: AnnotatedStr
7478
constructor(text: AnnotatedString) : this() {
7579
append(text)
7680
}
77-
81+
82+
override fun toAnnotatedString(): OudsAnnotatedHelperText {
83+
return OudsAnnotatedHelperText(builder.toAnnotatedString())
84+
}
85+
7886
override fun addStrong(start: Int, end: Int) = addStrongImpl(start, end)
7987

8088
override fun pushStrong(): Int = pushStrongImpl()
@@ -97,5 +105,5 @@ class OudsAnnotatedHelperText internal constructor(annotatedString: AnnotatedStr
97105
* @return The constructed annotated helper text.
98106
*/
99107
fun buildOudsAnnotatedHelperText(builder: (OudsAnnotatedHelperText.Builder).() -> Unit): OudsAnnotatedHelperText {
100-
return buildOudsAnnotatedString<OudsAnnotatedHelperText, OudsAnnotatedHelperText.Builder>(builder)
108+
return buildOudsAnnotatedString({ OudsAnnotatedHelperText.Builder() }, builder)
101109
}

0 commit comments

Comments
 (0)