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

Print this page




 404     /** Is this type a raw type?
 405      *  A class type is a raw type if it misses some of its parameters.
 406      *  An array type is a raw type if its element type is raw.
 407      *  All other types are not raw.
 408      *  Type validation will ensure that the only raw types
 409      *  in a program are types that miss all their type variables.
 410      */
 411     public boolean isRaw() {
 412         return false;
 413     }
 414 
 415     public boolean isCompound() {
 416         return tsym.completer == null
 417             // Compound types can't have a completer.  Calling
 418             // flags() will complete the symbol causing the
 419             // compiler to load classes unnecessarily.  This led
 420             // to regression 6180021.
 421             && (tsym.flags() & COMPOUND) != 0;
 422     }
 423 








 424     public boolean isInterface() {
 425         return (tsym.flags() & INTERFACE) != 0;
 426     }
 427 
 428     public boolean isFinal() {
 429         return (tsym.flags() & FINAL) != 0;
 430     }
 431 
 432     /**
 433      * Does this type contain occurrences of type t?
 434      */
 435     public boolean contains(Type t) {
 436         return t == this;
 437     }
 438 
 439     public static boolean contains(List<Type> ts, Type t) {
 440         for (List<Type> l = ts;
 441              l.tail != null /*inlined: l.nonEmpty()*/;
 442              l = l.tail)
 443             if (l.head.contains(t)) return true;


 953         final List<? extends Type> alternatives_field;
 954 
 955         public UnionClassType(ClassType ct, List<? extends Type> alternatives) {
 956             super(ct.outer_field, ct.typarams_field, ct.tsym);
 957             allparams_field = ct.allparams_field;
 958             supertype_field = ct.supertype_field;
 959             interfaces_field = ct.interfaces_field;
 960             all_interfaces_field = ct.interfaces_field;
 961             alternatives_field = alternatives;
 962         }
 963 
 964         public Type getLub() {
 965             return tsym.type;
 966         }
 967 
 968         public java.util.List<? extends TypeMirror> getAlternatives() {
 969             return Collections.unmodifiableList(alternatives_field);
 970         }
 971 
 972         @Override





 973         public TypeKind getKind() {
 974             return TypeKind.UNION;
 975         }
 976 
 977         @Override
 978         public <R, P> R accept(TypeVisitor<R, P> v, P p) {
 979             return v.visitUnion(this, p);
 980         }
 981     }
 982 
 983     // a clone of a ClassType that knows about the bounds of an intersection type.
 984     public static class IntersectionClassType extends ClassType implements IntersectionType {
 985 
 986         public boolean allInterfaces;
 987 
 988         public IntersectionClassType(List<Type> bounds, ClassSymbol csym, boolean allInterfaces) {
 989             super(Type.noType, List.<Type>nil(), csym);
 990             this.allInterfaces = allInterfaces;
 991             Assert.check((csym.flags() & COMPOUND) != 0);
 992             supertype_field = bounds.head;
 993             interfaces_field = bounds.tail;
 994             Assert.check(supertype_field.tsym.completer != null ||
 995                     !supertype_field.isInterface(), supertype_field);
 996         }
 997 
 998         public java.util.List<? extends TypeMirror> getBounds() {
 999             return Collections.unmodifiableList(getExplicitComponents());
1000         }
1001 
1002         public List<Type> getComponents() {
1003             return interfaces_field.prepend(supertype_field);
1004         }
1005 





1006         public List<Type> getExplicitComponents() {
1007             return allInterfaces ?
1008                     interfaces_field :
1009                     getComponents();
1010         }
1011 
1012         @Override
1013         public TypeKind getKind() {
1014             return TypeKind.INTERSECTION;
1015         }
1016 
1017         @Override
1018         public <R, P> R accept(TypeVisitor<R, P> v, P p) {
1019             return v.visitIntersection(this, p);
1020         }
1021     }
1022 
1023     public static class ArrayType extends Type
1024             implements javax.lang.model.type.ArrayType {
1025 




 404     /** Is this type a raw type?
 405      *  A class type is a raw type if it misses some of its parameters.
 406      *  An array type is a raw type if its element type is raw.
 407      *  All other types are not raw.
 408      *  Type validation will ensure that the only raw types
 409      *  in a program are types that miss all their type variables.
 410      */
 411     public boolean isRaw() {
 412         return false;
 413     }
 414 
 415     public boolean isCompound() {
 416         return tsym.completer == null
 417             // Compound types can't have a completer.  Calling
 418             // flags() will complete the symbol causing the
 419             // compiler to load classes unnecessarily.  This led
 420             // to regression 6180021.
 421             && (tsym.flags() & COMPOUND) != 0;
 422     }
 423 
 424     public boolean isIntersection() {
 425         return false;
 426     }
 427 
 428     public boolean isUnion() {
 429         return false;
 430     }
 431 
 432     public boolean isInterface() {
 433         return (tsym.flags() & INTERFACE) != 0;
 434     }
 435 
 436     public boolean isFinal() {
 437         return (tsym.flags() & FINAL) != 0;
 438     }
 439 
 440     /**
 441      * Does this type contain occurrences of type t?
 442      */
 443     public boolean contains(Type t) {
 444         return t == this;
 445     }
 446 
 447     public static boolean contains(List<Type> ts, Type t) {
 448         for (List<Type> l = ts;
 449              l.tail != null /*inlined: l.nonEmpty()*/;
 450              l = l.tail)
 451             if (l.head.contains(t)) return true;


 961         final List<? extends Type> alternatives_field;
 962 
 963         public UnionClassType(ClassType ct, List<? extends Type> alternatives) {
 964             super(ct.outer_field, ct.typarams_field, ct.tsym);
 965             allparams_field = ct.allparams_field;
 966             supertype_field = ct.supertype_field;
 967             interfaces_field = ct.interfaces_field;
 968             all_interfaces_field = ct.interfaces_field;
 969             alternatives_field = alternatives;
 970         }
 971 
 972         public Type getLub() {
 973             return tsym.type;
 974         }
 975 
 976         public java.util.List<? extends TypeMirror> getAlternatives() {
 977             return Collections.unmodifiableList(alternatives_field);
 978         }
 979 
 980         @Override
 981         public boolean isUnion() {
 982             return true;
 983         }
 984 
 985         @Override
 986         public TypeKind getKind() {
 987             return TypeKind.UNION;
 988         }
 989 
 990         @Override
 991         public <R, P> R accept(TypeVisitor<R, P> v, P p) {
 992             return v.visitUnion(this, p);
 993         }
 994     }
 995 
 996     // a clone of a ClassType that knows about the bounds of an intersection type.
 997     public static class IntersectionClassType extends ClassType implements IntersectionType {
 998 
 999         public boolean allInterfaces;
1000 
1001         public IntersectionClassType(List<Type> bounds, ClassSymbol csym, boolean allInterfaces) {
1002             super(Type.noType, List.<Type>nil(), csym);
1003             this.allInterfaces = allInterfaces;
1004             Assert.check((csym.flags() & COMPOUND) != 0);
1005             supertype_field = bounds.head;
1006             interfaces_field = bounds.tail;
1007             Assert.check(supertype_field.tsym.completer != null ||
1008                     !supertype_field.isInterface(), supertype_field);
1009         }
1010 
1011         public java.util.List<? extends TypeMirror> getBounds() {
1012             return Collections.unmodifiableList(getExplicitComponents());
1013         }
1014 
1015         public List<Type> getComponents() {
1016             return interfaces_field.prepend(supertype_field);
1017         }
1018 
1019         @Override
1020         public boolean isIntersection() {
1021             return true;
1022         }
1023 
1024         public List<Type> getExplicitComponents() {
1025             return allInterfaces ?
1026                     interfaces_field :
1027                     getComponents();
1028         }
1029 
1030         @Override
1031         public TypeKind getKind() {
1032             return TypeKind.INTERSECTION;
1033         }
1034 
1035         @Override
1036         public <R, P> R accept(TypeVisitor<R, P> v, P p) {
1037             return v.visitIntersection(this, p);
1038         }
1039     }
1040 
1041     public static class ArrayType extends Type
1042             implements javax.lang.model.type.ArrayType {
1043