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/GenericMethods.ast:14 027 * @production ParMethodAccess : {@link MethodAccess} ::= <span class="component">TypeArgument:{@link Access}*</span>; 028 029 */ 030 public class ParMethodAccess extends MethodAccess implements Cloneable { 031 /** 032 * @aspect GenericMethods 033 * @declaredat /home/jesper/git/extendj/java5/frontend/GenericMethods.jrag:33 034 */ 035 public void typeCheck() { 036 super.typeCheck(); 037 if (!decl().hostType().isUnknown()) { 038 // JLS 15.12.2.1 specifically permits type arguments on non-generic method access 039 if (decl() instanceof ParMethodDecl) { 040 ParMethodDecl m = (ParMethodDecl) decl(); 041 if (!(m instanceof RawMethodDecl) && m.numTypeParameter() != getNumTypeArgument()) { 042 errorf("generic method %s requires %s type arguments", 043 m.signature(), m.numTypeParameter()); 044 } else { 045 } 046 } 047 } 048 } 049 /** 050 * @aspect GenericMethodsPrettyPrint 051 * @declaredat /home/jesper/git/extendj/java5/frontend/GenericMethods.jrag:215 052 */ 053 public void prettyPrint(PrettyPrinter out) { 054 out.print("<"); 055 for (int i = 0; i < getNumTypeArgument(); i++) { 056 if (i != 0) { 057 out.print(", "); 058 } 059 out.print(getTypeArgument(i)); 060 } 061 out.print(">"); 062 super.prettyPrint(out); 063 } 064 /** 065 * @declaredat ASTNode:1 066 */ 067 public ParMethodAccess() { 068 super(); 069 } 070 /** 071 * Initializes the child array to the correct size. 072 * Initializes List and Opt nta children. 073 * @apilevel internal 074 * @ast method 075 * @declaredat ASTNode:10 076 */ 077 public void init$Children() { 078 children = new ASTNode[2]; 079 setChild(new List(), 0); 080 setChild(new List(), 1); 081 } 082 /** 083 * @declaredat ASTNode:15 084 */ 085 public ParMethodAccess(String p0, List<Expr> p1, List<Access> p2) { 086 setID(p0); 087 setChild(p1, 0); 088 setChild(p2, 1); 089 } 090 /** 091 * @declaredat ASTNode:20 092 */ 093 public ParMethodAccess(beaver.Symbol p0, List<Expr> p1, List<Access> p2) { 094 setID(p0); 095 setChild(p1, 0); 096 setChild(p2, 1); 097 } 098 /** 099 * @apilevel low-level 100 * @declaredat ASTNode:28 101 */ 102 protected int numChildren() { 103 return 2; 104 } 105 /** 106 * @apilevel internal 107 * @declaredat ASTNode:34 108 */ 109 public boolean mayHaveRewrite() { 110 return false; 111 } 112 /** 113 * @apilevel internal 114 * @declaredat ASTNode:40 115 */ 116 public void flushAttrCache() { 117 super.flushAttrCache(); 118 inferTypeArguments_TypeDecl_List_ParameterDeclaration__List_Expr__List_TypeVariable__reset(); 119 isPolyExpression_reset(); 120 } 121 /** 122 * @apilevel internal 123 * @declaredat ASTNode:48 124 */ 125 public void flushCollectionCache() { 126 super.flushCollectionCache(); 127 } 128 /** 129 * @apilevel internal 130 * @declaredat ASTNode:54 131 */ 132 public void flushRewriteCache() { 133 super.flushRewriteCache(); 134 } 135 /** 136 * @apilevel internal 137 * @declaredat ASTNode:60 138 */ 139 public ParMethodAccess clone() throws CloneNotSupportedException { 140 ParMethodAccess node = (ParMethodAccess) super.clone(); 141 return node; 142 } 143 /** 144 * @apilevel internal 145 * @declaredat ASTNode:67 146 */ 147 public ParMethodAccess copy() { 148 try { 149 ParMethodAccess node = (ParMethodAccess) clone(); 150 node.parent = null; 151 if (children != null) { 152 node.children = (ASTNode[]) children.clone(); 153 } 154 return node; 155 } catch (CloneNotSupportedException e) { 156 throw new Error("Error: clone not supported for " + getClass().getName()); 157 } 158 } 159 /** 160 * Create a deep copy of the AST subtree at this node. 161 * The copy is dangling, i.e. has no parent. 162 * @return dangling copy of the subtree at this node 163 * @apilevel low-level 164 * @deprecated Please use treeCopy or treeCopyNoTransform instead 165 * @declaredat ASTNode:86 166 */ 167 @Deprecated 168 public ParMethodAccess fullCopy() { 169 return treeCopyNoTransform(); 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 * @declaredat ASTNode:96 177 */ 178 public ParMethodAccess treeCopyNoTransform() { 179 ParMethodAccess tree = (ParMethodAccess) copy(); 180 if (children != null) { 181 for (int i = 0; i < children.length; ++i) { 182 ASTNode child = (ASTNode) children[i]; 183 if (child != null) { 184 child = child.treeCopyNoTransform(); 185 tree.setChild(child, i); 186 } 187 } 188 } 189 return tree; 190 } 191 /** 192 * Create a deep copy of the AST subtree at this node. 193 * The subtree of this node is traversed to trigger rewrites before copy. 194 * The copy is dangling, i.e. has no parent. 195 * @return dangling copy of the subtree at this node 196 * @apilevel low-level 197 * @declaredat ASTNode:116 198 */ 199 public ParMethodAccess treeCopy() { 200 doFullTraversal(); 201 return treeCopyNoTransform(); 202 } 203 /** 204 * @apilevel internal 205 * @declaredat ASTNode:123 206 */ 207 protected boolean is$Equal(ASTNode node) { 208 return super.is$Equal(node) && (tokenString_ID == ((ParMethodAccess)node).tokenString_ID); 209 } 210 /** 211 * Replaces the lexeme ID. 212 * @param value The new value for the lexeme ID. 213 * @apilevel high-level 214 */ 215 public void setID(String value) { 216 tokenString_ID = value; 217 } 218 /** 219 * JastAdd-internal setter for lexeme ID using the Beaver parser. 220 * @param symbol Symbol containing the new value for the lexeme ID 221 * @apilevel internal 222 */ 223 public void setID(beaver.Symbol symbol) { 224 if (symbol.value != null && !(symbol.value instanceof String)) 225 throw new UnsupportedOperationException("setID is only valid for String lexemes"); 226 tokenString_ID = (String)symbol.value; 227 IDstart = symbol.getStart(); 228 IDend = symbol.getEnd(); 229 } 230 /** 231 * Retrieves the value for the lexeme ID. 232 * @return The value for the lexeme ID. 233 * @apilevel high-level 234 */ 235 @ASTNodeAnnotation.Token(name="ID") 236 public String getID() { 237 return tokenString_ID != null ? tokenString_ID : ""; 238 } 239 /** 240 * Replaces the Arg list. 241 * @param list The new list node to be used as the Arg list. 242 * @apilevel high-level 243 */ 244 public void setArgList(List<Expr> list) { 245 setChild(list, 0); 246 } 247 /** 248 * Retrieves the number of children in the Arg list. 249 * @return Number of children in the Arg list. 250 * @apilevel high-level 251 */ 252 public int getNumArg() { 253 return getArgList().getNumChild(); 254 } 255 /** 256 * Retrieves the number of children in the Arg list. 257 * Calling this method will not trigger rewrites. 258 * @return Number of children in the Arg list. 259 * @apilevel low-level 260 */ 261 public int getNumArgNoTransform() { 262 return getArgListNoTransform().getNumChildNoTransform(); 263 } 264 /** 265 * Retrieves the element at index {@code i} in the Arg list. 266 * @param i Index of the element to return. 267 * @return The element at position {@code i} in the Arg list. 268 * @apilevel high-level 269 */ 270 public Expr getArg(int i) { 271 return (Expr) getArgList().getChild(i); 272 } 273 /** 274 * Check whether the Arg list has any children. 275 * @return {@code true} if it has at least one child, {@code false} otherwise. 276 * @apilevel high-level 277 */ 278 public boolean hasArg() { 279 return getArgList().getNumChild() != 0; 280 } 281 /** 282 * Append an element to the Arg list. 283 * @param node The element to append to the Arg list. 284 * @apilevel high-level 285 */ 286 public void addArg(Expr node) { 287 List<Expr> list = (parent == null) ? getArgListNoTransform() : getArgList(); 288 list.addChild(node); 289 } 290 /** 291 * @apilevel low-level 292 */ 293 public void addArgNoTransform(Expr node) { 294 List<Expr> list = getArgListNoTransform(); 295 list.addChild(node); 296 } 297 /** 298 * Replaces the Arg list element at index {@code i} with the new node {@code node}. 299 * @param node The new node to replace the old list element. 300 * @param i The list index of the node to be replaced. 301 * @apilevel high-level 302 */ 303 public void setArg(Expr node, int i) { 304 List<Expr> list = getArgList(); 305 list.setChild(node, i); 306 } 307 /** 308 * Retrieves the Arg list. 309 * @return The node representing the Arg list. 310 * @apilevel high-level 311 */ 312 @ASTNodeAnnotation.ListChild(name="Arg") 313 public List<Expr> getArgList() { 314 List<Expr> list = (List<Expr>) getChild(0); 315 return list; 316 } 317 /** 318 * Retrieves the Arg list. 319 * <p><em>This method does not invoke AST transformations.</em></p> 320 * @return The node representing the Arg list. 321 * @apilevel low-level 322 */ 323 public List<Expr> getArgListNoTransform() { 324 return (List<Expr>) getChildNoTransform(0); 325 } 326 /** 327 * Retrieves the Arg list. 328 * @return The node representing the Arg list. 329 * @apilevel high-level 330 */ 331 public List<Expr> getArgs() { 332 return getArgList(); 333 } 334 /** 335 * Retrieves the Arg list. 336 * <p><em>This method does not invoke AST transformations.</em></p> 337 * @return The node representing the Arg list. 338 * @apilevel low-level 339 */ 340 public List<Expr> getArgsNoTransform() { 341 return getArgListNoTransform(); 342 } 343 /** 344 * Replaces the TypeArgument list. 345 * @param list The new list node to be used as the TypeArgument list. 346 * @apilevel high-level 347 */ 348 public void setTypeArgumentList(List<Access> list) { 349 setChild(list, 1); 350 } 351 /** 352 * Retrieves the number of children in the TypeArgument list. 353 * @return Number of children in the TypeArgument list. 354 * @apilevel high-level 355 */ 356 public int getNumTypeArgument() { 357 return getTypeArgumentList().getNumChild(); 358 } 359 /** 360 * Retrieves the number of children in the TypeArgument list. 361 * Calling this method will not trigger rewrites. 362 * @return Number of children in the TypeArgument list. 363 * @apilevel low-level 364 */ 365 public int getNumTypeArgumentNoTransform() { 366 return getTypeArgumentListNoTransform().getNumChildNoTransform(); 367 } 368 /** 369 * Retrieves the element at index {@code i} in the TypeArgument list. 370 * @param i Index of the element to return. 371 * @return The element at position {@code i} in the TypeArgument list. 372 * @apilevel high-level 373 */ 374 public Access getTypeArgument(int i) { 375 return (Access) getTypeArgumentList().getChild(i); 376 } 377 /** 378 * Check whether the TypeArgument list has any children. 379 * @return {@code true} if it has at least one child, {@code false} otherwise. 380 * @apilevel high-level 381 */ 382 public boolean hasTypeArgument() { 383 return getTypeArgumentList().getNumChild() != 0; 384 } 385 /** 386 * Append an element to the TypeArgument list. 387 * @param node The element to append to the TypeArgument list. 388 * @apilevel high-level 389 */ 390 public void addTypeArgument(Access node) { 391 List<Access> list = (parent == null) ? getTypeArgumentListNoTransform() : getTypeArgumentList(); 392 list.addChild(node); 393 } 394 /** 395 * @apilevel low-level 396 */ 397 public void addTypeArgumentNoTransform(Access node) { 398 List<Access> list = getTypeArgumentListNoTransform(); 399 list.addChild(node); 400 } 401 /** 402 * Replaces the TypeArgument list element at index {@code i} with the new node {@code node}. 403 * @param node The new node to replace the old list element. 404 * @param i The list index of the node to be replaced. 405 * @apilevel high-level 406 */ 407 public void setTypeArgument(Access node, int i) { 408 List<Access> list = getTypeArgumentList(); 409 list.setChild(node, i); 410 } 411 /** 412 * Retrieves the TypeArgument list. 413 * @return The node representing the TypeArgument list. 414 * @apilevel high-level 415 */ 416 @ASTNodeAnnotation.ListChild(name="TypeArgument") 417 public List<Access> getTypeArgumentList() { 418 List<Access> list = (List<Access>) getChild(1); 419 return list; 420 } 421 /** 422 * Retrieves the TypeArgument list. 423 * <p><em>This method does not invoke AST transformations.</em></p> 424 * @return The node representing the TypeArgument list. 425 * @apilevel low-level 426 */ 427 public List<Access> getTypeArgumentListNoTransform() { 428 return (List<Access>) getChildNoTransform(1); 429 } 430 /** 431 * Retrieves the TypeArgument list. 432 * @return The node representing the TypeArgument list. 433 * @apilevel high-level 434 */ 435 public List<Access> getTypeArguments() { 436 return getTypeArgumentList(); 437 } 438 /** 439 * Retrieves the TypeArgument list. 440 * <p><em>This method does not invoke AST transformations.</em></p> 441 * @return The node representing the TypeArgument list. 442 * @apilevel low-level 443 */ 444 public List<Access> getTypeArgumentsNoTransform() { 445 return getTypeArgumentListNoTransform(); 446 } 447 /** 448 * @apilevel internal 449 */ 450 protected java.util.Map inferTypeArguments_TypeDecl_List_ParameterDeclaration__List_Expr__List_TypeVariable__values; 451 /** 452 * @apilevel internal 453 */ 454 private void inferTypeArguments_TypeDecl_List_ParameterDeclaration__List_Expr__List_TypeVariable__reset() { 455 inferTypeArguments_TypeDecl_List_ParameterDeclaration__List_Expr__List_TypeVariable__values = null; 456 } 457 /** 458 * Infers type arguments for this method invocation. 459 * @attribute syn 460 * @aspect MethodSignature15 461 * @declaredat /home/jesper/git/extendj/java5/frontend/MethodSignature.jrag:479 462 */ 463 @ASTNodeAnnotation.Attribute 464 public ArrayList<TypeDecl> inferTypeArguments(TypeDecl resultType, List<ParameterDeclaration> params, List<Expr> args, List<TypeVariable> typeParams) { 465 java.util.List _parameters = new java.util.ArrayList(4); 466 _parameters.add(resultType); 467 _parameters.add(params); 468 _parameters.add(args); 469 _parameters.add(typeParams); 470 if (inferTypeArguments_TypeDecl_List_ParameterDeclaration__List_Expr__List_TypeVariable__values == null) inferTypeArguments_TypeDecl_List_ParameterDeclaration__List_Expr__List_TypeVariable__values = new org.jastadd.util.RobustMap(new java.util.HashMap()); 471 ASTNode$State state = state(); 472 if (inferTypeArguments_TypeDecl_List_ParameterDeclaration__List_Expr__List_TypeVariable__values.containsKey(_parameters)) { 473 return (ArrayList<TypeDecl>) inferTypeArguments_TypeDecl_List_ParameterDeclaration__List_Expr__List_TypeVariable__values.get(_parameters); 474 } 475 boolean intermediate = state.INTERMEDIATE_VALUE; 476 state.INTERMEDIATE_VALUE = false; 477 int num = state.boundariesCrossed; 478 boolean isFinal = this.is$Final(); 479 ArrayList<TypeDecl> inferTypeArguments_TypeDecl_List_ParameterDeclaration__List_Expr__List_TypeVariable__value = inferTypeArguments_compute(resultType, params, args, typeParams); 480 if (isFinal && num == state().boundariesCrossed) { 481 inferTypeArguments_TypeDecl_List_ParameterDeclaration__List_Expr__List_TypeVariable__values.put(_parameters, inferTypeArguments_TypeDecl_List_ParameterDeclaration__List_Expr__List_TypeVariable__value); 482 } else { 483 } 484 state.INTERMEDIATE_VALUE |= intermediate; 485 486 return inferTypeArguments_TypeDecl_List_ParameterDeclaration__List_Expr__List_TypeVariable__value; 487 } 488 /** 489 * @apilevel internal 490 */ 491 private ArrayList<TypeDecl> inferTypeArguments_compute(TypeDecl resultType, List<ParameterDeclaration> params, List<Expr> args, List<TypeVariable> typeParams) { 492 ArrayList<TypeDecl> typeArguments = new ArrayList<TypeDecl>(); 493 for (Access typeArgument : getTypeArgumentList()) { 494 typeArguments.add(typeArgument.type()); 495 } 496 return typeArguments; 497 } 498 /** 499 * @apilevel internal 500 */ 501 protected boolean isPolyExpression_computed = false; 502 /** 503 * @apilevel internal 504 */ 505 protected boolean isPolyExpression_value; 506 /** 507 * @apilevel internal 508 */ 509 private void isPolyExpression_reset() { 510 isPolyExpression_computed = false; 511 } 512 /** 513 * @attribute syn 514 * @aspect PolyExpressions 515 * @declaredat /home/jesper/git/extendj/java8/frontend/PolyExpressions.jrag:80 516 */ 517 @ASTNodeAnnotation.Attribute 518 public boolean isPolyExpression() { 519 ASTNode$State state = state(); 520 if (isPolyExpression_computed) { 521 return isPolyExpression_value; 522 } 523 boolean intermediate = state.INTERMEDIATE_VALUE; 524 state.INTERMEDIATE_VALUE = false; 525 int num = state.boundariesCrossed; 526 boolean isFinal = this.is$Final(); 527 isPolyExpression_value = false; 528 if (isFinal && num == state().boundariesCrossed) { 529 isPolyExpression_computed = true; 530 } else { 531 } 532 state.INTERMEDIATE_VALUE |= intermediate; 533 534 return isPolyExpression_value; 535 } 536 /** 537 * @declaredat /home/jesper/git/extendj/java4/frontend/SyntacticClassification.jrag:36 538 * @apilevel internal 539 */ 540 public NameType Define_nameType(ASTNode caller, ASTNode child) { 541 if (caller == getTypeArgumentListNoTransform()) { 542 // @declaredat /home/jesper/git/extendj/java5/frontend/GenericMethods.jrag:176 543 int childIndex = caller.getIndexOfChild(child); 544 return NameType.TYPE_NAME; 545 } 546 else { 547 return super.Define_nameType(caller, child); 548 } 549 } 550 protected boolean canDefine_nameType(ASTNode caller, ASTNode child) { 551 return true; 552 } 553 /** 554 * @declaredat /home/jesper/git/extendj/java5/frontend/GenericMethods.jrag:197 555 * @apilevel internal 556 */ 557 public SimpleSet Define_lookupType(ASTNode caller, ASTNode child, String name) { 558 if (caller == getTypeArgumentListNoTransform()) { 559 // @declaredat /home/jesper/git/extendj/java5/frontend/GenericMethods.jrag:177 560 int childIndex = caller.getIndexOfChild(child); 561 return unqualifiedScope().lookupType(name); 562 } 563 else { 564 return super.Define_lookupType(caller, child, name); 565 } 566 } 567 protected boolean canDefine_lookupType(ASTNode caller, ASTNode child, String name) { 568 return true; 569 } 570 /** 571 * @apilevel internal 572 */ 573 public ASTNode rewriteTo() { 574 return super.rewriteTo(); 575 } 576 }