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:16 027 * @production AnnotatedCompilationUnit : {@link CompilationUnit} ::= <span class="component">{@link Modifiers}</span>; 028 029 */ 030 public class AnnotatedCompilationUnit extends CompilationUnit implements Cloneable { 031 /** 032 * @aspect Annotations 033 * @declaredat /home/jesper/git/extendj/java5/frontend/Annotations.jrag:42 034 */ 035 public void nameCheck() { 036 super.nameCheck(); 037 if (!relativeName().endsWith("package-info.java")) { 038 error("package annotations should be in a file package-info.java"); 039 } 040 } 041 /** 042 * @aspect AnnotationPrettyPrinting 043 * @declaredat /home/jesper/git/extendj/java5/frontend/Annotations.jrag:658 044 */ 045 public void prettyPrint(PrettyPrinter out) { 046 out.print(getModifiers()); 047 super.prettyPrint(out); 048 } 049 /** 050 * @declaredat ASTNode:1 051 */ 052 public AnnotatedCompilationUnit() { 053 super(); 054 } 055 /** 056 * Initializes the child array to the correct size. 057 * Initializes List and Opt nta children. 058 * @apilevel internal 059 * @ast method 060 * @declaredat ASTNode:10 061 */ 062 public void init$Children() { 063 children = new ASTNode[3]; 064 setChild(new List(), 0); 065 setChild(new List(), 1); 066 } 067 /** 068 * @declaredat ASTNode:15 069 */ 070 public AnnotatedCompilationUnit(String p0, List<ImportDecl> p1, List<TypeDecl> p2, Modifiers p3) { 071 setPackageDecl(p0); 072 setChild(p1, 0); 073 setChild(p2, 1); 074 setChild(p3, 2); 075 } 076 /** 077 * @declaredat ASTNode:21 078 */ 079 public AnnotatedCompilationUnit(beaver.Symbol p0, List<ImportDecl> p1, List<TypeDecl> p2, Modifiers p3) { 080 setPackageDecl(p0); 081 setChild(p1, 0); 082 setChild(p2, 1); 083 setChild(p3, 2); 084 } 085 /** 086 * @apilevel low-level 087 * @declaredat ASTNode:30 088 */ 089 protected int numChildren() { 090 return 3; 091 } 092 /** 093 * @apilevel internal 094 * @declaredat ASTNode:36 095 */ 096 public boolean mayHaveRewrite() { 097 return false; 098 } 099 /** 100 * @apilevel internal 101 * @declaredat ASTNode:42 102 */ 103 public void flushAttrCache() { 104 super.flushAttrCache(); 105 } 106 /** 107 * @apilevel internal 108 * @declaredat ASTNode:48 109 */ 110 public void flushCollectionCache() { 111 super.flushCollectionCache(); 112 } 113 /** 114 * @apilevel internal 115 * @declaredat ASTNode:54 116 */ 117 public void flushRewriteCache() { 118 super.flushRewriteCache(); 119 } 120 /** 121 * @apilevel internal 122 * @declaredat ASTNode:60 123 */ 124 public AnnotatedCompilationUnit clone() throws CloneNotSupportedException { 125 AnnotatedCompilationUnit node = (AnnotatedCompilationUnit) super.clone(); 126 return node; 127 } 128 /** 129 * @apilevel internal 130 * @declaredat ASTNode:67 131 */ 132 public AnnotatedCompilationUnit copy() { 133 try { 134 AnnotatedCompilationUnit node = (AnnotatedCompilationUnit) clone(); 135 node.parent = null; 136 if (children != null) { 137 node.children = (ASTNode[]) children.clone(); 138 } 139 return node; 140 } catch (CloneNotSupportedException e) { 141 throw new Error("Error: clone not supported for " + getClass().getName()); 142 } 143 } 144 /** 145 * Create a deep copy of the AST subtree at this node. 146 * The copy is dangling, i.e. has no parent. 147 * @return dangling copy of the subtree at this node 148 * @apilevel low-level 149 * @deprecated Please use treeCopy or treeCopyNoTransform instead 150 * @declaredat ASTNode:86 151 */ 152 @Deprecated 153 public AnnotatedCompilationUnit fullCopy() { 154 return treeCopyNoTransform(); 155 } 156 /** 157 * Create a deep copy of the AST subtree at this node. 158 * The copy is dangling, i.e. has no parent. 159 * @return dangling copy of the subtree at this node 160 * @apilevel low-level 161 * @declaredat ASTNode:96 162 */ 163 public AnnotatedCompilationUnit treeCopyNoTransform() { 164 AnnotatedCompilationUnit tree = (AnnotatedCompilationUnit) copy(); 165 if (children != null) { 166 for (int i = 0; i < children.length; ++i) { 167 ASTNode child = (ASTNode) children[i]; 168 if (child != null) { 169 child = child.treeCopyNoTransform(); 170 tree.setChild(child, i); 171 } 172 } 173 } 174 return tree; 175 } 176 /** 177 * Create a deep copy of the AST subtree at this node. 178 * The subtree of this node is traversed to trigger rewrites before copy. 179 * The copy is dangling, i.e. has no parent. 180 * @return dangling copy of the subtree at this node 181 * @apilevel low-level 182 * @declaredat ASTNode:116 183 */ 184 public AnnotatedCompilationUnit treeCopy() { 185 doFullTraversal(); 186 return treeCopyNoTransform(); 187 } 188 /** 189 * @apilevel internal 190 * @declaredat ASTNode:123 191 */ 192 protected boolean is$Equal(ASTNode node) { 193 return super.is$Equal(node) && (tokenString_PackageDecl == ((AnnotatedCompilationUnit)node).tokenString_PackageDecl); 194 } 195 /** 196 * Replaces the lexeme PackageDecl. 197 * @param value The new value for the lexeme PackageDecl. 198 * @apilevel high-level 199 */ 200 public void setPackageDecl(String value) { 201 tokenString_PackageDecl = value; 202 } 203 /** 204 * JastAdd-internal setter for lexeme PackageDecl using the Beaver parser. 205 * @param symbol Symbol containing the new value for the lexeme PackageDecl 206 * @apilevel internal 207 */ 208 public void setPackageDecl(beaver.Symbol symbol) { 209 if (symbol.value != null && !(symbol.value instanceof String)) 210 throw new UnsupportedOperationException("setPackageDecl is only valid for String lexemes"); 211 tokenString_PackageDecl = (String)symbol.value; 212 PackageDeclstart = symbol.getStart(); 213 PackageDeclend = symbol.getEnd(); 214 } 215 /** 216 * Retrieves the value for the lexeme PackageDecl. 217 * @return The value for the lexeme PackageDecl. 218 * @apilevel high-level 219 */ 220 @ASTNodeAnnotation.Token(name="PackageDecl") 221 public String getPackageDecl() { 222 return tokenString_PackageDecl != null ? tokenString_PackageDecl : ""; 223 } 224 /** 225 * Replaces the ImportDecl list. 226 * @param list The new list node to be used as the ImportDecl list. 227 * @apilevel high-level 228 */ 229 public void setImportDeclList(List<ImportDecl> list) { 230 setChild(list, 0); 231 } 232 /** 233 * Retrieves the number of children in the ImportDecl list. 234 * @return Number of children in the ImportDecl list. 235 * @apilevel high-level 236 */ 237 public int getNumImportDecl() { 238 return getImportDeclList().getNumChild(); 239 } 240 /** 241 * Retrieves the number of children in the ImportDecl list. 242 * Calling this method will not trigger rewrites. 243 * @return Number of children in the ImportDecl list. 244 * @apilevel low-level 245 */ 246 public int getNumImportDeclNoTransform() { 247 return getImportDeclListNoTransform().getNumChildNoTransform(); 248 } 249 /** 250 * Retrieves the element at index {@code i} in the ImportDecl list. 251 * @param i Index of the element to return. 252 * @return The element at position {@code i} in the ImportDecl list. 253 * @apilevel high-level 254 */ 255 public ImportDecl getImportDecl(int i) { 256 return (ImportDecl) getImportDeclList().getChild(i); 257 } 258 /** 259 * Check whether the ImportDecl list has any children. 260 * @return {@code true} if it has at least one child, {@code false} otherwise. 261 * @apilevel high-level 262 */ 263 public boolean hasImportDecl() { 264 return getImportDeclList().getNumChild() != 0; 265 } 266 /** 267 * Append an element to the ImportDecl list. 268 * @param node The element to append to the ImportDecl list. 269 * @apilevel high-level 270 */ 271 public void addImportDecl(ImportDecl node) { 272 List<ImportDecl> list = (parent == null) ? getImportDeclListNoTransform() : getImportDeclList(); 273 list.addChild(node); 274 } 275 /** 276 * @apilevel low-level 277 */ 278 public void addImportDeclNoTransform(ImportDecl node) { 279 List<ImportDecl> list = getImportDeclListNoTransform(); 280 list.addChild(node); 281 } 282 /** 283 * Replaces the ImportDecl list element at index {@code i} with the new node {@code node}. 284 * @param node The new node to replace the old list element. 285 * @param i The list index of the node to be replaced. 286 * @apilevel high-level 287 */ 288 public void setImportDecl(ImportDecl node, int i) { 289 List<ImportDecl> list = getImportDeclList(); 290 list.setChild(node, i); 291 } 292 /** 293 * Retrieves the ImportDecl list. 294 * @return The node representing the ImportDecl list. 295 * @apilevel high-level 296 */ 297 @ASTNodeAnnotation.ListChild(name="ImportDecl") 298 public List<ImportDecl> getImportDeclList() { 299 List<ImportDecl> list = (List<ImportDecl>) getChild(0); 300 return list; 301 } 302 /** 303 * Retrieves the ImportDecl list. 304 * <p><em>This method does not invoke AST transformations.</em></p> 305 * @return The node representing the ImportDecl list. 306 * @apilevel low-level 307 */ 308 public List<ImportDecl> getImportDeclListNoTransform() { 309 return (List<ImportDecl>) getChildNoTransform(0); 310 } 311 /** 312 * Retrieves the ImportDecl list. 313 * @return The node representing the ImportDecl list. 314 * @apilevel high-level 315 */ 316 public List<ImportDecl> getImportDecls() { 317 return getImportDeclList(); 318 } 319 /** 320 * Retrieves the ImportDecl list. 321 * <p><em>This method does not invoke AST transformations.</em></p> 322 * @return The node representing the ImportDecl list. 323 * @apilevel low-level 324 */ 325 public List<ImportDecl> getImportDeclsNoTransform() { 326 return getImportDeclListNoTransform(); 327 } 328 /** 329 * Replaces the TypeDecl list. 330 * @param list The new list node to be used as the TypeDecl list. 331 * @apilevel high-level 332 */ 333 public void setTypeDeclList(List<TypeDecl> list) { 334 setChild(list, 1); 335 } 336 /** 337 * Retrieves the number of children in the TypeDecl list. 338 * @return Number of children in the TypeDecl list. 339 * @apilevel high-level 340 */ 341 public int getNumTypeDecl() { 342 return getTypeDeclList().getNumChild(); 343 } 344 /** 345 * Retrieves the number of children in the TypeDecl list. 346 * Calling this method will not trigger rewrites. 347 * @return Number of children in the TypeDecl list. 348 * @apilevel low-level 349 */ 350 public int getNumTypeDeclNoTransform() { 351 return getTypeDeclListNoTransform().getNumChildNoTransform(); 352 } 353 /** 354 * Retrieves the element at index {@code i} in the TypeDecl list. 355 * @param i Index of the element to return. 356 * @return The element at position {@code i} in the TypeDecl list. 357 * @apilevel high-level 358 */ 359 public TypeDecl getTypeDecl(int i) { 360 return (TypeDecl) getTypeDeclList().getChild(i); 361 } 362 /** 363 * Check whether the TypeDecl list has any children. 364 * @return {@code true} if it has at least one child, {@code false} otherwise. 365 * @apilevel high-level 366 */ 367 public boolean hasTypeDecl() { 368 return getTypeDeclList().getNumChild() != 0; 369 } 370 /** 371 * Append an element to the TypeDecl list. 372 * @param node The element to append to the TypeDecl list. 373 * @apilevel high-level 374 */ 375 public void addTypeDecl(TypeDecl node) { 376 List<TypeDecl> list = (parent == null) ? getTypeDeclListNoTransform() : getTypeDeclList(); 377 list.addChild(node); 378 } 379 /** 380 * @apilevel low-level 381 */ 382 public void addTypeDeclNoTransform(TypeDecl node) { 383 List<TypeDecl> list = getTypeDeclListNoTransform(); 384 list.addChild(node); 385 } 386 /** 387 * Replaces the TypeDecl list element at index {@code i} with the new node {@code node}. 388 * @param node The new node to replace the old list element. 389 * @param i The list index of the node to be replaced. 390 * @apilevel high-level 391 */ 392 public void setTypeDecl(TypeDecl node, int i) { 393 List<TypeDecl> list = getTypeDeclList(); 394 list.setChild(node, i); 395 } 396 /** 397 * Retrieves the TypeDecl list. 398 * @return The node representing the TypeDecl list. 399 * @apilevel high-level 400 */ 401 @ASTNodeAnnotation.ListChild(name="TypeDecl") 402 public List<TypeDecl> getTypeDeclList() { 403 List<TypeDecl> list = (List<TypeDecl>) getChild(1); 404 return list; 405 } 406 /** 407 * Retrieves the TypeDecl list. 408 * <p><em>This method does not invoke AST transformations.</em></p> 409 * @return The node representing the TypeDecl list. 410 * @apilevel low-level 411 */ 412 public List<TypeDecl> getTypeDeclListNoTransform() { 413 return (List<TypeDecl>) getChildNoTransform(1); 414 } 415 /** 416 * Retrieves the TypeDecl list. 417 * @return The node representing the TypeDecl list. 418 * @apilevel high-level 419 */ 420 public List<TypeDecl> getTypeDecls() { 421 return getTypeDeclList(); 422 } 423 /** 424 * Retrieves the TypeDecl list. 425 * <p><em>This method does not invoke AST transformations.</em></p> 426 * @return The node representing the TypeDecl list. 427 * @apilevel low-level 428 */ 429 public List<TypeDecl> getTypeDeclsNoTransform() { 430 return getTypeDeclListNoTransform(); 431 } 432 /** 433 * Replaces the Modifiers child. 434 * @param node The new node to replace the Modifiers child. 435 * @apilevel high-level 436 */ 437 public void setModifiers(Modifiers node) { 438 setChild(node, 2); 439 } 440 /** 441 * Retrieves the Modifiers child. 442 * @return The current node used as the Modifiers child. 443 * @apilevel high-level 444 */ 445 @ASTNodeAnnotation.Child(name="Modifiers") 446 public Modifiers getModifiers() { 447 return (Modifiers) getChild(2); 448 } 449 /** 450 * Retrieves the Modifiers child. 451 * <p><em>This method does not invoke AST transformations.</em></p> 452 * @return The current node used as the Modifiers child. 453 * @apilevel low-level 454 */ 455 public Modifiers getModifiersNoTransform() { 456 return (Modifiers) getChildNoTransform(2); 457 } 458 /** 459 * @declaredat /home/jesper/git/extendj/java5/frontend/Annotations.jrag:96 460 * @apilevel internal 461 */ 462 public boolean Define_mayUseAnnotationTarget(ASTNode caller, ASTNode child, String name) { 463 if (caller == getModifiersNoTransform()) { 464 // @declaredat /home/jesper/git/extendj/java5/frontend/Annotations.jrag:98 465 return name.equals("PACKAGE"); 466 } 467 else { 468 return getParent().Define_mayUseAnnotationTarget(this, caller, name); 469 } 470 } 471 protected boolean canDefine_mayUseAnnotationTarget(ASTNode caller, ASTNode child, String name) { 472 return true; 473 } 474 /** 475 * @declaredat /home/jesper/git/extendj/java4/frontend/TypeAnalysis.jrag:622 476 * @apilevel internal 477 */ 478 public String Define_hostPackage(ASTNode caller, ASTNode child) { 479 if (caller == getModifiersNoTransform()) { 480 // @declaredat /home/jesper/git/extendj/java5/frontend/Annotations.jrag:649 481 return packageName(); 482 } 483 else { 484 return super.Define_hostPackage(caller, child); 485 } 486 } 487 protected boolean canDefine_hostPackage(ASTNode caller, ASTNode child) { 488 return true; 489 } 490 /** 491 * @apilevel internal 492 */ 493 public ASTNode rewriteTo() { 494 return super.rewriteTo(); 495 } 496 }