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

changeset 0
959103a6100f
child 2525
2eb010b6cb22
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Type.java	Wed Apr 27 01:34:52 2016 +0800
     1.3 @@ -0,0 +1,2063 @@
     1.4 +/*
     1.5 + * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package com.sun.tools.javac.code;
    1.30 +
    1.31 +import java.lang.annotation.Annotation;
    1.32 +import java.util.Collections;
    1.33 +import java.util.EnumMap;
    1.34 +import java.util.EnumSet;
    1.35 +import java.util.Map;
    1.36 +import java.util.Set;
    1.37 +
    1.38 +import javax.lang.model.type.*;
    1.39 +
    1.40 +import com.sun.tools.javac.code.Symbol.*;
    1.41 +import com.sun.tools.javac.util.*;
    1.42 +import static com.sun.tools.javac.code.BoundKind.*;
    1.43 +import static com.sun.tools.javac.code.Flags.*;
    1.44 +import static com.sun.tools.javac.code.Kinds.*;
    1.45 +import static com.sun.tools.javac.code.TypeTag.*;
    1.46 +
    1.47 +/** This class represents Java types. The class itself defines the behavior of
    1.48 + *  the following types:
    1.49 + *  <pre>
    1.50 + *  base types (tags: BYTE, CHAR, SHORT, INT, LONG, FLOAT, DOUBLE, BOOLEAN),
    1.51 + *  type `void' (tag: VOID),
    1.52 + *  the bottom type (tag: BOT),
    1.53 + *  the missing type (tag: NONE).
    1.54 + *  </pre>
    1.55 + *  <p>The behavior of the following types is defined in subclasses, which are
    1.56 + *  all static inner classes of this class:
    1.57 + *  <pre>
    1.58 + *  class types (tag: CLASS, class: ClassType),
    1.59 + *  array types (tag: ARRAY, class: ArrayType),
    1.60 + *  method types (tag: METHOD, class: MethodType),
    1.61 + *  package types (tag: PACKAGE, class: PackageType),
    1.62 + *  type variables (tag: TYPEVAR, class: TypeVar),
    1.63 + *  type arguments (tag: WILDCARD, class: WildcardType),
    1.64 + *  generic method types (tag: FORALL, class: ForAll),
    1.65 + *  the error type (tag: ERROR, class: ErrorType).
    1.66 + *  </pre>
    1.67 + *
    1.68 + *  <p><b>This is NOT part of any supported API.
    1.69 + *  If you write code that depends on this, you do so at your own risk.
    1.70 + *  This code and its internal interfaces are subject to change or
    1.71 + *  deletion without notice.</b>
    1.72 + *
    1.73 + *  @see TypeTag
    1.74 + */
    1.75 +public abstract class Type extends AnnoConstruct implements TypeMirror {
    1.76 +
    1.77 +    /** Constant type: no type at all. */
    1.78 +    public static final JCNoType noType = new JCNoType() {
    1.79 +        @Override
    1.80 +        public String toString() {
    1.81 +            return "none";
    1.82 +        }
    1.83 +    };
    1.84 +
    1.85 +    /** Constant type: special type to be used during recovery of deferred expressions. */
    1.86 +    public static final JCNoType recoveryType = new JCNoType(){
    1.87 +        @Override
    1.88 +        public String toString() {
    1.89 +            return "recovery";
    1.90 +        }
    1.91 +    };
    1.92 +
    1.93 +    /** Constant type: special type to be used for marking stuck trees. */
    1.94 +    public static final JCNoType stuckType = new JCNoType() {
    1.95 +        @Override
    1.96 +        public String toString() {
    1.97 +            return "stuck";
    1.98 +        }
    1.99 +    };
   1.100 +
   1.101 +    /** If this switch is turned on, the names of type variables
   1.102 +     *  and anonymous classes are printed with hashcodes appended.
   1.103 +     */
   1.104 +    public static boolean moreInfo = false;
   1.105 +
   1.106 +    /** The defining class / interface / package / type variable.
   1.107 +     */
   1.108 +    public TypeSymbol tsym;
   1.109 +
   1.110 +    /**
   1.111 +     * Checks if the current type tag is equal to the given tag.
   1.112 +     * @return true if tag is equal to the current type tag.
   1.113 +     */
   1.114 +    public boolean hasTag(TypeTag tag) {
   1.115 +        return tag == getTag();
   1.116 +    }
   1.117 +
   1.118 +    /**
   1.119 +     * Returns the current type tag.
   1.120 +     * @return the value of the current type tag.
   1.121 +     */
   1.122 +    public abstract TypeTag getTag();
   1.123 +
   1.124 +    public boolean isNumeric() {
   1.125 +        return false;
   1.126 +    }
   1.127 +
   1.128 +    public boolean isPrimitive() {
   1.129 +        return false;
   1.130 +    }
   1.131 +
   1.132 +    public boolean isPrimitiveOrVoid() {
   1.133 +        return false;
   1.134 +    }
   1.135 +
   1.136 +    public boolean isReference() {
   1.137 +        return false;
   1.138 +    }
   1.139 +
   1.140 +    public boolean isNullOrReference() {
   1.141 +        return false;
   1.142 +    }
   1.143 +
   1.144 +    public boolean isPartial() {
   1.145 +        return false;
   1.146 +    }
   1.147 +
   1.148 +    /**
   1.149 +     * The constant value of this type, null if this type does not
   1.150 +     * have a constant value attribute. Only primitive types and
   1.151 +     * strings (ClassType) can have a constant value attribute.
   1.152 +     * @return the constant value attribute of this type
   1.153 +     */
   1.154 +    public Object constValue() {
   1.155 +        return null;
   1.156 +    }
   1.157 +
   1.158 +    /** Is this a constant type whose value is false?
   1.159 +     */
   1.160 +    public boolean isFalse() {
   1.161 +        return false;
   1.162 +    }
   1.163 +
   1.164 +    /** Is this a constant type whose value is true?
   1.165 +     */
   1.166 +    public boolean isTrue() {
   1.167 +        return false;
   1.168 +    }
   1.169 +
   1.170 +    /**
   1.171 +     * Get the representation of this type used for modelling purposes.
   1.172 +     * By default, this is itself. For ErrorType, a different value
   1.173 +     * may be provided.
   1.174 +     */
   1.175 +    public Type getModelType() {
   1.176 +        return this;
   1.177 +    }
   1.178 +
   1.179 +    public static List<Type> getModelTypes(List<Type> ts) {
   1.180 +        ListBuffer<Type> lb = new ListBuffer<>();
   1.181 +        for (Type t: ts)
   1.182 +            lb.append(t.getModelType());
   1.183 +        return lb.toList();
   1.184 +    }
   1.185 +
   1.186 +    /**For ErrorType, returns the original type, otherwise returns the type itself.
   1.187 +     */
   1.188 +    public Type getOriginalType() {
   1.189 +        return this;
   1.190 +    }
   1.191 +
   1.192 +    public <R,S> R accept(Type.Visitor<R,S> v, S s) { return v.visitType(this, s); }
   1.193 +
   1.194 +    /** Define a type given its tag and type symbol
   1.195 +     */
   1.196 +    public Type(TypeSymbol tsym) {
   1.197 +        this.tsym = tsym;
   1.198 +    }
   1.199 +
   1.200 +    /** An abstract class for mappings from types to types
   1.201 +     */
   1.202 +    public static abstract class Mapping {
   1.203 +        private String name;
   1.204 +        public Mapping(String name) {
   1.205 +            this.name = name;
   1.206 +        }
   1.207 +        public abstract Type apply(Type t);
   1.208 +        public String toString() {
   1.209 +            return name;
   1.210 +        }
   1.211 +    }
   1.212 +
   1.213 +    /** map a type function over all immediate descendants of this type
   1.214 +     */
   1.215 +    public Type map(Mapping f) {
   1.216 +        return this;
   1.217 +    }
   1.218 +
   1.219 +    /** map a type function over a list of types
   1.220 +     */
   1.221 +    public static List<Type> map(List<Type> ts, Mapping f) {
   1.222 +        if (ts.nonEmpty()) {
   1.223 +            List<Type> tail1 = map(ts.tail, f);
   1.224 +            Type t = f.apply(ts.head);
   1.225 +            if (tail1 != ts.tail || t != ts.head)
   1.226 +                return tail1.prepend(t);
   1.227 +        }
   1.228 +        return ts;
   1.229 +    }
   1.230 +
   1.231 +    /** Define a constant type, of the same kind as this type
   1.232 +     *  and with given constant value
   1.233 +     */
   1.234 +    public Type constType(Object constValue) {
   1.235 +        throw new AssertionError();
   1.236 +    }
   1.237 +
   1.238 +    /**
   1.239 +     * If this is a constant type, return its underlying type.
   1.240 +     * Otherwise, return the type itself.
   1.241 +     */
   1.242 +    public Type baseType() {
   1.243 +        return this;
   1.244 +    }
   1.245 +
   1.246 +    public Type annotatedType(List<Attribute.TypeCompound> annos) {
   1.247 +        return new AnnotatedType(annos, this);
   1.248 +    }
   1.249 +
   1.250 +    public boolean isAnnotated() {
   1.251 +        return false;
   1.252 +    }
   1.253 +
   1.254 +    /**
   1.255 +     * If this is an annotated type, return the underlying type.
   1.256 +     * Otherwise, return the type itself.
   1.257 +     */
   1.258 +    public Type unannotatedType() {
   1.259 +        return this;
   1.260 +    }
   1.261 +
   1.262 +    @Override
   1.263 +    public List<Attribute.TypeCompound> getAnnotationMirrors() {
   1.264 +        return List.nil();
   1.265 +    }
   1.266 +
   1.267 +
   1.268 +    @Override
   1.269 +    public <A extends Annotation> A getAnnotation(Class<A> annotationType) {
   1.270 +        return null;
   1.271 +    }
   1.272 +
   1.273 +
   1.274 +    @Override
   1.275 +    public <A extends Annotation> A[] getAnnotationsByType(Class<A> annotationType) {
   1.276 +        @SuppressWarnings("unchecked")
   1.277 +        A[] tmp = (A[]) java.lang.reflect.Array.newInstance(annotationType, 0);
   1.278 +        return tmp;
   1.279 +    }
   1.280 +
   1.281 +    /** Return the base types of a list of types.
   1.282 +     */
   1.283 +    public static List<Type> baseTypes(List<Type> ts) {
   1.284 +        if (ts.nonEmpty()) {
   1.285 +            Type t = ts.head.baseType();
   1.286 +            List<Type> baseTypes = baseTypes(ts.tail);
   1.287 +            if (t != ts.head || baseTypes != ts.tail)
   1.288 +                return baseTypes.prepend(t);
   1.289 +        }
   1.290 +        return ts;
   1.291 +    }
   1.292 +
   1.293 +    /** The Java source which this type represents.
   1.294 +     */
   1.295 +    public String toString() {
   1.296 +        String s = (tsym == null || tsym.name == null)
   1.297 +            ? "<none>"
   1.298 +            : tsym.name.toString();
   1.299 +        if (moreInfo && hasTag(TYPEVAR)) {
   1.300 +            s = s + hashCode();
   1.301 +        }
   1.302 +        return s;
   1.303 +    }
   1.304 +
   1.305 +    /**
   1.306 +     * The Java source which this type list represents.  A List is
   1.307 +     * represented as a comma-spearated listing of the elements in
   1.308 +     * that list.
   1.309 +     */
   1.310 +    public static String toString(List<Type> ts) {
   1.311 +        if (ts.isEmpty()) {
   1.312 +            return "";
   1.313 +        } else {
   1.314 +            StringBuilder buf = new StringBuilder();
   1.315 +            buf.append(ts.head.toString());
   1.316 +            for (List<Type> l = ts.tail; l.nonEmpty(); l = l.tail)
   1.317 +                buf.append(",").append(l.head.toString());
   1.318 +            return buf.toString();
   1.319 +        }
   1.320 +    }
   1.321 +
   1.322 +    /**
   1.323 +     * The constant value of this type, converted to String
   1.324 +     */
   1.325 +    public String stringValue() {
   1.326 +        Object cv = Assert.checkNonNull(constValue());
   1.327 +        return cv.toString();
   1.328 +    }
   1.329 +
   1.330 +    /**
   1.331 +     * This method is analogous to isSameType, but weaker, since we
   1.332 +     * never complete classes. Where isSameType would complete a
   1.333 +     * class, equals assumes that the two types are different.
   1.334 +     */
   1.335 +    @Override
   1.336 +    public boolean equals(Object t) {
   1.337 +        return super.equals(t);
   1.338 +    }
   1.339 +
   1.340 +    @Override
   1.341 +    public int hashCode() {
   1.342 +        return super.hashCode();
   1.343 +    }
   1.344 +
   1.345 +    public String argtypes(boolean varargs) {
   1.346 +        List<Type> args = getParameterTypes();
   1.347 +        if (!varargs) return args.toString();
   1.348 +        StringBuilder buf = new StringBuilder();
   1.349 +        while (args.tail.nonEmpty()) {
   1.350 +            buf.append(args.head);
   1.351 +            args = args.tail;
   1.352 +            buf.append(',');
   1.353 +        }
   1.354 +        if (args.head.unannotatedType().hasTag(ARRAY)) {
   1.355 +            buf.append(((ArrayType)args.head.unannotatedType()).elemtype);
   1.356 +            if (args.head.getAnnotationMirrors().nonEmpty()) {
   1.357 +                buf.append(args.head.getAnnotationMirrors());
   1.358 +            }
   1.359 +            buf.append("...");
   1.360 +        } else {
   1.361 +            buf.append(args.head);
   1.362 +        }
   1.363 +        return buf.toString();
   1.364 +    }
   1.365 +
   1.366 +    /** Access methods.
   1.367 +     */
   1.368 +    public List<Type>        getTypeArguments()  { return List.nil(); }
   1.369 +    public Type              getEnclosingType()  { return null; }
   1.370 +    public List<Type>        getParameterTypes() { return List.nil(); }
   1.371 +    public Type              getReturnType()     { return null; }
   1.372 +    public Type              getReceiverType()   { return null; }
   1.373 +    public List<Type>        getThrownTypes()    { return List.nil(); }
   1.374 +    public Type              getUpperBound()     { return null; }
   1.375 +    public Type              getLowerBound()     { return null; }
   1.376 +
   1.377 +    /** Navigation methods, these will work for classes, type variables,
   1.378 +     *  foralls, but will return null for arrays and methods.
   1.379 +     */
   1.380 +
   1.381 +   /** Return all parameters of this type and all its outer types in order
   1.382 +    *  outer (first) to inner (last).
   1.383 +    */
   1.384 +    public List<Type> allparams() { return List.nil(); }
   1.385 +
   1.386 +    /** Does this type contain "error" elements?
   1.387 +     */
   1.388 +    public boolean isErroneous() {
   1.389 +        return false;
   1.390 +    }
   1.391 +
   1.392 +    public static boolean isErroneous(List<Type> ts) {
   1.393 +        for (List<Type> l = ts; l.nonEmpty(); l = l.tail)
   1.394 +            if (l.head.isErroneous()) return true;
   1.395 +        return false;
   1.396 +    }
   1.397 +
   1.398 +    /** Is this type parameterized?
   1.399 +     *  A class type is parameterized if it has some parameters.
   1.400 +     *  An array type is parameterized if its element type is parameterized.
   1.401 +     *  All other types are not parameterized.
   1.402 +     */
   1.403 +    public boolean isParameterized() {
   1.404 +        return false;
   1.405 +    }
   1.406 +
   1.407 +    /** Is this type a raw type?
   1.408 +     *  A class type is a raw type if it misses some of its parameters.
   1.409 +     *  An array type is a raw type if its element type is raw.
   1.410 +     *  All other types are not raw.
   1.411 +     *  Type validation will ensure that the only raw types
   1.412 +     *  in a program are types that miss all their type variables.
   1.413 +     */
   1.414 +    public boolean isRaw() {
   1.415 +        return false;
   1.416 +    }
   1.417 +
   1.418 +    public boolean isCompound() {
   1.419 +        return tsym.completer == null
   1.420 +            // Compound types can't have a completer.  Calling
   1.421 +            // flags() will complete the symbol causing the
   1.422 +            // compiler to load classes unnecessarily.  This led
   1.423 +            // to regression 6180021.
   1.424 +            && (tsym.flags() & COMPOUND) != 0;
   1.425 +    }
   1.426 +
   1.427 +    public boolean isInterface() {
   1.428 +        return (tsym.flags() & INTERFACE) != 0;
   1.429 +    }
   1.430 +
   1.431 +    public boolean isFinal() {
   1.432 +        return (tsym.flags() & FINAL) != 0;
   1.433 +    }
   1.434 +
   1.435 +    /**
   1.436 +     * Does this type contain occurrences of type t?
   1.437 +     */
   1.438 +    public boolean contains(Type t) {
   1.439 +        return t == this;
   1.440 +    }
   1.441 +
   1.442 +    public static boolean contains(List<Type> ts, Type t) {
   1.443 +        for (List<Type> l = ts;
   1.444 +             l.tail != null /*inlined: l.nonEmpty()*/;
   1.445 +             l = l.tail)
   1.446 +            if (l.head.contains(t)) return true;
   1.447 +        return false;
   1.448 +    }
   1.449 +
   1.450 +    /** Does this type contain an occurrence of some type in 'ts'?
   1.451 +     */
   1.452 +    public boolean containsAny(List<Type> ts) {
   1.453 +        for (Type t : ts)
   1.454 +            if (this.contains(t)) return true;
   1.455 +        return false;
   1.456 +    }
   1.457 +
   1.458 +    public static boolean containsAny(List<Type> ts1, List<Type> ts2) {
   1.459 +        for (Type t : ts1)
   1.460 +            if (t.containsAny(ts2)) return true;
   1.461 +        return false;
   1.462 +    }
   1.463 +
   1.464 +    public static List<Type> filter(List<Type> ts, Filter<Type> tf) {
   1.465 +        ListBuffer<Type> buf = new ListBuffer<>();
   1.466 +        for (Type t : ts) {
   1.467 +            if (tf.accepts(t)) {
   1.468 +                buf.append(t);
   1.469 +            }
   1.470 +        }
   1.471 +        return buf.toList();
   1.472 +    }
   1.473 +
   1.474 +    public boolean isSuperBound() { return false; }
   1.475 +    public boolean isExtendsBound() { return false; }
   1.476 +    public boolean isUnbound() { return false; }
   1.477 +    public Type withTypeVar(Type t) { return this; }
   1.478 +
   1.479 +    /** The underlying method type of this type.
   1.480 +     */
   1.481 +    public MethodType asMethodType() { throw new AssertionError(); }
   1.482 +
   1.483 +    /** Complete loading all classes in this type.
   1.484 +     */
   1.485 +    public void complete() {}
   1.486 +
   1.487 +    public TypeSymbol asElement() {
   1.488 +        return tsym;
   1.489 +    }
   1.490 +
   1.491 +    @Override
   1.492 +    public TypeKind getKind() {
   1.493 +        return TypeKind.OTHER;
   1.494 +    }
   1.495 +
   1.496 +    @Override
   1.497 +    public <R, P> R accept(TypeVisitor<R, P> v, P p) {
   1.498 +        throw new AssertionError();
   1.499 +    }
   1.500 +
   1.501 +    public static class JCPrimitiveType extends Type
   1.502 +            implements javax.lang.model.type.PrimitiveType {
   1.503 +
   1.504 +        TypeTag tag;
   1.505 +
   1.506 +        public JCPrimitiveType(TypeTag tag, TypeSymbol tsym) {
   1.507 +            super(tsym);
   1.508 +            this.tag = tag;
   1.509 +            Assert.check(tag.isPrimitive);
   1.510 +        }
   1.511 +
   1.512 +        @Override
   1.513 +        public boolean isNumeric() {
   1.514 +            return tag != BOOLEAN;
   1.515 +        }
   1.516 +
   1.517 +        @Override
   1.518 +        public boolean isPrimitive() {
   1.519 +            return true;
   1.520 +        }
   1.521 +
   1.522 +        @Override
   1.523 +        public TypeTag getTag() {
   1.524 +            return tag;
   1.525 +        }
   1.526 +
   1.527 +        @Override
   1.528 +        public boolean isPrimitiveOrVoid() {
   1.529 +            return true;
   1.530 +        }
   1.531 +
   1.532 +        /** Define a constant type, of the same kind as this type
   1.533 +         *  and with given constant value
   1.534 +         */
   1.535 +        @Override
   1.536 +        public Type constType(Object constValue) {
   1.537 +            final Object value = constValue;
   1.538 +            return new JCPrimitiveType(tag, tsym) {
   1.539 +                    @Override
   1.540 +                    public Object constValue() {
   1.541 +                        return value;
   1.542 +                    }
   1.543 +                    @Override
   1.544 +                    public Type baseType() {
   1.545 +                        return tsym.type;
   1.546 +                    }
   1.547 +                };
   1.548 +        }
   1.549 +
   1.550 +        /**
   1.551 +         * The constant value of this type, converted to String
   1.552 +         */
   1.553 +        @Override
   1.554 +        public String stringValue() {
   1.555 +            Object cv = Assert.checkNonNull(constValue());
   1.556 +            if (tag == BOOLEAN) {
   1.557 +                return ((Integer) cv).intValue() == 0 ? "false" : "true";
   1.558 +            }
   1.559 +            else if (tag == CHAR) {
   1.560 +                return String.valueOf((char) ((Integer) cv).intValue());
   1.561 +            }
   1.562 +            else {
   1.563 +                return cv.toString();
   1.564 +            }
   1.565 +        }
   1.566 +
   1.567 +        /** Is this a constant type whose value is false?
   1.568 +         */
   1.569 +        @Override
   1.570 +        public boolean isFalse() {
   1.571 +            return
   1.572 +                tag == BOOLEAN &&
   1.573 +                constValue() != null &&
   1.574 +                ((Integer)constValue()).intValue() == 0;
   1.575 +        }
   1.576 +
   1.577 +        /** Is this a constant type whose value is true?
   1.578 +         */
   1.579 +        @Override
   1.580 +        public boolean isTrue() {
   1.581 +            return
   1.582 +                tag == BOOLEAN &&
   1.583 +                constValue() != null &&
   1.584 +                ((Integer)constValue()).intValue() != 0;
   1.585 +        }
   1.586 +
   1.587 +        @Override
   1.588 +        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
   1.589 +            return v.visitPrimitive(this, p);
   1.590 +        }
   1.591 +
   1.592 +        @Override
   1.593 +        public TypeKind getKind() {
   1.594 +            switch (tag) {
   1.595 +                case BYTE:      return TypeKind.BYTE;
   1.596 +                case CHAR:      return TypeKind.CHAR;
   1.597 +                case SHORT:     return TypeKind.SHORT;
   1.598 +                case INT:       return TypeKind.INT;
   1.599 +                case LONG:      return TypeKind.LONG;
   1.600 +                case FLOAT:     return TypeKind.FLOAT;
   1.601 +                case DOUBLE:    return TypeKind.DOUBLE;
   1.602 +                case BOOLEAN:   return TypeKind.BOOLEAN;
   1.603 +            }
   1.604 +            throw new AssertionError();
   1.605 +        }
   1.606 +
   1.607 +    }
   1.608 +
   1.609 +    public static class WildcardType extends Type
   1.610 +            implements javax.lang.model.type.WildcardType {
   1.611 +
   1.612 +        public Type type;
   1.613 +        public BoundKind kind;
   1.614 +        public TypeVar bound;
   1.615 +
   1.616 +        @Override
   1.617 +        public <R,S> R accept(Type.Visitor<R,S> v, S s) {
   1.618 +            return v.visitWildcardType(this, s);
   1.619 +        }
   1.620 +
   1.621 +        public WildcardType(Type type, BoundKind kind, TypeSymbol tsym) {
   1.622 +            super(tsym);
   1.623 +            this.type = Assert.checkNonNull(type);
   1.624 +            this.kind = kind;
   1.625 +        }
   1.626 +        public WildcardType(WildcardType t, TypeVar bound) {
   1.627 +            this(t.type, t.kind, t.tsym, bound);
   1.628 +        }
   1.629 +
   1.630 +        public WildcardType(Type type, BoundKind kind, TypeSymbol tsym, TypeVar bound) {
   1.631 +            this(type, kind, tsym);
   1.632 +            this.bound = bound;
   1.633 +        }
   1.634 +
   1.635 +        @Override
   1.636 +        public TypeTag getTag() {
   1.637 +            return WILDCARD;
   1.638 +        }
   1.639 +
   1.640 +        @Override
   1.641 +        public boolean contains(Type t) {
   1.642 +            return kind != UNBOUND && type.contains(t);
   1.643 +        }
   1.644 +
   1.645 +        public boolean isSuperBound() {
   1.646 +            return kind == SUPER ||
   1.647 +                kind == UNBOUND;
   1.648 +        }
   1.649 +        public boolean isExtendsBound() {
   1.650 +            return kind == EXTENDS ||
   1.651 +                kind == UNBOUND;
   1.652 +        }
   1.653 +        public boolean isUnbound() {
   1.654 +            return kind == UNBOUND;
   1.655 +        }
   1.656 +
   1.657 +        @Override
   1.658 +        public boolean isReference() {
   1.659 +            return true;
   1.660 +        }
   1.661 +
   1.662 +        @Override
   1.663 +        public boolean isNullOrReference() {
   1.664 +            return true;
   1.665 +        }
   1.666 +
   1.667 +        @Override
   1.668 +        public Type withTypeVar(Type t) {
   1.669 +            //-System.err.println(this+".withTypeVar("+t+");");//DEBUG
   1.670 +            if (bound == t)
   1.671 +                return this;
   1.672 +            bound = (TypeVar)t;
   1.673 +            return this;
   1.674 +        }
   1.675 +
   1.676 +        boolean isPrintingBound = false;
   1.677 +        public String toString() {
   1.678 +            StringBuilder s = new StringBuilder();
   1.679 +            s.append(kind.toString());
   1.680 +            if (kind != UNBOUND)
   1.681 +                s.append(type);
   1.682 +            if (moreInfo && bound != null && !isPrintingBound)
   1.683 +                try {
   1.684 +                    isPrintingBound = true;
   1.685 +                    s.append("{:").append(bound.bound).append(":}");
   1.686 +                } finally {
   1.687 +                    isPrintingBound = false;
   1.688 +                }
   1.689 +            return s.toString();
   1.690 +        }
   1.691 +
   1.692 +        public Type map(Mapping f) {
   1.693 +            //- System.err.println("   (" + this + ").map(" + f + ")");//DEBUG
   1.694 +            Type t = type;
   1.695 +            if (t != null)
   1.696 +                t = f.apply(t);
   1.697 +            if (t == type)
   1.698 +                return this;
   1.699 +            else
   1.700 +                return new WildcardType(t, kind, tsym, bound);
   1.701 +        }
   1.702 +
   1.703 +        public Type getExtendsBound() {
   1.704 +            if (kind == EXTENDS)
   1.705 +                return type;
   1.706 +            else
   1.707 +                return null;
   1.708 +        }
   1.709 +
   1.710 +        public Type getSuperBound() {
   1.711 +            if (kind == SUPER)
   1.712 +                return type;
   1.713 +            else
   1.714 +                return null;
   1.715 +        }
   1.716 +
   1.717 +        public TypeKind getKind() {
   1.718 +            return TypeKind.WILDCARD;
   1.719 +        }
   1.720 +
   1.721 +        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
   1.722 +            return v.visitWildcard(this, p);
   1.723 +        }
   1.724 +    }
   1.725 +
   1.726 +    public static class ClassType extends Type implements DeclaredType {
   1.727 +
   1.728 +        /** The enclosing type of this type. If this is the type of an inner
   1.729 +         *  class, outer_field refers to the type of its enclosing
   1.730 +         *  instance class, in all other cases it refers to noType.
   1.731 +         */
   1.732 +        private Type outer_field;
   1.733 +
   1.734 +        /** The type parameters of this type (to be set once class is loaded).
   1.735 +         */
   1.736 +        public List<Type> typarams_field;
   1.737 +
   1.738 +        /** A cache variable for the type parameters of this type,
   1.739 +         *  appended to all parameters of its enclosing class.
   1.740 +         *  @see #allparams
   1.741 +         */
   1.742 +        public List<Type> allparams_field;
   1.743 +
   1.744 +        /** The supertype of this class (to be set once class is loaded).
   1.745 +         */
   1.746 +        public Type supertype_field;
   1.747 +
   1.748 +        /** The interfaces of this class (to be set once class is loaded).
   1.749 +         */
   1.750 +        public List<Type> interfaces_field;
   1.751 +
   1.752 +        /** All the interfaces of this class, including missing ones.
   1.753 +         */
   1.754 +        public List<Type> all_interfaces_field;
   1.755 +
   1.756 +        public ClassType(Type outer, List<Type> typarams, TypeSymbol tsym) {
   1.757 +            super(tsym);
   1.758 +            this.outer_field = outer;
   1.759 +            this.typarams_field = typarams;
   1.760 +            this.allparams_field = null;
   1.761 +            this.supertype_field = null;
   1.762 +            this.interfaces_field = null;
   1.763 +            /*
   1.764 +            // this can happen during error recovery
   1.765 +            assert
   1.766 +                outer.isParameterized() ?
   1.767 +                typarams.length() == tsym.type.typarams().length() :
   1.768 +                outer.isRaw() ?
   1.769 +                typarams.length() == 0 :
   1.770 +                true;
   1.771 +            */
   1.772 +        }
   1.773 +
   1.774 +        @Override
   1.775 +        public TypeTag getTag() {
   1.776 +            return CLASS;
   1.777 +        }
   1.778 +
   1.779 +        @Override
   1.780 +        public <R,S> R accept(Type.Visitor<R,S> v, S s) {
   1.781 +            return v.visitClassType(this, s);
   1.782 +        }
   1.783 +
   1.784 +        public Type constType(Object constValue) {
   1.785 +            final Object value = constValue;
   1.786 +            return new ClassType(getEnclosingType(), typarams_field, tsym) {
   1.787 +                    @Override
   1.788 +                    public Object constValue() {
   1.789 +                        return value;
   1.790 +                    }
   1.791 +                    @Override
   1.792 +                    public Type baseType() {
   1.793 +                        return tsym.type;
   1.794 +                    }
   1.795 +                };
   1.796 +        }
   1.797 +
   1.798 +        /** The Java source which this type represents.
   1.799 +         */
   1.800 +        public String toString() {
   1.801 +            StringBuilder buf = new StringBuilder();
   1.802 +            if (getEnclosingType().hasTag(CLASS) && tsym.owner.kind == TYP) {
   1.803 +                buf.append(getEnclosingType().toString());
   1.804 +                buf.append(".");
   1.805 +                buf.append(className(tsym, false));
   1.806 +            } else {
   1.807 +                buf.append(className(tsym, true));
   1.808 +            }
   1.809 +            if (getTypeArguments().nonEmpty()) {
   1.810 +                buf.append('<');
   1.811 +                buf.append(getTypeArguments().toString());
   1.812 +                buf.append(">");
   1.813 +            }
   1.814 +            return buf.toString();
   1.815 +        }
   1.816 +//where
   1.817 +            private String className(Symbol sym, boolean longform) {
   1.818 +                if (sym.name.isEmpty() && (sym.flags() & COMPOUND) != 0) {
   1.819 +                    StringBuilder s = new StringBuilder(supertype_field.toString());
   1.820 +                    for (List<Type> is=interfaces_field; is.nonEmpty(); is = is.tail) {
   1.821 +                        s.append("&");
   1.822 +                        s.append(is.head.toString());
   1.823 +                    }
   1.824 +                    return s.toString();
   1.825 +                } else if (sym.name.isEmpty()) {
   1.826 +                    String s;
   1.827 +                    ClassType norm = (ClassType) tsym.type.unannotatedType();
   1.828 +                    if (norm == null) {
   1.829 +                        s = Log.getLocalizedString("anonymous.class", (Object)null);
   1.830 +                    } else if (norm.interfaces_field != null && norm.interfaces_field.nonEmpty()) {
   1.831 +                        s = Log.getLocalizedString("anonymous.class",
   1.832 +                                                   norm.interfaces_field.head);
   1.833 +                    } else {
   1.834 +                        s = Log.getLocalizedString("anonymous.class",
   1.835 +                                                   norm.supertype_field);
   1.836 +                    }
   1.837 +                    if (moreInfo)
   1.838 +                        s += String.valueOf(sym.hashCode());
   1.839 +                    return s;
   1.840 +                } else if (longform) {
   1.841 +                    return sym.getQualifiedName().toString();
   1.842 +                } else {
   1.843 +                    return sym.name.toString();
   1.844 +                }
   1.845 +            }
   1.846 +
   1.847 +        public List<Type> getTypeArguments() {
   1.848 +            if (typarams_field == null) {
   1.849 +                complete();
   1.850 +                if (typarams_field == null)
   1.851 +                    typarams_field = List.nil();
   1.852 +            }
   1.853 +            return typarams_field;
   1.854 +        }
   1.855 +
   1.856 +        public boolean hasErasedSupertypes() {
   1.857 +            return isRaw();
   1.858 +        }
   1.859 +
   1.860 +        public Type getEnclosingType() {
   1.861 +            return outer_field;
   1.862 +        }
   1.863 +
   1.864 +        public void setEnclosingType(Type outer) {
   1.865 +            outer_field = outer;
   1.866 +        }
   1.867 +
   1.868 +        public List<Type> allparams() {
   1.869 +            if (allparams_field == null) {
   1.870 +                allparams_field = getTypeArguments().prependList(getEnclosingType().allparams());
   1.871 +            }
   1.872 +            return allparams_field;
   1.873 +        }
   1.874 +
   1.875 +        public boolean isErroneous() {
   1.876 +            return
   1.877 +                getEnclosingType().isErroneous() ||
   1.878 +                isErroneous(getTypeArguments()) ||
   1.879 +                this != tsym.type.unannotatedType() && tsym.type.isErroneous();
   1.880 +        }
   1.881 +
   1.882 +        public boolean isParameterized() {
   1.883 +            return allparams().tail != null;
   1.884 +            // optimization, was: allparams().nonEmpty();
   1.885 +        }
   1.886 +
   1.887 +        @Override
   1.888 +        public boolean isReference() {
   1.889 +            return true;
   1.890 +        }
   1.891 +
   1.892 +        @Override
   1.893 +        public boolean isNullOrReference() {
   1.894 +            return true;
   1.895 +        }
   1.896 +
   1.897 +        /** A cache for the rank. */
   1.898 +        int rank_field = -1;
   1.899 +
   1.900 +        /** A class type is raw if it misses some
   1.901 +         *  of its type parameter sections.
   1.902 +         *  After validation, this is equivalent to:
   1.903 +         *  {@code allparams.isEmpty() && tsym.type.allparams.nonEmpty(); }
   1.904 +         */
   1.905 +        public boolean isRaw() {
   1.906 +            return
   1.907 +                this != tsym.type && // necessary, but not sufficient condition
   1.908 +                tsym.type.allparams().nonEmpty() &&
   1.909 +                allparams().isEmpty();
   1.910 +        }
   1.911 +
   1.912 +        public Type map(Mapping f) {
   1.913 +            Type outer = getEnclosingType();
   1.914 +            Type outer1 = f.apply(outer);
   1.915 +            List<Type> typarams = getTypeArguments();
   1.916 +            List<Type> typarams1 = map(typarams, f);
   1.917 +            if (outer1 == outer && typarams1 == typarams) return this;
   1.918 +            else return new ClassType(outer1, typarams1, tsym);
   1.919 +        }
   1.920 +
   1.921 +        public boolean contains(Type elem) {
   1.922 +            return
   1.923 +                elem == this
   1.924 +                || (isParameterized()
   1.925 +                    && (getEnclosingType().contains(elem) || contains(getTypeArguments(), elem)))
   1.926 +                || (isCompound()
   1.927 +                    && (supertype_field.contains(elem) || contains(interfaces_field, elem)));
   1.928 +        }
   1.929 +
   1.930 +        public void complete() {
   1.931 +            if (tsym.completer != null) tsym.complete();
   1.932 +        }
   1.933 +
   1.934 +        public TypeKind getKind() {
   1.935 +            return TypeKind.DECLARED;
   1.936 +        }
   1.937 +
   1.938 +        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
   1.939 +            return v.visitDeclared(this, p);
   1.940 +        }
   1.941 +    }
   1.942 +
   1.943 +    public static class ErasedClassType extends ClassType {
   1.944 +        public ErasedClassType(Type outer, TypeSymbol tsym) {
   1.945 +            super(outer, List.<Type>nil(), tsym);
   1.946 +        }
   1.947 +
   1.948 +        @Override
   1.949 +        public boolean hasErasedSupertypes() {
   1.950 +            return true;
   1.951 +        }
   1.952 +    }
   1.953 +
   1.954 +    // a clone of a ClassType that knows about the alternatives of a union type.
   1.955 +    public static class UnionClassType extends ClassType implements UnionType {
   1.956 +        final List<? extends Type> alternatives_field;
   1.957 +
   1.958 +        public UnionClassType(ClassType ct, List<? extends Type> alternatives) {
   1.959 +            super(ct.outer_field, ct.typarams_field, ct.tsym);
   1.960 +            allparams_field = ct.allparams_field;
   1.961 +            supertype_field = ct.supertype_field;
   1.962 +            interfaces_field = ct.interfaces_field;
   1.963 +            all_interfaces_field = ct.interfaces_field;
   1.964 +            alternatives_field = alternatives;
   1.965 +        }
   1.966 +
   1.967 +        public Type getLub() {
   1.968 +            return tsym.type;
   1.969 +        }
   1.970 +
   1.971 +        public java.util.List<? extends TypeMirror> getAlternatives() {
   1.972 +            return Collections.unmodifiableList(alternatives_field);
   1.973 +        }
   1.974 +
   1.975 +        @Override
   1.976 +        public TypeKind getKind() {
   1.977 +            return TypeKind.UNION;
   1.978 +        }
   1.979 +
   1.980 +        @Override
   1.981 +        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
   1.982 +            return v.visitUnion(this, p);
   1.983 +        }
   1.984 +    }
   1.985 +
   1.986 +    // a clone of a ClassType that knows about the bounds of an intersection type.
   1.987 +    public static class IntersectionClassType extends ClassType implements IntersectionType {
   1.988 +
   1.989 +        public boolean allInterfaces;
   1.990 +
   1.991 +        public IntersectionClassType(List<Type> bounds, ClassSymbol csym, boolean allInterfaces) {
   1.992 +            super(Type.noType, List.<Type>nil(), csym);
   1.993 +            this.allInterfaces = allInterfaces;
   1.994 +            Assert.check((csym.flags() & COMPOUND) != 0);
   1.995 +            supertype_field = bounds.head;
   1.996 +            interfaces_field = bounds.tail;
   1.997 +            Assert.check(supertype_field.tsym.completer != null ||
   1.998 +                    !supertype_field.isInterface(), supertype_field);
   1.999 +        }
  1.1000 +
  1.1001 +        public java.util.List<? extends TypeMirror> getBounds() {
  1.1002 +            return Collections.unmodifiableList(getExplicitComponents());
  1.1003 +        }
  1.1004 +
  1.1005 +        public List<Type> getComponents() {
  1.1006 +            return interfaces_field.prepend(supertype_field);
  1.1007 +        }
  1.1008 +
  1.1009 +        public List<Type> getExplicitComponents() {
  1.1010 +            return allInterfaces ?
  1.1011 +                    interfaces_field :
  1.1012 +                    getComponents();
  1.1013 +        }
  1.1014 +
  1.1015 +        @Override
  1.1016 +        public TypeKind getKind() {
  1.1017 +            return TypeKind.INTERSECTION;
  1.1018 +        }
  1.1019 +
  1.1020 +        @Override
  1.1021 +        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
  1.1022 +            return v.visitIntersection(this, p);
  1.1023 +        }
  1.1024 +    }
  1.1025 +
  1.1026 +    public static class ArrayType extends Type
  1.1027 +            implements javax.lang.model.type.ArrayType {
  1.1028 +
  1.1029 +        public Type elemtype;
  1.1030 +
  1.1031 +        public ArrayType(Type elemtype, TypeSymbol arrayClass) {
  1.1032 +            super(arrayClass);
  1.1033 +            this.elemtype = elemtype;
  1.1034 +        }
  1.1035 +
  1.1036 +        @Override
  1.1037 +        public TypeTag getTag() {
  1.1038 +            return ARRAY;
  1.1039 +        }
  1.1040 +
  1.1041 +        public <R,S> R accept(Type.Visitor<R,S> v, S s) {
  1.1042 +            return v.visitArrayType(this, s);
  1.1043 +        }
  1.1044 +
  1.1045 +        public String toString() {
  1.1046 +            return elemtype + "[]";
  1.1047 +        }
  1.1048 +
  1.1049 +        public boolean equals(Object obj) {
  1.1050 +            return
  1.1051 +                this == obj ||
  1.1052 +                (obj instanceof ArrayType &&
  1.1053 +                 this.elemtype.equals(((ArrayType)obj).elemtype));
  1.1054 +        }
  1.1055 +
  1.1056 +        public int hashCode() {
  1.1057 +            return (ARRAY.ordinal() << 5) + elemtype.hashCode();
  1.1058 +        }
  1.1059 +
  1.1060 +        public boolean isVarargs() {
  1.1061 +            return false;
  1.1062 +        }
  1.1063 +
  1.1064 +        public List<Type> allparams() { return elemtype.allparams(); }
  1.1065 +
  1.1066 +        public boolean isErroneous() {
  1.1067 +            return elemtype.isErroneous();
  1.1068 +        }
  1.1069 +
  1.1070 +        public boolean isParameterized() {
  1.1071 +            return elemtype.isParameterized();
  1.1072 +        }
  1.1073 +
  1.1074 +        @Override
  1.1075 +        public boolean isReference() {
  1.1076 +            return true;
  1.1077 +        }
  1.1078 +
  1.1079 +        @Override
  1.1080 +        public boolean isNullOrReference() {
  1.1081 +            return true;
  1.1082 +        }
  1.1083 +
  1.1084 +        public boolean isRaw() {
  1.1085 +            return elemtype.isRaw();
  1.1086 +        }
  1.1087 +
  1.1088 +        public ArrayType makeVarargs() {
  1.1089 +            return new ArrayType(elemtype, tsym) {
  1.1090 +                @Override
  1.1091 +                public boolean isVarargs() {
  1.1092 +                    return true;
  1.1093 +                }
  1.1094 +            };
  1.1095 +        }
  1.1096 +
  1.1097 +        public Type map(Mapping f) {
  1.1098 +            Type elemtype1 = f.apply(elemtype);
  1.1099 +            if (elemtype1 == elemtype) return this;
  1.1100 +            else return new ArrayType(elemtype1, tsym);
  1.1101 +        }
  1.1102 +
  1.1103 +        public boolean contains(Type elem) {
  1.1104 +            return elem == this || elemtype.contains(elem);
  1.1105 +        }
  1.1106 +
  1.1107 +        public void complete() {
  1.1108 +            elemtype.complete();
  1.1109 +        }
  1.1110 +
  1.1111 +        public Type getComponentType() {
  1.1112 +            return elemtype;
  1.1113 +        }
  1.1114 +
  1.1115 +        public TypeKind getKind() {
  1.1116 +            return TypeKind.ARRAY;
  1.1117 +        }
  1.1118 +
  1.1119 +        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
  1.1120 +            return v.visitArray(this, p);
  1.1121 +        }
  1.1122 +    }
  1.1123 +
  1.1124 +    public static class MethodType extends Type implements ExecutableType {
  1.1125 +
  1.1126 +        public List<Type> argtypes;
  1.1127 +        public Type restype;
  1.1128 +        public List<Type> thrown;
  1.1129 +
  1.1130 +        /** The type annotations on the method receiver.
  1.1131 +         */
  1.1132 +        public Type recvtype;
  1.1133 +
  1.1134 +        public MethodType(List<Type> argtypes,
  1.1135 +                          Type restype,
  1.1136 +                          List<Type> thrown,
  1.1137 +                          TypeSymbol methodClass) {
  1.1138 +            super(methodClass);
  1.1139 +            this.argtypes = argtypes;
  1.1140 +            this.restype = restype;
  1.1141 +            this.thrown = thrown;
  1.1142 +        }
  1.1143 +
  1.1144 +        @Override
  1.1145 +        public TypeTag getTag() {
  1.1146 +            return METHOD;
  1.1147 +        }
  1.1148 +
  1.1149 +        public <R,S> R accept(Type.Visitor<R,S> v, S s) {
  1.1150 +            return v.visitMethodType(this, s);
  1.1151 +        }
  1.1152 +
  1.1153 +        /** The Java source which this type represents.
  1.1154 +         *
  1.1155 +         *  XXX 06/09/99 iris This isn't correct Java syntax, but it probably
  1.1156 +         *  should be.
  1.1157 +         */
  1.1158 +        public String toString() {
  1.1159 +            return "(" + argtypes + ")" + restype;
  1.1160 +        }
  1.1161 +
  1.1162 +        public List<Type>        getParameterTypes() { return argtypes; }
  1.1163 +        public Type              getReturnType()     { return restype; }
  1.1164 +        public Type              getReceiverType()   { return recvtype; }
  1.1165 +        public List<Type>        getThrownTypes()    { return thrown; }
  1.1166 +
  1.1167 +        public boolean isErroneous() {
  1.1168 +            return
  1.1169 +                isErroneous(argtypes) ||
  1.1170 +                restype != null && restype.isErroneous();
  1.1171 +        }
  1.1172 +
  1.1173 +        public Type map(Mapping f) {
  1.1174 +            List<Type> argtypes1 = map(argtypes, f);
  1.1175 +            Type restype1 = f.apply(restype);
  1.1176 +            List<Type> thrown1 = map(thrown, f);
  1.1177 +            if (argtypes1 == argtypes &&
  1.1178 +                restype1 == restype &&
  1.1179 +                thrown1 == thrown) return this;
  1.1180 +            else return new MethodType(argtypes1, restype1, thrown1, tsym);
  1.1181 +        }
  1.1182 +
  1.1183 +        public boolean contains(Type elem) {
  1.1184 +            return elem == this || contains(argtypes, elem) || restype.contains(elem) || contains(thrown, elem);
  1.1185 +        }
  1.1186 +
  1.1187 +        public MethodType asMethodType() { return this; }
  1.1188 +
  1.1189 +        public void complete() {
  1.1190 +            for (List<Type> l = argtypes; l.nonEmpty(); l = l.tail)
  1.1191 +                l.head.complete();
  1.1192 +            restype.complete();
  1.1193 +            recvtype.complete();
  1.1194 +            for (List<Type> l = thrown; l.nonEmpty(); l = l.tail)
  1.1195 +                l.head.complete();
  1.1196 +        }
  1.1197 +
  1.1198 +        public List<TypeVar> getTypeVariables() {
  1.1199 +            return List.nil();
  1.1200 +        }
  1.1201 +
  1.1202 +        public TypeSymbol asElement() {
  1.1203 +            return null;
  1.1204 +        }
  1.1205 +
  1.1206 +        public TypeKind getKind() {
  1.1207 +            return TypeKind.EXECUTABLE;
  1.1208 +        }
  1.1209 +
  1.1210 +        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
  1.1211 +            return v.visitExecutable(this, p);
  1.1212 +        }
  1.1213 +    }
  1.1214 +
  1.1215 +    public static class PackageType extends Type implements NoType {
  1.1216 +
  1.1217 +        PackageType(TypeSymbol tsym) {
  1.1218 +            super(tsym);
  1.1219 +        }
  1.1220 +
  1.1221 +        @Override
  1.1222 +        public TypeTag getTag() {
  1.1223 +            return PACKAGE;
  1.1224 +        }
  1.1225 +
  1.1226 +        @Override
  1.1227 +        public <R,S> R accept(Type.Visitor<R,S> v, S s) {
  1.1228 +            return v.visitPackageType(this, s);
  1.1229 +        }
  1.1230 +
  1.1231 +        public String toString() {
  1.1232 +            return tsym.getQualifiedName().toString();
  1.1233 +        }
  1.1234 +
  1.1235 +        public TypeKind getKind() {
  1.1236 +            return TypeKind.PACKAGE;
  1.1237 +        }
  1.1238 +
  1.1239 +        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
  1.1240 +            return v.visitNoType(this, p);
  1.1241 +        }
  1.1242 +    }
  1.1243 +
  1.1244 +    public static class TypeVar extends Type implements TypeVariable {
  1.1245 +
  1.1246 +        /** The upper bound of this type variable; set from outside.
  1.1247 +         *  Must be nonempty once it is set.
  1.1248 +         *  For a bound, `bound' is the bound type itself.
  1.1249 +         *  Multiple bounds are expressed as a single class type which has the
  1.1250 +         *  individual bounds as superclass, respectively interfaces.
  1.1251 +         *  The class type then has as `tsym' a compiler generated class `c',
  1.1252 +         *  which has a flag COMPOUND and whose owner is the type variable
  1.1253 +         *  itself. Furthermore, the erasure_field of the class
  1.1254 +         *  points to the first class or interface bound.
  1.1255 +         */
  1.1256 +        public Type bound = null;
  1.1257 +
  1.1258 +        /** The lower bound of this type variable.
  1.1259 +         *  TypeVars don't normally have a lower bound, so it is normally set
  1.1260 +         *  to syms.botType.
  1.1261 +         *  Subtypes, such as CapturedType, may provide a different value.
  1.1262 +         */
  1.1263 +        public Type lower;
  1.1264 +
  1.1265 +        public TypeVar(Name name, Symbol owner, Type lower) {
  1.1266 +            super(null);
  1.1267 +            tsym = new TypeVariableSymbol(0, name, this, owner);
  1.1268 +            this.lower = lower;
  1.1269 +        }
  1.1270 +
  1.1271 +        public TypeVar(TypeSymbol tsym, Type bound, Type lower) {
  1.1272 +            super(tsym);
  1.1273 +            this.bound = bound;
  1.1274 +            this.lower = lower;
  1.1275 +        }
  1.1276 +
  1.1277 +        @Override
  1.1278 +        public TypeTag getTag() {
  1.1279 +            return TYPEVAR;
  1.1280 +        }
  1.1281 +
  1.1282 +        @Override
  1.1283 +        public <R,S> R accept(Type.Visitor<R,S> v, S s) {
  1.1284 +            return v.visitTypeVar(this, s);
  1.1285 +        }
  1.1286 +
  1.1287 +        @Override
  1.1288 +        public Type getUpperBound() {
  1.1289 +            if ((bound == null || bound.hasTag(NONE)) && this != tsym.type) {
  1.1290 +                bound = tsym.type.getUpperBound();
  1.1291 +            }
  1.1292 +            return bound;
  1.1293 +        }
  1.1294 +
  1.1295 +        int rank_field = -1;
  1.1296 +
  1.1297 +        @Override
  1.1298 +        public Type getLowerBound() {
  1.1299 +            return lower;
  1.1300 +        }
  1.1301 +
  1.1302 +        public TypeKind getKind() {
  1.1303 +            return TypeKind.TYPEVAR;
  1.1304 +        }
  1.1305 +
  1.1306 +        public boolean isCaptured() {
  1.1307 +            return false;
  1.1308 +        }
  1.1309 +
  1.1310 +        @Override
  1.1311 +        public boolean isReference() {
  1.1312 +            return true;
  1.1313 +        }
  1.1314 +
  1.1315 +        @Override
  1.1316 +        public boolean isNullOrReference() {
  1.1317 +            return true;
  1.1318 +        }
  1.1319 +
  1.1320 +        @Override
  1.1321 +        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
  1.1322 +            return v.visitTypeVariable(this, p);
  1.1323 +        }
  1.1324 +    }
  1.1325 +
  1.1326 +    /** A captured type variable comes from wildcards which can have
  1.1327 +     *  both upper and lower bound.  CapturedType extends TypeVar with
  1.1328 +     *  a lower bound.
  1.1329 +     */
  1.1330 +    public static class CapturedType extends TypeVar {
  1.1331 +
  1.1332 +        public WildcardType wildcard;
  1.1333 +
  1.1334 +        public CapturedType(Name name,
  1.1335 +                            Symbol owner,
  1.1336 +                            Type upper,
  1.1337 +                            Type lower,
  1.1338 +                            WildcardType wildcard) {
  1.1339 +            super(name, owner, lower);
  1.1340 +            this.lower = Assert.checkNonNull(lower);
  1.1341 +            this.bound = upper;
  1.1342 +            this.wildcard = wildcard;
  1.1343 +        }
  1.1344 +
  1.1345 +        @Override
  1.1346 +        public <R,S> R accept(Type.Visitor<R,S> v, S s) {
  1.1347 +            return v.visitCapturedType(this, s);
  1.1348 +        }
  1.1349 +
  1.1350 +        @Override
  1.1351 +        public boolean isCaptured() {
  1.1352 +            return true;
  1.1353 +        }
  1.1354 +
  1.1355 +        @Override
  1.1356 +        public String toString() {
  1.1357 +            return "capture#"
  1.1358 +                + (hashCode() & 0xFFFFFFFFL) % Printer.PRIME
  1.1359 +                + " of "
  1.1360 +                + wildcard;
  1.1361 +        }
  1.1362 +    }
  1.1363 +
  1.1364 +    public static abstract class DelegatedType extends Type {
  1.1365 +        public Type qtype;
  1.1366 +        public TypeTag tag;
  1.1367 +        public DelegatedType(TypeTag tag, Type qtype) {
  1.1368 +            super(qtype.tsym);
  1.1369 +            this.tag = tag;
  1.1370 +            this.qtype = qtype;
  1.1371 +        }
  1.1372 +        public TypeTag getTag() { return tag; }
  1.1373 +        public String toString() { return qtype.toString(); }
  1.1374 +        public List<Type> getTypeArguments() { return qtype.getTypeArguments(); }
  1.1375 +        public Type getEnclosingType() { return qtype.getEnclosingType(); }
  1.1376 +        public List<Type> getParameterTypes() { return qtype.getParameterTypes(); }
  1.1377 +        public Type getReturnType() { return qtype.getReturnType(); }
  1.1378 +        public Type getReceiverType() { return qtype.getReceiverType(); }
  1.1379 +        public List<Type> getThrownTypes() { return qtype.getThrownTypes(); }
  1.1380 +        public List<Type> allparams() { return qtype.allparams(); }
  1.1381 +        public Type getUpperBound() { return qtype.getUpperBound(); }
  1.1382 +        public boolean isErroneous() { return qtype.isErroneous(); }
  1.1383 +    }
  1.1384 +
  1.1385 +    /**
  1.1386 +     * The type of a generic method type. It consists of a method type and
  1.1387 +     * a list of method type-parameters that are used within the method
  1.1388 +     * type.
  1.1389 +     */
  1.1390 +    public static class ForAll extends DelegatedType implements ExecutableType {
  1.1391 +        public List<Type> tvars;
  1.1392 +
  1.1393 +        public ForAll(List<Type> tvars, Type qtype) {
  1.1394 +            super(FORALL, (MethodType)qtype);
  1.1395 +            this.tvars = tvars;
  1.1396 +        }
  1.1397 +
  1.1398 +        @Override
  1.1399 +        public <R,S> R accept(Type.Visitor<R,S> v, S s) {
  1.1400 +            return v.visitForAll(this, s);
  1.1401 +        }
  1.1402 +
  1.1403 +        public String toString() {
  1.1404 +            return "<" + tvars + ">" + qtype;
  1.1405 +        }
  1.1406 +
  1.1407 +        public List<Type> getTypeArguments()   { return tvars; }
  1.1408 +
  1.1409 +        public boolean isErroneous()  {
  1.1410 +            return qtype.isErroneous();
  1.1411 +        }
  1.1412 +
  1.1413 +        public Type map(Mapping f) {
  1.1414 +            return f.apply(qtype);
  1.1415 +        }
  1.1416 +
  1.1417 +        public boolean contains(Type elem) {
  1.1418 +            return qtype.contains(elem);
  1.1419 +        }
  1.1420 +
  1.1421 +        public MethodType asMethodType() {
  1.1422 +            return (MethodType)qtype;
  1.1423 +        }
  1.1424 +
  1.1425 +        public void complete() {
  1.1426 +            for (List<Type> l = tvars; l.nonEmpty(); l = l.tail) {
  1.1427 +                ((TypeVar)l.head).bound.complete();
  1.1428 +            }
  1.1429 +            qtype.complete();
  1.1430 +        }
  1.1431 +
  1.1432 +        public List<TypeVar> getTypeVariables() {
  1.1433 +            return List.convert(TypeVar.class, getTypeArguments());
  1.1434 +        }
  1.1435 +
  1.1436 +        public TypeKind getKind() {
  1.1437 +            return TypeKind.EXECUTABLE;
  1.1438 +        }
  1.1439 +
  1.1440 +        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
  1.1441 +            return v.visitExecutable(this, p);
  1.1442 +        }
  1.1443 +    }
  1.1444 +
  1.1445 +    /** A class for inference variables, for use during method/diamond type
  1.1446 +     *  inference. An inference variable has upper/lower bounds and a set
  1.1447 +     *  of equality constraints. Such bounds are set during subtyping, type-containment,
  1.1448 +     *  type-equality checks, when the types being tested contain inference variables.
  1.1449 +     *  A change listener can be attached to an inference variable, to receive notifications
  1.1450 +     *  whenever the bounds of an inference variable change.
  1.1451 +     */
  1.1452 +    public static class UndetVar extends DelegatedType {
  1.1453 +
  1.1454 +        /** Inference variable change listener. The listener method is called
  1.1455 +         *  whenever a change to the inference variable's bounds occurs
  1.1456 +         */
  1.1457 +        public interface UndetVarListener {
  1.1458 +            /** called when some inference variable bounds (of given kinds ibs) change */
  1.1459 +            void varChanged(UndetVar uv, Set<InferenceBound> ibs);
  1.1460 +        }
  1.1461 +
  1.1462 +        /**
  1.1463 +         * Inference variable bound kinds
  1.1464 +         */
  1.1465 +        public enum InferenceBound {
  1.1466 +            UPPER {
  1.1467 +                public InferenceBound complement() { return LOWER; }
  1.1468 +            },
  1.1469 +             /** lower bounds */
  1.1470 +            LOWER {
  1.1471 +                public InferenceBound complement() { return UPPER; }
  1.1472 +            },
  1.1473 +             /** equality constraints */
  1.1474 +            EQ {
  1.1475 +                public InferenceBound complement() { return EQ; }
  1.1476 +            };
  1.1477 +
  1.1478 +            public abstract InferenceBound complement();
  1.1479 +        }
  1.1480 +
  1.1481 +        /** inference variable bounds */
  1.1482 +        protected Map<InferenceBound, List<Type>> bounds;
  1.1483 +
  1.1484 +        /** inference variable's inferred type (set from Infer.java) */
  1.1485 +        public Type inst = null;
  1.1486 +
  1.1487 +        /** number of declared (upper) bounds */
  1.1488 +        public int declaredCount;
  1.1489 +
  1.1490 +        /** inference variable's change listener */
  1.1491 +        public UndetVarListener listener = null;
  1.1492 +
  1.1493 +        @Override
  1.1494 +        public <R,S> R accept(Type.Visitor<R,S> v, S s) {
  1.1495 +            return v.visitUndetVar(this, s);
  1.1496 +        }
  1.1497 +
  1.1498 +        public UndetVar(TypeVar origin, Types types) {
  1.1499 +            super(UNDETVAR, origin);
  1.1500 +            bounds = new EnumMap<InferenceBound, List<Type>>(InferenceBound.class);
  1.1501 +            List<Type> declaredBounds = types.getBounds(origin);
  1.1502 +            declaredCount = declaredBounds.length();
  1.1503 +            bounds.put(InferenceBound.UPPER, declaredBounds);
  1.1504 +            bounds.put(InferenceBound.LOWER, List.<Type>nil());
  1.1505 +            bounds.put(InferenceBound.EQ, List.<Type>nil());
  1.1506 +        }
  1.1507 +
  1.1508 +        public String toString() {
  1.1509 +            return (inst == null) ? qtype + "?" : inst.toString();
  1.1510 +        }
  1.1511 +
  1.1512 +        public String debugString() {
  1.1513 +            String result = "inference var = " + qtype + "\n";
  1.1514 +            if (inst != null) {
  1.1515 +                result += "inst = " + inst + '\n';
  1.1516 +            }
  1.1517 +            for (InferenceBound bound: InferenceBound.values()) {
  1.1518 +                List<Type> aboundList = bounds.get(bound);
  1.1519 +                if (aboundList.size() > 0) {
  1.1520 +                    result += bound + " = " + aboundList + '\n';
  1.1521 +                }
  1.1522 +            }
  1.1523 +            return result;
  1.1524 +        }
  1.1525 +
  1.1526 +        @Override
  1.1527 +        public boolean isPartial() {
  1.1528 +            return true;
  1.1529 +        }
  1.1530 +
  1.1531 +        @Override
  1.1532 +        public Type baseType() {
  1.1533 +            return (inst == null) ? this : inst.baseType();
  1.1534 +        }
  1.1535 +
  1.1536 +        /** get all bounds of a given kind */
  1.1537 +        public List<Type> getBounds(InferenceBound... ibs) {
  1.1538 +            ListBuffer<Type> buf = new ListBuffer<>();
  1.1539 +            for (InferenceBound ib : ibs) {
  1.1540 +                buf.appendList(bounds.get(ib));
  1.1541 +            }
  1.1542 +            return buf.toList();
  1.1543 +        }
  1.1544 +
  1.1545 +        /** get the list of declared (upper) bounds */
  1.1546 +        public List<Type> getDeclaredBounds() {
  1.1547 +            ListBuffer<Type> buf = new ListBuffer<>();
  1.1548 +            int count = 0;
  1.1549 +            for (Type b : getBounds(InferenceBound.UPPER)) {
  1.1550 +                if (count++ == declaredCount) break;
  1.1551 +                buf.append(b);
  1.1552 +            }
  1.1553 +            return buf.toList();
  1.1554 +        }
  1.1555 +
  1.1556 +        /** internal method used to override an undetvar bounds */
  1.1557 +        public void setBounds(InferenceBound ib, List<Type> newBounds) {
  1.1558 +            bounds.put(ib, newBounds);
  1.1559 +        }
  1.1560 +
  1.1561 +        /** add a bound of a given kind - this might trigger listener notification */
  1.1562 +        public final void addBound(InferenceBound ib, Type bound, Types types) {
  1.1563 +            addBound(ib, bound, types, false);
  1.1564 +        }
  1.1565 +
  1.1566 +        protected void addBound(InferenceBound ib, Type bound, Types types, boolean update) {
  1.1567 +            Type bound2 = toTypeVarMap.apply(bound).baseType();
  1.1568 +            List<Type> prevBounds = bounds.get(ib);
  1.1569 +            for (Type b : prevBounds) {
  1.1570 +                //check for redundancy - use strict version of isSameType on tvars
  1.1571 +                //(as the standard version will lead to false positives w.r.t. clones ivars)
  1.1572 +                if (types.isSameType(b, bound2, true) || bound == qtype) return;
  1.1573 +            }
  1.1574 +            bounds.put(ib, prevBounds.prepend(bound2));
  1.1575 +            notifyChange(EnumSet.of(ib));
  1.1576 +        }
  1.1577 +        //where
  1.1578 +            Type.Mapping toTypeVarMap = new Mapping("toTypeVarMap") {
  1.1579 +                @Override
  1.1580 +                public Type apply(Type t) {
  1.1581 +                    if (t.hasTag(UNDETVAR)) {
  1.1582 +                        UndetVar uv = (UndetVar)t;
  1.1583 +                        return uv.inst != null ? uv.inst : uv.qtype;
  1.1584 +                    } else {
  1.1585 +                        return t.map(this);
  1.1586 +                    }
  1.1587 +                }
  1.1588 +            };
  1.1589 +
  1.1590 +        /** replace types in all bounds - this might trigger listener notification */
  1.1591 +        public void substBounds(List<Type> from, List<Type> to, Types types) {
  1.1592 +            List<Type> instVars = from.diff(to);
  1.1593 +            //if set of instantiated ivars is empty, there's nothing to do!
  1.1594 +            if (instVars.isEmpty()) return;
  1.1595 +            final EnumSet<InferenceBound> boundsChanged = EnumSet.noneOf(InferenceBound.class);
  1.1596 +            UndetVarListener prevListener = listener;
  1.1597 +            try {
  1.1598 +                //setup new listener for keeping track of changed bounds
  1.1599 +                listener = new UndetVarListener() {
  1.1600 +                    public void varChanged(UndetVar uv, Set<InferenceBound> ibs) {
  1.1601 +                        boundsChanged.addAll(ibs);
  1.1602 +                    }
  1.1603 +                };
  1.1604 +                for (Map.Entry<InferenceBound, List<Type>> _entry : bounds.entrySet()) {
  1.1605 +                    InferenceBound ib = _entry.getKey();
  1.1606 +                    List<Type> prevBounds = _entry.getValue();
  1.1607 +                    ListBuffer<Type> newBounds = new ListBuffer<>();
  1.1608 +                    ListBuffer<Type> deps = new ListBuffer<>();
  1.1609 +                    //step 1 - re-add bounds that are not dependent on ivars
  1.1610 +                    for (Type t : prevBounds) {
  1.1611 +                        if (!t.containsAny(instVars)) {
  1.1612 +                            newBounds.append(t);
  1.1613 +                        } else {
  1.1614 +                            deps.append(t);
  1.1615 +                        }
  1.1616 +                    }
  1.1617 +                    //step 2 - replace bounds
  1.1618 +                    bounds.put(ib, newBounds.toList());
  1.1619 +                    //step 3 - for each dependency, add new replaced bound
  1.1620 +                    for (Type dep : deps) {
  1.1621 +                        addBound(ib, types.subst(dep, from, to), types, true);
  1.1622 +                    }
  1.1623 +                }
  1.1624 +            } finally {
  1.1625 +                listener = prevListener;
  1.1626 +                if (!boundsChanged.isEmpty()) {
  1.1627 +                    notifyChange(boundsChanged);
  1.1628 +                }
  1.1629 +            }
  1.1630 +        }
  1.1631 +
  1.1632 +        private void notifyChange(EnumSet<InferenceBound> ibs) {
  1.1633 +            if (listener != null) {
  1.1634 +                listener.varChanged(this, ibs);
  1.1635 +            }
  1.1636 +        }
  1.1637 +
  1.1638 +        public boolean isCaptured() {
  1.1639 +            return false;
  1.1640 +        }
  1.1641 +    }
  1.1642 +
  1.1643 +    /**
  1.1644 +     * This class is used to represent synthetic captured inference variables
  1.1645 +     * that can be generated during nested generic method calls. The only difference
  1.1646 +     * between these inference variables and ordinary ones is that captured inference
  1.1647 +     * variables cannot get new bounds through incorporation.
  1.1648 +     */
  1.1649 +    public static class CapturedUndetVar extends UndetVar {
  1.1650 +
  1.1651 +        public CapturedUndetVar(CapturedType origin, Types types) {
  1.1652 +            super(origin, types);
  1.1653 +            if (!origin.lower.hasTag(BOT)) {
  1.1654 +                bounds.put(InferenceBound.LOWER, List.of(origin.lower));
  1.1655 +            }
  1.1656 +        }
  1.1657 +
  1.1658 +        @Override
  1.1659 +        public void addBound(InferenceBound ib, Type bound, Types types, boolean update) {
  1.1660 +            if (update) {
  1.1661 +                //only change bounds if request comes from substBounds
  1.1662 +                super.addBound(ib, bound, types, update);
  1.1663 +            }
  1.1664 +        }
  1.1665 +
  1.1666 +        @Override
  1.1667 +        public boolean isCaptured() {
  1.1668 +            return true;
  1.1669 +        }
  1.1670 +    }
  1.1671 +
  1.1672 +    /** Represents NONE.
  1.1673 +     */
  1.1674 +    public static class JCNoType extends Type implements NoType {
  1.1675 +        public JCNoType() {
  1.1676 +            super(null);
  1.1677 +        }
  1.1678 +
  1.1679 +        @Override
  1.1680 +        public TypeTag getTag() {
  1.1681 +            return NONE;
  1.1682 +        }
  1.1683 +
  1.1684 +        @Override
  1.1685 +        public TypeKind getKind() {
  1.1686 +            return TypeKind.NONE;
  1.1687 +        }
  1.1688 +
  1.1689 +        @Override
  1.1690 +        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
  1.1691 +            return v.visitNoType(this, p);
  1.1692 +        }
  1.1693 +
  1.1694 +        @Override
  1.1695 +        public boolean isCompound() { return false; }
  1.1696 +    }
  1.1697 +
  1.1698 +    /** Represents VOID.
  1.1699 +     */
  1.1700 +    public static class JCVoidType extends Type implements NoType {
  1.1701 +
  1.1702 +        public JCVoidType() {
  1.1703 +            super(null);
  1.1704 +        }
  1.1705 +
  1.1706 +        @Override
  1.1707 +        public TypeTag getTag() {
  1.1708 +            return VOID;
  1.1709 +        }
  1.1710 +
  1.1711 +        @Override
  1.1712 +        public TypeKind getKind() {
  1.1713 +            return TypeKind.VOID;
  1.1714 +        }
  1.1715 +
  1.1716 +        @Override
  1.1717 +        public boolean isCompound() { return false; }
  1.1718 +
  1.1719 +        @Override
  1.1720 +        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
  1.1721 +            return v.visitNoType(this, p);
  1.1722 +        }
  1.1723 +
  1.1724 +        @Override
  1.1725 +        public boolean isPrimitiveOrVoid() {
  1.1726 +            return true;
  1.1727 +        }
  1.1728 +    }
  1.1729 +
  1.1730 +    static class BottomType extends Type implements NullType {
  1.1731 +        public BottomType() {
  1.1732 +            super(null);
  1.1733 +        }
  1.1734 +
  1.1735 +        @Override
  1.1736 +        public TypeTag getTag() {
  1.1737 +            return BOT;
  1.1738 +        }
  1.1739 +
  1.1740 +        @Override
  1.1741 +        public TypeKind getKind() {
  1.1742 +            return TypeKind.NULL;
  1.1743 +        }
  1.1744 +
  1.1745 +        @Override
  1.1746 +        public boolean isCompound() { return false; }
  1.1747 +
  1.1748 +        @Override
  1.1749 +        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
  1.1750 +            return v.visitNull(this, p);
  1.1751 +        }
  1.1752 +
  1.1753 +        @Override
  1.1754 +        public Type constType(Object value) {
  1.1755 +            return this;
  1.1756 +        }
  1.1757 +
  1.1758 +        @Override
  1.1759 +        public String stringValue() {
  1.1760 +            return "null";
  1.1761 +        }
  1.1762 +
  1.1763 +        @Override
  1.1764 +        public boolean isNullOrReference() {
  1.1765 +            return true;
  1.1766 +        }
  1.1767 +
  1.1768 +    }
  1.1769 +
  1.1770 +    public static class ErrorType extends ClassType
  1.1771 +            implements javax.lang.model.type.ErrorType {
  1.1772 +
  1.1773 +        private Type originalType = null;
  1.1774 +
  1.1775 +        public ErrorType(Type originalType, TypeSymbol tsym) {
  1.1776 +            super(noType, List.<Type>nil(), null);
  1.1777 +            this.tsym = tsym;
  1.1778 +            this.originalType = (originalType == null ? noType : originalType);
  1.1779 +        }
  1.1780 +
  1.1781 +        public ErrorType(ClassSymbol c, Type originalType) {
  1.1782 +            this(originalType, c);
  1.1783 +            c.type = this;
  1.1784 +            c.kind = ERR;
  1.1785 +            c.members_field = new Scope.ErrorScope(c);
  1.1786 +        }
  1.1787 +
  1.1788 +        @Override
  1.1789 +        public TypeTag getTag() {
  1.1790 +            return ERROR;
  1.1791 +        }
  1.1792 +
  1.1793 +        @Override
  1.1794 +        public boolean isPartial() {
  1.1795 +            return true;
  1.1796 +        }
  1.1797 +
  1.1798 +        @Override
  1.1799 +        public boolean isReference() {
  1.1800 +            return true;
  1.1801 +        }
  1.1802 +
  1.1803 +        @Override
  1.1804 +        public boolean isNullOrReference() {
  1.1805 +            return true;
  1.1806 +        }
  1.1807 +
  1.1808 +        public ErrorType(Name name, TypeSymbol container, Type originalType) {
  1.1809 +            this(new ClassSymbol(PUBLIC|STATIC|ACYCLIC, name, null, container), originalType);
  1.1810 +        }
  1.1811 +
  1.1812 +        @Override
  1.1813 +        public <R,S> R accept(Type.Visitor<R,S> v, S s) {
  1.1814 +            return v.visitErrorType(this, s);
  1.1815 +        }
  1.1816 +
  1.1817 +        public Type constType(Object constValue) { return this; }
  1.1818 +        public Type getEnclosingType()           { return this; }
  1.1819 +        public Type getReturnType()              { return this; }
  1.1820 +        public Type asSub(Symbol sym)            { return this; }
  1.1821 +        public Type map(Mapping f)               { return this; }
  1.1822 +
  1.1823 +        public boolean isGenType(Type t)         { return true; }
  1.1824 +        public boolean isErroneous()             { return true; }
  1.1825 +        public boolean isCompound()              { return false; }
  1.1826 +        public boolean isInterface()             { return false; }
  1.1827 +
  1.1828 +        public List<Type> allparams()            { return List.nil(); }
  1.1829 +        public List<Type> getTypeArguments()     { return List.nil(); }
  1.1830 +
  1.1831 +        public TypeKind getKind() {
  1.1832 +            return TypeKind.ERROR;
  1.1833 +        }
  1.1834 +
  1.1835 +        public Type getOriginalType() {
  1.1836 +            return originalType;
  1.1837 +        }
  1.1838 +
  1.1839 +        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
  1.1840 +            return v.visitError(this, p);
  1.1841 +        }
  1.1842 +    }
  1.1843 +
  1.1844 +    public static class AnnotatedType extends Type
  1.1845 +            implements
  1.1846 +                javax.lang.model.type.ArrayType,
  1.1847 +                javax.lang.model.type.DeclaredType,
  1.1848 +                javax.lang.model.type.PrimitiveType,
  1.1849 +                javax.lang.model.type.TypeVariable,
  1.1850 +                javax.lang.model.type.WildcardType {
  1.1851 +        /** The type annotations on this type.
  1.1852 +         */
  1.1853 +        private List<Attribute.TypeCompound> typeAnnotations;
  1.1854 +
  1.1855 +        /** The underlying type that is annotated.
  1.1856 +         */
  1.1857 +        private Type underlyingType;
  1.1858 +
  1.1859 +        protected AnnotatedType(List<Attribute.TypeCompound> typeAnnotations,
  1.1860 +                Type underlyingType) {
  1.1861 +            super(underlyingType.tsym);
  1.1862 +            this.typeAnnotations = typeAnnotations;
  1.1863 +            this.underlyingType = underlyingType;
  1.1864 +            Assert.check(typeAnnotations != null && typeAnnotations.nonEmpty(),
  1.1865 +                    "Can't create AnnotatedType without annotations: " + underlyingType);
  1.1866 +            Assert.check(!underlyingType.isAnnotated(),
  1.1867 +                    "Can't annotate already annotated type: " + underlyingType +
  1.1868 +                    "; adding: " + typeAnnotations);
  1.1869 +        }
  1.1870 +
  1.1871 +        @Override
  1.1872 +        public TypeTag getTag() {
  1.1873 +            return underlyingType.getTag();
  1.1874 +        }
  1.1875 +
  1.1876 +        @Override
  1.1877 +        public boolean isAnnotated() {
  1.1878 +            return true;
  1.1879 +        }
  1.1880 +
  1.1881 +        @Override
  1.1882 +        public List<Attribute.TypeCompound> getAnnotationMirrors() {
  1.1883 +            return typeAnnotations;
  1.1884 +        }
  1.1885 +
  1.1886 +
  1.1887 +        @Override
  1.1888 +        public TypeKind getKind() {
  1.1889 +            return underlyingType.getKind();
  1.1890 +        }
  1.1891 +
  1.1892 +        @Override
  1.1893 +        public Type unannotatedType() {
  1.1894 +            return underlyingType;
  1.1895 +        }
  1.1896 +
  1.1897 +        @Override
  1.1898 +        public <R,S> R accept(Type.Visitor<R,S> v, S s) {
  1.1899 +            return v.visitAnnotatedType(this, s);
  1.1900 +        }
  1.1901 +
  1.1902 +        @Override
  1.1903 +        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
  1.1904 +            return underlyingType.accept(v, p);
  1.1905 +        }
  1.1906 +
  1.1907 +        @Override
  1.1908 +        public Type map(Mapping f) {
  1.1909 +            underlyingType.map(f);
  1.1910 +            return this;
  1.1911 +        }
  1.1912 +
  1.1913 +        @Override
  1.1914 +        public Type constType(Object constValue) { return underlyingType.constType(constValue); }
  1.1915 +        @Override
  1.1916 +        public Type getEnclosingType()           { return underlyingType.getEnclosingType(); }
  1.1917 +
  1.1918 +        @Override
  1.1919 +        public Type getReturnType()              { return underlyingType.getReturnType(); }
  1.1920 +        @Override
  1.1921 +        public List<Type> getTypeArguments()     { return underlyingType.getTypeArguments(); }
  1.1922 +        @Override
  1.1923 +        public List<Type> getParameterTypes()    { return underlyingType.getParameterTypes(); }
  1.1924 +        @Override
  1.1925 +        public Type getReceiverType()            { return underlyingType.getReceiverType(); }
  1.1926 +        @Override
  1.1927 +        public List<Type> getThrownTypes()       { return underlyingType.getThrownTypes(); }
  1.1928 +        @Override
  1.1929 +        public Type getUpperBound()              { return underlyingType.getUpperBound(); }
  1.1930 +        @Override
  1.1931 +        public Type getLowerBound()              { return underlyingType.getLowerBound(); }
  1.1932 +
  1.1933 +        @Override
  1.1934 +        public boolean isErroneous()             { return underlyingType.isErroneous(); }
  1.1935 +        @Override
  1.1936 +        public boolean isCompound()              { return underlyingType.isCompound(); }
  1.1937 +        @Override
  1.1938 +        public boolean isInterface()             { return underlyingType.isInterface(); }
  1.1939 +        @Override
  1.1940 +        public List<Type> allparams()            { return underlyingType.allparams(); }
  1.1941 +        @Override
  1.1942 +        public boolean isPrimitive()             { return underlyingType.isPrimitive(); }
  1.1943 +        @Override
  1.1944 +        public boolean isPrimitiveOrVoid()       { return underlyingType.isPrimitiveOrVoid(); }
  1.1945 +        @Override
  1.1946 +        public boolean isNumeric()               { return underlyingType.isNumeric(); }
  1.1947 +        @Override
  1.1948 +        public boolean isReference()             { return underlyingType.isReference(); }
  1.1949 +        @Override
  1.1950 +        public boolean isNullOrReference()       { return underlyingType.isNullOrReference(); }
  1.1951 +        @Override
  1.1952 +        public boolean isPartial()               { return underlyingType.isPartial(); }
  1.1953 +        @Override
  1.1954 +        public boolean isParameterized()         { return underlyingType.isParameterized(); }
  1.1955 +        @Override
  1.1956 +        public boolean isRaw()                   { return underlyingType.isRaw(); }
  1.1957 +        @Override
  1.1958 +        public boolean isFinal()                 { return underlyingType.isFinal(); }
  1.1959 +        @Override
  1.1960 +        public boolean isSuperBound()            { return underlyingType.isSuperBound(); }
  1.1961 +        @Override
  1.1962 +        public boolean isExtendsBound()          { return underlyingType.isExtendsBound(); }
  1.1963 +        @Override
  1.1964 +        public boolean isUnbound()               { return underlyingType.isUnbound(); }
  1.1965 +
  1.1966 +        @Override
  1.1967 +        public String toString() {
  1.1968 +            // This method is only used for internal debugging output.
  1.1969 +            // See
  1.1970 +            // com.sun.tools.javac.code.Printer.visitAnnotatedType(AnnotatedType, Locale)
  1.1971 +            // for the user-visible logic.
  1.1972 +            if (typeAnnotations != null &&
  1.1973 +                    !typeAnnotations.isEmpty()) {
  1.1974 +                return "(" + typeAnnotations.toString() + " :: " + underlyingType.toString() + ")";
  1.1975 +            } else {
  1.1976 +                return "({} :: " + underlyingType.toString() +")";
  1.1977 +            }
  1.1978 +        }
  1.1979 +
  1.1980 +        @Override
  1.1981 +        public boolean contains(Type t)          { return underlyingType.contains(t); }
  1.1982 +
  1.1983 +        @Override
  1.1984 +        public Type withTypeVar(Type t) {
  1.1985 +            // Don't create a new AnnotatedType, as 'this' will
  1.1986 +            // get its annotations set later.
  1.1987 +            underlyingType = underlyingType.withTypeVar(t);
  1.1988 +            return this;
  1.1989 +        }
  1.1990 +
  1.1991 +        // TODO: attach annotations?
  1.1992 +        @Override
  1.1993 +        public TypeSymbol asElement()            { return underlyingType.asElement(); }
  1.1994 +
  1.1995 +        // TODO: attach annotations?
  1.1996 +        @Override
  1.1997 +        public MethodType asMethodType()         { return underlyingType.asMethodType(); }
  1.1998 +
  1.1999 +        @Override
  1.2000 +        public void complete()                   { underlyingType.complete(); }
  1.2001 +
  1.2002 +        @Override
  1.2003 +        public TypeMirror getComponentType()     { return ((ArrayType)underlyingType).getComponentType(); }
  1.2004 +
  1.2005 +        // The result is an ArrayType, but only in the model sense, not the Type sense.
  1.2006 +        public Type makeVarargs() {
  1.2007 +            return ((ArrayType) underlyingType).makeVarargs().annotatedType(typeAnnotations);
  1.2008 +        }
  1.2009 +
  1.2010 +        @Override
  1.2011 +        public TypeMirror getExtendsBound()      { return ((WildcardType)underlyingType).getExtendsBound(); }
  1.2012 +        @Override
  1.2013 +        public TypeMirror getSuperBound()        { return ((WildcardType)underlyingType).getSuperBound(); }
  1.2014 +    }
  1.2015 +
  1.2016 +    public static class UnknownType extends Type {
  1.2017 +
  1.2018 +        public UnknownType() {
  1.2019 +            super(null);
  1.2020 +        }
  1.2021 +
  1.2022 +        @Override
  1.2023 +        public TypeTag getTag() {
  1.2024 +            return UNKNOWN;
  1.2025 +        }
  1.2026 +
  1.2027 +        @Override
  1.2028 +        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
  1.2029 +            return v.visitUnknown(this, p);
  1.2030 +        }
  1.2031 +
  1.2032 +        @Override
  1.2033 +        public boolean isPartial() {
  1.2034 +            return true;
  1.2035 +        }
  1.2036 +    }
  1.2037 +
  1.2038 +    /**
  1.2039 +     * A visitor for types.  A visitor is used to implement operations
  1.2040 +     * (or relations) on types.  Most common operations on types are
  1.2041 +     * binary relations and this interface is designed for binary
  1.2042 +     * relations, that is, operations of the form
  1.2043 +     * Type&nbsp;&times;&nbsp;S&nbsp;&rarr;&nbsp;R.
  1.2044 +     * <!-- In plain text: Type x S -> R -->
  1.2045 +     *
  1.2046 +     * @param <R> the return type of the operation implemented by this
  1.2047 +     * visitor; use Void if no return type is needed.
  1.2048 +     * @param <S> the type of the second argument (the first being the
  1.2049 +     * type itself) of the operation implemented by this visitor; use
  1.2050 +     * Void if a second argument is not needed.
  1.2051 +     */
  1.2052 +    public interface Visitor<R,S> {
  1.2053 +        R visitClassType(ClassType t, S s);
  1.2054 +        R visitWildcardType(WildcardType t, S s);
  1.2055 +        R visitArrayType(ArrayType t, S s);
  1.2056 +        R visitMethodType(MethodType t, S s);
  1.2057 +        R visitPackageType(PackageType t, S s);
  1.2058 +        R visitTypeVar(TypeVar t, S s);
  1.2059 +        R visitCapturedType(CapturedType t, S s);
  1.2060 +        R visitForAll(ForAll t, S s);
  1.2061 +        R visitUndetVar(UndetVar t, S s);
  1.2062 +        R visitErrorType(ErrorType t, S s);
  1.2063 +        R visitAnnotatedType(AnnotatedType t, S s);
  1.2064 +        R visitType(Type t, S s);
  1.2065 +    }
  1.2066 +}

mercurial