1+ package com .relogiclabs .json .schema .util ;
2+
3+ import com .relogiclabs .json .schema .time .DateTimeContext ;
4+ import com .relogiclabs .json .schema .tree .JsonTree ;
5+ import com .relogiclabs .json .schema .tree .SchemaTree ;
6+ import org .antlr .v4 .runtime .Parser ;
7+ import org .antlr .v4 .runtime .Recognizer ;
8+
9+ import java .util .Collections ;
10+ import java .util .List ;
11+
12+ public class DebugUtils {
13+
14+ public static boolean debugPrint = false ;
15+
16+ public static void print (SchemaTree schemaTree , JsonTree jsonTree ) {
17+ if (!debugPrint ) return ;
18+ System .out .println ("[DEBUG] Schema interpretation:" );
19+ System .out .println (schemaTree .getRoot ());
20+ System .out .println ("---" );
21+ System .out .println ("[DEBUG] Json interpretation:" );
22+ System .out .println (jsonTree .getRoot ());
23+ System .out .println ("---" );
24+ }
25+
26+ public static void print (JsonTree expectedTree , JsonTree actualTree ) {
27+ if (!debugPrint ) return ;
28+ System .out .println ("[DEBUG] Expected Json interpretation:" );
29+ System .out .println (expectedTree .getRoot ());
30+ System .out .println ("---" );
31+ System .out .println ("[DEBUG] Actual Json interpretation:" );
32+ System .out .println (actualTree .getRoot ());
33+ System .out .println ("---" );
34+ }
35+
36+ public static void print (Recognizer <?, ?> recognizer ) {
37+ if (!debugPrint ) return ;
38+ List <String > stack = ((Parser ) recognizer ).getRuleInvocationStack ();
39+ Collections .reverse (stack );
40+ System .err .println ("[DEBUG] Rule stack: " + String .join (" > " , stack ));
41+ }
42+
43+ public static void print (DateTimeContext context ) {
44+ if (!debugPrint ) return ;
45+ System .out .println ("[DEBUG] Date and time interpretation: " + context );
46+ }
47+
48+ public static void print (Exception e ) {
49+ if (!debugPrint ) return ;
50+ System .err .println ("[DEBUG] Print of exception: " + e );
51+ }
52+ }
0 commit comments