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 /** 015 * @production ParTypeAccess : {@link Access} ::= <span class="component">TypeAccess:{@link Access}</span> <span class="component">TypeArgument:{@link Access}*</span>; 016 * @ast node 017 * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Generics.ast:16 018 */ 019 public class ParTypeAccess extends Access implements Cloneable { 020 /** 021 * @apilevel low-level 022 */ 023 public void flushCache() { 024 } 025 /** 026 * @apilevel internal 027 */ 028 public void flushCollectionCache() { 029 } 030 /** 031 * @apilevel internal 032 */ 033 @SuppressWarnings({"unchecked", "cast"}) 034 public ParTypeAccess clone() throws CloneNotSupportedException { 035 ParTypeAccess node = (ParTypeAccess)super.clone(); 036 node.type_computed = false; 037 node.type_value = null; 038 node.in$Circle(false); 039 node.is$Final(false); 040 return node; 041 } 042 /** 043 * @apilevel internal 044 */ 045 @SuppressWarnings({"unchecked", "cast"}) 046 public ParTypeAccess copy() { 047 048 try { 049 ParTypeAccess node = (ParTypeAccess) clone(); 050 node.parent = null; 051 if(children != null) 052 node.children = (ASTNode[]) children.clone(); 053 054 return node; 055 } catch (CloneNotSupportedException e) { 056 throw new Error("Error: clone not supported for " + getClass().getName()); 057 } 058 059 }/** 060 * Create a deep copy of the AST subtree at this node. 061 * The copy is dangling, i.e. has no parent. 062 * @return dangling copy of the subtree at this node 063 * @apilevel low-level 064 */ 065 @SuppressWarnings({"unchecked", "cast"}) 066 public ParTypeAccess fullCopy() { 067 068 ParTypeAccess tree = (ParTypeAccess) copy(); 069 if (children != null) { 070 for (int i = 0; i < children.length; ++i) { 071 072 ASTNode child = (ASTNode) children[i]; 073 if(child != null) { 074 child = child.fullCopy(); 075 tree.setChild(child, i); 076 } 077 } 078 } 079 return tree; 080 081 } /** 082 * @ast method 083 * @aspect GenericsTypeAnalysis 084 * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Generics.jrag:336 085 */ 086 public boolean isRaw() { 087 return false; 088 } 089 /** 090 * @ast method 091 * @aspect GenericsTypeCheck 092 * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Generics.jrag:444 093 */ 094 public void typeCheck() { 095 super.typeCheck(); 096 if(!genericDecl().isUnknown()) { 097 TypeDecl type = type(); 098 if(!genericDecl().isGenericType()) { 099 error(genericDecl().typeName() + " is not a generic type but used as one in " + this); 100 } 101 else if(!type.isRawType() && type.isNestedType() && type.enclosingType().isRawType()) 102 error("Can not access a member type of a raw type as a parameterized type"); 103 else { 104 GenericTypeDecl decl = (GenericTypeDecl)genericDecl(); 105 GenericTypeDecl original = (GenericTypeDecl)decl.original(); 106 if(original.getNumTypeParameter() != getNumTypeArgument()) { 107 error(decl.typeName() + " takes " + original.getNumTypeParameter() + " type parameters, not " + getNumTypeArgument() + " as used in " + this); 108 } 109 else { 110 ParTypeDecl typeDecl = (ParTypeDecl)type(); 111 for(int i = 0; i < getNumTypeArgument(); i++) { 112 if(!getTypeArgument(i).type().instanceOf(original.getTypeParameter(i))) { 113 error("type argument " + i + " is of type " + getTypeArgument(i).type().typeName() 114 + " which is not a subtype of " + original.getTypeParameter(i).typeName()); 115 } 116 } 117 } 118 } 119 } 120 } 121 /** 122 * @ast method 123 * @aspect GenericsPrettyPrint 124 * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/GenericsPrettyPrint.jrag:23 125 */ 126 public void toString(StringBuffer s) { 127 getTypeAccess().toString(s); 128 s.append("<"); 129 for(int i = 0; i < getNumTypeArgument(); i++) { 130 if(i != 0) 131 s.append(", "); 132 getTypeArgument(i).toString(s); 133 } 134 s.append(">"); 135 } 136 /** 137 * @ast method 138 * 139 */ 140 public ParTypeAccess() { 141 super(); 142 143 144 } 145 /** 146 * Initializes the child array to the correct size. 147 * Initializes List and Opt nta children. 148 * @apilevel internal 149 * @ast method 150 * @ast method 151 * 152 */ 153 public void init$Children() { 154 children = new ASTNode[2]; 155 setChild(new List(), 1); 156 } 157 /** 158 * @ast method 159 * 160 */ 161 public ParTypeAccess(Access p0, List<Access> p1) { 162 setChild(p0, 0); 163 setChild(p1, 1); 164 } 165 /** 166 * @apilevel low-level 167 * @ast method 168 * 169 */ 170 protected int numChildren() { 171 return 2; 172 } 173 /** 174 * @apilevel internal 175 * @ast method 176 * 177 */ 178 public boolean mayHaveRewrite() { 179 return false; 180 } 181 /** 182 * Replaces the TypeAccess child. 183 * @param node The new node to replace the TypeAccess child. 184 * @apilevel high-level 185 * @ast method 186 * 187 */ 188 public void setTypeAccess(Access node) { 189 setChild(node, 0); 190 } 191 /** 192 * Retrieves the TypeAccess child. 193 * @return The current node used as the TypeAccess child. 194 * @apilevel high-level 195 * @ast method 196 * 197 */ 198 public Access getTypeAccess() { 199 return (Access)getChild(0); 200 } 201 /** 202 * Retrieves the TypeAccess child. 203 * <p><em>This method does not invoke AST transformations.</em></p> 204 * @return The current node used as the TypeAccess child. 205 * @apilevel low-level 206 * @ast method 207 * 208 */ 209 public Access getTypeAccessNoTransform() { 210 return (Access)getChildNoTransform(0); 211 } 212 /** 213 * Replaces the TypeArgument list. 214 * @param list The new list node to be used as the TypeArgument list. 215 * @apilevel high-level 216 * @ast method 217 * 218 */ 219 public void setTypeArgumentList(List<Access> list) { 220 setChild(list, 1); 221 } 222 /** 223 * Retrieves the number of children in the TypeArgument list. 224 * @return Number of children in the TypeArgument list. 225 * @apilevel high-level 226 * @ast method 227 * 228 */ 229 public int getNumTypeArgument() { 230 return getTypeArgumentList().getNumChild(); 231 } 232 /** 233 * Retrieves the number of children in the TypeArgument list. 234 * Calling this method will not trigger rewrites.. 235 * @return Number of children in the TypeArgument list. 236 * @apilevel low-level 237 * @ast method 238 * 239 */ 240 public int getNumTypeArgumentNoTransform() { 241 return getTypeArgumentListNoTransform().getNumChildNoTransform(); 242 } 243 /** 244 * Retrieves the element at index {@code i} in the TypeArgument list.. 245 * @param i Index of the element to return. 246 * @return The element at position {@code i} in the TypeArgument list. 247 * @apilevel high-level 248 * @ast method 249 * 250 */ 251 @SuppressWarnings({"unchecked", "cast"}) 252 public Access getTypeArgument(int i) { 253 return (Access)getTypeArgumentList().getChild(i); 254 } 255 /** 256 * Append an element to the TypeArgument list. 257 * @param node The element to append to the TypeArgument list. 258 * @apilevel high-level 259 * @ast method 260 * 261 */ 262 public void addTypeArgument(Access node) { 263 List<Access> list = (parent == null || state == null) ? getTypeArgumentListNoTransform() : getTypeArgumentList(); 264 list.addChild(node); 265 } 266 /** 267 * @apilevel low-level 268 * @ast method 269 * 270 */ 271 public void addTypeArgumentNoTransform(Access node) { 272 List<Access> list = getTypeArgumentListNoTransform(); 273 list.addChild(node); 274 } 275 /** 276 * Replaces the TypeArgument list element at index {@code i} with the new node {@code node}. 277 * @param node The new node to replace the old list element. 278 * @param i The list index of the node to be replaced. 279 * @apilevel high-level 280 * @ast method 281 * 282 */ 283 public void setTypeArgument(Access node, int i) { 284 List<Access> list = getTypeArgumentList(); 285 list.setChild(node, i); 286 } 287 /** 288 * Retrieves the TypeArgument list. 289 * @return The node representing the TypeArgument list. 290 * @apilevel high-level 291 * @ast method 292 * 293 */ 294 public List<Access> getTypeArguments() { 295 return getTypeArgumentList(); 296 } 297 /** 298 * Retrieves the TypeArgument list. 299 * <p><em>This method does not invoke AST transformations.</em></p> 300 * @return The node representing the TypeArgument list. 301 * @apilevel low-level 302 * @ast method 303 * 304 */ 305 public List<Access> getTypeArgumentsNoTransform() { 306 return getTypeArgumentListNoTransform(); 307 } 308 /** 309 * Retrieves the TypeArgument list. 310 * @return The node representing the TypeArgument list. 311 * @apilevel high-level 312 * @ast method 313 * 314 */ 315 @SuppressWarnings({"unchecked", "cast"}) 316 public List<Access> getTypeArgumentList() { 317 List<Access> list = (List<Access>)getChild(1); 318 list.getNumChild(); 319 return list; 320 } 321 /** 322 * Retrieves the TypeArgument list. 323 * <p><em>This method does not invoke AST transformations.</em></p> 324 * @return The node representing the TypeArgument list. 325 * @apilevel low-level 326 * @ast method 327 * 328 */ 329 @SuppressWarnings({"unchecked", "cast"}) 330 public List<Access> getTypeArgumentListNoTransform() { 331 return (List<Access>)getChildNoTransform(1); 332 } 333 /** 334 * @attribute syn 335 * @aspect LookupMethod 336 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/LookupMethod.jrag:17 337 */ 338 public Expr unqualifiedScope() { 339 ASTNode$State state = state(); 340 try { return getParent() instanceof Access ? ((Access)getParent()).unqualifiedScope() : super.unqualifiedScope(); } 341 finally { 342 } 343 } 344 /** 345 * @apilevel internal 346 */ 347 protected boolean type_computed = false; 348 /** 349 * @apilevel internal 350 */ 351 protected TypeDecl type_value; 352 /** 353 * @attribute syn 354 * @aspect GenericsTypeAnalysis 355 * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Generics.jrag:273 356 */ 357 @SuppressWarnings({"unchecked", "cast"}) 358 public TypeDecl type() { 359 if(type_computed) { 360 return type_value; 361 } 362 ASTNode$State state = state(); 363 int num = state.boundariesCrossed; 364 boolean isFinal = this.is$Final(); 365 type_value = type_compute(); 366 if(isFinal && num == state().boundariesCrossed){ type_computed = true; } 367 return type_value; 368 } 369 /** 370 * @apilevel internal 371 */ 372 private TypeDecl type_compute() { 373 TypeDecl typeDecl = genericDecl(); 374 if(typeDecl instanceof GenericTypeDecl) { 375 // use signature in lookup for types that are used in extends and implements clauses 376 if (unqualifiedScope().inExtendsOrImplements()) { 377 return ((GenericTypeDecl)typeDecl).lookupParTypeDecl(this); 378 } 379 ArrayList args = new ArrayList(); 380 for(int i = 0; i < getNumTypeArgument(); i++) 381 args.add(getTypeArgument(i).type()); 382 return ((GenericTypeDecl)typeDecl).lookupParTypeDecl(args); 383 } 384 return typeDecl; 385 } 386 /** 387 * @attribute syn 388 * @aspect GenericsTypeAnalysis 389 * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Generics.jrag:287 390 */ 391 public TypeDecl genericDecl() { 392 ASTNode$State state = state(); 393 try { return getTypeAccess().type(); } 394 finally { 395 } 396 } 397 /** 398 * @attribute syn 399 * @aspect AccessTypes 400 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/ResolveAmbiguousNames.jrag:13 401 */ 402 public boolean isTypeAccess() { 403 ASTNode$State state = state(); 404 try { return true; } 405 finally { 406 } 407 } 408 /** 409 * Builds a copy of this Access node where all occurrences 410 * of type variables in the original type parameter list have been replaced 411 * by the substitution type parameters. 412 * 413 * @return the substituted Access node 414 * @attribute syn 415 * @aspect TypeInference 416 * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/TypeInference.jrag:406 417 */ 418 public Access substituted(Collection<TypeVariable> original, List<TypeVariable> substitution) { 419 ASTNode$State state = state(); 420 try { 421 List<Access> substArgs = new List<Access>(); 422 for (Access arg : getTypeArgumentList()) 423 substArgs.add(arg.substituted(original, substitution)); 424 return new ParTypeAccess( 425 getTypeAccess().substituted(original, substitution), 426 substArgs); 427 } 428 finally { 429 } 430 } 431 /** 432 * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Generics.jrag:265 433 * @apilevel internal 434 */ 435 public SimpleSet Define_SimpleSet_lookupType(ASTNode caller, ASTNode child, String name) { 436 if(caller == getTypeArgumentListNoTransform()) { 437 int childIndex = caller.getIndexOfChild(child); 438 return unqualifiedScope().lookupType(name); 439 } 440 else { return getParent().Define_SimpleSet_lookupType(this, caller, name); 441 } 442 } 443 /** 444 * @apilevel internal 445 */ 446 public ASTNode rewriteTo() { 447 return super.rewriteTo(); 448 } 449 }