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 * 7.5.3 A single-static-import declaration imports all accessible (\u00a76.6) static members 026 * with a given simple name from a type. This makes these static members available 027 * under their simple name in the class and interface declarations of the 028 * compilation unit in which the single-static import declaration appears. 029 * @ast node 030 * @declaredat /home/jesper/git/extendj/java5/grammar/StaticImports.ast:12 031 * @production SingleStaticImportDecl : {@link StaticImportDecl} ::= <span class="component"><ID:String></span>; 032 033 */ 034 public class SingleStaticImportDecl extends StaticImportDecl implements Cloneable { 035 /** 036 * @aspect Java5PrettyPrint 037 * @declaredat /home/jesper/git/extendj/java5/frontend/PrettyPrint.jadd:385 038 */ 039 public void prettyPrint(PrettyPrinter out) { 040 out.print("import static "); 041 out.print(getAccess()); 042 out.print("."); 043 out.print(getID()); 044 out.print(";"); 045 } 046 /** 047 * The TypeName must be the canonical name of a class or interface type 048 * @aspect StaticImports 049 * @declaredat /home/jesper/git/extendj/java5/frontend/StaticImports.jrag:105 050 */ 051 public void typeCheck() { 052 if (!getAccess().type().typeName().equals(typeName()) && 053 !getAccess().type().isUnknown()) { 054 errorf("Single-type import %s is not the canonical name of type %s", 055 typeName(), getAccess().type().typeName()); 056 } else if (allImportedTypes(getID()).size() > 1) { 057 errorf("%s is imported multiple times", getID()); 058 } 059 } 060 /** 061 * Check for single static import errors. 062 * @aspect StaticImports 063 * @declaredat /home/jesper/git/extendj/java5/frontend/StaticImports.jrag:156 064 */ 065 public void nameCheck() { 066 if (importedFields(name()).isEmpty() 067 && importedMethods(name()).isEmpty() 068 && importedTypes(name()).isEmpty() 069 && !getAccess().type().isUnknown()) { 070 errorf("Semantic Error: At least one static member named %s must" 071 + " be available in static imported type %s", 072 name(), type().fullName()); 073 } 074 } 075 /** 076 * @declaredat ASTNode:1 077 */ 078 public SingleStaticImportDecl() { 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[1]; 090 } 091 /** 092 * @declaredat ASTNode:13 093 */ 094 public SingleStaticImportDecl(Access p0, String p1) { 095 setChild(p0, 0); 096 setID(p1); 097 } 098 /** 099 * @declaredat ASTNode:17 100 */ 101 public SingleStaticImportDecl(Access p0, beaver.Symbol p1) { 102 setChild(p0, 0); 103 setID(p1); 104 } 105 /** 106 * @apilevel low-level 107 * @declaredat ASTNode:24 108 */ 109 protected int numChildren() { 110 return 1; 111 } 112 /** 113 * @apilevel internal 114 * @declaredat ASTNode:30 115 */ 116 public boolean mayHaveRewrite() { 117 return false; 118 } 119 /** 120 * @apilevel internal 121 * @declaredat ASTNode:36 122 */ 123 public void flushAttrCache() { 124 super.flushAttrCache(); 125 importedTypes_reset(); 126 importedFields_String_reset(); 127 importedMethods_String_reset(); 128 } 129 /** 130 * @apilevel internal 131 * @declaredat ASTNode:45 132 */ 133 public void flushCollectionCache() { 134 super.flushCollectionCache(); 135 } 136 /** 137 * @apilevel internal 138 * @declaredat ASTNode:51 139 */ 140 public void flushRewriteCache() { 141 super.flushRewriteCache(); 142 } 143 /** 144 * @apilevel internal 145 * @declaredat ASTNode:57 146 */ 147 public SingleStaticImportDecl clone() throws CloneNotSupportedException { 148 SingleStaticImportDecl node = (SingleStaticImportDecl) super.clone(); 149 return node; 150 } 151 /** 152 * @apilevel internal 153 * @declaredat ASTNode:64 154 */ 155 public SingleStaticImportDecl copy() { 156 try { 157 SingleStaticImportDecl node = (SingleStaticImportDecl) clone(); 158 node.parent = null; 159 if (children != null) { 160 node.children = (ASTNode[]) children.clone(); 161 } 162 return node; 163 } catch (CloneNotSupportedException e) { 164 throw new Error("Error: clone not supported for " + getClass().getName()); 165 } 166 } 167 /** 168 * Create a deep copy of the AST subtree at this node. 169 * The copy is dangling, i.e. has no parent. 170 * @return dangling copy of the subtree at this node 171 * @apilevel low-level 172 * @deprecated Please use treeCopy or treeCopyNoTransform instead 173 * @declaredat ASTNode:83 174 */ 175 @Deprecated 176 public SingleStaticImportDecl fullCopy() { 177 return treeCopyNoTransform(); 178 } 179 /** 180 * Create a deep copy of the AST subtree at this node. 181 * The copy is dangling, i.e. has no parent. 182 * @return dangling copy of the subtree at this node 183 * @apilevel low-level 184 * @declaredat ASTNode:93 185 */ 186 public SingleStaticImportDecl treeCopyNoTransform() { 187 SingleStaticImportDecl tree = (SingleStaticImportDecl) copy(); 188 if (children != null) { 189 for (int i = 0; i < children.length; ++i) { 190 ASTNode child = (ASTNode) children[i]; 191 if (child != null) { 192 child = child.treeCopyNoTransform(); 193 tree.setChild(child, i); 194 } 195 } 196 } 197 return tree; 198 } 199 /** 200 * Create a deep copy of the AST subtree at this node. 201 * The subtree of this node is traversed to trigger rewrites before copy. 202 * The copy is dangling, i.e. has no parent. 203 * @return dangling copy of the subtree at this node 204 * @apilevel low-level 205 * @declaredat ASTNode:113 206 */ 207 public SingleStaticImportDecl treeCopy() { 208 doFullTraversal(); 209 return treeCopyNoTransform(); 210 } 211 /** 212 * @apilevel internal 213 * @declaredat ASTNode:120 214 */ 215 protected boolean is$Equal(ASTNode node) { 216 return super.is$Equal(node) && (tokenString_ID == ((SingleStaticImportDecl)node).tokenString_ID); 217 } 218 /** 219 * Replaces the Access child. 220 * @param node The new node to replace the Access child. 221 * @apilevel high-level 222 */ 223 public void setAccess(Access node) { 224 setChild(node, 0); 225 } 226 /** 227 * Retrieves the Access child. 228 * @return The current node used as the Access child. 229 * @apilevel high-level 230 */ 231 @ASTNodeAnnotation.Child(name="Access") 232 public Access getAccess() { 233 return (Access) getChild(0); 234 } 235 /** 236 * Retrieves the Access child. 237 * <p><em>This method does not invoke AST transformations.</em></p> 238 * @return The current node used as the Access child. 239 * @apilevel low-level 240 */ 241 public Access getAccessNoTransform() { 242 return (Access) getChildNoTransform(0); 243 } 244 /** 245 * Replaces the lexeme ID. 246 * @param value The new value for the lexeme ID. 247 * @apilevel high-level 248 */ 249 public void setID(String value) { 250 tokenString_ID = value; 251 } 252 /** 253 * @apilevel internal 254 */ 255 protected String tokenString_ID; 256 /** 257 */ 258 public int IDstart; 259 /** 260 */ 261 public int IDend; 262 /** 263 * JastAdd-internal setter for lexeme ID using the Beaver parser. 264 * @param symbol Symbol containing the new value for the lexeme ID 265 * @apilevel internal 266 */ 267 public void setID(beaver.Symbol symbol) { 268 if (symbol.value != null && !(symbol.value instanceof String)) 269 throw new UnsupportedOperationException("setID is only valid for String lexemes"); 270 tokenString_ID = (String)symbol.value; 271 IDstart = symbol.getStart(); 272 IDend = symbol.getEnd(); 273 } 274 /** 275 * Retrieves the value for the lexeme ID. 276 * @return The value for the lexeme ID. 277 * @apilevel high-level 278 */ 279 @ASTNodeAnnotation.Token(name="ID") 280 public String getID() { 281 return tokenString_ID != null ? tokenString_ID : ""; 282 } 283 /** 284 * @apilevel internal 285 */ 286 protected boolean importedTypes_computed = false; 287 /** 288 * @apilevel internal 289 */ 290 protected SimpleSet importedTypes_value; 291 /** 292 * @apilevel internal 293 */ 294 private void importedTypes_reset() { 295 importedTypes_computed = false; 296 importedTypes_value = null; 297 } 298 /** 299 * For a single-import declaration this will return a SimpleSet 300 * containing the TypeDecl for the imported type. For dynamic 301 * import declarations this returns the empty set. 302 * @return TypeDecl of imported type wrapped in SimpleSet 303 * @attribute syn 304 * @aspect TypeScopePropagation 305 * @declaredat /home/jesper/git/extendj/java4/frontend/LookupType.jrag:437 306 */ 307 @ASTNodeAnnotation.Attribute 308 public SimpleSet importedTypes() { 309 ASTNode$State state = state(); 310 if (importedTypes_computed) { 311 return importedTypes_value; 312 } 313 boolean intermediate = state.INTERMEDIATE_VALUE; 314 state.INTERMEDIATE_VALUE = false; 315 int num = state.boundariesCrossed; 316 boolean isFinal = this.is$Final(); 317 importedTypes_value = getAccess().type().memberTypes(getID()); 318 if (isFinal && num == state().boundariesCrossed) { 319 importedTypes_computed = true; 320 } else { 321 } 322 state.INTERMEDIATE_VALUE |= intermediate; 323 324 return importedTypes_value; 325 } 326 /** 327 * @apilevel internal 328 */ 329 protected java.util.Map importedFields_String_values; 330 /** 331 * @apilevel internal 332 */ 333 private void importedFields_String_reset() { 334 importedFields_String_values = null; 335 } 336 /** 337 * @attribute syn 338 * @aspect StaticImports 339 * @declaredat /home/jesper/git/extendj/java5/frontend/StaticImports.jrag:55 340 */ 341 @ASTNodeAnnotation.Attribute 342 public SimpleSet importedFields(String name) { 343 Object _parameters = name; 344 if (importedFields_String_values == null) importedFields_String_values = new org.jastadd.util.RobustMap(new java.util.HashMap()); 345 ASTNode$State state = state(); 346 if (importedFields_String_values.containsKey(_parameters)) { 347 return (SimpleSet) importedFields_String_values.get(_parameters); 348 } 349 boolean intermediate = state.INTERMEDIATE_VALUE; 350 state.INTERMEDIATE_VALUE = false; 351 int num = state.boundariesCrossed; 352 boolean isFinal = this.is$Final(); 353 SimpleSet importedFields_String_value = importedFields_compute(name); 354 if (isFinal && num == state().boundariesCrossed) { 355 importedFields_String_values.put(_parameters, importedFields_String_value); 356 } else { 357 } 358 state.INTERMEDIATE_VALUE |= intermediate; 359 360 return importedFields_String_value; 361 } 362 /** 363 * @apilevel internal 364 */ 365 private SimpleSet importedFields_compute(String name) { 366 if (name.equals(getID())) { 367 return super.importedFields(name); 368 } else { 369 return SimpleSet.emptySet; 370 } 371 } 372 /** 373 * @apilevel internal 374 */ 375 protected java.util.Map importedMethods_String_values; 376 /** 377 * @apilevel internal 378 */ 379 private void importedMethods_String_reset() { 380 importedMethods_String_values = null; 381 } 382 /** 383 * @attribute syn 384 * @aspect StaticImports 385 * @declaredat /home/jesper/git/extendj/java5/frontend/StaticImports.jrag:75 386 */ 387 @ASTNodeAnnotation.Attribute 388 public Collection importedMethods(String name) { 389 Object _parameters = name; 390 if (importedMethods_String_values == null) importedMethods_String_values = new org.jastadd.util.RobustMap(new java.util.HashMap()); 391 ASTNode$State state = state(); 392 if (importedMethods_String_values.containsKey(_parameters)) { 393 return (Collection) importedMethods_String_values.get(_parameters); 394 } 395 boolean intermediate = state.INTERMEDIATE_VALUE; 396 state.INTERMEDIATE_VALUE = false; 397 int num = state.boundariesCrossed; 398 boolean isFinal = this.is$Final(); 399 Collection importedMethods_String_value = importedMethods_compute(name); 400 if (isFinal && num == state().boundariesCrossed) { 401 importedMethods_String_values.put(_parameters, importedMethods_String_value); 402 } else { 403 } 404 state.INTERMEDIATE_VALUE |= intermediate; 405 406 return importedMethods_String_value; 407 } 408 /** 409 * @apilevel internal 410 */ 411 private Collection importedMethods_compute(String name) { 412 if (name.equals(getID())) { 413 return super.importedMethods(name); 414 } else { 415 return Collections.EMPTY_LIST; 416 } 417 } 418 /** 419 * @attribute syn 420 * @aspect StaticImports 421 * @declaredat /home/jesper/git/extendj/java5/frontend/StaticImports.jrag:95 422 */ 423 @ASTNodeAnnotation.Attribute 424 public TypeDecl type() { 425 TypeDecl type_value = getAccess().type(); 426 427 return type_value; 428 } 429 /** 430 * @attribute syn 431 * @aspect StaticImports 432 * @declaredat /home/jesper/git/extendj/java5/frontend/StaticImports.jrag:167 433 */ 434 @ASTNodeAnnotation.Attribute 435 public String name() { 436 String name_value = getID(); 437 438 return name_value; 439 } 440 /** 441 * @declaredat /home/jesper/git/extendj/java4/frontend/SyntacticClassification.jrag:36 442 * @apilevel internal 443 */ 444 public NameType Define_nameType(ASTNode caller, ASTNode child) { 445 if (caller == getAccessNoTransform()) { 446 // @declaredat /home/jesper/git/extendj/java5/frontend/StaticImports.jrag:295 447 return NameType.TYPE_NAME; 448 } 449 else { 450 return getParent().Define_nameType(this, caller); 451 } 452 } 453 protected boolean canDefine_nameType(ASTNode caller, ASTNode child) { 454 return true; 455 } 456 /** 457 * @apilevel internal 458 */ 459 public ASTNode rewriteTo() { 460 return super.rewriteTo(); 461 } 462 }