@@ -19,11 +19,6 @@ internal interface FieldFormatDirective<in Target> {
19
19
*/
20
20
val field: FieldSpec <Target , * >
21
21
22
- /* *
23
- * For numeric signed values, the way to check if the field is negative. For everything else, `null`.
24
- */
25
- val signGetter: ((Target ) -> Int )?
26
-
27
22
/* *
28
23
* The formatter operation that formats the field.
29
24
*/
@@ -32,7 +27,7 @@ internal interface FieldFormatDirective<in Target> {
32
27
/* *
33
28
* The parser structure that parses the field.
34
29
*/
35
- fun parser (signsInverted : Boolean ): ParserStructure <Target >
30
+ fun parser (): ParserStructure <Target >
36
31
}
37
32
38
33
/* *
@@ -45,8 +40,6 @@ internal abstract class UnsignedIntFieldFormatDirective<in Target>(
45
40
private val minDigits : Int ,
46
41
) : FieldFormatDirective<Target> {
47
42
48
- final override val signGetter: ((Target ) -> Int )? = null
49
-
50
43
private val maxDigits: Int = field.maxDigits
51
44
52
45
init {
@@ -62,7 +55,7 @@ internal abstract class UnsignedIntFieldFormatDirective<in Target>(
62
55
zeroPadding = minDigits,
63
56
)
64
57
65
- override fun parser (signsInverted : Boolean ): ParserStructure <Target > =
58
+ override fun parser (): ParserStructure <Target > =
66
59
ParserStructure (
67
60
listOf (
68
61
NumberSpanParserOperation (
@@ -94,8 +87,6 @@ internal abstract class NamedUnsignedIntFieldFormatDirective<in Target>(
94
87
}
95
88
}
96
89
97
- final override val signGetter: ((Target ) -> Int )? = null
98
-
99
90
private fun getStringValue (target : Target ): String = values[field.getNotNull(target) - field.minValue]
100
91
101
92
private fun setStringValue (target : Target , value : String ) {
@@ -105,7 +96,7 @@ internal abstract class NamedUnsignedIntFieldFormatDirective<in Target>(
105
96
override fun formatter (): FormatterOperation <Target > =
106
97
StringFormatterOperation (::getStringValue)
107
98
108
- override fun parser (signsInverted : Boolean ): ParserStructure <Target > =
99
+ override fun parser (): ParserStructure <Target > =
109
100
ParserStructure (listOf (
110
101
StringSetParserOperation (values, ::setStringValue, " One of $values for ${field.name} " )
111
102
), emptyList())
@@ -119,8 +110,6 @@ internal abstract class NamedEnumIntFieldFormatDirective<in Target, Type>(
119
110
private val mapping : Map <Type , String >,
120
111
) : FieldFormatDirective<Target> {
121
112
122
- final override val signGetter: ((Target ) -> Int )? = null
123
-
124
113
private val reverseMapping = mapping.entries.associate { it.value to it.key }
125
114
126
115
private fun getStringValue (target : Target ): String = mapping[field.getNotNull(target)]
@@ -136,7 +125,7 @@ internal abstract class NamedEnumIntFieldFormatDirective<in Target, Type>(
136
125
override fun formatter (): FormatterOperation <Target > =
137
126
StringFormatterOperation (::getStringValue)
138
127
139
- override fun parser (signsInverted : Boolean ): ParserStructure <Target > =
128
+ override fun parser (): ParserStructure <Target > =
140
129
ParserStructure (listOf (
141
130
StringSetParserOperation (mapping.values, ::setStringValue, " One of ${mapping.values} for ${field.name} " )
142
131
), emptyList())
@@ -147,16 +136,14 @@ internal abstract class StringFieldFormatDirective<in Target>(
147
136
private val acceptedStrings : Set <String >,
148
137
) : FieldFormatDirective<Target> {
149
138
150
- final override val signGetter: ((Target ) -> Int )? = null
151
-
152
139
init {
153
140
require(acceptedStrings.isNotEmpty())
154
141
}
155
142
156
143
override fun formatter (): FormatterOperation <Target > =
157
144
StringFormatterOperation (field::getNotNull)
158
145
159
- override fun parser (signsInverted : Boolean ): ParserStructure <Target > =
146
+ override fun parser (): ParserStructure <Target > =
160
147
ParserStructure (
161
148
listOf (StringSetParserOperation (acceptedStrings, field::setWithoutReassigning, field.name)),
162
149
emptyList()
@@ -170,9 +157,6 @@ internal abstract class SignedIntFieldFormatDirective<in Target>(
170
157
private val outputPlusOnExceededPadding : Boolean = false ,
171
158
) : FieldFormatDirective<Target> {
172
159
173
- final override val signGetter: ((Target ) -> Int ) = ::signGetterImpl
174
- private fun signGetterImpl (target : Target ): Int = (field.accessor.get(target) ? : 0 ).sign
175
-
176
160
init {
177
161
require(minDigits == null || minDigits >= 0 )
178
162
require(maxDigits == null || minDigits == null || maxDigits >= minDigits)
@@ -185,14 +169,13 @@ internal abstract class SignedIntFieldFormatDirective<in Target>(
185
169
outputPlusOnExceedsPad = outputPlusOnExceededPadding,
186
170
)
187
171
188
- override fun parser (signsInverted : Boolean ): ParserStructure <Target > =
172
+ override fun parser (): ParserStructure <Target > =
189
173
SignedIntParser (
190
174
minDigits = minDigits,
191
175
maxDigits = maxDigits,
192
176
field::setWithoutReassigning,
193
177
field.name,
194
178
plusOnExceedsPad = outputPlusOnExceededPadding,
195
- signsInverted = signsInverted
196
179
)
197
180
}
198
181
@@ -201,12 +184,10 @@ internal abstract class DecimalFractionFieldFormatDirective<in Target>(
201
184
private val minDigits : Int? ,
202
185
private val maxDigits : Int? ,
203
186
) : FieldFormatDirective<Target> {
204
- override val signGetter: ((Target ) -> Int )? = null
205
-
206
187
override fun formatter (): FormatterOperation <Target > =
207
188
DecimalFractionFormatterOperation (field::getNotNull, minDigits, maxDigits)
208
189
209
- override fun parser (signsInverted : Boolean ): ParserStructure <Target > = ParserStructure (
190
+ override fun parser (): ParserStructure <Target > = ParserStructure (
210
191
listOf (
211
192
NumberSpanParserOperation (
212
193
listOf (FractionPartConsumer (minDigits, maxDigits, field::setWithoutReassigning, field.name))
0 commit comments