1+ package com .relogiclabs .json .schema .internal .message ;
2+
3+ import com .relogiclabs .json .schema .message .ExpectedDetail ;
4+ import com .relogiclabs .json .schema .types .JDataType ;
5+ import com .relogiclabs .json .schema .types .JFunction ;
6+ import com .relogiclabs .json .schema .types .JNode ;
7+ import com .relogiclabs .json .schema .types .JObject ;
8+ import com .relogiclabs .json .schema .types .JProperty ;
9+
10+ import static com .relogiclabs .json .schema .internal .message .MessageHelper .getTypeName ;
11+ import static com .relogiclabs .json .schema .internal .util .StringHelper .quote ;
12+
13+ public class ExpectedHelper {
14+
15+ private ExpectedHelper () {
16+ throw new UnsupportedOperationException ();
17+ }
18+
19+ public static ExpectedDetail asArrayElementNotFound (JNode node , int index ) {
20+ return new ExpectedDetail (node , "element at " , index ,
21+ " (" , node .getOutline (), ")" );
22+ }
23+
24+ public static ExpectedDetail asValueMismatch (JNode node ) {
25+ return new ExpectedDetail (node , "value " , node .getOutline ());
26+ }
27+
28+ public static ExpectedDetail asDataTypeMismatch (JDataType dataType ) {
29+ return new ExpectedDetail (dataType , "data type " , dataType .toString (true ));
30+ }
31+
32+ public static ExpectedDetail asInvalidDataType (JDataType dataType ) {
33+ return new ExpectedDetail (dataType , "applying on composite type" );
34+ }
35+
36+ public static ExpectedDetail asDataTypeMismatch (JNode node ) {
37+ return new ExpectedDetail (node , getTypeName (node ), " inferred by " ,
38+ node .getOutline ());
39+ }
40+
41+ public static ExpectedDetail asPropertyNotFound (JProperty property ) {
42+ return new ExpectedDetail (property , "property schema (" , property .getOutline (), ")" );
43+ }
44+
45+ public static ExpectedDetail asUndefinedProperty (JObject object , JProperty property ) {
46+ return new ExpectedDetail (object , "no property with key " , quote (property .getKey ()));
47+ }
48+
49+ public static ExpectedDetail asPropertyOrderMismatch (JProperty property ) {
50+ return new ExpectedDetail (property , "property with key " ,
51+ quote (property .getKey ()), " at position" );
52+ }
53+
54+ public static ExpectedDetail asInvalidFunction (JFunction function ) {
55+ return new ExpectedDetail (function , "applying on composite type" );
56+ }
57+ }
0 commit comments