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:9 008 * @production Transition : {@link Declaration} ::= <span class="component"><Label:String></span> <span class="component"><SourceLabel:String></span> <span class="component"><TargetLabel:String></span>; 009 010 */ 011 public class Transition extends Declaration implements Cloneable { 012 /** 013 * @apilevel internal 014 */ 015 public Transition clone() throws CloneNotSupportedException { 016 Transition node = (Transition) super.clone(); 017 node.transitionOf_State_visited = null; 018 node.source_visited = false; 019 node.target_visited = false; 020 return node; 021 } 022 /** 023 * @apilevel internal 024 */ 025 public Transition copy() { 026 try { 027 Transition node = (Transition) clone(); 028 node.parent = null; 029 if(children != null) { 030 node.children = (ASTNode[]) children.clone(); 031 } 032 return node; 033 } catch (CloneNotSupportedException e) { 034 throw new Error("Error: clone not supported for " + getClass().getName()); 035 } 036 } 037 /** 038 * Create a deep copy of the AST subtree at this node. 039 * The copy is dangling, i.e. has no parent. 040 * @return dangling copy of the subtree at this node 041 * @apilevel low-level 042 */ 043 public Transition fullCopy() { 044 Transition tree = (Transition) copy(); 045 if (children != null) { 046 for (int i = 0; i < children.length; ++i) { 047 ASTNode child = (ASTNode) children[i]; 048 if(child != null) { 049 child = child.fullCopy(); 050 tree.setChild(child, i); 051 } 052 } 053 } 054 return tree; 055 } 056 /** 057 * @aspect PrettyPrint 058 * @declaredat /home/csz-naf/examples/StateMachine/spec/PrettyPrint.jrag:18 059 */ 060 public void pp() { 061 System.out.println("trans "+getLabel()+":"+getSourceLabel()+"->"+getTargetLabel()+";"); 062 } 063 /** 064 */ 065 public Transition() { 066 super(); 067 } 068 /** 069 * Initializes the child array to the correct size. 070 * Initializes List and Opt nta children. 071 * @apilevel internal 072 * @ast method 073 */ 074 public void init$Children() { 075 } 076 /** 077 */ 078 public Transition(String p0, String p1, String p2) { 079 setLabel(p0); 080 setSourceLabel(p1); 081 setTargetLabel(p2); 082 } 083 /** 084 */ 085 public Transition(beaver.Symbol p0, beaver.Symbol p1, beaver.Symbol p2) { 086 setLabel(p0); 087 setSourceLabel(p1); 088 setTargetLabel(p2); 089 } 090 /** 091 * @apilevel low-level 092 */ 093 protected int numChildren() { 094 return 0; 095 } 096 /** 097 * @apilevel low-level 098 */ 099 public void flushCache() { 100 super.flushCache(); 101 transitionOf_State_visited = null; 102 source_visited = false; 103 target_visited = false; 104 } 105 /** 106 * @apilevel internal 107 */ 108 public void flushCollectionCache() { 109 super.flushCollectionCache(); 110 } 111 /** 112 * Replaces the lexeme Label. 113 * @param value The new value for the lexeme Label. 114 * @apilevel high-level 115 */ 116 public void setLabel(String value) { 117 tokenString_Label = value; 118 } 119 /** 120 * @apilevel internal 121 */ 122 protected String tokenString_Label; 123 /** 124 */ 125 public int Labelstart; 126 /** 127 */ 128 public int Labelend; 129 /** 130 * JastAdd-internal setter for lexeme Label using the Beaver parser. 131 * @param symbol Symbol containing the new value for the lexeme Label 132 * @apilevel internal 133 */ 134 public void setLabel(beaver.Symbol symbol) { 135 if(symbol.value != null && !(symbol.value instanceof String)) 136 throw new UnsupportedOperationException("setLabel is only valid for String lexemes"); 137 tokenString_Label = (String)symbol.value; 138 Labelstart = symbol.getStart(); 139 Labelend = symbol.getEnd(); 140 } 141 /** 142 * Retrieves the value for the lexeme Label. 143 * @return The value for the lexeme Label. 144 * @apilevel high-level 145 */ 146 public String getLabel() { 147 return tokenString_Label != null ? tokenString_Label : ""; 148 } 149 /** 150 * Replaces the lexeme SourceLabel. 151 * @param value The new value for the lexeme SourceLabel. 152 * @apilevel high-level 153 */ 154 public void setSourceLabel(String value) { 155 tokenString_SourceLabel = value; 156 } 157 /** 158 * @apilevel internal 159 */ 160 protected String tokenString_SourceLabel; 161 /** 162 */ 163 public int SourceLabelstart; 164 /** 165 */ 166 public int SourceLabelend; 167 /** 168 * JastAdd-internal setter for lexeme SourceLabel using the Beaver parser. 169 * @param symbol Symbol containing the new value for the lexeme SourceLabel 170 * @apilevel internal 171 */ 172 public void setSourceLabel(beaver.Symbol symbol) { 173 if(symbol.value != null && !(symbol.value instanceof String)) 174 throw new UnsupportedOperationException("setSourceLabel is only valid for String lexemes"); 175 tokenString_SourceLabel = (String)symbol.value; 176 SourceLabelstart = symbol.getStart(); 177 SourceLabelend = symbol.getEnd(); 178 } 179 /** 180 * Retrieves the value for the lexeme SourceLabel. 181 * @return The value for the lexeme SourceLabel. 182 * @apilevel high-level 183 */ 184 public String getSourceLabel() { 185 return tokenString_SourceLabel != null ? tokenString_SourceLabel : ""; 186 } 187 /** 188 * Replaces the lexeme TargetLabel. 189 * @param value The new value for the lexeme TargetLabel. 190 * @apilevel high-level 191 */ 192 public void setTargetLabel(String value) { 193 tokenString_TargetLabel = value; 194 } 195 /** 196 * @apilevel internal 197 */ 198 protected String tokenString_TargetLabel; 199 /** 200 */ 201 public int TargetLabelstart; 202 /** 203 */ 204 public int TargetLabelend; 205 /** 206 * JastAdd-internal setter for lexeme TargetLabel using the Beaver parser. 207 * @param symbol Symbol containing the new value for the lexeme TargetLabel 208 * @apilevel internal 209 */ 210 public void setTargetLabel(beaver.Symbol symbol) { 211 if(symbol.value != null && !(symbol.value instanceof String)) 212 throw new UnsupportedOperationException("setTargetLabel is only valid for String lexemes"); 213 tokenString_TargetLabel = (String)symbol.value; 214 TargetLabelstart = symbol.getStart(); 215 TargetLabelend = symbol.getEnd(); 216 } 217 /** 218 * Retrieves the value for the lexeme TargetLabel. 219 * @return The value for the lexeme TargetLabel. 220 * @apilevel high-level 221 */ 222 public String getTargetLabel() { 223 return tokenString_TargetLabel != null ? tokenString_TargetLabel : ""; 224 } 225 /** 226 * @apilevel internal 227 */ 228 protected java.util.Set transitionOf_State_visited; 229 /** 230 * @attribute syn 231 * @aspect Exercises 232 * @declaredat /home/csz-naf/examples/StateMachine/spec/Exercises.jrag:39 233 */ 234 public Transition transitionOf(State s) { 235 Object _parameters = s; 236 if(transitionOf_State_visited == null) transitionOf_State_visited = new java.util.HashSet(4); 237 if (transitionOf_State_visited.contains(_parameters)) { 238 throw new RuntimeException("Circular definition of attr: transitionOf in class: org.jastadd.ast.AST.SynDecl"); 239 } 240 transitionOf_State_visited.add(_parameters); 241 try { 242 if (source() == s) 243 return this; 244 else 245 return null; 246 } 247 finally { 248 transitionOf_State_visited.remove(_parameters); 249 } 250 } 251 /** 252 * @apilevel internal 253 */ 254 protected boolean source_visited = false; 255 /** 256 * @attribute syn 257 * @aspect NameAnalysis 258 * @declaredat /home/csz-naf/examples/StateMachine/spec/NameAnalysis.jrag:6 259 */ 260 public State source() { 261 if (source_visited) { 262 throw new RuntimeException("Circular definition of attr: source in class: org.jastadd.ast.AST.SynDecl"); 263 } 264 source_visited = true; 265 try { return lookup(getSourceLabel()); } 266 finally { 267 source_visited = false; 268 } 269 } 270 /** 271 * @apilevel internal 272 */ 273 protected boolean target_visited = false; 274 /** 275 * @attribute syn 276 * @aspect NameAnalysis 277 * @declaredat /home/csz-naf/examples/StateMachine/spec/NameAnalysis.jrag:7 278 */ 279 public State target() { 280 if (target_visited) { 281 throw new RuntimeException("Circular definition of attr: target in class: org.jastadd.ast.AST.SynDecl"); 282 } 283 target_visited = true; 284 try { return lookup(getTargetLabel()); } 285 finally { 286 target_visited = false; 287 } 288 } 289 protected void collect_contributors_State_altSuccessors() { 290 /** 291 * @attribute coll 292 * @aspect Exercises 293 * @declaredat /home/csz-naf/examples/StateMachine/spec/Exercises.jrag:50 294 */ 295 if (target() != null && source() != null) { 296 { 297 State ref = (State) (source()); 298 if (ref != null) { 299 ref.State_altSuccessors_contributors().add(this); 300 } 301 } 302 } 303 super.collect_contributors_State_altSuccessors(); 304 } 305 protected void collect_contributors_StateMachine_numberOfTransitionsColl() { 306 /** 307 * @attribute coll 308 * @aspect Exercises 309 * @declaredat /home/csz-naf/examples/StateMachine/spec/Exercises.jrag:68 310 */ 311 { 312 StateMachine ref = (StateMachine) (theMachine()); 313 if (ref != null) { 314 ref.StateMachine_numberOfTransitionsColl_contributors().add(this); 315 } 316 } 317 super.collect_contributors_StateMachine_numberOfTransitionsColl(); 318 } 319 protected void collect_contributors_StateMachine_errors() { 320 /** 321 * @attribute coll 322 * @aspect Exercises 323 * @declaredat /home/csz-naf/examples/StateMachine/spec/Exercises.jrag:91 324 */ 325 if (source() == null) { 326 { 327 StateMachine ref = (StateMachine) (theMachine()); 328 if (ref != null) { 329 ref.StateMachine_errors_contributors().add(this); 330 } 331 } 332 } 333 /** 334 * @attribute coll 335 * @aspect Exercises 336 * @declaredat /home/csz-naf/examples/StateMachine/spec/Exercises.jrag:96 337 */ 338 if (target() == null) { 339 { 340 StateMachine ref = (StateMachine) (theMachine()); 341 if (ref != null) { 342 ref.StateMachine_errors_contributors().add(this); 343 } 344 } 345 } 346 super.collect_contributors_StateMachine_errors(); 347 } 348 protected void collect_contributors_State_transitions() { 349 /** 350 * @attribute coll 351 * @aspect Graph 352 * @declaredat /home/csz-naf/examples/StateMachine/spec/Graph.jrag:8 353 */ 354 if (source() != null) { 355 { 356 State ref = (State) (source()); 357 if (ref != null) { 358 ref.State_transitions_contributors().add(this); 359 } 360 } 361 } 362 super.collect_contributors_State_transitions(); 363 } 364 protected void contributeTo_State_State_altSuccessors(Set<State> collection) { 365 super.contributeTo_State_State_altSuccessors(collection); 366 if(target() != null && source() != null) 367 collection.add(target()); 368 } 369 370 protected void contributeTo_StateMachine_StateMachine_numberOfTransitionsColl(Counter collection) { 371 super.contributeTo_StateMachine_StateMachine_numberOfTransitionsColl(collection); 372 collection.add(1); 373 } 374 375 protected void contributeTo_StateMachine_StateMachine_errors(Set<String> collection) { 376 super.contributeTo_StateMachine_StateMachine_errors(collection); 377 if(source() == null) 378 collection.add("Missing declaration of "+getSourceLabel()); 379 if(target() == null) 380 collection.add("Missing declaration of "+getTargetLabel()); 381 } 382 383 protected void contributeTo_State_State_transitions(Set<Transition> collection) { 384 super.contributeTo_State_State_transitions(collection); 385 if(source() != null) 386 collection.add(this); 387 } 388 389 }