src/share/classes/com/sun/tools/javac/code/Symbol.java

changeset 1689
137994c189e5
parent 1645
97f6839673d6
child 1692
b26f36a7ae3b
equal deleted inserted replaced
1688:d13af7751456 1689:137994c189e5
494 // TODO: getEnclosedElements should return a javac List, fix in FilteredMemberList 494 // TODO: getEnclosedElements should return a javac List, fix in FilteredMemberList
495 public java.util.List<Symbol> getEnclosedElements() { 495 public java.util.List<Symbol> getEnclosedElements() {
496 return List.nil(); 496 return List.nil();
497 } 497 }
498 498
499 public List<TypeSymbol> getTypeParameters() { 499 public List<TypeVariableSymbol> getTypeParameters() {
500 ListBuffer<TypeSymbol> l = ListBuffer.lb(); 500 ListBuffer<TypeVariableSymbol> l = ListBuffer.lb();
501 for (Type t : type.getTypeArguments()) { 501 for (Type t : type.getTypeArguments()) {
502 l.append(t.tsym); 502 Assert.check(t.tsym.getKind() == ElementKind.TYPE_PARAMETER);
503 l.append((TypeVariableSymbol)t.tsym);
503 } 504 }
504 return l.toList(); 505 return l.toList();
505 } 506 }
506 507
507 public static class DelegatedSymbol<T extends Symbol> extends Symbol { 508 public static class DelegatedSymbol<T extends Symbol> extends Symbol {
544 public T getUnderlyingSymbol() { 545 public T getUnderlyingSymbol() {
545 return other; 546 return other;
546 } 547 }
547 } 548 }
548 549
549 /** A class for type symbols. Type variables are represented by instances 550 /** A base class for Symbols representing types.
550 * of this class, classes and packages by instances of subclasses. 551 */
551 */ 552 public static abstract class TypeSymbol extends Symbol {
552 public static class TypeSymbol 553 public TypeSymbol(int kind, long flags, Name name, Type type, Symbol owner) {
553 extends Symbol implements TypeParameterElement { 554 super(kind, flags, name, type, owner);
554 // Implements TypeParameterElement because type parameters don't 555 }
555 // have their own TypeSymbol subclass.
556 // TODO: type parameters should have their own TypeSymbol subclass
557
558 public TypeSymbol(long flags, Name name, Type type, Symbol owner) {
559 super(TYP, flags, name, type, owner);
560 }
561
562 /** form a fully qualified name from a name and an owner 556 /** form a fully qualified name from a name and an owner
563 */ 557 */
564 static public Name formFullName(Name name, Symbol owner) { 558 static public Name formFullName(Name name, Symbol owner) {
565 if (owner == null) return name; 559 if (owner == null) return name;
566 if (((owner.kind != ERR)) && 560 if (((owner.kind != ERR)) &&
608 } 602 }
609 } 603 }
610 return this.type.hasTag(TYPEVAR); 604 return this.type.hasTag(TYPEVAR);
611 } 605 }
612 606
613 // For type params; overridden in subclasses. 607 @Override
614 public ElementKind getKind() {
615 return ElementKind.TYPE_PARAMETER;
616 }
617
618 public java.util.List<Symbol> getEnclosedElements() { 608 public java.util.List<Symbol> getEnclosedElements() {
619 List<Symbol> list = List.nil(); 609 List<Symbol> list = List.nil();
620 if (kind == TYP && type.hasTag(TYPEVAR)) { 610 if (kind == TYP && type.hasTag(TYPEVAR)) {
621 return list; 611 return list;
622 } 612 }
625 list = list.prepend(e.sym); 615 list = list.prepend(e.sym);
626 } 616 }
627 return list; 617 return list;
628 } 618 }
629 619
630 // For type params. 620 @Override
631 // Perhaps not needed if getEnclosingElement can be spec'ed 621 public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
632 // to do the same thing. 622 return v.visitTypeSymbol(this, p);
633 // TODO: getGenericElement() might not be needed 623 }
624 }
625
626 /**
627 * Type variables are represented by instances of this class.
628 */
629 public static class TypeVariableSymbol
630 extends TypeSymbol implements TypeParameterElement {
631
632 public TypeVariableSymbol(long flags, Name name, Type type, Symbol owner) {
633 super(TYP, flags, name, type, owner);
634 }
635
636 public ElementKind getKind() {
637 return ElementKind.TYPE_PARAMETER;
638 }
639
640 @Override
634 public Symbol getGenericElement() { 641 public Symbol getGenericElement() {
635 return owner; 642 return owner;
636 }
637
638 public <R, P> R accept(ElementVisitor<R, P> v, P p) {
639 Assert.check(type.hasTag(TYPEVAR)); // else override will be invoked
640 return v.visitTypeParameter(this, p);
641 }
642
643 public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
644 return v.visitTypeSymbol(this, p);
645 } 643 }
646 644
647 public List<Type> getBounds() { 645 public List<Type> getBounds() {
648 TypeVar t = (TypeVar)type; 646 TypeVar t = (TypeVar)type;
649 Type bound = t.getUpperBound(); 647 Type bound = t.getUpperBound();
656 // No superclass was given in bounds. 654 // No superclass was given in bounds.
657 // In this case, supertype is Object, erasure is first interface. 655 // In this case, supertype is Object, erasure is first interface.
658 return ct.interfaces_field; 656 return ct.interfaces_field;
659 } 657 }
660 } 658 }
659
660 @Override
661 public <R, P> R accept(ElementVisitor<R, P> v, P p) {
662 return v.visitTypeParameter(this, p);
663 }
661 } 664 }
662 665
663 /** A class for package symbols 666 /** A class for package symbols
664 */ 667 */
665 public static class PackageSymbol extends TypeSymbol 668 public static class PackageSymbol extends TypeSymbol
668 public Scope members_field; 671 public Scope members_field;
669 public Name fullname; 672 public Name fullname;
670 public ClassSymbol package_info; // see bug 6443073 673 public ClassSymbol package_info; // see bug 6443073
671 674
672 public PackageSymbol(Name name, Type type, Symbol owner) { 675 public PackageSymbol(Name name, Type type, Symbol owner) {
673 super(0, name, type, owner); 676 super(PCK, 0, name, type, owner);
674 this.kind = PCK;
675 this.members_field = null; 677 this.members_field = null;
676 this.fullname = formFullName(name, owner); 678 this.fullname = formFullName(name, owner);
677 } 679 }
678 680
679 public PackageSymbol(Name name, Symbol owner) { 681 public PackageSymbol(Name name, Symbol owner) {
781 /** the constant pool of the class 783 /** the constant pool of the class
782 */ 784 */
783 public Pool pool; 785 public Pool pool;
784 786
785 public ClassSymbol(long flags, Name name, Type type, Symbol owner) { 787 public ClassSymbol(long flags, Name name, Type type, Symbol owner) {
786 super(flags, name, type, owner); 788 super(TYP, flags, name, type, owner);
787 this.members_field = null; 789 this.members_field = null;
788 this.fullname = formFullName(name, owner); 790 this.fullname = formFullName(name, owner);
789 this.flatname = formFlatName(name, owner); 791 this.flatname = formFlatName(name, owner);
790 this.sourcefile = null; 792 this.sourcefile = null;
791 this.classfile = null; 793 this.classfile = null;

mercurial