@@ -38,21 +38,36 @@ public static void validateStatement(RootStatement statement) {
3838 while (!stack .isEmpty ()) {
3939 Statement stat = stack .pop ();
4040
41- statements .putWithKey (stat , stat .id );
42-
43- stack .addAll (stat .getStats ());
41+ if (statements .containsKey (stat .id )) {
42+ if (statements .getWithKey (stat .id ) != stat ){
43+ throw new IllegalStateException ("2 stats with the same id: " + stat + " vs " + statements .getWithKey (stat .id ));
44+ }
45+ // The else case means multiple parent. A later check will produce better error than we could do here.
46+ } else {
47+ statements .putWithKey (stat , stat .id );
48+ stack .addAll (stat .getStats ());
49+ }
4450 }
4551
4652 for (Statement stat : statements ) {
4753 for (StatEdge edge : stat .getAllSuccessorEdges ()) {
54+ if (edge .getSource () != stat ) {
55+ throw new IllegalStateException ("Stat " + stat + " has successor edge for which it isn't the source: " + edge );
56+ }
4857 validateEdgeContext (statements , stat , edge );
4958 }
5059
5160 for (StatEdge edge : stat .getAllPredecessorEdges ()) {
61+ if (edge .getDestination () != stat ) {
62+ throw new IllegalStateException ("Stat " + stat + " has predecessor edge for which it isn't the destination: " + edge );
63+ }
5264 validateEdgeContext (statements , stat , edge );
5365 }
5466
5567 for (StatEdge edge : stat .getLabelEdges ()) {
68+ if (edge .closure != stat ) {
69+ throw new IllegalStateException ("Stat " + stat + " has a labelled edge for which it isn't the closure: " + edge );
70+ }
5671 validateEdgeContext (statements , stat , edge );
5772 }
5873
@@ -74,6 +89,9 @@ public static void validateStatement(RootStatement statement) {
7489 if (statStat .getParent () != stat ) {
7590 throw new IllegalStateException ("Statement parent is not set correctly [" + statStat + "]: Expected " + stat + " but was " + statStat .getParent ());
7691 }
92+ if (!stat .getStats ().containsKey (statStat .id )){
93+ throw new IllegalStateException ("Statement " + stat + " contains non stat without id lookup: " + statStat );
94+ }
7795 }
7896
7997 validateSingleStatement (stat );
0 commit comments