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/java4/grammar/Java.ast:22 027 * @production TypeAccess : {@link Access} ::= <span class="component"><Package:String></span> <span class="component"><ID:String></span>; 028 029 */ 030 public class TypeAccess extends Access implements Cloneable { 031 /** 032 * @aspect AccessControl 033 * @declaredat /home/jesper/git/extendj/java4/frontend/AccessControl.jrag:153 034 */ 035 public void accessControl() { 036 super.accessControl(); 037 TypeDecl hostType = hostType(); 038 if (hostType != null && !hostType.isUnknown() && !type().accessibleFrom(hostType)) { 039 errorf("%s in %s can not access type %s", 040 this.prettyPrint(), hostType().fullName(), type().fullName()); 041 } else if ((hostType == null || hostType.isUnknown()) 042 && !type().accessibleFromPackage(hostPackage())) { 043 errorf("%s can not access type %s", this.prettyPrint(), type().fullName()); 044 } 045 } 046 /** 047 * @aspect NameCheck 048 * @declaredat /home/jesper/git/extendj/java4/frontend/NameCheck.jrag:213 049 */ 050 public void nameCheck() { 051 if (isQualified() && !qualifier().isTypeAccess() && !qualifier().isPackageAccess()) { 052 errorf("can not access the type named %s in this context", decl().typeName()); 053 } 054 if (decls().isEmpty()) { 055 errorf("no visible type named %s", typeName()); 056 } 057 if (decls().size() > 1) { 058 StringBuilder sb = new StringBuilder(); 059 sb.append("several types named " + name() + ":"); 060 for (Iterator iter = decls().iterator(); iter.hasNext(); ) { 061 TypeDecl t = (TypeDecl) iter.next(); 062 sb.append(" " + t.typeName()); 063 } 064 error(sb.toString()); 065 } 066 } 067 /** 068 * @aspect NodeConstructors 069 * @declaredat /home/jesper/git/extendj/java4/frontend/NodeConstructors.jrag:44 070 */ 071 public TypeAccess(String name, int start, int end) { 072 this(name); 073 this.start = this.IDstart = start; 074 this.end = this.IDend = end; 075 } 076 /** 077 * @aspect NodeConstructors 078 * @declaredat /home/jesper/git/extendj/java4/frontend/NodeConstructors.jrag:55 079 */ 080 public TypeAccess(String typeName) { 081 this("", typeName); 082 } 083 /** 084 * @aspect Java4PrettyPrint 085 * @declaredat /home/jesper/git/extendj/java4/frontend/PrettyPrint.jadd:600 086 */ 087 public void prettyPrint(PrettyPrinter out) { 088 if (hasPackage()) { 089 out.print(getPackage()); 090 out.print("."); 091 } 092 out.print(getID()); 093 } 094 /** 095 * @aspect Annotations 096 * @declaredat /home/jesper/git/extendj/java5/frontend/Annotations.jrag:404 097 */ 098 public void checkModifiers() { 099 if (decl().isDeprecated() && 100 !withinDeprecatedAnnotation() && 101 (hostType() == null || hostType().topLevelType() != decl().topLevelType()) && 102 !withinSuppressWarnings("deprecation")) 103 warning(decl().typeName() + " has been deprecated"); 104 } 105 /** This method assumes that the bound type is generic. 106 * @aspect GenericsTypeAnalysis 107 * @declaredat /home/jesper/git/extendj/java5/frontend/Generics.jrag:369 108 */ 109 public boolean isRaw() { 110 /* 111 if (hasNextAccess()) { 112 return false; 113 } 114 */ 115 ASTNode parent = getParent(); 116 while (parent instanceof AbstractDot) { 117 parent = parent.getParent(); 118 } 119 if (parent instanceof ParTypeAccess) { 120 return false; 121 } 122 if (parent instanceof ImportDecl) { 123 return false; 124 } 125 /* 126 Access a = this; 127 while (a.isTypeAccess() && hasNextAccess()) { 128 a = a.nextAccess(); 129 } 130 if (a.isThisAccess() || a.isSuperAccess()) { 131 return false; 132 } 133 */ 134 return true; 135 } 136 /** 137 * @aspect GenericsTypeCheck 138 * @declaredat /home/jesper/git/extendj/java5/frontend/Generics.jrag:659 139 */ 140 public void typeCheck() { 141 TypeDecl type = type(); 142 if (type.isRawType() && type.isNestedType() 143 && type.enclosingType().isParameterizedType() 144 && !type.enclosingType().isRawType()) { 145 error("Can not access a member type of a paramterized type as a raw type"); 146 } 147 } 148 /** 149 * @aspect FunctionalInterface 150 * @declaredat /home/jesper/git/extendj/java8/frontend/FunctionalInterface.jrag:196 151 */ 152 public boolean sameType(TypeAccess t) { 153 /* 154 First, two type variables that are to be compared are checked to see if they are 155 both declared by methods and that one of the methods is not inside the scope of the other 156 method. If this is the case it is enough to simply check that the positions are equal. 157 Otherwise the types has to equal. 158 */ 159 160 if (type() instanceof TypeVariable && t.type() instanceof TypeVariable) { 161 TypeVariable t1 = (TypeVariable) type(); 162 TypeVariable t2 = (TypeVariable) t.type(); 163 if (t1.typeVarInMethod() && t2.typeVarInMethod() 164 && t1.genericMethodLevel() == t2.genericMethodLevel()) { 165 return t1.typeVarPosition() == t2.typeVarPosition(); 166 } else { 167 return t1 == t2; 168 } 169 } else if (type() instanceof TypeVariable && !(t.type() instanceof TypeVariable) 170 || t.type() instanceof TypeVariable && !(type() instanceof TypeVariable) ) { 171 return false; 172 } else if (type() == t.type()) { 173 return true; 174 } else { 175 return false; 176 } 177 } 178 /** 179 * @declaredat ASTNode:1 180 */ 181 public TypeAccess() { 182 super(); 183 } 184 /** 185 * Initializes the child array to the correct size. 186 * Initializes List and Opt nta children. 187 * @apilevel internal 188 * @ast method 189 * @declaredat ASTNode:10 190 */ 191 public void init$Children() { 192 } 193 /** 194 * @declaredat ASTNode:12 195 */ 196 public TypeAccess(String p0, String p1) { 197 setPackage(p0); 198 setID(p1); 199 } 200 /** 201 * @declaredat ASTNode:16 202 */ 203 public TypeAccess(beaver.Symbol p0, beaver.Symbol p1) { 204 setPackage(p0); 205 setID(p1); 206 } 207 /** 208 * @apilevel low-level 209 * @declaredat ASTNode:23 210 */ 211 protected int numChildren() { 212 return 0; 213 } 214 /** 215 * @apilevel internal 216 * @declaredat ASTNode:29 217 */ 218 public boolean mayHaveRewrite() { 219 return false; 220 } 221 /** 222 * @apilevel internal 223 * @declaredat ASTNode:35 224 */ 225 public void flushAttrCache() { 226 super.flushAttrCache(); 227 decls_reset(); 228 decl_reset(); 229 type_reset(); 230 } 231 /** 232 * @apilevel internal 233 * @declaredat ASTNode:44 234 */ 235 public void flushCollectionCache() { 236 super.flushCollectionCache(); 237 } 238 /** 239 * @apilevel internal 240 * @declaredat ASTNode:50 241 */ 242 public void flushRewriteCache() { 243 super.flushRewriteCache(); 244 } 245 /** 246 * @apilevel internal 247 * @declaredat ASTNode:56 248 */ 249 public TypeAccess clone() throws CloneNotSupportedException { 250 TypeAccess node = (TypeAccess) super.clone(); 251 return node; 252 } 253 /** 254 * @apilevel internal 255 * @declaredat ASTNode:63 256 */ 257 public TypeAccess copy() { 258 try { 259 TypeAccess node = (TypeAccess) clone(); 260 node.parent = null; 261 if (children != null) { 262 node.children = (ASTNode[]) children.clone(); 263 } 264 return node; 265 } catch (CloneNotSupportedException e) { 266 throw new Error("Error: clone not supported for " + getClass().getName()); 267 } 268 } 269 /** 270 * Create a deep copy of the AST subtree at this node. 271 * The copy is dangling, i.e. has no parent. 272 * @return dangling copy of the subtree at this node 273 * @apilevel low-level 274 * @deprecated Please use treeCopy or treeCopyNoTransform instead 275 * @declaredat ASTNode:82 276 */ 277 @Deprecated 278 public TypeAccess fullCopy() { 279 return treeCopyNoTransform(); 280 } 281 /** 282 * Create a deep copy of the AST subtree at this node. 283 * The copy is dangling, i.e. has no parent. 284 * @return dangling copy of the subtree at this node 285 * @apilevel low-level 286 * @declaredat ASTNode:92 287 */ 288 public TypeAccess treeCopyNoTransform() { 289 TypeAccess tree = (TypeAccess) copy(); 290 if (children != null) { 291 for (int i = 0; i < children.length; ++i) { 292 ASTNode child = (ASTNode) children[i]; 293 if (child != null) { 294 child = child.treeCopyNoTransform(); 295 tree.setChild(child, i); 296 } 297 } 298 } 299 return tree; 300 } 301 /** 302 * Create a deep copy of the AST subtree at this node. 303 * The subtree of this node is traversed to trigger rewrites before copy. 304 * The copy is dangling, i.e. has no parent. 305 * @return dangling copy of the subtree at this node 306 * @apilevel low-level 307 * @declaredat ASTNode:112 308 */ 309 public TypeAccess treeCopy() { 310 doFullTraversal(); 311 return treeCopyNoTransform(); 312 } 313 /** 314 * @apilevel internal 315 * @declaredat ASTNode:119 316 */ 317 protected boolean is$Equal(ASTNode node) { 318 return super.is$Equal(node) && (tokenString_Package == ((TypeAccess)node).tokenString_Package) && (tokenString_ID == ((TypeAccess)node).tokenString_ID); 319 } 320 /** 321 * Replaces the lexeme Package. 322 * @param value The new value for the lexeme Package. 323 * @apilevel high-level 324 */ 325 public void setPackage(String value) { 326 tokenString_Package = value; 327 } 328 /** 329 * @apilevel internal 330 */ 331 protected String tokenString_Package; 332 /** 333 */ 334 public int Packagestart; 335 /** 336 */ 337 public int Packageend; 338 /** 339 * JastAdd-internal setter for lexeme Package using the Beaver parser. 340 * @param symbol Symbol containing the new value for the lexeme Package 341 * @apilevel internal 342 */ 343 public void setPackage(beaver.Symbol symbol) { 344 if (symbol.value != null && !(symbol.value instanceof String)) 345 throw new UnsupportedOperationException("setPackage is only valid for String lexemes"); 346 tokenString_Package = (String)symbol.value; 347 Packagestart = symbol.getStart(); 348 Packageend = symbol.getEnd(); 349 } 350 /** 351 * Retrieves the value for the lexeme Package. 352 * @return The value for the lexeme Package. 353 * @apilevel high-level 354 */ 355 @ASTNodeAnnotation.Token(name="Package") 356 public String getPackage() { 357 return tokenString_Package != null ? tokenString_Package : ""; 358 } 359 /** 360 * Replaces the lexeme ID. 361 * @param value The new value for the lexeme ID. 362 * @apilevel high-level 363 */ 364 public void setID(String value) { 365 tokenString_ID = value; 366 } 367 /** 368 * @apilevel internal 369 */ 370 protected String tokenString_ID; 371 /** 372 */ 373 public int IDstart; 374 /** 375 */ 376 public int IDend; 377 /** 378 * JastAdd-internal setter for lexeme ID using the Beaver parser. 379 * @param symbol Symbol containing the new value for the lexeme ID 380 * @apilevel internal 381 */ 382 public void setID(beaver.Symbol symbol) { 383 if (symbol.value != null && !(symbol.value instanceof String)) 384 throw new UnsupportedOperationException("setID is only valid for String lexemes"); 385 tokenString_ID = (String)symbol.value; 386 IDstart = symbol.getStart(); 387 IDend = symbol.getEnd(); 388 } 389 /** 390 * Retrieves the value for the lexeme ID. 391 * @return The value for the lexeme ID. 392 * @apilevel high-level 393 */ 394 @ASTNodeAnnotation.Token(name="ID") 395 public String getID() { 396 return tokenString_ID != null ? tokenString_ID : ""; 397 } 398 /** 399 * @aspect GenericsCodegen 400 * @declaredat /home/jesper/git/extendj/java5/backend/GenericsCodegen.jrag:305 401 */ 402 public void transformation() { 403 super.transformation(); 404 if (type().elementType().isNestedType() && hostType() != null) { 405 hostType().addUsedNestedType(type().elementType().erasure().sourceTypeDecl()); 406 } 407 } 408 /** 409 * @aspect TypeScopePropagation 410 * @declaredat /home/jesper/git/extendj/java4/frontend/LookupType.jrag:307 411 */ 412 private TypeDecl refined_TypeScopePropagation_TypeAccess_decl() 413 { 414 SimpleSet decls = decls(); 415 if (decls.size() == 1) { 416 return (TypeDecl) decls.iterator().next(); 417 } 418 return unknownType(); 419 } 420 /** 421 * @apilevel internal 422 */ 423 protected boolean decls_computed = false; 424 /** 425 * @apilevel internal 426 */ 427 protected SimpleSet decls_value; 428 /** 429 * @apilevel internal 430 */ 431 private void decls_reset() { 432 decls_computed = false; 433 decls_value = null; 434 } 435 /** 436 * @attribute syn 437 * @aspect TypeScopePropagation 438 * @declaredat /home/jesper/git/extendj/java4/frontend/LookupType.jrag:291 439 */ 440 @ASTNodeAnnotation.Attribute 441 public SimpleSet decls() { 442 ASTNode$State state = state(); 443 if (decls_computed) { 444 return decls_value; 445 } 446 boolean intermediate = state.INTERMEDIATE_VALUE; 447 state.INTERMEDIATE_VALUE = false; 448 int num = state.boundariesCrossed; 449 boolean isFinal = this.is$Final(); 450 decls_value = packageName().equals("") 451 ? lookupType(name()) 452 : lookupType(packageName(), name()).asSet(); 453 if (isFinal && num == state().boundariesCrossed) { 454 decls_computed = true; 455 } else { 456 } 457 state.INTERMEDIATE_VALUE |= intermediate; 458 459 return decls_value; 460 } 461 /** 462 * @apilevel internal 463 */ 464 protected boolean decl_computed = false; 465 /** 466 * @apilevel internal 467 */ 468 protected TypeDecl decl_value; 469 /** 470 * @apilevel internal 471 */ 472 private void decl_reset() { 473 decl_computed = false; 474 decl_value = null; 475 } 476 /** 477 * @attribute syn 478 * @aspect TypeScopePropagation 479 * @declaredat /home/jesper/git/extendj/java4/frontend/LookupType.jrag:307 480 */ 481 @ASTNodeAnnotation.Attribute 482 public TypeDecl decl() { 483 ASTNode$State state = state(); 484 if (decl_computed) { 485 return decl_value; 486 } 487 boolean intermediate = state.INTERMEDIATE_VALUE; 488 state.INTERMEDIATE_VALUE = false; 489 int num = state.boundariesCrossed; 490 boolean isFinal = this.is$Final(); 491 decl_value = decl_compute(); 492 if (isFinal && num == state().boundariesCrossed) { 493 decl_computed = true; 494 } else { 495 } 496 state.INTERMEDIATE_VALUE |= intermediate; 497 498 return decl_value; 499 } 500 /** 501 * @apilevel internal 502 */ 503 private TypeDecl decl_compute() { 504 TypeDecl decl = refined_TypeScopePropagation_TypeAccess_decl(); 505 if (decl instanceof GenericTypeDecl && isRaw()) { 506 return ((GenericTypeDecl) decl).lookupParTypeDecl(Collections.<TypeDecl>emptyList()); 507 } 508 return decl; 509 } 510 /** 511 * @attribute syn 512 * @aspect VariableScope 513 * @declaredat /home/jesper/git/extendj/java4/frontend/LookupVariable.jrag:237 514 */ 515 @ASTNodeAnnotation.Attribute 516 public SimpleSet qualifiedLookupVariable(String name) { 517 { 518 if (type().accessibleFrom(hostType())) { 519 SimpleSet c = type().memberFields(name); 520 c = keepAccessibleFields(c); 521 if (type().isClassDecl() && c.size() == 1) { 522 c = removeInstanceVariables(c); 523 } 524 return c; 525 } 526 return SimpleSet.emptySet; 527 } 528 } 529 /** 530 * Has package name (not @primitive) 531 * @attribute syn 532 * @aspect PrettyPrintUtil 533 * @declaredat /home/jesper/git/extendj/java4/frontend/PrettyPrintUtil.jrag:213 534 */ 535 @ASTNodeAnnotation.Attribute 536 public boolean hasPackage() { 537 boolean hasPackage_value = decl().isReferenceType() && !getPackage().isEmpty(); 538 539 return hasPackage_value; 540 } 541 /** 542 * @attribute syn 543 * @aspect Names 544 * @declaredat /home/jesper/git/extendj/java4/frontend/QualifiedNames.jrag:40 545 */ 546 @ASTNodeAnnotation.Attribute 547 public String name() { 548 String name_value = getID(); 549 550 return name_value; 551 } 552 /** 553 * @attribute syn 554 * @aspect Names 555 * @declaredat /home/jesper/git/extendj/java4/frontend/QualifiedNames.jrag:44 556 */ 557 @ASTNodeAnnotation.Attribute 558 public String packageName() { 559 String packageName_value = getPackage(); 560 561 return packageName_value; 562 } 563 /** 564 * @attribute syn 565 * @aspect Names 566 * @declaredat /home/jesper/git/extendj/java4/frontend/QualifiedNames.jrag:58 567 */ 568 @ASTNodeAnnotation.Attribute 569 public String nameWithPackage() { 570 String nameWithPackage_value = getPackage().equals("") ? name() : (getPackage() + "." + name()); 571 572 return nameWithPackage_value; 573 } 574 /** 575 * @attribute syn 576 * @aspect Names 577 * @declaredat /home/jesper/git/extendj/java4/frontend/QualifiedNames.jrag:72 578 */ 579 @ASTNodeAnnotation.Attribute 580 public String typeName() { 581 String typeName_value = isQualified() ? (qualifier().typeName() + "." + name()) : nameWithPackage(); 582 583 return typeName_value; 584 } 585 /** 586 * @attribute syn 587 * @aspect AccessTypes 588 * @declaredat /home/jesper/git/extendj/java4/frontend/ResolveAmbiguousNames.jrag:35 589 */ 590 @ASTNodeAnnotation.Attribute 591 public boolean isTypeAccess() { 592 boolean isTypeAccess_value = true; 593 594 return isTypeAccess_value; 595 } 596 /** 597 * Defines the expected kind of name for the left hand side in a qualified 598 * expression. 599 * @attribute syn 600 * @aspect SyntacticClassification 601 * @declaredat /home/jesper/git/extendj/java4/frontend/SyntacticClassification.jrag:58 602 */ 603 @ASTNodeAnnotation.Attribute 604 public NameType predNameType() { 605 NameType predNameType_value = NameType.PACKAGE_OR_TYPE_NAME; 606 607 return predNameType_value; 608 } 609 /** 610 * @apilevel internal 611 */ 612 protected boolean type_computed = false; 613 /** 614 * @apilevel internal 615 */ 616 protected TypeDecl type_value; 617 /** 618 * @apilevel internal 619 */ 620 private void type_reset() { 621 type_computed = false; 622 type_value = null; 623 } 624 /** 625 * @attribute syn 626 * @aspect TypeAnalysis 627 * @declaredat /home/jesper/git/extendj/java4/frontend/TypeAnalysis.jrag:302 628 */ 629 @ASTNodeAnnotation.Attribute 630 public TypeDecl type() { 631 ASTNode$State state = state(); 632 if (type_computed) { 633 return type_value; 634 } 635 boolean intermediate = state.INTERMEDIATE_VALUE; 636 state.INTERMEDIATE_VALUE = false; 637 int num = state.boundariesCrossed; 638 boolean isFinal = this.is$Final(); 639 type_value = decl(); 640 if (isFinal && num == state().boundariesCrossed) { 641 type_computed = true; 642 } else { 643 } 644 state.INTERMEDIATE_VALUE |= intermediate; 645 646 return type_value; 647 } 648 /** 649 * @attribute syn 650 * @aspect TypeHierarchyCheck 651 * @declaredat /home/jesper/git/extendj/java4/frontend/TypeHierarchyCheck.jrag:199 652 */ 653 @ASTNodeAnnotation.Attribute 654 public boolean staticContextQualifier() { 655 boolean staticContextQualifier_value = true; 656 657 return staticContextQualifier_value; 658 } 659 /** 660 * @attribute syn 661 * @aspect LookupParTypeDecl 662 * @declaredat /home/jesper/git/extendj/java5/frontend/Generics.jrag:1240 663 */ 664 @ASTNodeAnnotation.Attribute 665 public boolean usesTypeVariable() { 666 boolean usesTypeVariable_value = decl().usesTypeVariable() || super.usesTypeVariable(); 667 668 return usesTypeVariable_value; 669 } 670 /** 671 * Finds the host type declaration of a class access. 672 * Call this attribute only on expressions that return true for 673 * isClassAccess or it may throw an error! 674 * @return The TypeDecl corresponding to the accesssed class 675 * @attribute syn 676 * @aspect AnnotationsCodegen 677 * @declaredat /home/jesper/git/extendj/java5/backend/AnnotationsCodegen.jrag:241 678 */ 679 @ASTNodeAnnotation.Attribute 680 public TypeDecl classAccess() { 681 TypeDecl classAccess_value = type(); 682 683 return classAccess_value; 684 } 685 /** 686 * Builds a copy of this Access node where all occurrences 687 * of type variables in the original type parameter list have been replaced 688 * by the substitution type parameters. 689 * 690 * @return the substituted Access node 691 * @attribute syn 692 * @aspect Diamond 693 * @declaredat /home/jesper/git/extendj/java7/frontend/Diamond.jrag:361 694 */ 695 @ASTNodeAnnotation.Attribute 696 public Access substituted(Collection<TypeVariable> original, List<TypeVariable> substitution) { 697 { 698 TypeDecl decl = decl(); 699 int i = 0; 700 for (TypeVariable typeVar : original) { 701 if (typeVar == decl) { 702 return new TypeAccess(substitution.getChild(i).getID()); 703 } 704 i += 1; 705 } 706 return super.substituted(original, substitution); 707 } 708 } 709 /** 710 * @apilevel internal 711 */ 712 public ASTNode rewriteTo() { 713 return super.rewriteTo(); 714 } 715 }