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

Wed, 12 Mar 2008 13:06:00 -0700

author
jjg
date
Wed, 12 Mar 2008 13:06:00 -0700
changeset 12
7366066839bb
parent 1
9a66ca7c79fa
child 30
a1d1f335633f
permissions
-rw-r--r--

6668794: javac puts localized text in raw diagnostics
6668796: bad diagnostic "bad class file" given for source files
Summary: Replace internal use of localized text with JCDiagnostic fragments; fix diagnostic for bad source file
Reviewed-by: mcimadamore

duke@1 1 /*
duke@1 2 * Copyright 1999-2006 Sun Microsystems, Inc. All Rights Reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
duke@1 7 * published by the Free Software Foundation. Sun designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
duke@1 9 * by Sun in the LICENSE file that accompanied this code.
duke@1 10 *
duke@1 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 15 * accompanied this code).
duke@1 16 *
duke@1 17 * You should have received a copy of the GNU General Public License version
duke@1 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 20 *
duke@1 21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@1 22 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@1 23 * have any questions.
duke@1 24 */
duke@1 25
duke@1 26 package com.sun.tools.javac.code;
duke@1 27
duke@1 28 import javax.lang.model.element.Element;
duke@1 29 import javax.lang.model.type.*;
duke@1 30 import com.sun.tools.javac.util.*;
duke@1 31 import com.sun.tools.javac.code.Symbol.*;
duke@1 32 import javax.lang.model.element.Element;
duke@1 33
duke@1 34 import javax.lang.model.type.*;
duke@1 35
duke@1 36 import static com.sun.tools.javac.code.Flags.*;
duke@1 37 import static com.sun.tools.javac.code.Kinds.*;
duke@1 38 import static com.sun.tools.javac.code.BoundKind.*;
duke@1 39 import static com.sun.tools.javac.code.TypeTags.*;
duke@1 40
duke@1 41 /** This class represents Java types. The class itself defines the behavior of
duke@1 42 * the following types:
duke@1 43 * <pre>
duke@1 44 * base types (tags: BYTE, CHAR, SHORT, INT, LONG, FLOAT, DOUBLE, BOOLEAN),
duke@1 45 * type `void' (tag: VOID),
duke@1 46 * the bottom type (tag: BOT),
duke@1 47 * the missing type (tag: NONE).
duke@1 48 * </pre>
duke@1 49 * <p>The behavior of the following types is defined in subclasses, which are
duke@1 50 * all static inner classes of this class:
duke@1 51 * <pre>
duke@1 52 * class types (tag: CLASS, class: ClassType),
duke@1 53 * array types (tag: ARRAY, class: ArrayType),
duke@1 54 * method types (tag: METHOD, class: MethodType),
duke@1 55 * package types (tag: PACKAGE, class: PackageType),
duke@1 56 * type variables (tag: TYPEVAR, class: TypeVar),
duke@1 57 * type arguments (tag: WILDCARD, class: WildcardType),
duke@1 58 * polymorphic types (tag: FORALL, class: ForAll),
duke@1 59 * the error type (tag: ERROR, class: ErrorType).
duke@1 60 * </pre>
duke@1 61 *
duke@1 62 * <p><b>This is NOT part of any API supported by Sun Microsystems. If
duke@1 63 * you write code that depends on this, you do so at your own risk.
duke@1 64 * This code and its internal interfaces are subject to change or
duke@1 65 * deletion without notice.</b>
duke@1 66 *
duke@1 67 * @see TypeTags
duke@1 68 */
duke@1 69 public class Type implements PrimitiveType {
duke@1 70
duke@1 71 /** Constant type: no type at all. */
duke@1 72 public static final JCNoType noType = new JCNoType(NONE);
duke@1 73
duke@1 74 /** If this switch is turned on, the names of type variables
duke@1 75 * and anonymous classes are printed with hashcodes appended.
duke@1 76 */
duke@1 77 public static boolean moreInfo = false;
duke@1 78
duke@1 79 /** The tag of this type.
duke@1 80 *
duke@1 81 * @see TypeTags
duke@1 82 */
duke@1 83 public int tag;
duke@1 84
duke@1 85 /** The defining class / interface / package / type variable
duke@1 86 */
duke@1 87 public TypeSymbol tsym;
duke@1 88
duke@1 89 /**
duke@1 90 * The constant value of this type, null if this type does not
duke@1 91 * have a constant value attribute. Only primitive types and
duke@1 92 * strings (ClassType) can have a constant value attribute.
duke@1 93 * @return the constant value attribute of this type
duke@1 94 */
duke@1 95 public Object constValue() {
duke@1 96 return null;
duke@1 97 }
duke@1 98
duke@1 99 public <R,S> R accept(Type.Visitor<R,S> v, S s) { return v.visitType(this, s); }
duke@1 100
duke@1 101 /** Define a type given its tag and type symbol
duke@1 102 */
duke@1 103 public Type(int tag, TypeSymbol tsym) {
duke@1 104 this.tag = tag;
duke@1 105 this.tsym = tsym;
duke@1 106 }
duke@1 107
duke@1 108 /** An abstract class for mappings from types to types
duke@1 109 */
duke@1 110 public static abstract class Mapping {
duke@1 111 private String name;
duke@1 112 public Mapping(String name) {
duke@1 113 this.name = name;
duke@1 114 }
duke@1 115 public abstract Type apply(Type t);
duke@1 116 public String toString() {
duke@1 117 return name;
duke@1 118 }
duke@1 119 }
duke@1 120
duke@1 121 /** map a type function over all immediate descendants of this type
duke@1 122 */
duke@1 123 public Type map(Mapping f) {
duke@1 124 return this;
duke@1 125 }
duke@1 126
duke@1 127 /** map a type function over a list of types
duke@1 128 */
duke@1 129 public static List<Type> map(List<Type> ts, Mapping f) {
duke@1 130 if (ts.nonEmpty()) {
duke@1 131 List<Type> tail1 = map(ts.tail, f);
duke@1 132 Type t = f.apply(ts.head);
duke@1 133 if (tail1 != ts.tail || t != ts.head)
duke@1 134 return tail1.prepend(t);
duke@1 135 }
duke@1 136 return ts;
duke@1 137 }
duke@1 138
duke@1 139 /** Define a constant type, of the same kind as this type
duke@1 140 * and with given constant value
duke@1 141 */
duke@1 142 public Type constType(Object constValue) {
duke@1 143 final Object value = constValue;
duke@1 144 assert tag <= BOOLEAN;
duke@1 145 return new Type(tag, tsym) {
duke@1 146 @Override
duke@1 147 public Object constValue() {
duke@1 148 return value;
duke@1 149 }
duke@1 150 @Override
duke@1 151 public Type baseType() {
duke@1 152 return tsym.type;
duke@1 153 }
duke@1 154 };
duke@1 155 }
duke@1 156
duke@1 157 /**
duke@1 158 * If this is a constant type, return its underlying type.
duke@1 159 * Otherwise, return the type itself.
duke@1 160 */
duke@1 161 public Type baseType() {
duke@1 162 return this;
duke@1 163 }
duke@1 164
duke@1 165 /** Return the base types of a list of types.
duke@1 166 */
duke@1 167 public static List<Type> baseTypes(List<Type> ts) {
duke@1 168 if (ts.nonEmpty()) {
duke@1 169 Type t = ts.head.baseType();
duke@1 170 List<Type> baseTypes = baseTypes(ts.tail);
duke@1 171 if (t != ts.head || baseTypes != ts.tail)
duke@1 172 return baseTypes.prepend(t);
duke@1 173 }
duke@1 174 return ts;
duke@1 175 }
duke@1 176
duke@1 177 /** The Java source which this type represents.
duke@1 178 */
duke@1 179 public String toString() {
duke@1 180 String s = (tsym == null || tsym.name == null)
duke@1 181 ? "<none>"
duke@1 182 : tsym.name.toString();
duke@1 183 if (moreInfo && tag == TYPEVAR) s = s + hashCode();
duke@1 184 return s;
duke@1 185 }
duke@1 186
duke@1 187 /**
duke@1 188 * The Java source which this type list represents. A List is
duke@1 189 * represented as a comma-spearated listing of the elements in
duke@1 190 * that list.
duke@1 191 */
duke@1 192 public static String toString(List<Type> ts) {
duke@1 193 if (ts.isEmpty()) {
duke@1 194 return "";
duke@1 195 } else {
duke@1 196 StringBuffer buf = new StringBuffer();
duke@1 197 buf.append(ts.head.toString());
duke@1 198 for (List<Type> l = ts.tail; l.nonEmpty(); l = l.tail)
duke@1 199 buf.append(",").append(l.head.toString());
duke@1 200 return buf.toString();
duke@1 201 }
duke@1 202 }
duke@1 203
duke@1 204 /**
duke@1 205 * The constant value of this type, converted to String
duke@1 206 */
duke@1 207 public String stringValue() {
duke@1 208 assert constValue() != null;
duke@1 209 if (tag == BOOLEAN)
duke@1 210 return ((Integer) constValue()).intValue() == 0 ? "false" : "true";
duke@1 211 else if (tag == CHAR)
duke@1 212 return String.valueOf((char) ((Integer) constValue()).intValue());
duke@1 213 else
duke@1 214 return constValue().toString();
duke@1 215 }
duke@1 216
duke@1 217 /**
duke@1 218 * This method is analogous to isSameType, but weaker, since we
duke@1 219 * never complete classes. Where isSameType would complete a
duke@1 220 * class, equals assumes that the two types are different.
duke@1 221 */
duke@1 222 public boolean equals(Object t) {
duke@1 223 return super.equals(t);
duke@1 224 }
duke@1 225
duke@1 226 public int hashCode() {
duke@1 227 return super.hashCode();
duke@1 228 }
duke@1 229
duke@1 230 /** Is this a constant type whose value is false?
duke@1 231 */
duke@1 232 public boolean isFalse() {
duke@1 233 return
duke@1 234 tag == BOOLEAN &&
duke@1 235 constValue() != null &&
duke@1 236 ((Integer)constValue()).intValue() == 0;
duke@1 237 }
duke@1 238
duke@1 239 /** Is this a constant type whose value is true?
duke@1 240 */
duke@1 241 public boolean isTrue() {
duke@1 242 return
duke@1 243 tag == BOOLEAN &&
duke@1 244 constValue() != null &&
duke@1 245 ((Integer)constValue()).intValue() != 0;
duke@1 246 }
duke@1 247
duke@1 248 public String argtypes(boolean varargs) {
duke@1 249 List<Type> args = getParameterTypes();
duke@1 250 if (!varargs) return args.toString();
duke@1 251 StringBuffer buf = new StringBuffer();
duke@1 252 while (args.tail.nonEmpty()) {
duke@1 253 buf.append(args.head);
duke@1 254 args = args.tail;
duke@1 255 buf.append(',');
duke@1 256 }
duke@1 257 if (args.head.tag == ARRAY) {
duke@1 258 buf.append(((ArrayType)args.head).elemtype);
duke@1 259 buf.append("...");
duke@1 260 } else {
duke@1 261 buf.append(args.head);
duke@1 262 }
duke@1 263 return buf.toString();
duke@1 264 }
duke@1 265
duke@1 266 /** Access methods.
duke@1 267 */
duke@1 268 public List<Type> getTypeArguments() { return List.nil(); }
duke@1 269 public Type getEnclosingType() { return null; }
duke@1 270 public List<Type> getParameterTypes() { return List.nil(); }
duke@1 271 public Type getReturnType() { return null; }
duke@1 272 public List<Type> getThrownTypes() { return List.nil(); }
duke@1 273 public Type getUpperBound() { return null; }
duke@1 274 public Type getLowerBound() { return null; }
duke@1 275
duke@1 276 public void setThrown(List<Type> ts) {
duke@1 277 throw new AssertionError();
duke@1 278 }
duke@1 279
duke@1 280 /** Navigation methods, these will work for classes, type variables,
duke@1 281 * foralls, but will return null for arrays and methods.
duke@1 282 */
duke@1 283
duke@1 284 /** Return all parameters of this type and all its outer types in order
duke@1 285 * outer (first) to inner (last).
duke@1 286 */
duke@1 287 public List<Type> allparams() { return List.nil(); }
duke@1 288
duke@1 289 /** Does this type contain "error" elements?
duke@1 290 */
duke@1 291 public boolean isErroneous() {
duke@1 292 return false;
duke@1 293 }
duke@1 294
duke@1 295 public static boolean isErroneous(List<Type> ts) {
duke@1 296 for (List<Type> l = ts; l.nonEmpty(); l = l.tail)
duke@1 297 if (l.head.isErroneous()) return true;
duke@1 298 return false;
duke@1 299 }
duke@1 300
duke@1 301 /** Is this type parameterized?
duke@1 302 * A class type is parameterized if it has some parameters.
duke@1 303 * An array type is parameterized if its element type is parameterized.
duke@1 304 * All other types are not parameterized.
duke@1 305 */
duke@1 306 public boolean isParameterized() {
duke@1 307 return false;
duke@1 308 }
duke@1 309
duke@1 310 /** Is this type a raw type?
duke@1 311 * A class type is a raw type if it misses some of its parameters.
duke@1 312 * An array type is a raw type if its element type is raw.
duke@1 313 * All other types are not raw.
duke@1 314 * Type validation will ensure that the only raw types
duke@1 315 * in a program are types that miss all their type variables.
duke@1 316 */
duke@1 317 public boolean isRaw() {
duke@1 318 return false;
duke@1 319 }
duke@1 320
duke@1 321 public boolean isCompound() {
duke@1 322 return tsym.completer == null
duke@1 323 // Compound types can't have a completer. Calling
duke@1 324 // flags() will complete the symbol causing the
duke@1 325 // compiler to load classes unnecessarily. This led
duke@1 326 // to regression 6180021.
duke@1 327 && (tsym.flags() & COMPOUND) != 0;
duke@1 328 }
duke@1 329
duke@1 330 public boolean isInterface() {
duke@1 331 return (tsym.flags() & INTERFACE) != 0;
duke@1 332 }
duke@1 333
duke@1 334 public boolean isPrimitive() {
duke@1 335 return tag < VOID;
duke@1 336 }
duke@1 337
duke@1 338 /**
duke@1 339 * Does this type contain occurrences of type t?
duke@1 340 */
duke@1 341 public boolean contains(Type t) {
duke@1 342 return t == this;
duke@1 343 }
duke@1 344
duke@1 345 public static boolean contains(List<Type> ts, Type t) {
duke@1 346 for (List<Type> l = ts;
duke@1 347 l.tail != null /*inlined: l.nonEmpty()*/;
duke@1 348 l = l.tail)
duke@1 349 if (l.head.contains(t)) return true;
duke@1 350 return false;
duke@1 351 }
duke@1 352
duke@1 353 /** Does this type contain an occurrence of some type in `elems'?
duke@1 354 */
duke@1 355 public boolean containsSome(List<Type> ts) {
duke@1 356 for (List<Type> l = ts; l.nonEmpty(); l = l.tail)
duke@1 357 if (this.contains(ts.head)) return true;
duke@1 358 return false;
duke@1 359 }
duke@1 360
duke@1 361 public boolean isSuperBound() { return false; }
duke@1 362 public boolean isExtendsBound() { return false; }
duke@1 363 public boolean isUnbound() { return false; }
duke@1 364 public Type withTypeVar(Type t) { return this; }
duke@1 365
duke@1 366 public static List<Type> removeBounds(List<Type> ts) {
duke@1 367 ListBuffer<Type> result = new ListBuffer<Type>();
duke@1 368 for(;ts.nonEmpty(); ts = ts.tail) {
duke@1 369 result.append(ts.head.removeBounds());
duke@1 370 }
duke@1 371 return result.toList();
duke@1 372 }
duke@1 373 public Type removeBounds() {
duke@1 374 return this;
duke@1 375 }
duke@1 376
duke@1 377 /** The underlying method type of this type.
duke@1 378 */
duke@1 379 public MethodType asMethodType() { throw new AssertionError(); }
duke@1 380
duke@1 381 /** Complete loading all classes in this type.
duke@1 382 */
duke@1 383 public void complete() {}
duke@1 384
duke@1 385 public Object clone() {
duke@1 386 try {
duke@1 387 return super.clone();
duke@1 388 } catch (CloneNotSupportedException e) {
duke@1 389 throw new AssertionError(e);
duke@1 390 }
duke@1 391 }
duke@1 392
duke@1 393 public TypeSymbol asElement() {
duke@1 394 return tsym;
duke@1 395 }
duke@1 396
duke@1 397 public TypeKind getKind() {
duke@1 398 switch (tag) {
duke@1 399 case BYTE: return TypeKind.BYTE;
duke@1 400 case CHAR: return TypeKind.CHAR;
duke@1 401 case SHORT: return TypeKind.SHORT;
duke@1 402 case INT: return TypeKind.INT;
duke@1 403 case LONG: return TypeKind.LONG;
duke@1 404 case FLOAT: return TypeKind.FLOAT;
duke@1 405 case DOUBLE: return TypeKind.DOUBLE;
duke@1 406 case BOOLEAN: return TypeKind.BOOLEAN;
duke@1 407 case VOID: return TypeKind.VOID;
duke@1 408 case BOT: return TypeKind.NULL;
duke@1 409 case NONE: return TypeKind.NONE;
duke@1 410 default: return TypeKind.OTHER;
duke@1 411 }
duke@1 412 }
duke@1 413
duke@1 414 public <R, P> R accept(TypeVisitor<R, P> v, P p) {
duke@1 415 if (isPrimitive())
duke@1 416 return v.visitPrimitive(this, p);
duke@1 417 else
duke@1 418 throw new AssertionError();
duke@1 419 }
duke@1 420
duke@1 421 public static class WildcardType extends Type
duke@1 422 implements javax.lang.model.type.WildcardType {
duke@1 423
duke@1 424 public Type type;
duke@1 425 public BoundKind kind;
duke@1 426 public TypeVar bound;
duke@1 427
duke@1 428 @Override
duke@1 429 public <R,S> R accept(Type.Visitor<R,S> v, S s) {
duke@1 430 return v.visitWildcardType(this, s);
duke@1 431 }
duke@1 432
duke@1 433 public WildcardType(Type type, BoundKind kind, TypeSymbol tsym) {
duke@1 434 super(WILDCARD, tsym);
duke@1 435 assert(type != null);
duke@1 436 this.kind = kind;
duke@1 437 this.type = type;
duke@1 438 }
duke@1 439 public WildcardType(WildcardType t, TypeVar bound) {
duke@1 440 this(t.type, t.kind, t.tsym, bound);
duke@1 441 }
duke@1 442
duke@1 443 public WildcardType(Type type, BoundKind kind, TypeSymbol tsym, TypeVar bound) {
duke@1 444 this(type, kind, tsym);
duke@1 445 this.bound = bound;
duke@1 446 }
duke@1 447
duke@1 448 public boolean isSuperBound() {
duke@1 449 return kind == SUPER ||
duke@1 450 kind == UNBOUND;
duke@1 451 }
duke@1 452 public boolean isExtendsBound() {
duke@1 453 return kind == EXTENDS ||
duke@1 454 kind == UNBOUND;
duke@1 455 }
duke@1 456 public boolean isUnbound() {
duke@1 457 return kind == UNBOUND;
duke@1 458 }
duke@1 459
duke@1 460 public Type withTypeVar(Type t) {
duke@1 461 //-System.err.println(this+".withTypeVar("+t+");");//DEBUG
duke@1 462 if (bound == t)
duke@1 463 return this;
duke@1 464 bound = (TypeVar)t;
duke@1 465 return this;
duke@1 466 }
duke@1 467
duke@1 468 boolean isPrintingBound = false;
duke@1 469 public String toString() {
duke@1 470 StringBuffer s = new StringBuffer();
duke@1 471 s.append(kind.toString());
duke@1 472 if (kind != UNBOUND)
duke@1 473 s.append(type);
duke@1 474 if (moreInfo && bound != null && !isPrintingBound)
duke@1 475 try {
duke@1 476 isPrintingBound = true;
duke@1 477 s.append("{:").append(bound.bound).append(":}");
duke@1 478 } finally {
duke@1 479 isPrintingBound = false;
duke@1 480 }
duke@1 481 return s.toString();
duke@1 482 }
duke@1 483
duke@1 484 public Type map(Mapping f) {
duke@1 485 //- System.err.println(" (" + this + ").map(" + f + ")");//DEBUG
duke@1 486 Type t = type;
duke@1 487 if (t != null)
duke@1 488 t = f.apply(t);
duke@1 489 if (t == type)
duke@1 490 return this;
duke@1 491 else
duke@1 492 return new WildcardType(t, kind, tsym, bound);
duke@1 493 }
duke@1 494
duke@1 495 public Type removeBounds() {
duke@1 496 return isUnbound() ? this : type;
duke@1 497 }
duke@1 498
duke@1 499 public Type getExtendsBound() {
duke@1 500 if (kind == EXTENDS)
duke@1 501 return type;
duke@1 502 else
duke@1 503 return null;
duke@1 504 }
duke@1 505
duke@1 506 public Type getSuperBound() {
duke@1 507 if (kind == SUPER)
duke@1 508 return type;
duke@1 509 else
duke@1 510 return null;
duke@1 511 }
duke@1 512
duke@1 513 public TypeKind getKind() {
duke@1 514 return TypeKind.WILDCARD;
duke@1 515 }
duke@1 516
duke@1 517 public <R, P> R accept(TypeVisitor<R, P> v, P p) {
duke@1 518 return v.visitWildcard(this, p);
duke@1 519 }
duke@1 520 }
duke@1 521
duke@1 522 public static class ClassType extends Type implements DeclaredType {
duke@1 523
duke@1 524 /** The enclosing type of this type. If this is the type of an inner
duke@1 525 * class, outer_field refers to the type of its enclosing
duke@1 526 * instance class, in all other cases it referes to noType.
duke@1 527 */
duke@1 528 private Type outer_field;
duke@1 529
duke@1 530 /** The type parameters of this type (to be set once class is loaded).
duke@1 531 */
duke@1 532 public List<Type> typarams_field;
duke@1 533
duke@1 534 /** A cache variable for the type parameters of this type,
duke@1 535 * appended to all parameters of its enclosing class.
duke@1 536 * @see #allparams
duke@1 537 */
duke@1 538 public List<Type> allparams_field;
duke@1 539
duke@1 540 /** The supertype of this class (to be set once class is loaded).
duke@1 541 */
duke@1 542 public Type supertype_field;
duke@1 543
duke@1 544 /** The interfaces of this class (to be set once class is loaded).
duke@1 545 */
duke@1 546 public List<Type> interfaces_field;
duke@1 547
duke@1 548 public ClassType(Type outer, List<Type> typarams, TypeSymbol tsym) {
duke@1 549 super(CLASS, tsym);
duke@1 550 this.outer_field = outer;
duke@1 551 this.typarams_field = typarams;
duke@1 552 this.allparams_field = null;
duke@1 553 this.supertype_field = null;
duke@1 554 this.interfaces_field = null;
duke@1 555 /*
duke@1 556 // this can happen during error recovery
duke@1 557 assert
duke@1 558 outer.isParameterized() ?
duke@1 559 typarams.length() == tsym.type.typarams().length() :
duke@1 560 outer.isRaw() ?
duke@1 561 typarams.length() == 0 :
duke@1 562 true;
duke@1 563 */
duke@1 564 }
duke@1 565
duke@1 566 @Override
duke@1 567 public <R,S> R accept(Type.Visitor<R,S> v, S s) {
duke@1 568 return v.visitClassType(this, s);
duke@1 569 }
duke@1 570
duke@1 571 public Type constType(Object constValue) {
duke@1 572 final Object value = constValue;
duke@1 573 return new ClassType(getEnclosingType(), typarams_field, tsym) {
duke@1 574 @Override
duke@1 575 public Object constValue() {
duke@1 576 return value;
duke@1 577 }
duke@1 578 @Override
duke@1 579 public Type baseType() {
duke@1 580 return tsym.type;
duke@1 581 }
duke@1 582 };
duke@1 583 }
duke@1 584
duke@1 585 /** The Java source which this type represents.
duke@1 586 */
duke@1 587 public String toString() {
duke@1 588 StringBuffer buf = new StringBuffer();
duke@1 589 if (getEnclosingType().tag == CLASS && tsym.owner.kind == TYP) {
duke@1 590 buf.append(getEnclosingType().toString());
duke@1 591 buf.append(".");
duke@1 592 buf.append(className(tsym, false));
duke@1 593 } else {
duke@1 594 buf.append(className(tsym, true));
duke@1 595 }
duke@1 596 if (getTypeArguments().nonEmpty()) {
duke@1 597 buf.append('<');
duke@1 598 buf.append(getTypeArguments().toString());
duke@1 599 buf.append(">");
duke@1 600 }
duke@1 601 return buf.toString();
duke@1 602 }
duke@1 603 //where
duke@1 604 private String className(Symbol sym, boolean longform) {
duke@1 605 if (sym.name.len == 0 && (sym.flags() & COMPOUND) != 0) {
duke@1 606 StringBuffer s = new StringBuffer(supertype_field.toString());
duke@1 607 for (List<Type> is=interfaces_field; is.nonEmpty(); is = is.tail) {
duke@1 608 s.append("&");
duke@1 609 s.append(is.head.toString());
duke@1 610 }
duke@1 611 return s.toString();
duke@1 612 } else if (sym.name.len == 0) {
duke@1 613 String s;
duke@1 614 ClassType norm = (ClassType) tsym.type;
duke@1 615 if (norm == null) {
duke@1 616 s = Log.getLocalizedString("anonymous.class", (Object)null);
duke@1 617 } else if (norm.interfaces_field != null && norm.interfaces_field.nonEmpty()) {
duke@1 618 s = Log.getLocalizedString("anonymous.class",
duke@1 619 norm.interfaces_field.head);
duke@1 620 } else {
duke@1 621 s = Log.getLocalizedString("anonymous.class",
duke@1 622 norm.supertype_field);
duke@1 623 }
duke@1 624 if (moreInfo)
duke@1 625 s += String.valueOf(sym.hashCode());
duke@1 626 return s;
duke@1 627 } else if (longform) {
duke@1 628 return sym.getQualifiedName().toString();
duke@1 629 } else {
duke@1 630 return sym.name.toString();
duke@1 631 }
duke@1 632 }
duke@1 633
duke@1 634 public List<Type> getTypeArguments() {
duke@1 635 if (typarams_field == null) {
duke@1 636 complete();
duke@1 637 if (typarams_field == null)
duke@1 638 typarams_field = List.nil();
duke@1 639 }
duke@1 640 return typarams_field;
duke@1 641 }
duke@1 642
duke@1 643 public Type getEnclosingType() {
duke@1 644 return outer_field;
duke@1 645 }
duke@1 646
duke@1 647 public void setEnclosingType(Type outer) {
duke@1 648 outer_field = outer;
duke@1 649 }
duke@1 650
duke@1 651 public List<Type> allparams() {
duke@1 652 if (allparams_field == null) {
duke@1 653 allparams_field = getTypeArguments().prependList(getEnclosingType().allparams());
duke@1 654 }
duke@1 655 return allparams_field;
duke@1 656 }
duke@1 657
duke@1 658 public boolean isErroneous() {
duke@1 659 return
duke@1 660 getEnclosingType().isErroneous() ||
duke@1 661 isErroneous(getTypeArguments()) ||
duke@1 662 this != tsym.type && tsym.type.isErroneous();
duke@1 663 }
duke@1 664
duke@1 665 public boolean isParameterized() {
duke@1 666 return allparams().tail != null;
duke@1 667 // optimization, was: allparams().nonEmpty();
duke@1 668 }
duke@1 669
duke@1 670 /** A cache for the rank. */
duke@1 671 int rank_field = -1;
duke@1 672
duke@1 673 /** A class type is raw if it misses some
duke@1 674 * of its type parameter sections.
duke@1 675 * After validation, this is equivalent to:
duke@1 676 * allparams.isEmpty() && tsym.type.allparams.nonEmpty();
duke@1 677 */
duke@1 678 public boolean isRaw() {
duke@1 679 return
duke@1 680 this != tsym.type && // necessary, but not sufficient condition
duke@1 681 tsym.type.allparams().nonEmpty() &&
duke@1 682 allparams().isEmpty();
duke@1 683 }
duke@1 684
duke@1 685 public Type map(Mapping f) {
duke@1 686 Type outer = getEnclosingType();
duke@1 687 Type outer1 = f.apply(outer);
duke@1 688 List<Type> typarams = getTypeArguments();
duke@1 689 List<Type> typarams1 = map(typarams, f);
duke@1 690 if (outer1 == outer && typarams1 == typarams) return this;
duke@1 691 else return new ClassType(outer1, typarams1, tsym);
duke@1 692 }
duke@1 693
duke@1 694 public boolean contains(Type elem) {
duke@1 695 return
duke@1 696 elem == this
duke@1 697 || (isParameterized()
duke@1 698 && (getEnclosingType().contains(elem) || contains(getTypeArguments(), elem)));
duke@1 699 }
duke@1 700
duke@1 701 public void complete() {
duke@1 702 if (tsym.completer != null) tsym.complete();
duke@1 703 }
duke@1 704
duke@1 705 public TypeKind getKind() {
duke@1 706 return TypeKind.DECLARED;
duke@1 707 }
duke@1 708
duke@1 709 public <R, P> R accept(TypeVisitor<R, P> v, P p) {
duke@1 710 return v.visitDeclared(this, p);
duke@1 711 }
duke@1 712 }
duke@1 713
duke@1 714 public static class ArrayType extends Type
duke@1 715 implements javax.lang.model.type.ArrayType {
duke@1 716
duke@1 717 public Type elemtype;
duke@1 718
duke@1 719 public ArrayType(Type elemtype, TypeSymbol arrayClass) {
duke@1 720 super(ARRAY, arrayClass);
duke@1 721 this.elemtype = elemtype;
duke@1 722 }
duke@1 723
duke@1 724 @Override
duke@1 725 public <R,S> R accept(Type.Visitor<R,S> v, S s) {
duke@1 726 return v.visitArrayType(this, s);
duke@1 727 }
duke@1 728
duke@1 729 public String toString() {
duke@1 730 return elemtype + "[]";
duke@1 731 }
duke@1 732
duke@1 733 public boolean equals(Object obj) {
duke@1 734 return
duke@1 735 this == obj ||
duke@1 736 (obj instanceof ArrayType &&
duke@1 737 this.elemtype.equals(((ArrayType)obj).elemtype));
duke@1 738 }
duke@1 739
duke@1 740 public int hashCode() {
duke@1 741 return (ARRAY << 5) + elemtype.hashCode();
duke@1 742 }
duke@1 743
duke@1 744 public List<Type> allparams() { return elemtype.allparams(); }
duke@1 745
duke@1 746 public boolean isErroneous() {
duke@1 747 return elemtype.isErroneous();
duke@1 748 }
duke@1 749
duke@1 750 public boolean isParameterized() {
duke@1 751 return elemtype.isParameterized();
duke@1 752 }
duke@1 753
duke@1 754 public boolean isRaw() {
duke@1 755 return elemtype.isRaw();
duke@1 756 }
duke@1 757
duke@1 758 public Type map(Mapping f) {
duke@1 759 Type elemtype1 = f.apply(elemtype);
duke@1 760 if (elemtype1 == elemtype) return this;
duke@1 761 else return new ArrayType(elemtype1, tsym);
duke@1 762 }
duke@1 763
duke@1 764 public boolean contains(Type elem) {
duke@1 765 return elem == this || elemtype.contains(elem);
duke@1 766 }
duke@1 767
duke@1 768 public void complete() {
duke@1 769 elemtype.complete();
duke@1 770 }
duke@1 771
duke@1 772 public Type getComponentType() {
duke@1 773 return elemtype;
duke@1 774 }
duke@1 775
duke@1 776 public TypeKind getKind() {
duke@1 777 return TypeKind.ARRAY;
duke@1 778 }
duke@1 779
duke@1 780 public <R, P> R accept(TypeVisitor<R, P> v, P p) {
duke@1 781 return v.visitArray(this, p);
duke@1 782 }
duke@1 783 }
duke@1 784
duke@1 785 public static class MethodType extends Type
duke@1 786 implements Cloneable, ExecutableType {
duke@1 787
duke@1 788 public List<Type> argtypes;
duke@1 789 public Type restype;
duke@1 790 public List<Type> thrown;
duke@1 791
duke@1 792 public MethodType(List<Type> argtypes,
duke@1 793 Type restype,
duke@1 794 List<Type> thrown,
duke@1 795 TypeSymbol methodClass) {
duke@1 796 super(METHOD, methodClass);
duke@1 797 this.argtypes = argtypes;
duke@1 798 this.restype = restype;
duke@1 799 this.thrown = thrown;
duke@1 800 }
duke@1 801
duke@1 802 @Override
duke@1 803 public <R,S> R accept(Type.Visitor<R,S> v, S s) {
duke@1 804 return v.visitMethodType(this, s);
duke@1 805 }
duke@1 806
duke@1 807 /** The Java source which this type represents.
duke@1 808 *
duke@1 809 * XXX 06/09/99 iris This isn't correct Java syntax, but it probably
duke@1 810 * should be.
duke@1 811 */
duke@1 812 public String toString() {
duke@1 813 return "(" + argtypes + ")" + restype;
duke@1 814 }
duke@1 815
duke@1 816 public boolean equals(Object obj) {
duke@1 817 if (this == obj)
duke@1 818 return true;
duke@1 819 if (!(obj instanceof MethodType))
duke@1 820 return false;
duke@1 821 MethodType m = (MethodType)obj;
duke@1 822 List<Type> args1 = argtypes;
duke@1 823 List<Type> args2 = m.argtypes;
duke@1 824 while (!args1.isEmpty() && !args2.isEmpty()) {
duke@1 825 if (!args1.head.equals(args2.head))
duke@1 826 return false;
duke@1 827 args1 = args1.tail;
duke@1 828 args2 = args2.tail;
duke@1 829 }
duke@1 830 if (!args1.isEmpty() || !args2.isEmpty())
duke@1 831 return false;
duke@1 832 return restype.equals(m.restype);
duke@1 833 }
duke@1 834
duke@1 835 public int hashCode() {
duke@1 836 int h = METHOD;
duke@1 837 for (List<Type> thisargs = this.argtypes;
duke@1 838 thisargs.tail != null; /*inlined: thisargs.nonEmpty()*/
duke@1 839 thisargs = thisargs.tail)
duke@1 840 h = (h << 5) + thisargs.head.hashCode();
duke@1 841 return (h << 5) + this.restype.hashCode();
duke@1 842 }
duke@1 843
duke@1 844 public List<Type> getParameterTypes() { return argtypes; }
duke@1 845 public Type getReturnType() { return restype; }
duke@1 846 public List<Type> getThrownTypes() { return thrown; }
duke@1 847
duke@1 848 public void setThrown(List<Type> t) {
duke@1 849 thrown = t;
duke@1 850 }
duke@1 851
duke@1 852 public boolean isErroneous() {
duke@1 853 return
duke@1 854 isErroneous(argtypes) ||
duke@1 855 restype != null && restype.isErroneous();
duke@1 856 }
duke@1 857
duke@1 858 public Type map(Mapping f) {
duke@1 859 List<Type> argtypes1 = map(argtypes, f);
duke@1 860 Type restype1 = f.apply(restype);
duke@1 861 List<Type> thrown1 = map(thrown, f);
duke@1 862 if (argtypes1 == argtypes &&
duke@1 863 restype1 == restype &&
duke@1 864 thrown1 == thrown) return this;
duke@1 865 else return new MethodType(argtypes1, restype1, thrown1, tsym);
duke@1 866 }
duke@1 867
duke@1 868 public boolean contains(Type elem) {
duke@1 869 return elem == this || contains(argtypes, elem) || restype.contains(elem);
duke@1 870 }
duke@1 871
duke@1 872 public MethodType asMethodType() { return this; }
duke@1 873
duke@1 874 public void complete() {
duke@1 875 for (List<Type> l = argtypes; l.nonEmpty(); l = l.tail)
duke@1 876 l.head.complete();
duke@1 877 restype.complete();
duke@1 878 for (List<Type> l = thrown; l.nonEmpty(); l = l.tail)
duke@1 879 l.head.complete();
duke@1 880 }
duke@1 881
duke@1 882 public List<TypeVar> getTypeVariables() {
duke@1 883 return List.nil();
duke@1 884 }
duke@1 885
duke@1 886 public TypeSymbol asElement() {
duke@1 887 return null;
duke@1 888 }
duke@1 889
duke@1 890 public TypeKind getKind() {
duke@1 891 return TypeKind.EXECUTABLE;
duke@1 892 }
duke@1 893
duke@1 894 public <R, P> R accept(TypeVisitor<R, P> v, P p) {
duke@1 895 return v.visitExecutable(this, p);
duke@1 896 }
duke@1 897 }
duke@1 898
duke@1 899 public static class PackageType extends Type implements NoType {
duke@1 900
duke@1 901 PackageType(TypeSymbol tsym) {
duke@1 902 super(PACKAGE, tsym);
duke@1 903 }
duke@1 904
duke@1 905 @Override
duke@1 906 public <R,S> R accept(Type.Visitor<R,S> v, S s) {
duke@1 907 return v.visitPackageType(this, s);
duke@1 908 }
duke@1 909
duke@1 910 public String toString() {
duke@1 911 return tsym.getQualifiedName().toString();
duke@1 912 }
duke@1 913
duke@1 914 public TypeKind getKind() {
duke@1 915 return TypeKind.PACKAGE;
duke@1 916 }
duke@1 917
duke@1 918 public <R, P> R accept(TypeVisitor<R, P> v, P p) {
duke@1 919 return v.visitNoType(this, p);
duke@1 920 }
duke@1 921 }
duke@1 922
duke@1 923 public static class TypeVar extends Type implements TypeVariable {
duke@1 924
duke@1 925 /** The bound of this type variable; set from outside.
duke@1 926 * Must be nonempty once it is set.
duke@1 927 * For a bound, `bound' is the bound type itself.
duke@1 928 * Multiple bounds are expressed as a single class type which has the
duke@1 929 * individual bounds as superclass, respectively interfaces.
duke@1 930 * The class type then has as `tsym' a compiler generated class `c',
duke@1 931 * which has a flag COMPOUND and whose owner is the type variable
duke@1 932 * itself. Furthermore, the erasure_field of the class
duke@1 933 * points to the first class or interface bound.
duke@1 934 */
duke@1 935 public Type bound = null;
duke@1 936 public Type lower;
duke@1 937
duke@1 938 public TypeVar(Name name, Symbol owner, Type lower) {
duke@1 939 super(TYPEVAR, null);
duke@1 940 tsym = new TypeSymbol(0, name, this, owner);
duke@1 941 this.lower = lower;
duke@1 942 }
duke@1 943
duke@1 944 public TypeVar(TypeSymbol tsym, Type bound, Type lower) {
duke@1 945 super(TYPEVAR, tsym);
duke@1 946 this.bound = bound;
duke@1 947 this.lower = lower;
duke@1 948 }
duke@1 949
duke@1 950 @Override
duke@1 951 public <R,S> R accept(Type.Visitor<R,S> v, S s) {
duke@1 952 return v.visitTypeVar(this, s);
duke@1 953 }
duke@1 954
duke@1 955 public Type getUpperBound() { return bound; }
duke@1 956
duke@1 957 int rank_field = -1;
duke@1 958
duke@1 959 public Type getLowerBound() {
duke@1 960 return lower;
duke@1 961 }
duke@1 962
duke@1 963 public TypeKind getKind() {
duke@1 964 return TypeKind.TYPEVAR;
duke@1 965 }
duke@1 966
duke@1 967 public <R, P> R accept(TypeVisitor<R, P> v, P p) {
duke@1 968 return v.visitTypeVariable(this, p);
duke@1 969 }
duke@1 970 }
duke@1 971
duke@1 972 /** A captured type variable comes from wildcards which can have
duke@1 973 * both upper and lower bound. CapturedType extends TypeVar with
duke@1 974 * a lower bound.
duke@1 975 */
duke@1 976 public static class CapturedType extends TypeVar {
duke@1 977
duke@1 978 public Type lower;
duke@1 979 public WildcardType wildcard;
duke@1 980
duke@1 981 public CapturedType(Name name,
duke@1 982 Symbol owner,
duke@1 983 Type upper,
duke@1 984 Type lower,
duke@1 985 WildcardType wildcard) {
duke@1 986 super(name, owner, lower);
duke@1 987 assert lower != null;
duke@1 988 this.bound = upper;
duke@1 989 this.lower = lower;
duke@1 990 this.wildcard = wildcard;
duke@1 991 }
duke@1 992
duke@1 993 @Override
duke@1 994 public <R,S> R accept(Type.Visitor<R,S> v, S s) {
duke@1 995 return v.visitCapturedType(this, s);
duke@1 996 }
duke@1 997
duke@1 998 public Type getLowerBound() {
duke@1 999 return lower;
duke@1 1000 }
duke@1 1001
duke@1 1002 @Override
duke@1 1003 public String toString() {
duke@1 1004 return "capture#"
duke@1 1005 + (hashCode() & 0xFFFFFFFFL) % PRIME
duke@1 1006 + " of "
duke@1 1007 + wildcard;
duke@1 1008 }
duke@1 1009 static final int PRIME = 997; // largest prime less than 1000
duke@1 1010 }
duke@1 1011
duke@1 1012 public static abstract class DelegatedType extends Type {
duke@1 1013 public Type qtype;
duke@1 1014 public DelegatedType(int tag, Type qtype) {
duke@1 1015 super(tag, qtype.tsym);
duke@1 1016 this.qtype = qtype;
duke@1 1017 }
duke@1 1018 public String toString() { return qtype.toString(); }
duke@1 1019 public List<Type> getTypeArguments() { return qtype.getTypeArguments(); }
duke@1 1020 public Type getEnclosingType() { return qtype.getEnclosingType(); }
duke@1 1021 public List<Type> getParameterTypes() { return qtype.getParameterTypes(); }
duke@1 1022 public Type getReturnType() { return qtype.getReturnType(); }
duke@1 1023 public List<Type> getThrownTypes() { return qtype.getThrownTypes(); }
duke@1 1024 public List<Type> allparams() { return qtype.allparams(); }
duke@1 1025 public Type getUpperBound() { return qtype.getUpperBound(); }
duke@1 1026 public Object clone() { DelegatedType t = (DelegatedType)super.clone(); t.qtype = (Type)qtype.clone(); return t; }
duke@1 1027 public boolean isErroneous() { return qtype.isErroneous(); }
duke@1 1028 }
duke@1 1029
duke@1 1030 public static class ForAll extends DelegatedType
duke@1 1031 implements Cloneable, ExecutableType {
duke@1 1032 public List<Type> tvars;
duke@1 1033
duke@1 1034 public ForAll(List<Type> tvars, Type qtype) {
duke@1 1035 super(FORALL, qtype);
duke@1 1036 this.tvars = tvars;
duke@1 1037 }
duke@1 1038
duke@1 1039 @Override
duke@1 1040 public <R,S> R accept(Type.Visitor<R,S> v, S s) {
duke@1 1041 return v.visitForAll(this, s);
duke@1 1042 }
duke@1 1043
duke@1 1044 public String toString() {
duke@1 1045 return "<" + tvars + ">" + qtype;
duke@1 1046 }
duke@1 1047
duke@1 1048 public List<Type> getTypeArguments() { return tvars; }
duke@1 1049
duke@1 1050 public void setThrown(List<Type> t) {
duke@1 1051 qtype.setThrown(t);
duke@1 1052 }
duke@1 1053
duke@1 1054 public Object clone() {
duke@1 1055 ForAll result = (ForAll)super.clone();
duke@1 1056 result.qtype = (Type)result.qtype.clone();
duke@1 1057 return result;
duke@1 1058 }
duke@1 1059
duke@1 1060 public boolean isErroneous() {
duke@1 1061 return qtype.isErroneous();
duke@1 1062 }
duke@1 1063
duke@1 1064 public Type map(Mapping f) {
duke@1 1065 return f.apply(qtype);
duke@1 1066 }
duke@1 1067
duke@1 1068 public boolean contains(Type elem) {
duke@1 1069 return qtype.contains(elem);
duke@1 1070 }
duke@1 1071
duke@1 1072 public MethodType asMethodType() {
duke@1 1073 return qtype.asMethodType();
duke@1 1074 }
duke@1 1075
duke@1 1076 public void complete() {
duke@1 1077 for (List<Type> l = tvars; l.nonEmpty(); l = l.tail) {
duke@1 1078 ((TypeVar)l.head).bound.complete();
duke@1 1079 }
duke@1 1080 qtype.complete();
duke@1 1081 }
duke@1 1082
duke@1 1083 public List<TypeVar> getTypeVariables() {
duke@1 1084 return List.convert(TypeVar.class, getTypeArguments());
duke@1 1085 }
duke@1 1086
duke@1 1087 public TypeKind getKind() {
duke@1 1088 return TypeKind.EXECUTABLE;
duke@1 1089 }
duke@1 1090
duke@1 1091 public <R, P> R accept(TypeVisitor<R, P> v, P p) {
duke@1 1092 return v.visitExecutable(this, p);
duke@1 1093 }
duke@1 1094 }
duke@1 1095
duke@1 1096 /** A class for instantiatable variables, for use during type
duke@1 1097 * inference.
duke@1 1098 */
duke@1 1099 public static class UndetVar extends DelegatedType {
duke@1 1100 public List<Type> lobounds = List.nil();
duke@1 1101 public List<Type> hibounds = List.nil();
duke@1 1102 public Type inst = null;
duke@1 1103
duke@1 1104 @Override
duke@1 1105 public <R,S> R accept(Type.Visitor<R,S> v, S s) {
duke@1 1106 return v.visitUndetVar(this, s);
duke@1 1107 }
duke@1 1108
duke@1 1109 public UndetVar(Type origin) {
duke@1 1110 super(UNDETVAR, origin);
duke@1 1111 }
duke@1 1112
duke@1 1113 public String toString() {
duke@1 1114 if (inst != null) return inst.toString();
duke@1 1115 else return qtype + "?";
duke@1 1116 }
duke@1 1117
duke@1 1118 public Type baseType() {
duke@1 1119 if (inst != null) return inst.baseType();
duke@1 1120 else return this;
duke@1 1121 }
duke@1 1122 }
duke@1 1123
duke@1 1124 /** Represents VOID or NONE.
duke@1 1125 */
duke@1 1126 static class JCNoType extends Type implements NoType {
duke@1 1127 public JCNoType(int tag) {
duke@1 1128 super(tag, null);
duke@1 1129 }
duke@1 1130
duke@1 1131 @Override
duke@1 1132 public TypeKind getKind() {
duke@1 1133 switch (tag) {
duke@1 1134 case VOID: return TypeKind.VOID;
duke@1 1135 case NONE: return TypeKind.NONE;
duke@1 1136 default:
duke@1 1137 throw new AssertionError("Unexpected tag: " + tag);
duke@1 1138 }
duke@1 1139 }
duke@1 1140
duke@1 1141 @Override
duke@1 1142 public <R, P> R accept(TypeVisitor<R, P> v, P p) {
duke@1 1143 return v.visitNoType(this, p);
duke@1 1144 }
duke@1 1145 }
duke@1 1146
duke@1 1147 static class BottomType extends Type implements NullType {
duke@1 1148 public BottomType() {
duke@1 1149 super(TypeTags.BOT, null);
duke@1 1150 }
duke@1 1151
duke@1 1152 @Override
duke@1 1153 public TypeKind getKind() {
duke@1 1154 return TypeKind.NULL;
duke@1 1155 }
duke@1 1156
duke@1 1157 @Override
duke@1 1158 public <R, P> R accept(TypeVisitor<R, P> v, P p) {
duke@1 1159 return v.visitNull(this, p);
duke@1 1160 }
duke@1 1161
duke@1 1162 @Override
duke@1 1163 public Type constType(Object value) {
duke@1 1164 return this;
duke@1 1165 }
duke@1 1166
duke@1 1167 @Override
duke@1 1168 public String stringValue() {
duke@1 1169 return "null";
duke@1 1170 }
duke@1 1171 }
duke@1 1172
duke@1 1173 public static class ErrorType extends ClassType
duke@1 1174 implements javax.lang.model.type.ErrorType {
duke@1 1175
duke@1 1176 public ErrorType() {
duke@1 1177 super(noType, List.<Type>nil(), null);
duke@1 1178 tag = ERROR;
duke@1 1179 }
duke@1 1180
duke@1 1181 public ErrorType(ClassSymbol c) {
duke@1 1182 this();
duke@1 1183 tsym = c;
duke@1 1184 c.type = this;
duke@1 1185 c.kind = ERR;
duke@1 1186 c.members_field = new Scope.ErrorScope(c);
duke@1 1187 }
duke@1 1188
duke@1 1189 public ErrorType(Name name, TypeSymbol container) {
duke@1 1190 this(new ClassSymbol(PUBLIC|STATIC|ACYCLIC, name, null, container));
duke@1 1191 }
duke@1 1192
duke@1 1193 @Override
duke@1 1194 public <R,S> R accept(Type.Visitor<R,S> v, S s) {
duke@1 1195 return v.visitErrorType(this, s);
duke@1 1196 }
duke@1 1197
duke@1 1198 public Type constType(Object constValue) { return this; }
duke@1 1199 public Type getEnclosingType() { return this; }
duke@1 1200 public Type getReturnType() { return this; }
duke@1 1201 public Type asSub(Symbol sym) { return this; }
duke@1 1202 public Type map(Mapping f) { return this; }
duke@1 1203
duke@1 1204 public boolean isGenType(Type t) { return true; }
duke@1 1205 public boolean isErroneous() { return true; }
duke@1 1206 public boolean isCompound() { return false; }
duke@1 1207 public boolean isInterface() { return false; }
duke@1 1208
duke@1 1209 public List<Type> allparams() { return List.nil(); }
duke@1 1210 public List<Type> getTypeArguments() { return List.nil(); }
duke@1 1211
duke@1 1212 public TypeKind getKind() {
duke@1 1213 return TypeKind.ERROR;
duke@1 1214 }
duke@1 1215
duke@1 1216 public <R, P> R accept(TypeVisitor<R, P> v, P p) {
duke@1 1217 return v.visitError(this, p);
duke@1 1218 }
duke@1 1219 }
duke@1 1220
duke@1 1221 /**
duke@1 1222 * A visitor for types. A visitor is used to implement operations
duke@1 1223 * (or relations) on types. Most common operations on types are
duke@1 1224 * binary relations and this interface is designed for binary
duke@1 1225 * relations, that is, operations on the form
duke@1 1226 * Type&nbsp;&times;&nbsp;S&nbsp;&rarr;&nbsp;R.
duke@1 1227 * <!-- In plain text: Type x S -> R -->
duke@1 1228 *
duke@1 1229 * @param <R> the return type of the operation implemented by this
duke@1 1230 * visitor; use Void if no return type is needed.
duke@1 1231 * @param <S> the type of the second argument (the first being the
duke@1 1232 * type itself) of the operation implemented by this visitor; use
duke@1 1233 * Void if a second argument is not needed.
duke@1 1234 */
duke@1 1235 public interface Visitor<R,S> {
duke@1 1236 R visitClassType(ClassType t, S s);
duke@1 1237 R visitWildcardType(WildcardType t, S s);
duke@1 1238 R visitArrayType(ArrayType t, S s);
duke@1 1239 R visitMethodType(MethodType t, S s);
duke@1 1240 R visitPackageType(PackageType t, S s);
duke@1 1241 R visitTypeVar(TypeVar t, S s);
duke@1 1242 R visitCapturedType(CapturedType t, S s);
duke@1 1243 R visitForAll(ForAll t, S s);
duke@1 1244 R visitUndetVar(UndetVar t, S s);
duke@1 1245 R visitErrorType(ErrorType t, S s);
duke@1 1246 R visitType(Type t, S s);
duke@1 1247 }
duke@1 1248 }

mercurial