@@ -32,11 +32,13 @@ import io.spine.option.IfMissingOption
32
32
import io.spine.protobuf.unpack
33
33
import io.spine.protodata.Compilation
34
34
import io.spine.protodata.ast.Field
35
+ import io.spine.protodata.ast.FieldType
35
36
import io.spine.protodata.ast.File
36
37
import io.spine.protodata.ast.PrimitiveType.TYPE_BYTES
37
38
import io.spine.protodata.ast.PrimitiveType.TYPE_STRING
38
39
import io.spine.protodata.ast.event.FieldOptionDiscovered
39
40
import io.spine.protodata.ast.qualifiedName
41
+ import io.spine.protodata.check
40
42
import io.spine.protodata.plugin.Policy
41
43
import io.spine.server.event.NoReaction
42
44
import io.spine.server.event.React
@@ -97,16 +99,15 @@ internal class RequiredPolicy : Policy<FieldOptionDiscovered>() {
97
99
}
98
100
}
99
101
100
- private fun checkFieldType (field : Field , file : File ) {
101
- val type = field.type
102
- if (type.isPrimitive && type.primitive !in SUPPORTED_PRIMITIVES ) {
103
- Compilation .error(file, field.span) {
104
- " The field type `${field.type} ` of `${field.qualifiedName} ` is not supported " +
105
- " by the `($REQUIRED )` option. Supported field types: messages, enums, " +
106
- " strings, bytes, repeated, and maps."
107
- }
102
+ private fun checkFieldType (field : Field , file : File ) =
103
+ Compilation .check(field.type.isSupported(), file, field.span) {
104
+ " The field type `${field.type} ` of `${field.qualifiedName} ` is not supported " +
105
+ " by the `($REQUIRED )` option. Supported field types: messages, enums, " +
106
+ " strings, bytes, repeated, and maps."
108
107
}
109
- }
108
+
109
+ private fun FieldType.isSupported (): Boolean =
110
+ ! isPrimitive || primitive in SUPPORTED_PRIMITIVES
110
111
111
112
private val SUPPORTED_PRIMITIVES = listOf (
112
113
TYPE_STRING , TYPE_BYTES
0 commit comments