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 EnumDecl : {@link ClassDecl} ::= <span class="component">{@link Modifiers}</span> <span class="component"><ID:String></span> <span class="component">[SuperClassAccess:{@link Access}]</span> <span class="component">Implements:{@link Access}*</span> <span class="component">{@link BodyDecl}*</span>; 015 * @ast node 016 * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Enums.ast:1 017 */ 018 public class EnumDecl extends ClassDecl 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 EnumDecl clone() throws CloneNotSupportedException { 034 EnumDecl node = (EnumDecl)super.clone(); 035 node.isStatic_computed = false; 036 node.getSuperClassAccessOpt_computed = false; 037 node.getSuperClassAccessOpt_value = null; 038 node.enumConstants_computed = false; 039 node.enumConstants_value = null; 040 node.unimplementedMethods_computed = false; 041 node.unimplementedMethods_value = null; 042 node.flags_computed = false; 043 node.in$Circle(false); 044 node.is$Final(false); 045 return node; 046 } 047 /** 048 * @apilevel internal 049 */ 050 @SuppressWarnings({"unchecked", "cast"}) 051 public EnumDecl copy() { 052 053 try { 054 EnumDecl node = (EnumDecl) clone(); 055 node.parent = null; 056 if(children != null) 057 node.children = (ASTNode[]) children.clone(); 058 059 return node; 060 } catch (CloneNotSupportedException e) { 061 throw new Error("Error: clone not supported for " + getClass().getName()); 062 } 063 064 }/** 065 * Create a deep copy of the AST subtree at this node. 066 * The copy is dangling, i.e. has no parent. 067 * @return dangling copy of the subtree at this node 068 * @apilevel low-level 069 */ 070 @SuppressWarnings({"unchecked", "cast"}) 071 public EnumDecl fullCopy() { 072 073 EnumDecl tree = (EnumDecl) copy(); 074 if (children != null) { 075 for (int i = 0; i < children.length; ++i) { 076 switch (i) { 077 case 4: 078 tree.children[i] = new Opt(); 079 continue; 080 } 081 ASTNode child = (ASTNode) children[i]; 082 if(child != null) { 083 child = child.fullCopy(); 084 tree.setChild(child, i); 085 } 086 } 087 } 088 return tree; 089 090 } /** 091 * @ast method 092 * @aspect Enums 093 * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Enums.jrag:46 094 */ 095 public void typeCheck() { 096 super.typeCheck(); 097 for(Iterator iter = memberMethods("finalize").iterator(); iter.hasNext(); ) { 098 MethodDecl m = (MethodDecl)iter.next(); 099 if(m.getNumParameter() == 0 && m.hostType() == this) 100 error("an enum may not declare a finalizer"); 101 } 102 checkEnum(this); 103 } 104 /** 105 * @ast method 106 * @aspect Enums 107 * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Enums.jrag:81 108 */ 109 110 111 private boolean done = false; 112 /** 113 * @ast method 114 * @aspect Enums 115 * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Enums.jrag:82 116 */ 117 private boolean done() { 118 if(done) return true; 119 done = true; 120 return false; 121 } 122 /** 123 * @ast method 124 * @aspect Enums 125 * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Enums.jrag:309 126 */ 127 private void addValues() { 128 int numConstants = enumConstants().size(); 129 List initValues = new List(); 130 for(Iterator iter = enumConstants().iterator(); iter.hasNext(); ) { 131 EnumConstant c = (EnumConstant)iter.next(); 132 initValues.add(c.createBoundFieldAccess()); 133 } 134 FieldDeclaration values = new FieldDeclaration( 135 new Modifiers(new List().add( 136 new Modifier("private")).add( 137 new Modifier("static")).add( 138 new Modifier("final")).add( 139 new Modifier("synthetic")) 140 ), 141 arrayType().createQualifiedAccess(), 142 "$VALUES", 143 new Opt( 144 new ArrayCreationExpr( 145 new ArrayTypeWithSizeAccess( 146 createQualifiedAccess(), 147 Literal.buildIntegerLiteral(enumConstants().size()) 148 ), 149 new Opt( 150 new ArrayInit( 151 initValues 152 ) 153 ) 154 ) 155 ) 156 ); 157 addBodyDecl(values); 158 // public static final Test[] values() { return (Test[])$VALUES.clone(); } 159 addBodyDecl( 160 new MethodDecl( 161 new Modifiers(new List().add( 162 new Modifier("public")).add( 163 new Modifier("static")).add( 164 new Modifier("final")).add( 165 new Modifier("synthetic")) 166 ), 167 arrayType().createQualifiedAccess(), 168 "values", 169 new List(), 170 new List(), 171 new Opt( 172 new Block( 173 new List().add( 174 new ReturnStmt( 175 new Opt( 176 new CastExpr( 177 arrayType().createQualifiedAccess(), 178 values.createBoundFieldAccess().qualifiesAccess( 179 new MethodAccess( 180 "clone", 181 new List() 182 ) 183 ) 184 ) 185 ) 186 ) 187 ) 188 ) 189 ) 190 ) 191 ); 192 // public static Test valueOf(String s) { return (Test)java.lang.Enum.valueOf(Test.class, s); } 193 addBodyDecl( 194 new MethodDecl( 195 new Modifiers(new List().add( 196 new Modifier("public")).add( 197 new Modifier("static")).add( 198 new Modifier("synthetic")) 199 ), 200 createQualifiedAccess(), 201 "valueOf", 202 new List().add( 203 new ParameterDeclaration( 204 new Modifiers(new List()), 205 typeString().createQualifiedAccess(), 206 "s" 207 ) 208 ), 209 new List(), 210 new Opt( 211 new Block( 212 new List().add( 213 new ReturnStmt( 214 new Opt( 215 new CastExpr( 216 createQualifiedAccess(), 217 lookupType("java.lang", "Enum").createQualifiedAccess().qualifiesAccess( 218 new MethodAccess( 219 "valueOf", 220 new List().add( 221 createQualifiedAccess().qualifiesAccess(new ClassAccess()) 222 ).add( 223 new VarAccess( 224 "s" 225 ) 226 ) 227 ) 228 ) 229 ) 230 ) 231 ) 232 ) 233 ) 234 ) 235 ) 236 ); 237 } 238 /** 239 * @ast method 240 * @aspect Enums 241 * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Enums.jrag:448 242 */ 243 protected void checkEnum(EnumDecl enumDecl) { 244 for(int i = 0; i < getNumBodyDecl(); i++) { 245 if(getBodyDecl(i) instanceof ConstructorDecl) 246 getBodyDecl(i).checkEnum(enumDecl); 247 else if(getBodyDecl(i) instanceof InstanceInitializer) 248 getBodyDecl(i).checkEnum(enumDecl); 249 else if(getBodyDecl(i) instanceof FieldDeclaration) { 250 FieldDeclaration f = (FieldDeclaration)getBodyDecl(i); 251 if(!f.isStatic() && f.hasInit()) 252 f.checkEnum(enumDecl); 253 } 254 } 255 } 256 /** 257 * @ast method 258 * @aspect Enums 259 * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Enums.jrag:527 260 */ 261 public void toString(StringBuffer s) { 262 getModifiers().toString(s); 263 s.append("enum " + name()); 264 if(getNumImplements() > 0) { 265 s.append(" implements "); 266 getImplements(0).toString(s); 267 for(int i = 1; i < getNumImplements(); i++) { 268 s.append(", "); 269 getImplements(i).toString(s); 270 } 271 } 272 s.append(" {"); 273 for(int i=0; i < getNumBodyDecl(); i++) { 274 BodyDecl d = getBodyDecl(i); 275 if(d instanceof EnumConstant) { 276 d.toString(s); 277 if(i + 1 < getNumBodyDecl() && !(getBodyDecl(i + 1) instanceof EnumConstant)) 278 s.append(indent() + ";"); 279 } 280 else if(d instanceof ConstructorDecl) { 281 ConstructorDecl c = (ConstructorDecl)d; 282 if(!c.isSynthetic()) { 283 s.append(indent()); 284 c.getModifiers().toString(s); 285 s.append(c.name() + "("); 286 if(c.getNumParameter() > 2) { 287 c.getParameter(2).toString(s); 288 for(int j = 3; j < c.getNumParameter(); j++) { 289 s.append(", "); 290 c.getParameter(j).toString(s); 291 } 292 } 293 s.append(")"); 294 if(c.getNumException() > 0) { 295 s.append(" throws "); 296 c.getException(0).toString(s); 297 for(int j = 1; j < c.getNumException(); j++) { 298 s.append(", "); 299 c.getException(j).toString(s); 300 } 301 } 302 s.append(" {"); 303 for(int j = 0; j < c.getBlock().getNumStmt(); j++) { 304 c.getBlock().getStmt(j).toString(s); 305 } 306 s.append(indent()); 307 s.append("}"); 308 } 309 } 310 else if(d instanceof MethodDecl) { 311 MethodDecl m = (MethodDecl)d; 312 if(!m.isSynthetic()) 313 m.toString(s); 314 } 315 else if(d instanceof FieldDeclaration) { 316 FieldDeclaration f = (FieldDeclaration)d; 317 if(!f.isSynthetic()) 318 f.toString(s); 319 } 320 else 321 d.toString(s); 322 } 323 s.append(indent() + "}"); 324 } 325 /** 326 * Check that the enum does not contain unimplemented abstract methods. 327 * @ast method 328 * @aspect Enums 329 * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Enums.jrag:675 330 */ 331 public void checkModifiers() { 332 super.checkModifiers(); 333 if (!unimplementedMethods().isEmpty()) { 334 StringBuffer s = new StringBuffer(); 335 s.append("" + name() + " lacks implementations in one or more " + 336 "enum constants for the following methods:\n"); 337 for (Iterator iter = unimplementedMethods().iterator(); iter.hasNext(); ) { 338 MethodDecl m = (MethodDecl)iter.next(); 339 s.append(" " + m.signature() + " in " + m.hostType().typeName() + "\n"); 340 } 341 error(s.toString()); 342 } 343 } 344 /** 345 * @ast method 346 * 347 */ 348 public EnumDecl() { 349 super(); 350 351 352 } 353 /** 354 * Initializes the child array to the correct size. 355 * Initializes List and Opt nta children. 356 * @apilevel internal 357 * @ast method 358 * @ast method 359 * 360 */ 361 public void init$Children() { 362 children = new ASTNode[4]; 363 setChild(new List(), 1); 364 setChild(new List(), 2); 365 setChild(new Opt(), 3); 366 } 367 /** 368 * @ast method 369 * 370 */ 371 public EnumDecl(Modifiers p0, String p1, List<Access> p2, List<BodyDecl> p3) { 372 setChild(p0, 0); 373 setID(p1); 374 setChild(p2, 1); 375 setChild(p3, 2); 376 } 377 /** 378 * @ast method 379 * 380 */ 381 public EnumDecl(Modifiers p0, beaver.Symbol p1, List<Access> p2, List<BodyDecl> p3) { 382 setChild(p0, 0); 383 setID(p1); 384 setChild(p2, 1); 385 setChild(p3, 2); 386 } 387 /** 388 * @apilevel low-level 389 * @ast method 390 * 391 */ 392 protected int numChildren() { 393 return 3; 394 } 395 /** 396 * @apilevel internal 397 * @ast method 398 * 399 */ 400 public boolean mayHaveRewrite() { 401 return true; 402 } 403 /** 404 * Replaces the Modifiers child. 405 * @param node The new node to replace the Modifiers child. 406 * @apilevel high-level 407 * @ast method 408 * 409 */ 410 public void setModifiers(Modifiers node) { 411 setChild(node, 0); 412 } 413 /** 414 * Retrieves the Modifiers child. 415 * @return The current node used as the Modifiers child. 416 * @apilevel high-level 417 * @ast method 418 * 419 */ 420 public Modifiers getModifiers() { 421 return (Modifiers)getChild(0); 422 } 423 /** 424 * Retrieves the Modifiers child. 425 * <p><em>This method does not invoke AST transformations.</em></p> 426 * @return The current node used as the Modifiers child. 427 * @apilevel low-level 428 * @ast method 429 * 430 */ 431 public Modifiers getModifiersNoTransform() { 432 return (Modifiers)getChildNoTransform(0); 433 } 434 /** 435 * Replaces the lexeme ID. 436 * @param value The new value for the lexeme ID. 437 * @apilevel high-level 438 * @ast method 439 * 440 */ 441 public void setID(String value) { 442 tokenString_ID = value; 443 } 444 /** 445 * JastAdd-internal setter for lexeme ID using the Beaver parser. 446 * @apilevel internal 447 * @ast method 448 * 449 */ 450 public void setID(beaver.Symbol symbol) { 451 if(symbol.value != null && !(symbol.value instanceof String)) 452 throw new UnsupportedOperationException("setID is only valid for String lexemes"); 453 tokenString_ID = (String)symbol.value; 454 IDstart = symbol.getStart(); 455 IDend = symbol.getEnd(); 456 } 457 /** 458 * Retrieves the value for the lexeme ID. 459 * @return The value for the lexeme ID. 460 * @apilevel high-level 461 * @ast method 462 * 463 */ 464 public String getID() { 465 return tokenString_ID != null ? tokenString_ID : ""; 466 } 467 /** 468 * Replaces the Implements list. 469 * @param list The new list node to be used as the Implements list. 470 * @apilevel high-level 471 * @ast method 472 * 473 */ 474 public void setImplementsList(List<Access> list) { 475 setChild(list, 1); 476 } 477 /** 478 * Retrieves the number of children in the Implements list. 479 * @return Number of children in the Implements list. 480 * @apilevel high-level 481 * @ast method 482 * 483 */ 484 public int getNumImplements() { 485 return getImplementsList().getNumChild(); 486 } 487 /** 488 * Retrieves the number of children in the Implements list. 489 * Calling this method will not trigger rewrites.. 490 * @return Number of children in the Implements list. 491 * @apilevel low-level 492 * @ast method 493 * 494 */ 495 public int getNumImplementsNoTransform() { 496 return getImplementsListNoTransform().getNumChildNoTransform(); 497 } 498 /** 499 * Retrieves the element at index {@code i} in the Implements list.. 500 * @param i Index of the element to return. 501 * @return The element at position {@code i} in the Implements list. 502 * @apilevel high-level 503 * @ast method 504 * 505 */ 506 @SuppressWarnings({"unchecked", "cast"}) 507 public Access getImplements(int i) { 508 return (Access)getImplementsList().getChild(i); 509 } 510 /** 511 * Append an element to the Implements list. 512 * @param node The element to append to the Implements list. 513 * @apilevel high-level 514 * @ast method 515 * 516 */ 517 public void addImplements(Access node) { 518 List<Access> list = (parent == null || state == null) ? getImplementsListNoTransform() : getImplementsList(); 519 list.addChild(node); 520 } 521 /** 522 * @apilevel low-level 523 * @ast method 524 * 525 */ 526 public void addImplementsNoTransform(Access node) { 527 List<Access> list = getImplementsListNoTransform(); 528 list.addChild(node); 529 } 530 /** 531 * Replaces the Implements list element at index {@code i} with the new node {@code node}. 532 * @param node The new node to replace the old list element. 533 * @param i The list index of the node to be replaced. 534 * @apilevel high-level 535 * @ast method 536 * 537 */ 538 public void setImplements(Access node, int i) { 539 List<Access> list = getImplementsList(); 540 list.setChild(node, i); 541 } 542 /** 543 * Retrieves the Implements list. 544 * @return The node representing the Implements list. 545 * @apilevel high-level 546 * @ast method 547 * 548 */ 549 public List<Access> getImplementss() { 550 return getImplementsList(); 551 } 552 /** 553 * Retrieves the Implements list. 554 * <p><em>This method does not invoke AST transformations.</em></p> 555 * @return The node representing the Implements list. 556 * @apilevel low-level 557 * @ast method 558 * 559 */ 560 public List<Access> getImplementssNoTransform() { 561 return getImplementsListNoTransform(); 562 } 563 /** 564 * Retrieves the Implements list. 565 * @return The node representing the Implements list. 566 * @apilevel high-level 567 * @ast method 568 * 569 */ 570 @SuppressWarnings({"unchecked", "cast"}) 571 public List<Access> getImplementsList() { 572 List<Access> list = (List<Access>)getChild(1); 573 list.getNumChild(); 574 return list; 575 } 576 /** 577 * Retrieves the Implements list. 578 * <p><em>This method does not invoke AST transformations.</em></p> 579 * @return The node representing the Implements list. 580 * @apilevel low-level 581 * @ast method 582 * 583 */ 584 @SuppressWarnings({"unchecked", "cast"}) 585 public List<Access> getImplementsListNoTransform() { 586 return (List<Access>)getChildNoTransform(1); 587 } 588 /** 589 * Replaces the BodyDecl list. 590 * @param list The new list node to be used as the BodyDecl list. 591 * @apilevel high-level 592 * @ast method 593 * 594 */ 595 public void setBodyDeclList(List<BodyDecl> list) { 596 setChild(list, 2); 597 } 598 /** 599 * Retrieves the number of children in the BodyDecl list. 600 * @return Number of children in the BodyDecl list. 601 * @apilevel high-level 602 * @ast method 603 * 604 */ 605 public int getNumBodyDecl() { 606 return getBodyDeclList().getNumChild(); 607 } 608 /** 609 * Retrieves the number of children in the BodyDecl list. 610 * Calling this method will not trigger rewrites.. 611 * @return Number of children in the BodyDecl list. 612 * @apilevel low-level 613 * @ast method 614 * 615 */ 616 public int getNumBodyDeclNoTransform() { 617 return getBodyDeclListNoTransform().getNumChildNoTransform(); 618 } 619 /** 620 * Retrieves the element at index {@code i} in the BodyDecl list.. 621 * @param i Index of the element to return. 622 * @return The element at position {@code i} in the BodyDecl list. 623 * @apilevel high-level 624 * @ast method 625 * 626 */ 627 @SuppressWarnings({"unchecked", "cast"}) 628 public BodyDecl getBodyDecl(int i) { 629 return (BodyDecl)getBodyDeclList().getChild(i); 630 } 631 /** 632 * Append an element to the BodyDecl list. 633 * @param node The element to append to the BodyDecl list. 634 * @apilevel high-level 635 * @ast method 636 * 637 */ 638 public void addBodyDecl(BodyDecl node) { 639 List<BodyDecl> list = (parent == null || state == null) ? getBodyDeclListNoTransform() : getBodyDeclList(); 640 list.addChild(node); 641 } 642 /** 643 * @apilevel low-level 644 * @ast method 645 * 646 */ 647 public void addBodyDeclNoTransform(BodyDecl node) { 648 List<BodyDecl> list = getBodyDeclListNoTransform(); 649 list.addChild(node); 650 } 651 /** 652 * Replaces the BodyDecl list element at index {@code i} with the new node {@code node}. 653 * @param node The new node to replace the old list element. 654 * @param i The list index of the node to be replaced. 655 * @apilevel high-level 656 * @ast method 657 * 658 */ 659 public void setBodyDecl(BodyDecl node, int i) { 660 List<BodyDecl> list = getBodyDeclList(); 661 list.setChild(node, i); 662 } 663 /** 664 * Retrieves the BodyDecl list. 665 * @return The node representing the BodyDecl list. 666 * @apilevel high-level 667 * @ast method 668 * 669 */ 670 public List<BodyDecl> getBodyDecls() { 671 return getBodyDeclList(); 672 } 673 /** 674 * Retrieves the BodyDecl list. 675 * <p><em>This method does not invoke AST transformations.</em></p> 676 * @return The node representing the BodyDecl list. 677 * @apilevel low-level 678 * @ast method 679 * 680 */ 681 public List<BodyDecl> getBodyDeclsNoTransform() { 682 return getBodyDeclListNoTransform(); 683 } 684 /** 685 * Retrieves the BodyDecl list. 686 * @return The node representing the BodyDecl list. 687 * @apilevel high-level 688 * @ast method 689 * 690 */ 691 @SuppressWarnings({"unchecked", "cast"}) 692 public List<BodyDecl> getBodyDeclList() { 693 List<BodyDecl> list = (List<BodyDecl>)getChild(2); 694 list.getNumChild(); 695 return list; 696 } 697 /** 698 * Retrieves the BodyDecl list. 699 * <p><em>This method does not invoke AST transformations.</em></p> 700 * @return The node representing the BodyDecl list. 701 * @apilevel low-level 702 * @ast method 703 * 704 */ 705 @SuppressWarnings({"unchecked", "cast"}) 706 public List<BodyDecl> getBodyDeclListNoTransform() { 707 return (List<BodyDecl>)getChildNoTransform(2); 708 } 709 /** 710 * Replaces the optional node for the SuperClassAccess child. This is the {@code Opt} node containing the child SuperClassAccess, not the actual child! 711 * @param opt The new node to be used as the optional node for the SuperClassAccess child. 712 * @apilevel low-level 713 * @ast method 714 * 715 */ 716 public void setSuperClassAccessOpt(Opt<Access> opt) { 717 setChild(opt, 3); 718 } 719 /** 720 * Check whether the optional SuperClassAccess child exists. 721 * @return {@code true} if the optional SuperClassAccess child exists, {@code false} if it does not. 722 * @apilevel high-level 723 * @ast method 724 * 725 */ 726 public boolean hasSuperClassAccess() { 727 return getSuperClassAccessOpt().getNumChild() != 0; 728 } 729 /** 730 * Retrieves the (optional) SuperClassAccess child. 731 * @return The SuperClassAccess child, if it exists. Returns {@code null} otherwise. 732 * @apilevel low-level 733 * @ast method 734 * 735 */ 736 @SuppressWarnings({"unchecked", "cast"}) 737 public Access getSuperClassAccess() { 738 return (Access)getSuperClassAccessOpt().getChild(0); 739 } 740 /** 741 * Replaces the (optional) SuperClassAccess child. 742 * @param node The new node to be used as the SuperClassAccess child. 743 * @apilevel high-level 744 * @ast method 745 * 746 */ 747 public void setSuperClassAccess(Access node) { 748 getSuperClassAccessOpt().setChild(node, 0); 749 } 750 /** 751 * Retrieves the optional node for child SuperClassAccess. This is the {@code Opt} node containing the child SuperClassAccess, not the actual child! 752 * <p><em>This method does not invoke AST transformations.</em></p> 753 * @return The optional node for child SuperClassAccess. 754 * @apilevel low-level 755 * @ast method 756 * 757 */ 758 @SuppressWarnings({"unchecked", "cast"}) 759 public Opt<Access> getSuperClassAccessOptNoTransform() { 760 return (Opt<Access>)getChildNoTransform(3); 761 } 762 /** 763 * Retrieves the child position of the optional child SuperClassAccess. 764 * @return The the child position of the optional child SuperClassAccess. 765 * @apilevel low-level 766 * @ast method 767 * 768 */ 769 protected int getSuperClassAccessOptChildPosition() { 770 return 3; 771 } 772 /* It is a compile-time error if the return type of a method declared in an 773 annotation type is any type other than one of the following: one of the 774 primitive types, String, Class and any invocation of Class, an enum type 775 (\ufffd8.9), an annotation type, or an array (\ufffd10) of one of the preceding types.* @attribute syn 776 * @aspect Annotations 777 * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Annotations.jrag:121 778 */ 779 public boolean isValidAnnotationMethodReturnType() { 780 ASTNode$State state = state(); 781 try { return true; } 782 finally { 783 } 784 } 785 /* 786 1) It is a compile-time error to attempt to explicitly instantiate an enum type 787 (\ufffd15.9.1). 788 * @attribute syn 789 * @aspect Enums 790 * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Enums.jrag:16 791 */ 792 public boolean isEnumDecl() { 793 ASTNode$State state = state(); 794 try { return true; } 795 finally { 796 } 797 } 798 /** 799 * @apilevel internal 800 */ 801 protected boolean isStatic_computed = false; 802 /** 803 * @apilevel internal 804 */ 805 protected boolean isStatic_value; 806 /* 807 9) Nested enum types are implicitly static. It is permissable to explicitly 808 declare a nested enum type to be static. 809 * @attribute syn 810 * @aspect Enums 811 * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Enums.jrag:39 812 */ 813 @SuppressWarnings({"unchecked", "cast"}) 814 public boolean isStatic() { 815 if(isStatic_computed) { 816 return isStatic_value; 817 } 818 ASTNode$State state = state(); 819 int num = state.boundariesCrossed; 820 boolean isFinal = this.is$Final(); 821 isStatic_value = isStatic_compute(); 822 if(isFinal && num == state().boundariesCrossed){ isStatic_computed = true; } 823 return isStatic_value; 824 } 825 /** 826 * @apilevel internal 827 */ 828 private boolean isStatic_compute() { return isNestedType(); } 829 /** 830 * @apilevel internal 831 */ 832 protected boolean getSuperClassAccessOpt_computed = false; 833 /** 834 * @apilevel internal 835 */ 836 protected Opt getSuperClassAccessOpt_value; 837 /* 838 10) The direct superclass of an enum type named E is Enum<E>. 839 * @attribute syn nta 840 * @aspect Enums 841 * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Enums.jrag:60 842 */ 843 @SuppressWarnings({"unchecked", "cast"}) 844 public Opt getSuperClassAccessOpt() { 845 if(getSuperClassAccessOpt_computed) { 846 return (Opt) getChild(getSuperClassAccessOptChildPosition()); 847 } 848 ASTNode$State state = state(); 849 int num = state.boundariesCrossed; 850 boolean isFinal = this.is$Final(); 851 getSuperClassAccessOpt_value = getSuperClassAccessOpt_compute(); 852 setSuperClassAccessOpt(getSuperClassAccessOpt_value); 853 if(isFinal && num == state().boundariesCrossed){ getSuperClassAccessOpt_computed = true; } 854 Opt node = (Opt) this.getChild(getSuperClassAccessOptChildPosition()); 855 return node; 856 } 857 /** 858 * @apilevel internal 859 */ 860 private Opt getSuperClassAccessOpt_compute() { 861 return new Opt( 862 new ParTypeAccess( 863 new TypeAccess( 864 "java.lang", 865 "Enum" 866 ), 867 new List().add(createQualifiedAccess()) 868 ) 869 ); 870 } 871 /** 872 * @attribute syn 873 * @aspect Modifiers 874 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/Modifiers.jrag:209 875 */ 876 public boolean isFinal() { 877 ASTNode$State state = state(); 878 try { 879 for(Iterator iter = enumConstants().iterator(); iter.hasNext(); ) { 880 EnumConstant c = (EnumConstant)iter.next(); 881 ClassInstanceExpr e = (ClassInstanceExpr)c.getInit(); 882 if(e.hasTypeDecl()) 883 return false; 884 } 885 return true; 886 } 887 finally { 888 } 889 } 890 /** 891 * @apilevel internal 892 */ 893 protected boolean enumConstants_computed = false; 894 /** 895 * @apilevel internal 896 */ 897 protected ArrayList enumConstants_value; 898 /** 899 * @attribute syn 900 * @aspect Enums 901 * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Enums.jrag:294 902 */ 903 @SuppressWarnings({"unchecked", "cast"}) 904 public ArrayList enumConstants() { 905 if(enumConstants_computed) { 906 return enumConstants_value; 907 } 908 ASTNode$State state = state(); 909 int num = state.boundariesCrossed; 910 boolean isFinal = this.is$Final(); 911 enumConstants_value = enumConstants_compute(); 912 if(isFinal && num == state().boundariesCrossed){ enumConstants_computed = true; } 913 return enumConstants_value; 914 } 915 /** 916 * @apilevel internal 917 */ 918 private ArrayList enumConstants_compute() { 919 ArrayList list = new ArrayList(); 920 for(int i = 0; i < getNumBodyDecl(); i++) 921 if(getBodyDecl(i).isEnumConstant()) 922 list.add(getBodyDecl(i)); 923 return list; 924 } 925 /** 926 * @attribute syn 927 * @aspect Modifiers 928 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/Modifiers.jrag:204 929 */ 930 public boolean isAbstract() { 931 ASTNode$State state = state(); 932 try { 933 for (int i = 0; i < getNumBodyDecl(); i++) { 934 if (getBodyDecl(i) instanceof MethodDecl) { 935 MethodDecl m = (MethodDecl)getBodyDecl(i); 936 if (m.isAbstract()) 937 return true; 938 } 939 } 940 return false; 941 } 942 finally { 943 } 944 } 945 /** 946 * @apilevel internal 947 */ 948 protected boolean unimplementedMethods_computed = false; 949 /** 950 * @apilevel internal 951 */ 952 protected Collection unimplementedMethods_value; 953 /** 954 * From the Java Language Specification, third edition, section 8.9 Enums: 955 * 956 * It is a compile-time error for an enum type E to have an abstract method 957 * m as a member unless E has one or more enum constants, and all of E's enum 958 * constants have class bodies that provide concrete implementations of m. 959 * @attribute syn 960 * @aspect Enums 961 * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Enums.jrag:623 962 */ 963 @SuppressWarnings({"unchecked", "cast"}) 964 public Collection unimplementedMethods() { 965 if(unimplementedMethods_computed) { 966 return unimplementedMethods_value; 967 } 968 ASTNode$State state = state(); 969 int num = state.boundariesCrossed; 970 boolean isFinal = this.is$Final(); 971 unimplementedMethods_value = unimplementedMethods_compute(); 972 if(isFinal && num == state().boundariesCrossed){ unimplementedMethods_computed = true; } 973 return unimplementedMethods_value; 974 } 975 /** 976 * @apilevel internal 977 */ 978 private Collection unimplementedMethods_compute() { 979 Collection<MethodDecl> methods = new LinkedList<MethodDecl>(); 980 for (Iterator iter = interfacesMethodsIterator(); iter.hasNext(); ) { 981 MethodDecl method = (MethodDecl)iter.next(); 982 SimpleSet set = (SimpleSet)localMethodsSignature(method.signature()); 983 if (set.size() == 1) { 984 MethodDecl n = (MethodDecl)set.iterator().next(); 985 if (!n.isAbstract()) 986 continue; 987 } 988 boolean implemented = false; 989 set = (SimpleSet)ancestorMethods(method.signature()); 990 for (Iterator i2 = set.iterator(); i2.hasNext(); ) { 991 MethodDecl n = (MethodDecl)i2.next(); 992 if (!n.isAbstract()) { 993 implemented = true; 994 break; 995 } 996 } 997 if (!implemented) 998 methods.add(method); 999 } 1000 1001 for (Iterator iter = localMethodsIterator(); iter.hasNext(); ) { 1002 MethodDecl method = (MethodDecl)iter.next(); 1003 if (method.isAbstract()) 1004 methods.add(method); 1005 } 1006 1007 Collection unimplemented = new ArrayList(); 1008 for (MethodDecl method : methods) { 1009 if (enumConstants().isEmpty()) { 1010 unimplemented.add(method); 1011 continue; 1012 } 1013 boolean missing = false; 1014 for (Iterator iter = enumConstants().iterator(); iter.hasNext(); ) { 1015 if (!((EnumConstant) iter.next()).implementsMethod(method)) { 1016 missing = true; 1017 break; 1018 } 1019 } 1020 if (missing) 1021 unimplemented.add(method); 1022 } 1023 1024 return unimplemented; 1025 } 1026 /** 1027 * @apilevel internal 1028 */ 1029 protected boolean flags_computed = false; 1030 /** 1031 * @apilevel internal 1032 */ 1033 protected int flags_value; 1034 /** 1035 * @attribute syn 1036 * @aspect EnumsCodegen 1037 * @declaredat /home/jesper/svn/JastAddJ/Java1.5Backend/EnumsCodegen.jrag:13 1038 */ 1039 @SuppressWarnings({"unchecked", "cast"}) 1040 public int flags() { 1041 if(flags_computed) { 1042 return flags_value; 1043 } 1044 ASTNode$State state = state(); 1045 int num = state.boundariesCrossed; 1046 boolean isFinal = this.is$Final(); 1047 flags_value = flags_compute(); 1048 if(isFinal && num == state().boundariesCrossed){ flags_computed = true; } 1049 return flags_value; 1050 } 1051 /** 1052 * @apilevel internal 1053 */ 1054 private int flags_compute() { return super.flags() | Modifiers.ACC_ENUM; } 1055 /** 1056 * @attribute inh 1057 * @aspect Enums 1058 * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Enums.jrag:421 1059 */ 1060 @SuppressWarnings({"unchecked", "cast"}) 1061 public TypeDecl typeString() { 1062 ASTNode$State state = state(); 1063 TypeDecl typeString_value = getParent().Define_TypeDecl_typeString(this, null); 1064 return typeString_value; 1065 } 1066 /** 1067 * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Enums.jrag:33 1068 * @apilevel internal 1069 */ 1070 public boolean Define_boolean_mayBeAbstract(ASTNode caller, ASTNode child) { 1071 if(caller == getModifiersNoTransform()) { 1072 return false; 1073 } 1074 else { return super.Define_boolean_mayBeAbstract(caller, child); 1075 } 1076 } 1077 /** 1078 * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Enums.jrag:40 1079 * @apilevel internal 1080 */ 1081 public boolean Define_boolean_mayBeStatic(ASTNode caller, ASTNode child) { 1082 if(caller == getModifiersNoTransform()) { 1083 return isNestedType(); 1084 } 1085 else { return super.Define_boolean_mayBeStatic(caller, child); 1086 } 1087 } 1088 /** 1089 * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Enums.jrag:292 1090 * @apilevel internal 1091 */ 1092 public boolean Define_boolean_mayBeFinal(ASTNode caller, ASTNode child) { 1093 if(caller == getModifiersNoTransform()) { 1094 return false; 1095 } 1096 else { return super.Define_boolean_mayBeFinal(caller, child); 1097 } 1098 } 1099 /** 1100 * @apilevel internal 1101 */ 1102 public ASTNode rewriteTo() { 1103 // Declared in /home/jesper/svn/JastAddJ/Java1.5Frontend/Enums.jrag at line 88 1104 if(!done()) { 1105 state().duringEnums++; 1106 ASTNode result = rewriteRule0(); 1107 state().duringEnums--; 1108 return result; 1109 } 1110 1111 return super.rewriteTo(); 1112 } 1113 /** 1114 * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Enums.jrag:88 1115 * @apilevel internal 1116 */ private EnumDecl rewriteRule0() { 1117 { 1118 if(noConstructor()) { 1119 List parameterList = new List(); 1120 parameterList.add( 1121 new ParameterDeclaration(new TypeAccess("java.lang", "String"), "p0") 1122 ); 1123 parameterList.add( 1124 new ParameterDeclaration(new TypeAccess("int"), "p1") 1125 ); 1126 addBodyDecl( 1127 new ConstructorDecl( 1128 new Modifiers(new List().add( 1129 new Modifier("private")).add( 1130 new Modifier("synthetic")) 1131 ), 1132 name(), 1133 parameterList, 1134 new List(), 1135 new Opt( 1136 new ExprStmt( 1137 new SuperConstructorAccess( 1138 "super", 1139 new List().add( 1140 new VarAccess("p0") 1141 ).add( 1142 new VarAccess("p1") 1143 ) 1144 ) 1145 ) 1146 ), 1147 new Block(new List()) 1148 ) 1149 ); 1150 } 1151 else { 1152 transformEnumConstructors(); 1153 } 1154 addValues(); // Add the values() and getValue(String s) methods 1155 return this; 1156 } } 1157 }