@@ -80,7 +80,7 @@ internal class RequiredPolicy : Policy<FieldOptionDiscovered>() {
80
80
val field = event.subject
81
81
val file = event.file
82
82
checkFieldType(field, file)
83
- val message = determineErrorMessage(field, file )
83
+ val message = determineErrorMessage(field)
84
84
return if (event.option.boolValue) {
85
85
accepted(field, message).asA()
86
86
} else {
@@ -111,21 +111,14 @@ private fun checkFieldType(field: Field, file: File) {
111
111
112
112
// TODO:2025-01-31:yevhenii.nadtochii: Locally changed ProtoData.
113
113
// `Field.optionList` is empty when it is part of `FieldOptionDiscovered` event.
114
- private fun determineErrorMessage (field : Field , file : File ): String {
115
- val ifMissingOptions = field.optionList.filter { it.name == IF_MISSING }
116
- return when (ifMissingOptions.size) {
117
- 0 -> DefaultErrorMessage .from(IfMissingOption .getDescriptor())
118
- 1 -> {
119
- val companion = ifMissingOptions.first().value.unpack<IfMissingOption >()
120
- companion .errorMsg
121
- }
122
-
123
- else -> {
124
- file.compilationError(field.span) {
125
- " The field `${field.qualifiedName} ` is allowed to have zero or one " +
126
- " `($IF_MISSING )` companion option."
127
- }
128
- }
114
+ // TODO:2025-02-03:yevhenii.nadtochii: No need to check the number of declarations.
115
+ private fun determineErrorMessage (field : Field ): String {
116
+ val companion = field.optionList.find { it.name == IF_MISSING }
117
+ return if (companion == null ) {
118
+ DefaultErrorMessage .from(IfMissingOption .getDescriptor())
119
+ } else {
120
+ companion .value.unpack<IfMissingOption >()
121
+ .errorMsg
129
122
}
130
123
}
131
124
0 commit comments