001 /* This file was generated with JastAdd2 (http://jastadd.org) version 2.1.13-12-g880e696 */ 002 package org.extendj.ast; 003 004 import java.util.HashSet; 005 import java.io.File; 006 import java.util.Set; 007 import java.util.Collections; 008 import java.util.Collection; 009 import java.util.ArrayList; 010 import beaver.*; 011 import java.util.*; 012 import java.io.ByteArrayOutputStream; 013 import java.io.PrintStream; 014 import java.lang.reflect.InvocationTargetException; 015 import java.lang.reflect.Method; 016 import org.jastadd.util.*; 017 import java.util.zip.*; 018 import java.io.*; 019 import org.jastadd.util.PrettyPrintable; 020 import org.jastadd.util.PrettyPrinter; 021 import java.io.FileNotFoundException; 022 import java.io.BufferedInputStream; 023 import java.io.DataInputStream; 024 /** 025 * @ast node 026 * @declaredat /home/jesper/git/extendj/java5/grammar/Annotations.ast:2 027 * @production AnnotationDecl : {@link InterfaceDecl} ::= <span class="component">SuperInterface:{@link Access}*</span>; 028 029 */ 030 public class AnnotationDecl extends InterfaceDecl implements Cloneable { 031 /** 032 * @aspect Annotations 033 * @declaredat /home/jesper/git/extendj/java5/frontend/Annotations.jrag:130 034 */ 035 public void typeCheck() { 036 super.typeCheck(); 037 for (int i = 0; i < getNumBodyDecl(); i++) { 038 if (getBodyDecl(i) instanceof MethodDecl) { 039 MethodDecl m = (MethodDecl) getBodyDecl(i); 040 if (!m.type().isValidAnnotationMethodReturnType()) { 041 m.error("invalid type for annotation member"); 042 } 043 if (m.annotationMethodOverride()) { 044 m.errorf("annotation method overrides %s", m.signature()); 045 } 046 } 047 } 048 if (containsElementOf(this)) { 049 error("cyclic annotation element type"); 050 } 051 } 052 /** 053 * @aspect Java5PrettyPrint 054 * @declaredat /home/jesper/git/extendj/java5/frontend/PrettyPrint.jadd:292 055 */ 056 public void prettyPrint(PrettyPrinter out) { 057 out.print(getModifiers()); 058 out.print("@interface "); 059 out.print(getID()); 060 out.print(" {"); 061 out.println(); 062 out.indent(1); 063 out.join(getBodyDecls(), new PrettyPrinter.Joiner() { 064 @Override 065 public void printSeparator(PrettyPrinter out) { 066 out.println(); 067 out.println(); 068 } 069 }); 070 if (!out.isNewLine()) { 071 out.println(); 072 } 073 out.print("}"); 074 } 075 /** 076 * @declaredat ASTNode:1 077 */ 078 public AnnotationDecl() { 079 super(); 080 } 081 /** 082 * Initializes the child array to the correct size. 083 * Initializes List and Opt nta children. 084 * @apilevel internal 085 * @ast method 086 * @declaredat ASTNode:10 087 */ 088 public void init$Children() { 089 children = new ASTNode[3]; 090 setChild(new List(), 1); 091 setChild(new List(), 2); 092 } 093 /** 094 * @declaredat ASTNode:15 095 */ 096 public AnnotationDecl(Modifiers p0, String p1, List<BodyDecl> p2) { 097 setChild(p0, 0); 098 setID(p1); 099 setChild(p2, 1); 100 } 101 /** 102 * @declaredat ASTNode:20 103 */ 104 public AnnotationDecl(Modifiers p0, beaver.Symbol p1, List<BodyDecl> p2) { 105 setChild(p0, 0); 106 setID(p1); 107 setChild(p2, 1); 108 } 109 /** 110 * @apilevel low-level 111 * @declaredat ASTNode:28 112 */ 113 protected int numChildren() { 114 return 2; 115 } 116 /** 117 * @apilevel internal 118 * @declaredat ASTNode:34 119 */ 120 public boolean mayHaveRewrite() { 121 return false; 122 } 123 /** 124 * @apilevel internal 125 * @declaredat ASTNode:40 126 */ 127 public void flushAttrCache() { 128 super.flushAttrCache(); 129 getSuperInterfaceList_reset(); 130 containsElementOf_TypeDecl_reset(); 131 flags_reset(); 132 } 133 /** 134 * @apilevel internal 135 * @declaredat ASTNode:49 136 */ 137 public void flushCollectionCache() { 138 super.flushCollectionCache(); 139 } 140 /** 141 * @apilevel internal 142 * @declaredat ASTNode:55 143 */ 144 public void flushRewriteCache() { 145 super.flushRewriteCache(); 146 } 147 /** 148 * @apilevel internal 149 * @declaredat ASTNode:61 150 */ 151 public AnnotationDecl clone() throws CloneNotSupportedException { 152 AnnotationDecl node = (AnnotationDecl) super.clone(); 153 return node; 154 } 155 /** 156 * @apilevel internal 157 * @declaredat ASTNode:68 158 */ 159 public AnnotationDecl copy() { 160 try { 161 AnnotationDecl node = (AnnotationDecl) clone(); 162 node.parent = null; 163 if (children != null) { 164 node.children = (ASTNode[]) children.clone(); 165 } 166 return node; 167 } catch (CloneNotSupportedException e) { 168 throw new Error("Error: clone not supported for " + getClass().getName()); 169 } 170 } 171 /** 172 * Create a deep copy of the AST subtree at this node. 173 * The copy is dangling, i.e. has no parent. 174 * @return dangling copy of the subtree at this node 175 * @apilevel low-level 176 * @deprecated Please use treeCopy or treeCopyNoTransform instead 177 * @declaredat ASTNode:87 178 */ 179 @Deprecated 180 public AnnotationDecl fullCopy() { 181 return treeCopyNoTransform(); 182 } 183 /** 184 * Create a deep copy of the AST subtree at this node. 185 * The copy is dangling, i.e. has no parent. 186 * @return dangling copy of the subtree at this node 187 * @apilevel low-level 188 * @declaredat ASTNode:97 189 */ 190 public AnnotationDecl treeCopyNoTransform() { 191 AnnotationDecl tree = (AnnotationDecl) copy(); 192 if (children != null) { 193 for (int i = 0; i < children.length; ++i) { 194 switch (i) { 195 case 2: 196 tree.children[i] = new List(); 197 continue; 198 } 199 ASTNode child = (ASTNode) children[i]; 200 if (child != null) { 201 child = child.treeCopyNoTransform(); 202 tree.setChild(child, i); 203 } 204 } 205 } 206 return tree; 207 } 208 /** 209 * Create a deep copy of the AST subtree at this node. 210 * The subtree of this node is traversed to trigger rewrites before copy. 211 * The copy is dangling, i.e. has no parent. 212 * @return dangling copy of the subtree at this node 213 * @apilevel low-level 214 * @declaredat ASTNode:122 215 */ 216 public AnnotationDecl treeCopy() { 217 doFullTraversal(); 218 return treeCopyNoTransform(); 219 } 220 /** 221 * @apilevel internal 222 * @declaredat ASTNode:129 223 */ 224 protected boolean is$Equal(ASTNode node) { 225 return super.is$Equal(node) && (tokenString_ID == ((AnnotationDecl)node).tokenString_ID); 226 } 227 /** 228 * Replaces the Modifiers child. 229 * @param node The new node to replace the Modifiers child. 230 * @apilevel high-level 231 */ 232 public void setModifiers(Modifiers node) { 233 setChild(node, 0); 234 } 235 /** 236 * Retrieves the Modifiers child. 237 * @return The current node used as the Modifiers child. 238 * @apilevel high-level 239 */ 240 @ASTNodeAnnotation.Child(name="Modifiers") 241 public Modifiers getModifiers() { 242 return (Modifiers) getChild(0); 243 } 244 /** 245 * Retrieves the Modifiers child. 246 * <p><em>This method does not invoke AST transformations.</em></p> 247 * @return The current node used as the Modifiers child. 248 * @apilevel low-level 249 */ 250 public Modifiers getModifiersNoTransform() { 251 return (Modifiers) getChildNoTransform(0); 252 } 253 /** 254 * Replaces the lexeme ID. 255 * @param value The new value for the lexeme ID. 256 * @apilevel high-level 257 */ 258 public void setID(String value) { 259 tokenString_ID = value; 260 } 261 /** 262 * JastAdd-internal setter for lexeme ID using the Beaver parser. 263 * @param symbol Symbol containing the new value for the lexeme ID 264 * @apilevel internal 265 */ 266 public void setID(beaver.Symbol symbol) { 267 if (symbol.value != null && !(symbol.value instanceof String)) 268 throw new UnsupportedOperationException("setID is only valid for String lexemes"); 269 tokenString_ID = (String)symbol.value; 270 IDstart = symbol.getStart(); 271 IDend = symbol.getEnd(); 272 } 273 /** 274 * Retrieves the value for the lexeme ID. 275 * @return The value for the lexeme ID. 276 * @apilevel high-level 277 */ 278 @ASTNodeAnnotation.Token(name="ID") 279 public String getID() { 280 return tokenString_ID != null ? tokenString_ID : ""; 281 } 282 /** 283 * Replaces the BodyDecl list. 284 * @param list The new list node to be used as the BodyDecl list. 285 * @apilevel high-level 286 */ 287 public void setBodyDeclList(List<BodyDecl> list) { 288 setChild(list, 1); 289 } 290 /** 291 * Retrieves the number of children in the BodyDecl list. 292 * @return Number of children in the BodyDecl list. 293 * @apilevel high-level 294 */ 295 public int getNumBodyDecl() { 296 return getBodyDeclList().getNumChild(); 297 } 298 /** 299 * Retrieves the number of children in the BodyDecl list. 300 * Calling this method will not trigger rewrites. 301 * @return Number of children in the BodyDecl list. 302 * @apilevel low-level 303 */ 304 public int getNumBodyDeclNoTransform() { 305 return getBodyDeclListNoTransform().getNumChildNoTransform(); 306 } 307 /** 308 * Retrieves the element at index {@code i} in the BodyDecl list. 309 * @param i Index of the element to return. 310 * @return The element at position {@code i} in the BodyDecl list. 311 * @apilevel high-level 312 */ 313 public BodyDecl getBodyDecl(int i) { 314 return (BodyDecl) getBodyDeclList().getChild(i); 315 } 316 /** 317 * Check whether the BodyDecl list has any children. 318 * @return {@code true} if it has at least one child, {@code false} otherwise. 319 * @apilevel high-level 320 */ 321 public boolean hasBodyDecl() { 322 return getBodyDeclList().getNumChild() != 0; 323 } 324 /** 325 * Append an element to the BodyDecl list. 326 * @param node The element to append to the BodyDecl list. 327 * @apilevel high-level 328 */ 329 public void addBodyDecl(BodyDecl node) { 330 List<BodyDecl> list = (parent == null) ? getBodyDeclListNoTransform() : getBodyDeclList(); 331 list.addChild(node); 332 } 333 /** 334 * @apilevel low-level 335 */ 336 public void addBodyDeclNoTransform(BodyDecl node) { 337 List<BodyDecl> list = getBodyDeclListNoTransform(); 338 list.addChild(node); 339 } 340 /** 341 * Replaces the BodyDecl list element at index {@code i} with the new node {@code node}. 342 * @param node The new node to replace the old list element. 343 * @param i The list index of the node to be replaced. 344 * @apilevel high-level 345 */ 346 public void setBodyDecl(BodyDecl node, int i) { 347 List<BodyDecl> list = getBodyDeclList(); 348 list.setChild(node, i); 349 } 350 /** 351 * Retrieves the BodyDecl list. 352 * @return The node representing the BodyDecl list. 353 * @apilevel high-level 354 */ 355 @ASTNodeAnnotation.ListChild(name="BodyDecl") 356 public List<BodyDecl> getBodyDeclList() { 357 List<BodyDecl> list = (List<BodyDecl>) getChild(1); 358 return list; 359 } 360 /** 361 * Retrieves the BodyDecl list. 362 * <p><em>This method does not invoke AST transformations.</em></p> 363 * @return The node representing the BodyDecl list. 364 * @apilevel low-level 365 */ 366 public List<BodyDecl> getBodyDeclListNoTransform() { 367 return (List<BodyDecl>) getChildNoTransform(1); 368 } 369 /** 370 * Retrieves the BodyDecl list. 371 * @return The node representing the BodyDecl list. 372 * @apilevel high-level 373 */ 374 public List<BodyDecl> getBodyDecls() { 375 return getBodyDeclList(); 376 } 377 /** 378 * Retrieves the BodyDecl list. 379 * <p><em>This method does not invoke AST transformations.</em></p> 380 * @return The node representing the BodyDecl list. 381 * @apilevel low-level 382 */ 383 public List<BodyDecl> getBodyDeclsNoTransform() { 384 return getBodyDeclListNoTransform(); 385 } 386 /** 387 * This method should not be called. This method throws an exception due to 388 * the corresponding child being an NTA shadowing a non-NTA child. 389 * @param node 390 * @apilevel internal 391 */ 392 public void setSuperInterfaceList(List<Access> node) { 393 throw new Error("Can not replace NTA child SuperInterfaceList in AnnotationDecl!"); 394 } 395 /** 396 * Retrieves the number of children in the SuperInterface list. 397 * @return Number of children in the SuperInterface list. 398 * @apilevel high-level 399 */ 400 public int getNumSuperInterface() { 401 return getSuperInterfaceList().getNumChild(); 402 } 403 /** 404 * Retrieves the number of children in the SuperInterface list. 405 * Calling this method will not trigger rewrites. 406 * @return Number of children in the SuperInterface list. 407 * @apilevel low-level 408 */ 409 public int getNumSuperInterfaceNoTransform() { 410 return getSuperInterfaceListNoTransform().getNumChildNoTransform(); 411 } 412 /** 413 * Retrieves the element at index {@code i} in the SuperInterface list. 414 * @param i Index of the element to return. 415 * @return The element at position {@code i} in the SuperInterface list. 416 * @apilevel high-level 417 */ 418 public Access getSuperInterface(int i) { 419 return (Access) getSuperInterfaceList().getChild(i); 420 } 421 /** 422 * Check whether the SuperInterface list has any children. 423 * @return {@code true} if it has at least one child, {@code false} otherwise. 424 * @apilevel high-level 425 */ 426 public boolean hasSuperInterface() { 427 return getSuperInterfaceList().getNumChild() != 0; 428 } 429 /** 430 * Append an element to the SuperInterface list. 431 * @param node The element to append to the SuperInterface list. 432 * @apilevel high-level 433 */ 434 public void addSuperInterface(Access node) { 435 List<Access> list = (parent == null) ? getSuperInterfaceListNoTransform() : getSuperInterfaceList(); 436 list.addChild(node); 437 } 438 /** 439 * @apilevel low-level 440 */ 441 public void addSuperInterfaceNoTransform(Access node) { 442 List<Access> list = getSuperInterfaceListNoTransform(); 443 list.addChild(node); 444 } 445 /** 446 * Replaces the SuperInterface list element at index {@code i} with the new node {@code node}. 447 * @param node The new node to replace the old list element. 448 * @param i The list index of the node to be replaced. 449 * @apilevel high-level 450 */ 451 public void setSuperInterface(Access node, int i) { 452 List<Access> list = getSuperInterfaceList(); 453 list.setChild(node, i); 454 } 455 /** 456 * Retrieves the child position of the SuperInterface list. 457 * @return The the child position of the SuperInterface list. 458 * @apilevel low-level 459 */ 460 protected int getSuperInterfaceListChildPosition() { 461 return 2; 462 } 463 /** 464 * Retrieves the SuperInterface list. 465 * <p><em>This method does not invoke AST transformations.</em></p> 466 * @return The node representing the SuperInterface list. 467 * @apilevel low-level 468 */ 469 public List<Access> getSuperInterfaceListNoTransform() { 470 return (List<Access>) getChildNoTransform(2); 471 } 472 /** 473 * Retrieves the SuperInterface list. 474 * @return The node representing the SuperInterface list. 475 * @apilevel high-level 476 */ 477 public List<Access> getSuperInterfaces() { 478 return getSuperInterfaceList(); 479 } 480 /** 481 * Retrieves the SuperInterface list. 482 * <p><em>This method does not invoke AST transformations.</em></p> 483 * @return The node representing the SuperInterface list. 484 * @apilevel low-level 485 */ 486 public List<Access> getSuperInterfacesNoTransform() { 487 return getSuperInterfaceListNoTransform(); 488 } 489 /** 490 * @apilevel internal 491 */ 492 protected boolean getSuperInterfaceList_computed = false; 493 /** 494 * @apilevel internal 495 */ 496 protected List getSuperInterfaceList_value; 497 /** 498 * @apilevel internal 499 */ 500 private void getSuperInterfaceList_reset() { 501 getSuperInterfaceList_computed = false; 502 getSuperInterfaceList_value = null; 503 } 504 /** 505 * @attribute syn nta 506 * @aspect Annotations 507 * @declaredat /home/jesper/git/extendj/java5/frontend/Annotations.jrag:126 508 */ 509 @ASTNodeAnnotation.Attribute 510 public List getSuperInterfaceList() { 511 ASTNode$State state = state(); 512 if (getSuperInterfaceList_computed) { 513 return (List) getChild(getSuperInterfaceListChildPosition()); 514 } 515 boolean intermediate = state.INTERMEDIATE_VALUE; 516 state.INTERMEDIATE_VALUE = false; 517 int num = state.boundariesCrossed; 518 boolean isFinal = this.is$Final(); 519 getSuperInterfaceList_value = getSuperInterfaceList_compute(); 520 setChild(getSuperInterfaceList_value, getSuperInterfaceListChildPosition()); 521 if (isFinal && num == state().boundariesCrossed) { 522 getSuperInterfaceList_computed = true; 523 } else { 524 } 525 state.INTERMEDIATE_VALUE |= intermediate; 526 527 List node = (List) this.getChild(getSuperInterfaceListChildPosition()); 528 return node; 529 } 530 /** 531 * @apilevel internal 532 */ 533 private List getSuperInterfaceList_compute() { 534 return new List().add(new TypeAccess("java.lang.annotation", "Annotation")); 535 } 536 /** 537 * @attribute syn 538 * @aspect Annotations 539 * @declaredat /home/jesper/git/extendj/java5/frontend/Annotations.jrag:151 540 */ 541 @ASTNodeAnnotation.Attribute 542 public boolean isValidAnnotationMethodReturnType() { 543 boolean isValidAnnotationMethodReturnType_value = true; 544 545 return isValidAnnotationMethodReturnType_value; 546 } 547 /** 548 * @apilevel internal 549 */ 550 private void containsElementOf_TypeDecl_reset() { 551 containsElementOf_TypeDecl_values = null; 552 } 553 protected java.util.Map containsElementOf_TypeDecl_values; 554 @ASTNodeAnnotation.Attribute 555 public boolean containsElementOf(TypeDecl typeDecl) { 556 Object _parameters = typeDecl; 557 if (containsElementOf_TypeDecl_values == null) containsElementOf_TypeDecl_values = new org.jastadd.util.RobustMap(new java.util.HashMap()); 558 ASTNode$State.CircularValue _value; 559 if (containsElementOf_TypeDecl_values.containsKey(_parameters)) { 560 Object _o = containsElementOf_TypeDecl_values.get(_parameters); 561 if (!(_o instanceof ASTNode$State.CircularValue)) { 562 return (Boolean) _o; 563 } else { 564 _value = (ASTNode$State.CircularValue) _o; 565 } 566 } else { 567 _value = new ASTNode$State.CircularValue(); 568 containsElementOf_TypeDecl_values.put(_parameters, _value); 569 _value.value = false; 570 } 571 ASTNode$State state = state(); 572 boolean new_containsElementOf_TypeDecl_value; 573 if (!state.IN_CIRCLE) { 574 state.IN_CIRCLE = true; 575 int num = state.boundariesCrossed; 576 boolean isFinal = this.is$Final(); 577 // TODO: fixme 578 // state().CIRCLE_INDEX = 1; 579 do { 580 _value.visited = state.CIRCLE_INDEX; 581 state.CHANGE = false; 582 new_containsElementOf_TypeDecl_value = containsElementOf_compute(typeDecl); 583 if (new_containsElementOf_TypeDecl_value != ((Boolean)_value.value)) { 584 state.CHANGE = true; 585 _value.value = new_containsElementOf_TypeDecl_value; 586 } 587 state.CIRCLE_INDEX++; 588 } while (state.CHANGE); 589 if (isFinal && num == state().boundariesCrossed) { 590 containsElementOf_TypeDecl_values.put(_parameters, new_containsElementOf_TypeDecl_value); 591 } else { 592 containsElementOf_TypeDecl_values.remove(_parameters); 593 state.RESET_CYCLE = true; 594 boolean $tmp = containsElementOf_compute(typeDecl); 595 state.RESET_CYCLE = false; 596 } 597 state.IN_CIRCLE = false; 598 state.INTERMEDIATE_VALUE = false; 599 return new_containsElementOf_TypeDecl_value; 600 } 601 if (state.CIRCLE_INDEX != _value.visited) { 602 _value.visited = state.CIRCLE_INDEX; 603 new_containsElementOf_TypeDecl_value = containsElementOf_compute(typeDecl); 604 if (state.RESET_CYCLE) { 605 containsElementOf_TypeDecl_values.remove(_parameters); 606 } 607 else if (new_containsElementOf_TypeDecl_value != ((Boolean)_value.value)) { 608 state.CHANGE = true; 609 _value.value = new_containsElementOf_TypeDecl_value; 610 } 611 state.INTERMEDIATE_VALUE = true; 612 return new_containsElementOf_TypeDecl_value; 613 } 614 state.INTERMEDIATE_VALUE = true; 615 return (Boolean) _value.value; 616 } 617 /** 618 * @apilevel internal 619 */ 620 private boolean containsElementOf_compute(TypeDecl typeDecl) { 621 for (int i = 0; i < getNumBodyDecl(); i++) { 622 if (getBodyDecl(i) instanceof MethodDecl) { 623 MethodDecl m = (MethodDecl) getBodyDecl(i); 624 if (m.type() == typeDecl) { 625 return true; 626 } 627 if (m.type() instanceof AnnotationDecl && ((AnnotationDecl) m.type()).containsElementOf(typeDecl)) { 628 return true; 629 } 630 } 631 } 632 return false; 633 } 634 /** 635 * @attribute syn 636 * @aspect Annotations 637 * @declaredat /home/jesper/git/extendj/java5/frontend/Annotations.jrag:642 638 */ 639 @ASTNodeAnnotation.Attribute 640 public boolean isAnnotationDecl() { 641 boolean isAnnotationDecl_value = true; 642 643 return isAnnotationDecl_value; 644 } 645 /** 646 * @apilevel internal 647 */ 648 protected boolean flags_computed = false; 649 /** 650 * @apilevel internal 651 */ 652 protected int flags_value; 653 /** 654 * @apilevel internal 655 */ 656 private void flags_reset() { 657 flags_computed = false; 658 } 659 /** 660 * @attribute syn 661 * @aspect Flags 662 * @declaredat /home/jesper/git/extendj/java4/backend/Flags.jrag:110 663 */ 664 @ASTNodeAnnotation.Attribute 665 public int flags() { 666 ASTNode$State state = state(); 667 if (flags_computed) { 668 return flags_value; 669 } 670 boolean intermediate = state.INTERMEDIATE_VALUE; 671 state.INTERMEDIATE_VALUE = false; 672 int num = state.boundariesCrossed; 673 boolean isFinal = this.is$Final(); 674 flags_value = super.flags() | Modifiers.ACC_ANNOTATION; 675 if (isFinal && num == state().boundariesCrossed) { 676 flags_computed = true; 677 } else { 678 } 679 state.INTERMEDIATE_VALUE |= intermediate; 680 681 return flags_value; 682 } 683 /** 684 * @declaredat /home/jesper/git/extendj/java5/frontend/Annotations.jrag:96 685 * @apilevel internal 686 */ 687 public boolean Define_mayUseAnnotationTarget(ASTNode caller, ASTNode child, String name) { 688 if (caller == getModifiersNoTransform()) { 689 // @declaredat /home/jesper/git/extendj/java5/frontend/Annotations.jrag:104 690 return name.equals("ANNOTATION_TYPE") || name.equals("TYPE"); 691 } 692 else { 693 return super.Define_mayUseAnnotationTarget(caller, child, name); 694 } 695 } 696 protected boolean canDefine_mayUseAnnotationTarget(ASTNode caller, ASTNode child, String name) { 697 return true; 698 } 699 /** 700 * @apilevel internal 701 */ 702 public ASTNode rewriteTo() { 703 return super.rewriteTo(); 704 } 705 }