@@ -33,8 +33,11 @@ import io.spine.protodata.ast.PrimitiveType.TYPE_STRING
33
33
import io.spine.protodata.ast.Type
34
34
import io.spine.protodata.ast.isList
35
35
import io.spine.protodata.ast.isMap
36
+ import io.spine.protodata.ast.qualifiedName
37
+ import io.spine.protodata.ast.typeName
36
38
import io.spine.protodata.java.ClassName
37
39
import io.spine.protodata.java.Expression
40
+ import io.spine.protodata.java.StringLiteral
38
41
import io.spine.protodata.java.call
39
42
import io.spine.protodata.value.Value
40
43
import io.spine.string.shortly
@@ -45,7 +48,6 @@ import io.spine.validation.ComparisonOperator.GREATER_THAN
45
48
import io.spine.validation.ComparisonOperator.LESS_OR_EQUAL
46
49
import io.spine.validation.ComparisonOperator.LESS_THAN
47
50
import io.spine.validation.ComparisonOperator.NOT_EQUAL
48
- import io.spine.validation.ErrorMessage
49
51
import io.spine.validation.SimpleRule
50
52
import io.spine.validation.SimpleRule.OperatorKindCase.CUSTOM_OPERATOR
51
53
import io.spine.validation.SimpleRule.OperatorKindCase.OPERATOR
@@ -142,18 +144,32 @@ internal open class SimpleRuleGenerator(ctx: GenerationContext) : CodeGenerator(
142
144
PRIMITIVE_COMPARISON_OPS
143
145
}
144
146
145
- override fun error (): ErrorMessage {
146
- val actualValue = ClassName (String ::class )
147
+ override fun error (): Pair < String , Map < Expression < * >, Expression<*>>> {
148
+ val fieldValue = ClassName (String ::class )
147
149
.call<String >(" valueOf" , ctx.fieldOrElement!! )
148
- return ErrorMessage .forRule(
149
- rule.errorMessage,
150
- actualValue.toCode(),
151
- otherValue?.toCode()
150
+ val fieldPath = rule.field.value
151
+ val fieldType = ctx.simpleRuleField.type.typeName.qualifiedName
152
+ val parentType = ctx.validatedType.qualifiedName
153
+ return rule.errorMessage to mapOf (
154
+ StringLiteral (" field.path" ) to StringLiteral (fieldPath),
155
+ StringLiteral (" parent.type" ) to StringLiteral (parentType),
156
+ StringLiteral (" field.type" ) to StringLiteral (fieldType),
157
+ StringLiteral (" field.value" ) to fieldValue
152
158
)
153
159
}
154
160
155
- override fun createViolation (): CodeBlock =
156
- error().createViolation(ctx)
161
+ override fun createViolation (): CodeBlock {
162
+ val error = error()
163
+ val violation = buildViolation(
164
+ error.first,
165
+ ctx.validatedType,
166
+ ctx.fieldFromSimpleRule,
167
+ ctx.fieldOrElement,
168
+ ignoreCardinality = ctx.isElement,
169
+ error.second
170
+ )
171
+ return addViolation(violation, ctx.violationList)
172
+ }
157
173
}
158
174
159
175
internal fun generatorForSimple (ctx : GenerationContext ): CodeGenerator {
0 commit comments