001    /* This file was generated with JastAdd2 (http://jastadd.org) version 2.1.3 */
002    package AST;
003    
004    import java.util.*;
005    /**
006     * @ast node
007     * @declaredat /home/csz-naf/examples/StateMachine/spec/StateMachine.ast:8
008     * @production State : {@link Declaration} ::= <span class="component">&lt;Label:String&gt;</span>;
009    
010     */
011    public class State extends Declaration implements Cloneable {
012      /**
013       * @apilevel internal
014       */
015      public State clone() throws CloneNotSupportedException {
016        State node = (State) super.clone();
017        node.alreadyDeclared_visited = false;
018        node.multiplyDeclared_visited = false;
019        node.hasLaterNamesake_visited = false;
020        node.altTransitions_visited = false;
021        node.successors_visited = false;
022        node.localLookup_String_visited = null;
023        node.reachable_visited = -1;
024        node.reachable_computed = false;
025        node.reachable_initialized = false;
026        node.reachable_value = null;
027        node.transitionsOf_State_visited = null;
028        return node;
029      }
030      /**
031       * @apilevel internal
032       */
033      public State copy() {
034        try {
035          State node = (State) clone();
036          node.parent = null;
037          if(children != null) {
038            node.children = (ASTNode[]) children.clone();
039          }
040          return node;
041        } catch (CloneNotSupportedException e) {
042          throw new Error("Error: clone not supported for " + getClass().getName());
043        }
044      }
045      /**
046       * Create a deep copy of the AST subtree at this node.
047       * The copy is dangling, i.e. has no parent.
048       * @return dangling copy of the subtree at this node
049       * @apilevel low-level
050       */
051      public State fullCopy() {
052        State tree = (State) copy();
053        if (children != null) {
054          for (int i = 0; i < children.length; ++i) {
055            ASTNode child = (ASTNode) children[i];
056            if(child != null) {
057              child = child.fullCopy();
058              tree.setChild(child, i);
059            }
060          }
061        }
062        return tree;
063      }
064      /**
065       * @aspect PrettyPrint
066       * @declaredat /home/csz-naf/examples/StateMachine/spec/PrettyPrint.jrag:14
067       */
068      public void pp() {
069        System.out.println("state "+getLabel()+";");
070      }
071      /**
072       * @aspect PrintInfoAboutCycles
073       * @declaredat /home/csz-naf/examples/StateMachine/spec/PrintInfoAboutCycles.jrag:12
074       */
075      public void printInfoAboutCycles() {
076        System.out.print("State "+getLabel()+" is ");
077        if (!reachable().contains(this)) {
078          System.out.print("not ");
079        }
080        System.out.println("on a cycle.");
081      }
082      /**
083       * @aspect PrintReachable
084       * @declaredat /home/csz-naf/examples/StateMachine/spec/PrintReachable.jrag:10
085       */
086      public void printReachable() {
087        System.out.println(getLabel() + " can reach {" +
088            listOfReachableStateLabels() + "}");
089      }
090      /**
091       * @aspect PrintReachable
092       * @declaredat /home/csz-naf/examples/StateMachine/spec/PrintReachable.jrag:15
093       */
094      public String listOfReachableStateLabels() {
095        boolean insideList = false;
096        StringBuffer result = new StringBuffer();
097        for (State s : reachable()) {
098          if (insideList)
099            result.append(", ");
100          else
101            insideList = true;
102          result.append(s.getLabel());
103        }
104        return result.toString();
105      }
106      /**
107       */
108      public State() {
109        super();
110      }
111      /**
112       * Initializes the child array to the correct size.
113       * Initializes List and Opt nta children.
114       * @apilevel internal
115       * @ast method
116       */
117      public void init$Children() {
118      }
119      /**
120       */
121      public State(String p0) {
122        setLabel(p0);
123      }
124      /**
125       */
126      public State(beaver.Symbol p0) {
127        setLabel(p0);
128      }
129      /**
130       * @apilevel low-level
131       */
132      protected int numChildren() {
133        return 0;
134      }
135      /**
136       * @apilevel low-level
137       */
138      public void flushCache() {
139        super.flushCache();
140        alreadyDeclared_visited = false;
141        multiplyDeclared_visited = false;
142        hasLaterNamesake_visited = false;
143        altTransitions_visited = false;
144        successors_visited = false;
145        localLookup_String_visited = null;
146        reachable_visited = -1;
147        reachable_computed = false;
148        reachable_initialized = false;
149        reachable_value = null;
150        transitionsOf_State_visited = null;
151        State_altSuccessors_visited = false;
152        State_altSuccessors_computed = false;
153        State_altSuccessors_value = null;
154            State_altSuccessors_contributors = null;
155        State_predecessors_visited = false;
156        State_predecessors_computed = false;
157        State_predecessors_value = null;
158            State_predecessors_contributors = null;
159        State_altReachable_visited = -1;
160        State_altReachable_computed = false;
161        State_altReachable_initialized = false;
162        State_altReachable_value = null;
163            State_altReachable_contributors = null;
164        State_transitions_visited = false;
165        State_transitions_computed = false;
166        State_transitions_value = null;
167            State_transitions_contributors = null;
168      }
169      /**
170       * @apilevel internal
171       */
172      public void flushCollectionCache() {
173        super.flushCollectionCache();
174        State_altSuccessors_visited = false;
175        State_altSuccessors_computed = false;
176        State_altSuccessors_value = null;
177            State_altSuccessors_contributors = null;
178        State_predecessors_visited = false;
179        State_predecessors_computed = false;
180        State_predecessors_value = null;
181            State_predecessors_contributors = null;
182        State_altReachable_visited = -1;
183        State_altReachable_computed = false;
184        State_altReachable_initialized = false;
185        State_altReachable_value = null;
186            State_altReachable_contributors = null;
187        State_transitions_visited = false;
188        State_transitions_computed = false;
189        State_transitions_value = null;
190            State_transitions_contributors = null;
191      }
192      /**
193       * Replaces the lexeme Label.
194       * @param value The new value for the lexeme Label.
195       * @apilevel high-level
196       */
197      public void setLabel(String value) {
198        tokenString_Label = value;
199      }
200      /**
201       * @apilevel internal
202       */
203      protected String tokenString_Label;
204      /**
205       */
206      public int Labelstart;
207      /**
208       */
209      public int Labelend;
210      /**
211       * JastAdd-internal setter for lexeme Label using the Beaver parser.
212       * @param symbol Symbol containing the new value for the lexeme Label
213       * @apilevel internal
214       */
215      public void setLabel(beaver.Symbol symbol) {
216        if(symbol.value != null && !(symbol.value instanceof String))
217        throw new UnsupportedOperationException("setLabel is only valid for String lexemes");
218        tokenString_Label = (String)symbol.value;
219        Labelstart = symbol.getStart();
220        Labelend = symbol.getEnd();
221      }
222      /**
223       * Retrieves the value for the lexeme Label.
224       * @return The value for the lexeme Label.
225       * @apilevel high-level
226       */
227      public String getLabel() {
228        return tokenString_Label != null ? tokenString_Label : "";
229      }
230      /**
231       * @apilevel internal
232       */
233      protected boolean alreadyDeclared_visited = false;
234      /**
235       * @attribute syn
236       * @aspect Exercises
237       * @declaredat /home/csz-naf/examples/StateMachine/spec/Exercises.jrag:6
238       */
239      public boolean alreadyDeclared() {
240        if (alreadyDeclared_visited) {
241          throw new RuntimeException("Circular definition of attr: alreadyDeclared in class: org.jastadd.ast.AST.SynDecl");
242        }
243        alreadyDeclared_visited = true;
244        try {  return lookup(this.getLabel()) != this;  }
245        finally {
246          alreadyDeclared_visited = false;
247        }
248      }
249      /**
250       * @apilevel internal
251       */
252      protected boolean multiplyDeclared_visited = false;
253      /**
254       * @attribute syn
255       * @aspect Exercises
256       * @declaredat /home/csz-naf/examples/StateMachine/spec/Exercises.jrag:9
257       */
258      public boolean multiplyDeclared() {
259        if (multiplyDeclared_visited) {
260          throw new RuntimeException("Circular definition of attr: multiplyDeclared in class: org.jastadd.ast.AST.SynDecl");
261        }
262        multiplyDeclared_visited = true;
263        try {  return alreadyDeclared() || hasLaterNamesake();  }
264        finally {
265          multiplyDeclared_visited = false;
266        }
267      }
268      /**
269       * @apilevel internal
270       */
271      protected boolean hasLaterNamesake_visited = false;
272      /**
273       * @attribute syn
274       * @aspect Exercises
275       * @declaredat /home/csz-naf/examples/StateMachine/spec/Exercises.jrag:12
276       */
277      public boolean hasLaterNamesake() {
278        if (hasLaterNamesake_visited) {
279          throw new RuntimeException("Circular definition of attr: hasLaterNamesake in class: org.jastadd.ast.AST.SynDecl");
280        }
281        hasLaterNamesake_visited = true;
282        try {  return lookupForward(getLabel()) != null;  }
283        finally {
284          hasLaterNamesake_visited = false;
285        }
286      }
287      /**
288       * @apilevel internal
289       */
290      protected boolean altTransitions_visited = false;
291      /**
292       * @attribute syn
293       * @aspect Exercises
294       * @declaredat /home/csz-naf/examples/StateMachine/spec/Exercises.jrag:27
295       */
296      public Set<Transition> altTransitions() {
297        if (altTransitions_visited) {
298          throw new RuntimeException("Circular definition of attr: altTransitions in class: org.jastadd.ast.AST.SynDecl");
299        }
300        altTransitions_visited = true;
301        try {  return transitionsOf(this);  }
302        finally {
303          altTransitions_visited = false;
304        }
305      }
306      /**
307       * @apilevel internal
308       */
309      protected boolean successors_visited = false;
310      /**
311       * @attribute syn
312       * @aspect Graph
313       * @declaredat /home/csz-naf/examples/StateMachine/spec/Graph.jrag:13
314       */
315      public Set<State> successors() {
316        if (successors_visited) {
317          throw new RuntimeException("Circular definition of attr: successors in class: org.jastadd.ast.AST.SynDecl");
318        }
319        successors_visited = true;
320        try {
321            Set<State> result = new HashSet<State>();
322            for (Transition t : transitions()) {
323              if (t.target() != null) result.add(t.target());
324            }
325            return result;
326          }
327        finally {
328          successors_visited = false;
329        }
330      }
331      /**
332       * @apilevel internal
333       */
334      protected java.util.Set localLookup_String_visited;
335      /**
336       * @attribute syn
337       * @aspect NameAnalysis
338       * @declaredat /home/csz-naf/examples/StateMachine/spec/NameAnalysis.jrag:18
339       */
340      public State localLookup(String label) {
341        Object _parameters = label;
342        if(localLookup_String_visited == null) localLookup_String_visited = new java.util.HashSet(4);
343        if (localLookup_String_visited.contains(_parameters)) {
344          throw new RuntimeException("Circular definition of attr: localLookup in class: org.jastadd.ast.AST.SynDecl");
345        }
346        localLookup_String_visited.add(_parameters);
347        try {  return // R6
348              (label.equals(getLabel())) ? this : null;  }
349        finally {
350          localLookup_String_visited.remove(_parameters);
351        }
352      }
353      /**
354       * @apilevel internal
355       */
356      protected int reachable_visited = -1;
357      /**
358       * @apilevel internal
359       */
360      protected boolean reachable_computed = false;
361      /**
362       * @apilevel internal
363       */
364      protected boolean reachable_initialized = false;
365      /**
366       * @apilevel internal
367       */
368      protected Set<State> reachable_value;
369      /**
370       * @attribute syn
371       * @aspect Reachability
372       * @declaredat /home/csz-naf/examples/StateMachine/spec/Reachability.jrag:9
373       */
374      public Set<State> reachable() {
375        if(reachable_computed) {
376          return reachable_value;
377        }
378        ASTNode$State state = state();
379        if (!reachable_initialized) {
380          reachable_initialized = true;
381          reachable_value = new HashSet<State>();
382        }
383        if (!state.IN_CIRCLE) {
384          state.IN_CIRCLE = true;
385          // TODO: fixme
386          // state().CIRCLE_INDEX = 1;
387          do {
388            reachable_visited = state.CIRCLE_INDEX;
389            state.CHANGE = false;
390            Set<State> new_reachable_value = reachable_compute();
391            if ((new_reachable_value==null && reachable_value!=null) || (new_reachable_value!=null && !new_reachable_value.equals(reachable_value))) {
392              state.CHANGE = true;
393            }
394            reachable_value = new_reachable_value;
395            state.CIRCLE_INDEX++;
396          } while (state.CHANGE);
397          if(true) {
398            reachable_computed = true;
399            state.LAST_CYCLE = true;
400            reachable_compute();
401            state.LAST_CYCLE = false;
402          } else {
403            state.RESET_CYCLE = true;
404            reachable_compute();
405            state.RESET_CYCLE = false;
406            reachable_computed = false;
407            reachable_initialized = false;
408          }
409          state.IN_CIRCLE = false;
410          return reachable_value;
411        }
412        if(reachable_visited != state.CIRCLE_INDEX) {
413          reachable_visited = state.CIRCLE_INDEX;
414          if (state.LAST_CYCLE) {
415          reachable_computed = true;
416            Set<State> new_reachable_value = reachable_compute();
417            return new_reachable_value;
418          }
419          if (state.RESET_CYCLE) {
420            reachable_computed = false;
421            reachable_initialized = false;
422            reachable_visited = -1;
423            return reachable_value;
424          }
425          Set<State> new_reachable_value = reachable_compute();
426          if ((new_reachable_value==null && reachable_value!=null) || (new_reachable_value!=null && !new_reachable_value.equals(reachable_value))) {
427            state.CHANGE = true;
428          }
429          reachable_value = new_reachable_value;
430          return reachable_value;
431        }
432        return reachable_value;
433      }
434      /**
435       * @apilevel internal
436       */
437      private Set<State> reachable_compute() { // R2
438          HashSet<State> result = new HashSet<State>();
439          for (State s : successors()) {
440            result.add(s);
441            result.addAll(s.reachable());
442          }
443          return result;
444        }
445      /**
446       * @attribute inh
447       * @aspect Exercises
448       * @declaredat /home/csz-naf/examples/StateMachine/spec/Exercises.jrag:28
449       */
450      public Set<Transition> transitionsOf(State s) {
451        Object _parameters = s;
452        if(transitionsOf_State_visited == null) transitionsOf_State_visited = new java.util.HashSet(4);
453        if (transitionsOf_State_visited.contains(_parameters)) {
454          throw new RuntimeException("Circular definition of attr: transitionsOf in class: org.jastadd.ast.AST.InhDecl");
455        }
456        transitionsOf_State_visited.add(_parameters);
457        Set<Transition> transitionsOf_State_value = getParent().Define_Set_Transition__transitionsOf(this, null, s);
458    
459        transitionsOf_State_visited.remove(_parameters);
460        return transitionsOf_State_value;
461      }
462      /**
463       * @apilevel internal
464       */
465      protected java.util.Set transitionsOf_State_visited;
466      /**
467       * @attribute coll
468       * @aspect Exercises
469       * @declaredat /home/csz-naf/examples/StateMachine/spec/Exercises.jrag:48
470       */
471      public Set<State> altSuccessors() {
472        if(State_altSuccessors_computed) {
473          return State_altSuccessors_value;
474        }
475        if (State_altSuccessors_visited) {
476          throw new RuntimeException("Circular definition of attr: altSuccessors in class: org.jastadd.ast.AST.CollDecl");
477        }
478        State_altSuccessors_visited = true;
479        State_altSuccessors_value = altSuccessors_compute();
480        if(true) {
481          State_altSuccessors_computed = true;
482        } else {
483        }
484    
485        State_altSuccessors_visited = false;
486        return State_altSuccessors_value;
487      }
488      java.util.Set State_altSuccessors_contributors;
489    
490      /**
491       * @apilevel internal
492       * @return the contributor set for altSuccessors
493       */
494      public java.util.Set State_altSuccessors_contributors() {
495        if(State_altSuccessors_contributors == null)
496          State_altSuccessors_contributors  = new ASTNode$State.IdentityHashSet(4);
497        return State_altSuccessors_contributors;
498      }
499    
500      /**
501       * @apilevel internal
502       */
503      private Set<State> altSuccessors_compute() {
504        ASTNode node = this;
505        while(node.getParent() != null && !(node instanceof StateMachine)) {
506          node = node.getParent();
507        }
508        StateMachine root = (StateMachine) node;
509        root.collect_contributors_State_altSuccessors();
510        State_altSuccessors_value = new HashSet<State>();
511        if(State_altSuccessors_contributors != null)
512        for (java.util.Iterator iter = State_altSuccessors_contributors.iterator(); iter.hasNext(); ) {
513          ASTNode contributor = (ASTNode) iter.next();
514          contributor.contributeTo_State_State_altSuccessors(State_altSuccessors_value);
515        }
516        // TODO: disabled temporarily since collections may not be cached
517        //State_altSuccessors_contributors = null;
518        return State_altSuccessors_value;
519      }
520      /**
521       * @apilevel internal
522       */
523      protected boolean State_altSuccessors_visited = false;
524      /**
525       * @apilevel internal
526       */
527      protected boolean State_altSuccessors_computed = false;
528      /**
529       * @apilevel internal
530       */
531      protected Set<State> State_altSuccessors_value;
532      /**
533       * @attribute coll
534       * @aspect Exercises
535       * @declaredat /home/csz-naf/examples/StateMachine/spec/Exercises.jrag:57
536       */
537      public Set<State> predecessors() {
538        if(State_predecessors_computed) {
539          return State_predecessors_value;
540        }
541        if (State_predecessors_visited) {
542          throw new RuntimeException("Circular definition of attr: predecessors in class: org.jastadd.ast.AST.CollDecl");
543        }
544        State_predecessors_visited = true;
545        State_predecessors_value = predecessors_compute();
546        if(true) {
547          State_predecessors_computed = true;
548        } else {
549        }
550    
551        State_predecessors_visited = false;
552        return State_predecessors_value;
553      }
554      java.util.Set State_predecessors_contributors;
555    
556      /**
557       * @apilevel internal
558       * @return the contributor set for predecessors
559       */
560      public java.util.Set State_predecessors_contributors() {
561        if(State_predecessors_contributors == null)
562          State_predecessors_contributors  = new ASTNode$State.IdentityHashSet(4);
563        return State_predecessors_contributors;
564      }
565    
566      /**
567       * @apilevel internal
568       */
569      private Set<State> predecessors_compute() {
570        ASTNode node = this;
571        while(node.getParent() != null && !(node instanceof StateMachine)) {
572          node = node.getParent();
573        }
574        StateMachine root = (StateMachine) node;
575        root.collect_contributors_State_predecessors();
576        State_predecessors_value = new HashSet<State>();
577        if(State_predecessors_contributors != null)
578        for (java.util.Iterator iter = State_predecessors_contributors.iterator(); iter.hasNext(); ) {
579          ASTNode contributor = (ASTNode) iter.next();
580          contributor.contributeTo_State_State_predecessors(State_predecessors_value);
581        }
582        // TODO: disabled temporarily since collections may not be cached
583        //State_predecessors_contributors = null;
584        return State_predecessors_value;
585      }
586      /**
587       * @apilevel internal
588       */
589      protected boolean State_predecessors_visited = false;
590      /**
591       * @apilevel internal
592       */
593      protected boolean State_predecessors_computed = false;
594      /**
595       * @apilevel internal
596       */
597      protected Set<State> State_predecessors_value;
598      /**
599       * @apilevel internal
600       */
601      protected int State_altReachable_visited = -1;
602      /**
603       * @apilevel internal
604       */
605      protected boolean State_altReachable_computed = false;
606    
607      /**
608       * @apilevel internal
609       */
610      protected boolean State_altReachable_initialized = false;
611    
612      /**
613       * @apilevel internal
614       */
615      protected Set<State> State_altReachable_value;
616    
617    
618      /**
619       * @attribute coll
620       * @aspect Exercises
621       * @declaredat /home/csz-naf/examples/StateMachine/spec/Exercises.jrag:102
622       */
623      public Set<State> altReachable() {
624        if(State_altReachable_computed) {
625          return State_altReachable_value;
626        }
627        ASTNode node = this;
628        while(node.getParent() != null && !(node instanceof StateMachine))
629          node = node.getParent();
630        StateMachine root = (StateMachine) node;
631    
632        if(root.collecting_contributors_State_altReachable)
633          throw new RuntimeException("Circularity during phase 1");
634        root.collect_contributors_State_altReachable();
635    
636        if (!State_altReachable_initialized) {
637          State_altReachable_initialized = true;
638          State_altReachable_value = new HashSet<State>();
639        }
640    
641        if (!state().IN_CIRCLE) {
642          state().IN_CIRCLE = true;
643          state().CIRCLE_INDEX = 1;
644          do {
645            State_altReachable_visited = state().CIRCLE_INDEX;
646            state().CHANGE = false;
647    
648            Set<State> new_State_altReachable_value = new HashSet<State>();
649            combine_State_altReachable_contributions(new_State_altReachable_value);
650            if ((new_State_altReachable_value==null && State_altReachable_value!=null) || (new_State_altReachable_value!=null && !new_State_altReachable_value.equals(State_altReachable_value))) {
651              state().CHANGE = true;
652            }
653            State_altReachable_value = new_State_altReachable_value;
654            state().CIRCLE_INDEX++;
655          } while (state().CHANGE);
656    
657          if(true) {
658            State_altReachable_computed = true;
659            state.LAST_CYCLE = true;
660            State_altReachable_value = combine_State_altReachable_contributions(new HashSet<State>());
661            state.LAST_CYCLE = false;
662          } else {
663            state.RESET_CYCLE = true;
664            State_altReachable_value = combine_State_altReachable_contributions(new HashSet<State>());
665            state.RESET_CYCLE = false;
666            State_altReachable_computed = false;
667            State_altReachable_initialized = false;
668          }
669          state().IN_CIRCLE = false;
670          return State_altReachable_value;
671        }
672        if(State_altReachable_visited != state().CIRCLE_INDEX) {
673          State_altReachable_visited = state().CIRCLE_INDEX;
674          if (state.LAST_CYCLE) {
675          State_altReachable_computed = true;
676            Set<State> new_State_altReachable_value = State_altReachable_value = combine_State_altReachable_contributions(new HashSet<State>());
677            return new_State_altReachable_value;
678          }
679          if (state.RESET_CYCLE) {
680            State_altReachable_computed = false;
681            State_altReachable_initialized = false;
682            State_altReachable_visited = -1;
683            return State_altReachable_value;
684          }
685          Set<State> new_State_altReachable_value = new HashSet<State>();
686          combine_State_altReachable_contributions(new_State_altReachable_value);
687          if ((new_State_altReachable_value==null && State_altReachable_value!=null) || (new_State_altReachable_value!=null && !new_State_altReachable_value.equals(State_altReachable_value))) {
688            state().CHANGE = true;
689          }
690          State_altReachable_value = new_State_altReachable_value;
691          return State_altReachable_value;
692        }
693        return State_altReachable_value;
694      }
695      java.util.Set State_altReachable_contributors;
696    
697      /**
698       * @apilevel internal
699       * @return the contributor set for altReachable
700       */
701      public java.util.Set State_altReachable_contributors() {
702        if(State_altReachable_contributors == null)
703          State_altReachable_contributors  = new ASTNode$State.IdentityHashSet(4);
704        return State_altReachable_contributors;
705      }
706    
707      private Set<State> combine_State_altReachable_contributions(Set<State> h) {
708        if(State_altReachable_contributors != null)
709        for(java.util.Iterator iter = State_altReachable_contributors.iterator(); iter.hasNext(); ) {
710          ASTNode contributor = (ASTNode) iter.next();
711          contributor.contributeTo_State_State_altReachable(h);
712        }
713        // TODO: disabled temporarily since collections may not be cached
714        //State_altReachable_contributors = null;
715        return h;
716      }
717      /**
718       * @attribute coll
719       * @aspect Graph
720       * @declaredat /home/csz-naf/examples/StateMachine/spec/Graph.jrag:6
721       */
722      public Set<Transition> transitions() {
723        if(State_transitions_computed) {
724          return State_transitions_value;
725        }
726        if (State_transitions_visited) {
727          throw new RuntimeException("Circular definition of attr: transitions in class: org.jastadd.ast.AST.CollDecl");
728        }
729        State_transitions_visited = true;
730        State_transitions_value = transitions_compute();
731        if(true) {
732          State_transitions_computed = true;
733        } else {
734        }
735    
736        State_transitions_visited = false;
737        return State_transitions_value;
738      }
739      java.util.Set State_transitions_contributors;
740    
741      /**
742       * @apilevel internal
743       * @return the contributor set for transitions
744       */
745      public java.util.Set State_transitions_contributors() {
746        if(State_transitions_contributors == null)
747          State_transitions_contributors  = new ASTNode$State.IdentityHashSet(4);
748        return State_transitions_contributors;
749      }
750    
751      /**
752       * @apilevel internal
753       */
754      private Set<Transition> transitions_compute() {
755        ASTNode node = this;
756        while(node.getParent() != null && !(node instanceof StateMachine)) {
757          node = node.getParent();
758        }
759        StateMachine root = (StateMachine) node;
760        root.collect_contributors_State_transitions();
761        State_transitions_value = new HashSet<Transition>();
762        if(State_transitions_contributors != null)
763        for (java.util.Iterator iter = State_transitions_contributors.iterator(); iter.hasNext(); ) {
764          ASTNode contributor = (ASTNode) iter.next();
765          contributor.contributeTo_State_State_transitions(State_transitions_value);
766        }
767        // TODO: disabled temporarily since collections may not be cached
768        //State_transitions_contributors = null;
769        return State_transitions_value;
770      }
771      /**
772       * @apilevel internal
773       */
774      protected boolean State_transitions_visited = false;
775      /**
776       * @apilevel internal
777       */
778      protected boolean State_transitions_computed = false;
779      /**
780       * @apilevel internal
781       */
782      protected Set<Transition> State_transitions_value;
783      protected void collect_contributors_State_predecessors() {
784      /**
785       * @attribute coll
786       * @aspect Exercises
787       * @declaredat /home/csz-naf/examples/StateMachine/spec/Exercises.jrag:59
788       */
789          for(java.util.Iterator iter = (successors()).iterator(); iter.hasNext(); ) {
790            State ref = (State) iter.next();
791            if (ref != null) {
792              ref.State_predecessors_contributors().add(this);
793            }
794          }
795        super.collect_contributors_State_predecessors();
796      }
797      protected void collect_contributors_StateMachine_errors() {
798      /**
799       * @attribute coll
800       * @aspect Exercises
801       * @declaredat /home/csz-naf/examples/StateMachine/spec/Exercises.jrag:86
802       */
803        if (alreadyDeclared()) {
804          {
805            StateMachine ref = (StateMachine) (theMachine());
806            if (ref != null) {
807              ref.StateMachine_errors_contributors().add(this);
808            }
809          }
810        }
811        super.collect_contributors_StateMachine_errors();
812      }
813      protected void collect_contributors_State_altReachable() {
814      /**
815       * @attribute coll
816       * @aspect Exercises
817       * @declaredat /home/csz-naf/examples/StateMachine/spec/Exercises.jrag:104
818       */
819          for(java.util.Iterator iter = (predecessors()).iterator(); iter.hasNext(); ) {
820            State ref = (State) iter.next();
821            if (ref != null) {
822              ref.State_altReachable_contributors().add(this);
823            }
824          }
825        super.collect_contributors_State_altReachable();
826      }
827      protected void contributeTo_State_State_predecessors(Set<State> collection) {
828        super.contributeTo_State_State_predecessors(collection);
829        collection.add(this);
830      }
831    
832      protected void contributeTo_StateMachine_StateMachine_errors(Set<String> collection) {
833        super.contributeTo_StateMachine_StateMachine_errors(collection);
834        if(alreadyDeclared())
835          collection.add(getLabel()+" is already declared");
836      }
837    
838      protected void contributeTo_State_State_altReachable(Set<State> collection) {
839        super.contributeTo_State_State_altReachable(collection);
840        collection.addAll(union(asSet(this),altReachable()));
841      }
842    
843    }