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 * A resource declaration in a try with resources statement. 026 * @ast node 027 * @declaredat /home/jesper/git/extendj/java7/grammar/TryWithResources.ast:9 028 * @production ResourceDeclaration : {@link VariableDeclaration}; 029 030 */ 031 public class ResourceDeclaration extends VariableDeclaration implements Cloneable { 032 /** 033 * Type checking for TWR. 034 * @aspect TryWithResources 035 * @declaredat /home/jesper/git/extendj/java7/frontend/TryWithResources.jrag:45 036 */ 037 public void typeCheck() { 038 TypeDecl typeAutoCloseable = lookupType("java.lang", "AutoCloseable"); 039 if (typeAutoCloseable.isUnknown()) { 040 error("java.lang.AutoCloseable not found"); 041 } else if (!getTypeAccess().type().instanceOf(typeAutoCloseable)) { 042 error("Resource specification must declare an AutoCloseable resource"); 043 } 044 } 045 /** 046 * @aspect TryWithResources 047 * @declaredat /home/jesper/git/extendj/java7/frontend/TryWithResources.jrag:195 048 */ 049 public void nameCheck() { 050 // Special name check for resource specification 051 if (resourcePreviouslyDeclared(name())) { 052 errorf("A resource with the name %s has already been declared in this try statement.", 053 name()); 054 } 055 056 // Do regular name check for variable declaration 057 super.nameCheck(); 058 } 059 /** 060 * @declaredat ASTNode:1 061 */ 062 public ResourceDeclaration() { 063 super(); 064 } 065 /** 066 * Initializes the child array to the correct size. 067 * Initializes List and Opt nta children. 068 * @apilevel internal 069 * @ast method 070 * @declaredat ASTNode:10 071 */ 072 public void init$Children() { 073 children = new ASTNode[3]; 074 setChild(new Opt(), 2); 075 } 076 /** 077 * @declaredat ASTNode:14 078 */ 079 public ResourceDeclaration(Modifiers p0, Access p1, String p2, Opt<Expr> p3) { 080 setChild(p0, 0); 081 setChild(p1, 1); 082 setID(p2); 083 setChild(p3, 2); 084 } 085 /** 086 * @declaredat ASTNode:20 087 */ 088 public ResourceDeclaration(Modifiers p0, Access p1, beaver.Symbol p2, Opt<Expr> p3) { 089 setChild(p0, 0); 090 setChild(p1, 1); 091 setID(p2); 092 setChild(p3, 2); 093 } 094 /** 095 * @apilevel low-level 096 * @declaredat ASTNode:29 097 */ 098 protected int numChildren() { 099 return 3; 100 } 101 /** 102 * @apilevel internal 103 * @declaredat ASTNode:35 104 */ 105 public boolean mayHaveRewrite() { 106 return false; 107 } 108 /** 109 * @apilevel internal 110 * @declaredat ASTNode:41 111 */ 112 public void flushAttrCache() { 113 super.flushAttrCache(); 114 } 115 /** 116 * @apilevel internal 117 * @declaredat ASTNode:47 118 */ 119 public void flushCollectionCache() { 120 super.flushCollectionCache(); 121 } 122 /** 123 * @apilevel internal 124 * @declaredat ASTNode:53 125 */ 126 public void flushRewriteCache() { 127 super.flushRewriteCache(); 128 } 129 /** 130 * @apilevel internal 131 * @declaredat ASTNode:59 132 */ 133 public ResourceDeclaration clone() throws CloneNotSupportedException { 134 ResourceDeclaration node = (ResourceDeclaration) super.clone(); 135 return node; 136 } 137 /** 138 * @apilevel internal 139 * @declaredat ASTNode:66 140 */ 141 public ResourceDeclaration copy() { 142 try { 143 ResourceDeclaration node = (ResourceDeclaration) clone(); 144 node.parent = null; 145 if (children != null) { 146 node.children = (ASTNode[]) children.clone(); 147 } 148 return node; 149 } catch (CloneNotSupportedException e) { 150 throw new Error("Error: clone not supported for " + getClass().getName()); 151 } 152 } 153 /** 154 * Create a deep copy of the AST subtree at this node. 155 * The copy is dangling, i.e. has no parent. 156 * @return dangling copy of the subtree at this node 157 * @apilevel low-level 158 * @deprecated Please use treeCopy or treeCopyNoTransform instead 159 * @declaredat ASTNode:85 160 */ 161 @Deprecated 162 public ResourceDeclaration fullCopy() { 163 return treeCopyNoTransform(); 164 } 165 /** 166 * Create a deep copy of the AST subtree at this node. 167 * The copy is dangling, i.e. has no parent. 168 * @return dangling copy of the subtree at this node 169 * @apilevel low-level 170 * @declaredat ASTNode:95 171 */ 172 public ResourceDeclaration treeCopyNoTransform() { 173 ResourceDeclaration tree = (ResourceDeclaration) copy(); 174 if (children != null) { 175 for (int i = 0; i < children.length; ++i) { 176 ASTNode child = (ASTNode) children[i]; 177 if (child != null) { 178 child = child.treeCopyNoTransform(); 179 tree.setChild(child, i); 180 } 181 } 182 } 183 return tree; 184 } 185 /** 186 * Create a deep copy of the AST subtree at this node. 187 * The subtree of this node is traversed to trigger rewrites before copy. 188 * The copy is dangling, i.e. has no parent. 189 * @return dangling copy of the subtree at this node 190 * @apilevel low-level 191 * @declaredat ASTNode:115 192 */ 193 public ResourceDeclaration treeCopy() { 194 doFullTraversal(); 195 return treeCopyNoTransform(); 196 } 197 /** 198 * @apilevel internal 199 * @declaredat ASTNode:122 200 */ 201 protected boolean is$Equal(ASTNode node) { 202 return super.is$Equal(node) && (tokenString_ID == ((ResourceDeclaration)node).tokenString_ID); 203 } 204 /** 205 * Replaces the Modifiers child. 206 * @param node The new node to replace the Modifiers child. 207 * @apilevel high-level 208 */ 209 public void setModifiers(Modifiers node) { 210 setChild(node, 0); 211 } 212 /** 213 * Retrieves the Modifiers child. 214 * @return The current node used as the Modifiers child. 215 * @apilevel high-level 216 */ 217 @ASTNodeAnnotation.Child(name="Modifiers") 218 public Modifiers getModifiers() { 219 return (Modifiers) getChild(0); 220 } 221 /** 222 * Retrieves the Modifiers child. 223 * <p><em>This method does not invoke AST transformations.</em></p> 224 * @return The current node used as the Modifiers child. 225 * @apilevel low-level 226 */ 227 public Modifiers getModifiersNoTransform() { 228 return (Modifiers) getChildNoTransform(0); 229 } 230 /** 231 * Replaces the TypeAccess child. 232 * @param node The new node to replace the TypeAccess child. 233 * @apilevel high-level 234 */ 235 public void setTypeAccess(Access node) { 236 setChild(node, 1); 237 } 238 /** 239 * Retrieves the TypeAccess child. 240 * @return The current node used as the TypeAccess child. 241 * @apilevel high-level 242 */ 243 @ASTNodeAnnotation.Child(name="TypeAccess") 244 public Access getTypeAccess() { 245 return (Access) getChild(1); 246 } 247 /** 248 * Retrieves the TypeAccess child. 249 * <p><em>This method does not invoke AST transformations.</em></p> 250 * @return The current node used as the TypeAccess child. 251 * @apilevel low-level 252 */ 253 public Access getTypeAccessNoTransform() { 254 return (Access) getChildNoTransform(1); 255 } 256 /** 257 * Replaces the lexeme ID. 258 * @param value The new value for the lexeme ID. 259 * @apilevel high-level 260 */ 261 public void setID(String value) { 262 tokenString_ID = value; 263 } 264 /** 265 * JastAdd-internal setter for lexeme ID using the Beaver parser. 266 * @param symbol Symbol containing the new value for the lexeme ID 267 * @apilevel internal 268 */ 269 public void setID(beaver.Symbol symbol) { 270 if (symbol.value != null && !(symbol.value instanceof String)) 271 throw new UnsupportedOperationException("setID is only valid for String lexemes"); 272 tokenString_ID = (String)symbol.value; 273 IDstart = symbol.getStart(); 274 IDend = symbol.getEnd(); 275 } 276 /** 277 * Retrieves the value for the lexeme ID. 278 * @return The value for the lexeme ID. 279 * @apilevel high-level 280 */ 281 @ASTNodeAnnotation.Token(name="ID") 282 public String getID() { 283 return tokenString_ID != null ? tokenString_ID : ""; 284 } 285 /** 286 * Replaces the optional node for the Init child. This is the <code>Opt</code> 287 * node containing the child Init, not the actual child! 288 * @param opt The new node to be used as the optional node for the Init child. 289 * @apilevel low-level 290 */ 291 public void setInitOpt(Opt<Expr> opt) { 292 setChild(opt, 2); 293 } 294 /** 295 * Replaces the (optional) Init child. 296 * @param node The new node to be used as the Init child. 297 * @apilevel high-level 298 */ 299 public void setInit(Expr node) { 300 getInitOpt().setChild(node, 0); 301 } 302 /** 303 * Check whether the optional Init child exists. 304 * @return {@code true} if the optional Init child exists, {@code false} if it does not. 305 * @apilevel high-level 306 */ 307 public boolean hasInit() { 308 return getInitOpt().getNumChild() != 0; 309 } 310 /** 311 * Retrieves the (optional) Init child. 312 * @return The Init child, if it exists. Returns {@code null} otherwise. 313 * @apilevel low-level 314 */ 315 public Expr getInit() { 316 return (Expr) getInitOpt().getChild(0); 317 } 318 /** 319 * Retrieves the optional node for the Init child. This is the <code>Opt</code> node containing the child Init, not the actual child! 320 * @return The optional node for child the Init child. 321 * @apilevel low-level 322 */ 323 @ASTNodeAnnotation.OptChild(name="Init") 324 public Opt<Expr> getInitOpt() { 325 return (Opt<Expr>) getChild(2); 326 } 327 /** 328 * Retrieves the optional node for child Init. This is the <code>Opt</code> node containing the child Init, not the actual child! 329 * <p><em>This method does not invoke AST transformations.</em></p> 330 * @return The optional node for child Init. 331 * @apilevel low-level 332 */ 333 public Opt<Expr> getInitOptNoTransform() { 334 return (Opt<Expr>) getChildNoTransform(2); 335 } 336 /** 337 * Inherit the lookupType attribute in ResourceDeclaration. 338 * @attribute inh 339 * @aspect TryWithResources 340 * @declaredat /home/jesper/git/extendj/java7/frontend/TryWithResources.jrag:40 341 */ 342 /** 343 * Inherit the lookupType attribute in ResourceDeclaration. 344 * @attribute inh 345 * @aspect TryWithResources 346 * @declaredat /home/jesper/git/extendj/java7/frontend/TryWithResources.jrag:40 347 */ 348 @ASTNodeAnnotation.Attribute 349 public TypeDecl lookupType(String packageName, String typeName) { 350 TypeDecl lookupType_String_String_value = getParent().Define_lookupType(this, null, packageName, typeName); 351 352 return lookupType_String_String_value; 353 } 354 /** 355 * @declaredat /home/jesper/git/extendj/java4/frontend/SyntacticClassification.jrag:36 356 * @apilevel internal 357 */ 358 public NameType Define_nameType(ASTNode caller, ASTNode child) { 359 if (caller == getTypeAccessNoTransform()) { 360 // @declaredat /home/jesper/git/extendj/java7/frontend/TryWithResources.jrag:35 361 return NameType.TYPE_NAME; 362 } 363 else { 364 return super.Define_nameType(caller, child); 365 } 366 } 367 protected boolean canDefine_nameType(ASTNode caller, ASTNode child) { 368 return true; 369 } 370 /** 371 * @apilevel internal 372 */ 373 public ASTNode rewriteTo() { 374 return super.rewriteTo(); 375 } 376 }