Skip to content

Commit c79cbba

Browse files
committed
setting edit builder extension function fix
1 parent c9c7183 commit c79cbba

File tree

4 files changed

+39
-31
lines changed

4 files changed

+39
-31
lines changed

src/main/kotlin/com/lambda/config/settings/NumericSetting.kt

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -96,21 +96,23 @@ abstract class NumericSetting<T>(
9696
}
9797
}
9898

99-
@SettingGroup.SettingEditorDsl
100-
@Suppress("unchecked_cast")
101-
fun SettingGroup.TypedEditBuilder<T>.range(range: ClosedRange<T>) {
102-
(settings as Collection<NumericSetting<T>>).forEach { it.range = range }
103-
}
99+
companion object {
100+
@SettingGroup.SettingEditorDsl
101+
@Suppress("unchecked_cast")
102+
fun <T> SettingGroup.TypedEditBuilder<T>.range(range: ClosedRange<T>) where T : Number, T : Comparable<T> {
103+
(settings as Collection<NumericSetting<T>>).forEach { it.range = range }
104+
}
104105

105-
@SettingGroup.SettingEditorDsl
106-
@Suppress("unchecked_cast")
107-
fun SettingGroup.TypedEditBuilder<T>.step(step: T) {
108-
(settings as Collection<NumericSetting<T>>).forEach { it.step = step }
109-
}
106+
@SettingGroup.SettingEditorDsl
107+
@Suppress("unchecked_cast")
108+
fun <T> SettingGroup.TypedEditBuilder<T>.step(step: T) where T : Number, T : Comparable<T> {
109+
(settings as Collection<NumericSetting<T>>).forEach { it.step = step }
110+
}
110111

111-
@SettingGroup.SettingEditorDsl
112-
@Suppress("unchecked_cast")
113-
fun SettingGroup.TypedEditBuilder<*>.unit(unit: String) {
114-
(settings as Collection<NumericSetting<T>>).forEach { it.unit = unit}
112+
@SettingGroup.SettingEditorDsl
113+
@Suppress("unchecked_cast")
114+
fun <T> SettingGroup.TypedEditBuilder<T>.unit(unit: String) where T : Number, T : Comparable<T> {
115+
(settings as Collection<NumericSetting<T>>).forEach { it.unit = unit}
116+
}
115117
}
116118
}

src/main/kotlin/com/lambda/config/settings/StringSetting.kt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,17 @@ class StringSetting(
6363
}
6464
}
6565

66-
@SettingGroup.SettingEditorDsl
67-
@Suppress("unchecked_cast")
68-
fun SettingGroup.TypedEditBuilder<String>.multiline(multiline: Boolean) {
69-
(settings as Collection<StringSetting>).forEach { it.multiline = multiline }
70-
}
66+
companion object {
67+
@SettingGroup.SettingEditorDsl
68+
@Suppress("unchecked_cast")
69+
fun SettingGroup.TypedEditBuilder<String>.multiline(multiline: Boolean) {
70+
(settings as Collection<StringSetting>).forEach { it.multiline = multiline }
71+
}
7172

72-
@SettingGroup.SettingEditorDsl
73-
@Suppress("unchecked_cast")
74-
fun SettingGroup.TypedEditBuilder<String>.flags(flags: Int) {
75-
(settings as Collection<StringSetting>).forEach { it.flags = flags }
73+
@SettingGroup.SettingEditorDsl
74+
@Suppress("unchecked_cast")
75+
fun SettingGroup.TypedEditBuilder<String>.flags(flags: Int) {
76+
(settings as Collection<StringSetting>).forEach { it.flags = flags }
77+
}
7678
}
7779
}

src/main/kotlin/com/lambda/config/settings/collections/ListSetting.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,11 @@ class ListSetting<T : Any>(
7474
value = strList
7575
}
7676

77-
@SettingGroup.SettingEditorDsl
78-
@Suppress("unchecked_cast")
79-
fun <T> SettingGroup.TypedEditBuilder<MutableList<T>>.immutableList(immutableList: List<T>) {
80-
(settings as Collection<ListSetting<T>>).forEach { it.immutableList = immutableList }
77+
companion object {
78+
@SettingGroup.SettingEditorDsl
79+
@Suppress("unchecked_cast")
80+
fun <T : Any> SettingGroup.TypedEditBuilder<MutableList<T>>.immutableList(immutableList: List<T>) {
81+
(settings as Collection<ListSetting<T>>).forEach { it.immutableList = immutableList }
82+
}
8183
}
8284
}

src/main/kotlin/com/lambda/config/settings/collections/SetSetting.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,11 @@ class SetSetting<T : Any>(
7575
value = strSet
7676
}
7777

78-
@SettingGroup.SettingEditorDsl
79-
@Suppress("unchecked_cast")
80-
fun <T> SettingGroup.TypedEditBuilder<MutableSet<T>>.immutableSet(immutableSet: Set<T>) {
81-
(settings as Collection<SetSetting<T>>).forEach { it.immutableSet = immutableSet }
78+
companion object {
79+
@SettingGroup.SettingEditorDsl
80+
@Suppress("unchecked_cast")
81+
fun <T : Any> SettingGroup.TypedEditBuilder<MutableSet<T>>.immutableSet(immutableSet: Set<T>) {
82+
(settings as Collection<SetSetting<T>>).forEach { it.immutableSet = immutableSet }
83+
}
8284
}
8385
}

0 commit comments

Comments
 (0)