001 /* This file was generated with JastAdd2 (http://jastadd.org) version R20130213 */ 002 package AST; 003 004 import java.util.HashSet; 005 import java.io.File; 006 import java.util.*; 007 import beaver.*; 008 import java.util.ArrayList; 009 import java.util.zip.*; 010 import java.io.*; 011 import java.io.FileNotFoundException; 012 import java.util.Collection; 013 /** 014 * @production EnumInstanceExpr : {@link ClassInstanceExpr} ::= <span class="component">{@link Access}</span> <span class="component">Arg:{@link Expr}*</span> <span class="component">[{@link TypeDecl}]</span>; 015 * @ast node 016 * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Enums.ast:5 017 */ 018 public class EnumInstanceExpr extends ClassInstanceExpr implements Cloneable { 019 /** 020 * @apilevel low-level 021 */ 022 public void flushCache() { 023 } 024 /** 025 * @apilevel internal 026 */ 027 public void flushCollectionCache() { 028 } 029 /** 030 * @apilevel internal 031 */ 032 @SuppressWarnings({"unchecked", "cast"}) 033 public EnumInstanceExpr clone() throws CloneNotSupportedException { 034 EnumInstanceExpr node = (EnumInstanceExpr)super.clone(); 035 node.getAccess_computed = false; 036 node.getAccess_value = null; 037 node.getArgList_computed = false; 038 node.getArgList_value = null; 039 node.in$Circle(false); 040 node.is$Final(false); 041 return node; 042 } 043 /** 044 * @apilevel internal 045 */ 046 @SuppressWarnings({"unchecked", "cast"}) 047 public EnumInstanceExpr copy() { 048 049 try { 050 EnumInstanceExpr node = (EnumInstanceExpr) clone(); 051 node.parent = null; 052 if(children != null) 053 node.children = (ASTNode[]) children.clone(); 054 055 return node; 056 } catch (CloneNotSupportedException e) { 057 throw new Error("Error: clone not supported for " + getClass().getName()); 058 } 059 060 }/** 061 * Create a deep copy of the AST subtree at this node. 062 * The copy is dangling, i.e. has no parent. 063 * @return dangling copy of the subtree at this node 064 * @apilevel low-level 065 */ 066 @SuppressWarnings({"unchecked", "cast"}) 067 public EnumInstanceExpr fullCopy() { 068 069 EnumInstanceExpr tree = (EnumInstanceExpr) copy(); 070 if (children != null) { 071 for (int i = 0; i < children.length; ++i) { 072 switch (i) { 073 case 1: 074 tree.children[i] = null; 075 continue; 076 case 2: 077 tree.children[i] = new List(); 078 continue; 079 } 080 ASTNode child = (ASTNode) children[i]; 081 if(child != null) { 082 child = child.fullCopy(); 083 tree.setChild(child, i); 084 } 085 } 086 } 087 return tree; 088 089 } /** 090 * @ast method 091 * 092 */ 093 public EnumInstanceExpr() { 094 super(); 095 096 097 } 098 /** 099 * Initializes the child array to the correct size. 100 * Initializes List and Opt nta children. 101 * @apilevel internal 102 * @ast method 103 * @ast method 104 * 105 */ 106 public void init$Children() { 107 children = new ASTNode[3]; 108 setChild(new Opt(), 0); 109 setChild(new List(), 2); 110 } 111 /** 112 * @ast method 113 * 114 */ 115 public EnumInstanceExpr(Opt<TypeDecl> p0) { 116 setChild(p0, 0); 117 } 118 /** 119 * @apilevel low-level 120 * @ast method 121 * 122 */ 123 protected int numChildren() { 124 return 1; 125 } 126 /** 127 * @apilevel internal 128 * @ast method 129 * 130 */ 131 public boolean mayHaveRewrite() { 132 return false; 133 } 134 /** 135 * Replaces the optional node for the TypeDecl child. This is the {@code Opt} node containing the child TypeDecl, not the actual child! 136 * @param opt The new node to be used as the optional node for the TypeDecl child. 137 * @apilevel low-level 138 * @ast method 139 * 140 */ 141 public void setTypeDeclOpt(Opt<TypeDecl> opt) { 142 setChild(opt, 0); 143 } 144 /** 145 * Check whether the optional TypeDecl child exists. 146 * @return {@code true} if the optional TypeDecl child exists, {@code false} if it does not. 147 * @apilevel high-level 148 * @ast method 149 * 150 */ 151 public boolean hasTypeDecl() { 152 return getTypeDeclOpt().getNumChild() != 0; 153 } 154 /** 155 * Retrieves the (optional) TypeDecl child. 156 * @return The TypeDecl child, if it exists. Returns {@code null} otherwise. 157 * @apilevel low-level 158 * @ast method 159 * 160 */ 161 @SuppressWarnings({"unchecked", "cast"}) 162 public TypeDecl getTypeDecl() { 163 return (TypeDecl)getTypeDeclOpt().getChild(0); 164 } 165 /** 166 * Replaces the (optional) TypeDecl child. 167 * @param node The new node to be used as the TypeDecl child. 168 * @apilevel high-level 169 * @ast method 170 * 171 */ 172 public void setTypeDecl(TypeDecl node) { 173 getTypeDeclOpt().setChild(node, 0); 174 } 175 /** 176 * @apilevel low-level 177 * @ast method 178 * 179 */ 180 @SuppressWarnings({"unchecked", "cast"}) 181 public Opt<TypeDecl> getTypeDeclOpt() { 182 return (Opt<TypeDecl>)getChild(0); 183 } 184 /** 185 * Retrieves the optional node for child TypeDecl. This is the {@code Opt} node containing the child TypeDecl, not the actual child! 186 * <p><em>This method does not invoke AST transformations.</em></p> 187 * @return The optional node for child TypeDecl. 188 * @apilevel low-level 189 * @ast method 190 * 191 */ 192 @SuppressWarnings({"unchecked", "cast"}) 193 public Opt<TypeDecl> getTypeDeclOptNoTransform() { 194 return (Opt<TypeDecl>)getChildNoTransform(0); 195 } 196 /** 197 * Replaces the Access child. 198 * @param node The new node to replace the Access child. 199 * @apilevel high-level 200 * @ast method 201 * 202 */ 203 public void setAccess(Access node) { 204 setChild(node, 1); 205 } 206 /** 207 * Retrieves the Access child. 208 * <p><em>This method does not invoke AST transformations.</em></p> 209 * @return The current node used as the Access child. 210 * @apilevel low-level 211 * @ast method 212 * 213 */ 214 public Access getAccessNoTransform() { 215 return (Access)getChildNoTransform(1); 216 } 217 /** 218 * Retrieves the child position of the optional child Access. 219 * @return The the child position of the optional child Access. 220 * @apilevel low-level 221 * @ast method 222 * 223 */ 224 protected int getAccessChildPosition() { 225 return 1; 226 } 227 /** 228 * Replaces the Arg list. 229 * @param list The new list node to be used as the Arg list. 230 * @apilevel high-level 231 * @ast method 232 * 233 */ 234 public void setArgList(List<Expr> list) { 235 setChild(list, 2); 236 } 237 /** 238 * Retrieves the number of children in the Arg list. 239 * @return Number of children in the Arg list. 240 * @apilevel high-level 241 * @ast method 242 * 243 */ 244 public int getNumArg() { 245 return getArgList().getNumChild(); 246 } 247 /** 248 * Retrieves the number of children in the Arg list. 249 * Calling this method will not trigger rewrites.. 250 * @return Number of children in the Arg list. 251 * @apilevel low-level 252 * @ast method 253 * 254 */ 255 public int getNumArgNoTransform() { 256 return getArgListNoTransform().getNumChildNoTransform(); 257 } 258 /** 259 * Retrieves the element at index {@code i} in the Arg list.. 260 * @param i Index of the element to return. 261 * @return The element at position {@code i} in the Arg list. 262 * @apilevel high-level 263 * @ast method 264 * 265 */ 266 @SuppressWarnings({"unchecked", "cast"}) 267 public Expr getArg(int i) { 268 return (Expr)getArgList().getChild(i); 269 } 270 /** 271 * Append an element to the Arg list. 272 * @param node The element to append to the Arg list. 273 * @apilevel high-level 274 * @ast method 275 * 276 */ 277 public void addArg(Expr node) { 278 List<Expr> list = (parent == null || state == null) ? getArgListNoTransform() : getArgList(); 279 list.addChild(node); 280 } 281 /** 282 * @apilevel low-level 283 * @ast method 284 * 285 */ 286 public void addArgNoTransform(Expr node) { 287 List<Expr> list = getArgListNoTransform(); 288 list.addChild(node); 289 } 290 /** 291 * Replaces the Arg list element at index {@code i} with the new node {@code node}. 292 * @param node The new node to replace the old list element. 293 * @param i The list index of the node to be replaced. 294 * @apilevel high-level 295 * @ast method 296 * 297 */ 298 public void setArg(Expr node, int i) { 299 List<Expr> list = getArgList(); 300 list.setChild(node, i); 301 } 302 /** 303 * Retrieves the Arg list. 304 * @return The node representing the Arg list. 305 * @apilevel high-level 306 * @ast method 307 * 308 */ 309 public List<Expr> getArgs() { 310 return getArgList(); 311 } 312 /** 313 * Retrieves the Arg list. 314 * <p><em>This method does not invoke AST transformations.</em></p> 315 * @return The node representing the Arg list. 316 * @apilevel low-level 317 * @ast method 318 * 319 */ 320 public List<Expr> getArgsNoTransform() { 321 return getArgListNoTransform(); 322 } 323 /** 324 * Retrieves the Arg list. 325 * <p><em>This method does not invoke AST transformations.</em></p> 326 * @return The node representing the Arg list. 327 * @apilevel low-level 328 * @ast method 329 * 330 */ 331 public List<Expr> getArgListNoTransform() { 332 return (List<Expr>)getChildNoTransform(2); 333 } 334 /** 335 * Retrieves the child position of the Arg list. 336 * @return The the child position of the Arg list. 337 * @apilevel low-level 338 * @ast method 339 * 340 */ 341 protected int getArgListChildPosition() { 342 return 2; 343 } 344 /** 345 * @apilevel internal 346 */ 347 protected boolean getAccess_computed = false; 348 /** 349 * @apilevel internal 350 */ 351 protected Access getAccess_value; 352 /* 353 3) An enum constant may be followed by arguments, which are passed to the 354 constructor of the enum type when the constant is created during class 355 initialization as described later in this section. The constructor to be 356 invoked is chosen using the normal overloading rules (\ufffd15.12.2). If the 357 arguments are omitted, an empty argument list is assumed. 358 * @attribute syn nta 359 * @aspect Enums 360 * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Enums.jrag:209 361 */ 362 @SuppressWarnings({"unchecked", "cast"}) 363 public Access getAccess() { 364 if(getAccess_computed) { 365 return (Access) getChild(getAccessChildPosition()); 366 } 367 ASTNode$State state = state(); 368 int num = state.boundariesCrossed; 369 boolean isFinal = this.is$Final(); 370 getAccess_value = getAccess_compute(); 371 setAccess(getAccess_value); 372 if(isFinal && num == state().boundariesCrossed){ getAccess_computed = true; } 373 Access node = (Access) this.getChild(getAccessChildPosition()); 374 return node; 375 } 376 /** 377 * @apilevel internal 378 */ 379 private Access getAccess_compute() { 380 return hostType().createQualifiedAccess(); 381 } 382 /** 383 * @apilevel internal 384 */ 385 protected boolean getArgList_computed = false; 386 /** 387 * @apilevel internal 388 */ 389 protected List<Expr> getArgList_value; 390 /** 391 * @attribute syn nta 392 * @aspect Enums 393 * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Enums.jrag:213 394 */ 395 @SuppressWarnings({"unchecked", "cast"}) 396 public List<Expr> getArgList() { 397 if(getArgList_computed) { 398 return (List<Expr>) getChild(getArgListChildPosition()); 399 } 400 ASTNode$State state = state(); 401 int num = state.boundariesCrossed; 402 boolean isFinal = this.is$Final(); 403 getArgList_value = getArgList_compute(); 404 setArgList(getArgList_value); 405 if(isFinal && num == state().boundariesCrossed){ getArgList_computed = true; } 406 List<Expr> node = (List<Expr>) this.getChild(getArgListChildPosition()); 407 return node; 408 } 409 /** 410 * @apilevel internal 411 */ 412 private List<Expr> getArgList_compute() { 413 EnumConstant ec = (EnumConstant)getParent().getParent(); 414 List<EnumConstant> ecs = (List<EnumConstant>)ec.getParent(); 415 int idx = ecs.getIndexOfChild(ec); 416 if(idx == -1) 417 throw new Error("internal: cannot determine numeric value of enum constant"); 418 List<Expr> argList = new List<Expr>(); 419 argList.add(Literal.buildStringLiteral(ec.name())); 420 argList.add(Literal.buildIntegerLiteral(idx)); 421 for(Expr arg : ec.getArgs()) 422 argList.add((Expr)arg.fullCopy()); 423 return argList; 424 } 425 /** 426 * @apilevel internal 427 */ 428 public ASTNode rewriteTo() { 429 return super.rewriteTo(); 430 } 431 }