1 /*
   2  * Copyright 1999-2009 Sun Microsystems, Inc.  All Rights Reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Sun designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Sun in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  22  * CA 95054 USA or visit www.sun.com if you need additional information or
  23  * have any questions.
  24  */
  25 
  26 package com.sun.tools.javac.jvm;
  27 
  28 import java.io.*;
  29 import java.net.URI;
  30 import java.net.URISyntaxException;
  31 import java.nio.CharBuffer;
  32 import java.util.Arrays;
  33 import java.util.EnumSet;
  34 import java.util.HashMap;
  35 import java.util.Map;
  36 import java.util.Set;
  37 import javax.lang.model.SourceVersion;
  38 import javax.tools.JavaFileObject;
  39 import javax.tools.JavaFileManager;
  40 import javax.tools.JavaFileManager.Location;
  41 import javax.tools.StandardJavaFileManager;
  42 
  43 import static javax.tools.StandardLocation.*;
  44 
  45 import com.sun.tools.javac.comp.Annotate;
  46 import com.sun.tools.javac.code.*;
  47 import com.sun.tools.javac.code.Type.*;
  48 import com.sun.tools.javac.code.Symbol.*;
  49 import com.sun.tools.javac.code.Symtab;
  50 import com.sun.tools.javac.file.BaseFileObject;
  51 import com.sun.tools.javac.util.*;
  52 
  53 import static com.sun.tools.javac.code.Flags.*;
  54 import static com.sun.tools.javac.code.Kinds.*;
  55 import static com.sun.tools.javac.code.TypeTags.*;
  56 import static com.sun.tools.javac.jvm.ClassFile.*;
  57 import static com.sun.tools.javac.jvm.ClassFile.Version.*;
  58 
  59 /** This class provides operations to read a classfile into an internal
  60  *  representation. The internal representation is anchored in a
  61  *  ClassSymbol which contains in its scope symbol representations
  62  *  for all other definitions in the classfile. Top-level Classes themselves
  63  *  appear as members of the scopes of PackageSymbols.
  64  *
  65  *  <p><b>This is NOT part of any API supported by Sun Microsystems.  If
  66  *  you write code that depends on this, you do so at your own risk.
  67  *  This code and its internal interfaces are subject to change or
  68  *  deletion without notice.</b>
  69  */
  70 public class ClassReader implements Completer {
  71     /** The context key for the class reader. */
  72     protected static final Context.Key<ClassReader> classReaderKey =
  73         new Context.Key<ClassReader>();
  74 
  75     Annotate annotate;
  76 
  77     /** Switch: verbose output.
  78      */
  79     boolean verbose;
  80 
  81     /** Switch: check class file for correct minor version, unrecognized
  82      *  attributes.
  83      */
  84     boolean checkClassFile;
  85 
  86     /** Switch: read constant pool and code sections. This switch is initially
  87      *  set to false but can be turned on from outside.
  88      */
  89     public boolean readAllOfClassFile = false;
  90 
  91     /** Switch: read GJ signature information.
  92      */
  93     boolean allowGenerics;
  94 
  95     /** Switch: read varargs attribute.
  96      */
  97     boolean allowVarargs;
  98 
  99     /** Switch: allow annotations.
 100      */
 101     boolean allowAnnotations;
 102 
 103     /** Switch: preserve parameter names from the variable table.
 104      */
 105     public boolean saveParameterNames;
 106 
 107     /**
 108      * Switch: cache completion failures unless -XDdev is used
 109      */
 110     private boolean cacheCompletionFailure;
 111 
 112     /**
 113      * Switch: prefer source files instead of newer when both source
 114      * and class are available
 115      **/
 116     public boolean preferSource;
 117 
 118     /** The log to use for verbose output
 119      */
 120     final Log log;
 121 
 122     /** The symbol table. */
 123     Symtab syms;
 124 
 125     Types types;
 126 
 127     /** The name table. */
 128     final Names names;
 129 
 130     /** Force a completion failure on this name
 131      */
 132     final Name completionFailureName;
 133 
 134     /** Access to files
 135      */
 136     private final JavaFileManager fileManager;
 137 
 138     /** Factory for diagnostics
 139      */
 140     JCDiagnostic.Factory diagFactory;
 141 
 142     /** Can be reassigned from outside:
 143      *  the completer to be used for ".java" files. If this remains unassigned
 144      *  ".java" files will not be loaded.
 145      */
 146     public SourceCompleter sourceCompleter = null;
 147 
 148     /** A hashtable containing the encountered top-level and member classes,
 149      *  indexed by flat names. The table does not contain local classes.
 150      */
 151     private Map<Name,ClassSymbol> classes;
 152 
 153     /** A hashtable containing the encountered packages.
 154      */
 155     private Map<Name, PackageSymbol> packages;
 156 
 157     /** The current scope where type variables are entered.
 158      */
 159     protected Scope typevars;
 160 
 161     /** The path name of the class file currently being read.
 162      */
 163     protected JavaFileObject currentClassFile = null;
 164 
 165     /** The class or method currently being read.
 166      */
 167     protected Symbol currentOwner = null;
 168 
 169     /** The buffer containing the currently read class file.
 170      */
 171     byte[] buf = new byte[0x0fff0];
 172 
 173     /** The current input pointer.
 174      */
 175     int bp;
 176 
 177     /** The objects of the constant pool.
 178      */
 179     Object[] poolObj;
 180 
 181     /** For every constant pool entry, an index into buf where the
 182      *  defining section of the entry is found.
 183      */
 184     int[] poolIdx;
 185 
 186     /** The major version number of the class file being read. */
 187     int majorVersion;
 188     /** The minor version number of the class file being read. */
 189     int minorVersion;
 190 
 191     /** Switch: debug output for JSR 308-related operations.
 192      */
 193     boolean debugJSR308;
 194 
 195     /** A table to hold the constant pool indices for method parameter
 196      * names, as given in LocalVariableTable attributes.
 197      */
 198     int[] parameterNameIndices;
 199 
 200     /** Get the ClassReader instance for this invocation. */
 201     public static ClassReader instance(Context context) {
 202         ClassReader instance = context.get(classReaderKey);
 203         if (instance == null)
 204             instance = new ClassReader(context, true);
 205         return instance;
 206     }
 207 
 208     /** Initialize classes and packages, treating this as the definitive classreader. */
 209     public void init(Symtab syms) {
 210         init(syms, true);
 211     }
 212 
 213     /** Initialize classes and packages, optionally treating this as
 214      *  the definitive classreader.
 215      */
 216     private void init(Symtab syms, boolean definitive) {
 217         if (classes != null) return;
 218 
 219         if (definitive) {
 220             assert packages == null || packages == syms.packages;
 221             packages = syms.packages;
 222             assert classes == null || classes == syms.classes;
 223             classes = syms.classes;
 224         } else {
 225             packages = new HashMap<Name, PackageSymbol>();
 226             classes = new HashMap<Name, ClassSymbol>();
 227         }
 228 
 229         packages.put(names.empty, syms.rootPackage);
 230         syms.rootPackage.completer = this;
 231         syms.unnamedPackage.completer = this;
 232     }
 233 
 234     /** Construct a new class reader, optionally treated as the
 235      *  definitive classreader for this invocation.
 236      */
 237     protected ClassReader(Context context, boolean definitive) {
 238         if (definitive) context.put(classReaderKey, this);
 239 
 240         names = Names.instance(context);
 241         syms = Symtab.instance(context);
 242         types = Types.instance(context);
 243         fileManager = context.get(JavaFileManager.class);
 244         if (fileManager == null)
 245             throw new AssertionError("FileManager initialization error");
 246         diagFactory = JCDiagnostic.Factory.instance(context);
 247 
 248         init(syms, definitive);
 249         log = Log.instance(context);
 250 
 251         Options options = Options.instance(context);
 252         annotate = Annotate.instance(context);
 253         verbose        = options.get("-verbose")        != null;
 254         checkClassFile = options.get("-checkclassfile") != null;
 255         Source source = Source.instance(context);
 256         allowGenerics    = source.allowGenerics();
 257         allowVarargs     = source.allowVarargs();
 258         allowAnnotations = source.allowAnnotations();
 259         saveParameterNames = options.get("save-parameter-names") != null;
 260         cacheCompletionFailure = options.get("dev") == null;
 261         preferSource = "source".equals(options.get("-Xprefer"));
 262 
 263         completionFailureName =
 264             (options.get("failcomplete") != null)
 265             ? names.fromString(options.get("failcomplete"))
 266             : null;
 267 
 268         typevars = new Scope(syms.noSymbol);
 269         debugJSR308 = options.get("TA:reader") != null;
 270 
 271         initAttributeReaders();
 272     }
 273 
 274     /** Add member to class unless it is synthetic.
 275      */
 276     private void enterMember(ClassSymbol c, Symbol sym) {
 277         if ((sym.flags_field & (SYNTHETIC|BRIDGE)) != SYNTHETIC)
 278             c.members_field.enter(sym);
 279     }
 280 
 281 /************************************************************************
 282  * Error Diagnoses
 283  ***********************************************************************/
 284 
 285 
 286     public class BadClassFile extends CompletionFailure {
 287         private static final long serialVersionUID = 0;
 288 
 289         public BadClassFile(TypeSymbol sym, JavaFileObject file, JCDiagnostic diag) {
 290             super(sym, createBadClassFileDiagnostic(file, diag));
 291         }
 292     }
 293     // where
 294     private JCDiagnostic createBadClassFileDiagnostic(JavaFileObject file, JCDiagnostic diag) {
 295         String key = (file.getKind() == JavaFileObject.Kind.SOURCE
 296                     ? "bad.source.file.header" : "bad.class.file.header");
 297         return diagFactory.fragment(key, file, diag);
 298     }
 299 
 300     public BadClassFile badClassFile(String key, Object... args) {
 301         return new BadClassFile (
 302             currentOwner.enclClass(),
 303             currentClassFile,
 304             diagFactory.fragment(key, args));
 305     }
 306 
 307 /************************************************************************
 308  * Buffer Access
 309  ***********************************************************************/
 310 
 311     /** Read a character.
 312      */
 313     char nextChar() {
 314         return (char)(((buf[bp++] & 0xFF) << 8) + (buf[bp++] & 0xFF));
 315     }
 316 
 317     /** Read a byte.
 318      */
 319     byte nextByte() {
 320         return buf[bp++];
 321     }
 322 
 323     /** Read an integer.
 324      */
 325     int nextInt() {
 326         return
 327             ((buf[bp++] & 0xFF) << 24) +
 328             ((buf[bp++] & 0xFF) << 16) +
 329             ((buf[bp++] & 0xFF) << 8) +
 330             (buf[bp++] & 0xFF);
 331     }
 332 
 333     /** Extract a character at position bp from buf.
 334      */
 335     char getChar(int bp) {
 336         return
 337             (char)(((buf[bp] & 0xFF) << 8) + (buf[bp+1] & 0xFF));
 338     }
 339 
 340     /** Extract an integer at position bp from buf.
 341      */
 342     int getInt(int bp) {
 343         return
 344             ((buf[bp] & 0xFF) << 24) +
 345             ((buf[bp+1] & 0xFF) << 16) +
 346             ((buf[bp+2] & 0xFF) << 8) +
 347             (buf[bp+3] & 0xFF);
 348     }
 349 
 350 
 351     /** Extract a long integer at position bp from buf.
 352      */
 353     long getLong(int bp) {
 354         DataInputStream bufin =
 355             new DataInputStream(new ByteArrayInputStream(buf, bp, 8));
 356         try {
 357             return bufin.readLong();
 358         } catch (IOException e) {
 359             throw new AssertionError(e);
 360         }
 361     }
 362 
 363     /** Extract a float at position bp from buf.
 364      */
 365     float getFloat(int bp) {
 366         DataInputStream bufin =
 367             new DataInputStream(new ByteArrayInputStream(buf, bp, 4));
 368         try {
 369             return bufin.readFloat();
 370         } catch (IOException e) {
 371             throw new AssertionError(e);
 372         }
 373     }
 374 
 375     /** Extract a double at position bp from buf.
 376      */
 377     double getDouble(int bp) {
 378         DataInputStream bufin =
 379             new DataInputStream(new ByteArrayInputStream(buf, bp, 8));
 380         try {
 381             return bufin.readDouble();
 382         } catch (IOException e) {
 383             throw new AssertionError(e);
 384         }
 385     }
 386 
 387 /************************************************************************
 388  * Constant Pool Access
 389  ***********************************************************************/
 390 
 391     /** Index all constant pool entries, writing their start addresses into
 392      *  poolIdx.
 393      */
 394     void indexPool() {
 395         poolIdx = new int[nextChar()];
 396         poolObj = new Object[poolIdx.length];
 397         int i = 1;
 398         while (i < poolIdx.length) {
 399             poolIdx[i++] = bp;
 400             byte tag = buf[bp++];
 401             switch (tag) {
 402             case CONSTANT_Utf8: case CONSTANT_Unicode: {
 403                 int len = nextChar();
 404                 bp = bp + len;
 405                 break;
 406             }
 407             case CONSTANT_Class:
 408             case CONSTANT_String:
 409                 bp = bp + 2;
 410                 break;
 411             case CONSTANT_Fieldref:
 412             case CONSTANT_Methodref:
 413             case CONSTANT_InterfaceMethodref:
 414             case CONSTANT_NameandType:
 415             case CONSTANT_Integer:
 416             case CONSTANT_Float:
 417                 bp = bp + 4;
 418                 break;
 419             case CONSTANT_Long:
 420             case CONSTANT_Double:
 421                 bp = bp + 8;
 422                 i++;
 423                 break;
 424             default:
 425                 throw badClassFile("bad.const.pool.tag.at",
 426                                    Byte.toString(tag),
 427                                    Integer.toString(bp -1));
 428             }
 429         }
 430     }
 431 
 432     /** Read constant pool entry at start address i, use pool as a cache.
 433      */
 434     Object readPool(int i) {
 435         Object result = poolObj[i];
 436         if (result != null) return result;
 437 
 438         int index = poolIdx[i];
 439         if (index == 0) return null;
 440 
 441         byte tag = buf[index];
 442         switch (tag) {
 443         case CONSTANT_Utf8:
 444             poolObj[i] = names.fromUtf(buf, index + 3, getChar(index + 1));
 445             break;
 446         case CONSTANT_Unicode:
 447             throw badClassFile("unicode.str.not.supported");
 448         case CONSTANT_Class:
 449             poolObj[i] = readClassOrType(getChar(index + 1));
 450             break;
 451         case CONSTANT_String:
 452             // FIXME: (footprint) do not use toString here
 453             poolObj[i] = readName(getChar(index + 1)).toString();
 454             break;
 455         case CONSTANT_Fieldref: {
 456             ClassSymbol owner = readClassSymbol(getChar(index + 1));
 457             NameAndType nt = (NameAndType)readPool(getChar(index + 3));
 458             poolObj[i] = new VarSymbol(0, nt.name, nt.type, owner);
 459             break;
 460         }
 461         case CONSTANT_Methodref:
 462         case CONSTANT_InterfaceMethodref: {
 463             ClassSymbol owner = readClassSymbol(getChar(index + 1));
 464             NameAndType nt = (NameAndType)readPool(getChar(index + 3));
 465             poolObj[i] = new MethodSymbol(0, nt.name, nt.type, owner);
 466             break;
 467         }
 468         case CONSTANT_NameandType:
 469             poolObj[i] = new NameAndType(
 470                 readName(getChar(index + 1)),
 471                 readType(getChar(index + 3)));
 472             break;
 473         case CONSTANT_Integer:
 474             poolObj[i] = getInt(index + 1);
 475             break;
 476         case CONSTANT_Float:
 477             poolObj[i] = new Float(getFloat(index + 1));
 478             break;
 479         case CONSTANT_Long:
 480             poolObj[i] = new Long(getLong(index + 1));
 481             break;
 482         case CONSTANT_Double:
 483             poolObj[i] = new Double(getDouble(index + 1));
 484             break;
 485         default:
 486             throw badClassFile("bad.const.pool.tag", Byte.toString(tag));
 487         }
 488         return poolObj[i];
 489     }
 490 
 491     /** Read signature and convert to type.
 492      */
 493     Type readType(int i) {
 494         int index = poolIdx[i];
 495         return sigToType(buf, index + 3, getChar(index + 1));
 496     }
 497 
 498     /** If name is an array type or class signature, return the
 499      *  corresponding type; otherwise return a ClassSymbol with given name.
 500      */
 501     Object readClassOrType(int i) {
 502         int index =  poolIdx[i];
 503         int len = getChar(index + 1);
 504         int start = index + 3;
 505         assert buf[start] == '[' || buf[start + len - 1] != ';';
 506         // by the above assertion, the following test can be
 507         // simplified to (buf[start] == '[')
 508         return (buf[start] == '[' || buf[start + len - 1] == ';')
 509             ? (Object)sigToType(buf, start, len)
 510             : (Object)enterClass(names.fromUtf(internalize(buf, start,
 511                                                            len)));
 512     }
 513 
 514     /** Read signature and convert to type parameters.
 515      */
 516     List<Type> readTypeParams(int i) {
 517         int index = poolIdx[i];
 518         return sigToTypeParams(buf, index + 3, getChar(index + 1));
 519     }
 520 
 521     /** Read class entry.
 522      */
 523     ClassSymbol readClassSymbol(int i) {
 524         return (ClassSymbol) (readPool(i));
 525     }
 526 
 527     /** Read name.
 528      */
 529     Name readName(int i) {
 530         return (Name) (readPool(i));
 531     }
 532 
 533 /************************************************************************
 534  * Reading Types
 535  ***********************************************************************/
 536 
 537     /** The unread portion of the currently read type is
 538      *  signature[sigp..siglimit-1].
 539      */
 540     byte[] signature;
 541     int sigp;
 542     int siglimit;
 543     boolean sigEnterPhase = false;
 544 
 545     /** Convert signature to type, where signature is a byte array segment.
 546      */
 547     Type sigToType(byte[] sig, int offset, int len) {
 548         signature = sig;
 549         sigp = offset;
 550         siglimit = offset + len;
 551         return sigToType();
 552     }
 553 
 554     /** Convert signature to type, where signature is implicit.
 555      */
 556     Type sigToType() {
 557         switch ((char) signature[sigp]) {
 558         case 'T':
 559             sigp++;
 560             int start = sigp;
 561             while (signature[sigp] != ';') sigp++;
 562             sigp++;
 563             return sigEnterPhase
 564                 ? Type.noType
 565                 : findTypeVar(names.fromUtf(signature, start, sigp - 1 - start));
 566         case '+': {
 567             sigp++;
 568             Type t = sigToType();
 569             return new WildcardType(t, BoundKind.EXTENDS,
 570                                     syms.boundClass);
 571         }
 572         case '*':
 573             sigp++;
 574             return new WildcardType(syms.objectType, BoundKind.UNBOUND,
 575                                     syms.boundClass);
 576         case '-': {
 577             sigp++;
 578             Type t = sigToType();
 579             return new WildcardType(t, BoundKind.SUPER,
 580                                     syms.boundClass);
 581         }
 582         case 'B':
 583             sigp++;
 584             return syms.byteType;
 585         case 'C':
 586             sigp++;
 587             return syms.charType;
 588         case 'D':
 589             sigp++;
 590             return syms.doubleType;
 591         case 'F':
 592             sigp++;
 593             return syms.floatType;
 594         case 'I':
 595             sigp++;
 596             return syms.intType;
 597         case 'J':
 598             sigp++;
 599             return syms.longType;
 600         case 'L':
 601             {
 602                 // int oldsigp = sigp;
 603                 Type t = classSigToType();
 604                 if (sigp < siglimit && signature[sigp] == '.')
 605                     throw badClassFile("deprecated inner class signature syntax " +
 606                                        "(please recompile from source)");
 607                 /*
 608                 System.err.println(" decoded " +
 609                                    new String(signature, oldsigp, sigp-oldsigp) +
 610                                    " => " + t + " outer " + t.outer());
 611                 */
 612                 return t;
 613             }
 614         case 'S':
 615             sigp++;
 616             return syms.shortType;
 617         case 'V':
 618             sigp++;
 619             return syms.voidType;
 620         case 'Z':
 621             sigp++;
 622             return syms.booleanType;
 623         case '[':
 624             sigp++;
 625             return new ArrayType(sigToType(), syms.arrayClass);
 626         case '(':
 627             sigp++;
 628             List<Type> argtypes = sigToTypes(')');
 629             Type restype = sigToType();
 630             List<Type> thrown = List.nil();
 631             while (signature[sigp] == '^') {
 632                 sigp++;
 633                 thrown = thrown.prepend(sigToType());
 634             }
 635             return new MethodType(argtypes,
 636                                   restype,
 637                                   thrown.reverse(),
 638                                   syms.methodClass);
 639         case '<':
 640             typevars = typevars.dup(currentOwner);
 641             Type poly = new ForAll(sigToTypeParams(), sigToType());
 642             typevars = typevars.leave();
 643             return poly;
 644         default:
 645             throw badClassFile("bad.signature",
 646                                Convert.utf2string(signature, sigp, 10));
 647         }
 648     }
 649 
 650     byte[] signatureBuffer = new byte[0];
 651     int sbp = 0;
 652     /** Convert class signature to type, where signature is implicit.
 653      */
 654     Type classSigToType() {
 655         if (signature[sigp] != 'L')
 656             throw badClassFile("bad.class.signature",
 657                                Convert.utf2string(signature, sigp, 10));
 658         sigp++;
 659         Type outer = Type.noType;
 660         int startSbp = sbp;
 661 
 662         while (true) {
 663             final byte c = signature[sigp++];
 664             switch (c) {
 665 
 666             case ';': {         // end
 667                 ClassSymbol t = enterClass(names.fromUtf(signatureBuffer,
 668                                                          startSbp,
 669                                                          sbp - startSbp));
 670                 if (outer == Type.noType)
 671                     outer = t.erasure(types);
 672                 else
 673                     outer = new ClassType(outer, List.<Type>nil(), t);
 674                 sbp = startSbp;
 675                 return outer;
 676             }
 677 
 678             case '<':           // generic arguments
 679                 ClassSymbol t = enterClass(names.fromUtf(signatureBuffer,
 680                                                          startSbp,
 681                                                          sbp - startSbp));
 682                 outer = new ClassType(outer, sigToTypes('>'), t) {
 683                         boolean completed = false;
 684                         @Override
 685                         public Type getEnclosingType() {
 686                             if (!completed) {
 687                                 completed = true;
 688                                 tsym.complete();
 689                                 Type enclosingType = tsym.type.getEnclosingType();
 690                                 if (enclosingType != Type.noType) {
 691                                     List<Type> typeArgs =
 692                                         super.getEnclosingType().allparams();
 693                                     List<Type> typeParams =
 694                                         enclosingType.allparams();
 695                                     if (typeParams.length() != typeArgs.length()) {
 696                                         // no "rare" types
 697                                         super.setEnclosingType(types.erasure(enclosingType));
 698                                     } else {
 699                                         super.setEnclosingType(types.subst(enclosingType,
 700                                                                            typeParams,
 701                                                                            typeArgs));
 702                                     }
 703                                 } else {
 704                                     super.setEnclosingType(Type.noType);
 705                                 }
 706                             }
 707                             return super.getEnclosingType();
 708                         }
 709                         @Override
 710                         public void setEnclosingType(Type outer) {
 711                             throw new UnsupportedOperationException();
 712                         }
 713                     };
 714                 switch (signature[sigp++]) {
 715                 case ';':
 716                     if (sigp < signature.length && signature[sigp] == '.') {
 717                         // support old-style GJC signatures
 718                         // The signature produced was
 719                         // Lfoo/Outer<Lfoo/X;>;.Lfoo/Outer$Inner<Lfoo/Y;>;
 720                         // rather than say
 721                         // Lfoo/Outer<Lfoo/X;>.Inner<Lfoo/Y;>;
 722                         // so we skip past ".Lfoo/Outer$"
 723                         sigp += (sbp - startSbp) + // "foo/Outer"
 724                             3;  // ".L" and "$"
 725                         signatureBuffer[sbp++] = (byte)'$';
 726                         break;
 727                     } else {
 728                         sbp = startSbp;
 729                         return outer;
 730                     }
 731                 case '.':
 732                     signatureBuffer[sbp++] = (byte)'$';
 733                     break;
 734                 default:
 735                     throw new AssertionError(signature[sigp-1]);
 736                 }
 737                 continue;
 738 
 739             case '.':
 740                 signatureBuffer[sbp++] = (byte)'$';
 741                 continue;
 742             case '/':
 743                 signatureBuffer[sbp++] = (byte)'.';
 744                 continue;
 745             default:
 746                 signatureBuffer[sbp++] = c;
 747                 continue;
 748             }
 749         }
 750     }
 751 
 752     /** Convert (implicit) signature to list of types
 753      *  until `terminator' is encountered.
 754      */
 755     List<Type> sigToTypes(char terminator) {
 756         List<Type> head = List.of(null);
 757         List<Type> tail = head;
 758         while (signature[sigp] != terminator)
 759             tail = tail.setTail(List.of(sigToType()));
 760         sigp++;
 761         return head.tail;
 762     }
 763 
 764     /** Convert signature to type parameters, where signature is a byte
 765      *  array segment.
 766      */
 767     List<Type> sigToTypeParams(byte[] sig, int offset, int len) {
 768         signature = sig;
 769         sigp = offset;
 770         siglimit = offset + len;
 771         return sigToTypeParams();
 772     }
 773 
 774     /** Convert signature to type parameters, where signature is implicit.
 775      */
 776     List<Type> sigToTypeParams() {
 777         List<Type> tvars = List.nil();
 778         if (signature[sigp] == '<') {
 779             sigp++;
 780             int start = sigp;
 781             sigEnterPhase = true;
 782             while (signature[sigp] != '>')
 783                 tvars = tvars.prepend(sigToTypeParam());
 784             sigEnterPhase = false;
 785             sigp = start;
 786             while (signature[sigp] != '>')
 787                 sigToTypeParam();
 788             sigp++;
 789         }
 790         return tvars.reverse();
 791     }
 792 
 793     /** Convert (implicit) signature to type parameter.
 794      */
 795     Type sigToTypeParam() {
 796         int start = sigp;
 797         while (signature[sigp] != ':') sigp++;
 798         Name name = names.fromUtf(signature, start, sigp - start);
 799         TypeVar tvar;
 800         if (sigEnterPhase) {
 801             tvar = new TypeVar(name, currentOwner, syms.botType);
 802             typevars.enter(tvar.tsym);
 803         } else {
 804             tvar = (TypeVar)findTypeVar(name);
 805         }
 806         List<Type> bounds = List.nil();
 807         Type st = null;
 808         if (signature[sigp] == ':' && signature[sigp+1] == ':') {
 809             sigp++;
 810             st = syms.objectType;
 811         }
 812         while (signature[sigp] == ':') {
 813             sigp++;
 814             bounds = bounds.prepend(sigToType());
 815         }
 816         if (!sigEnterPhase) {
 817             types.setBounds(tvar, bounds.reverse(), st);
 818         }
 819         return tvar;
 820     }
 821 
 822     /** Find type variable with given name in `typevars' scope.
 823      */
 824     Type findTypeVar(Name name) {
 825         Scope.Entry e = typevars.lookup(name);
 826         if (e.scope != null) {
 827             return e.sym.type;
 828         } else {
 829             if (readingClassAttr) {
 830                 // While reading the class attribute, the supertypes
 831                 // might refer to a type variable from an enclosing element
 832                 // (method or class).
 833                 // If the type variable is defined in the enclosing class,
 834                 // we can actually find it in
 835                 // currentOwner.owner.type.getTypeArguments()
 836                 // However, until we have read the enclosing method attribute
 837                 // we don't know for sure if this owner is correct.  It could
 838                 // be a method and there is no way to tell before reading the
 839                 // enclosing method attribute.
 840                 TypeVar t = new TypeVar(name, currentOwner, syms.botType);
 841                 missingTypeVariables = missingTypeVariables.prepend(t);
 842                 // System.err.println("Missing type var " + name);
 843                 return t;
 844             }
 845             throw badClassFile("undecl.type.var", name);
 846         }
 847     }
 848 
 849 /************************************************************************
 850  * Reading Attributes
 851  ***********************************************************************/
 852 
 853     protected enum AttributeKind { CLASS, MEMBER };
 854     protected abstract class AttributeReader {
 855         AttributeReader(Name name, Version version, Set<AttributeKind> kinds) {
 856             this.name = name;
 857             this.version = version;
 858             this.kinds = kinds;
 859         }
 860 
 861         boolean accepts(AttributeKind kind) {
 862             return kinds.contains(kind) && majorVersion >= version.major;
 863         }
 864 
 865         abstract void read(Symbol sym, int attrLen);
 866 
 867         final Name name;
 868         final Version version;
 869         final Set<AttributeKind> kinds;
 870     }
 871 
 872     protected Set<AttributeKind> CLASS_ATTRIBUTE =
 873             EnumSet.of(AttributeKind.CLASS);
 874     protected Set<AttributeKind> MEMBER_ATTRIBUTE =
 875             EnumSet.of(AttributeKind.MEMBER);
 876     protected Set<AttributeKind> CLASS_OR_MEMBER_ATTRIBUTE =
 877             EnumSet.of(AttributeKind.CLASS, AttributeKind.MEMBER);
 878 
 879     protected Map<Name, AttributeReader> attributeReaders = new HashMap<Name, AttributeReader>();
 880 
 881     protected void initAttributeReaders() {
 882         AttributeReader[] readers = {
 883             // v45.3 attributes
 884 
 885             new AttributeReader(names.Code, V45_3, MEMBER_ATTRIBUTE) {
 886                 void read(Symbol sym, int attrLen) {
 887                     if (readAllOfClassFile || saveParameterNames)
 888                         ((MethodSymbol)sym).code = readCode(sym);
 889                     else
 890                         bp = bp + attrLen;
 891                 }
 892             },
 893 
 894             new AttributeReader(names.ConstantValue, V45_3, MEMBER_ATTRIBUTE) {
 895                 void read(Symbol sym, int attrLen) {
 896                     Object v = readPool(nextChar());
 897                     // Ignore ConstantValue attribute if field not final.
 898                     if ((sym.flags() & FINAL) != 0)
 899                         ((VarSymbol) sym).setData(v);
 900                 }
 901             },
 902 
 903             new AttributeReader(names.Deprecated, V45_3, CLASS_OR_MEMBER_ATTRIBUTE) {
 904                 void read(Symbol sym, int attrLen) {
 905                     sym.flags_field |= DEPRECATED;
 906                 }
 907             },
 908 
 909             new AttributeReader(names.Exceptions, V45_3, CLASS_OR_MEMBER_ATTRIBUTE) {
 910                 void read(Symbol sym, int attrLen) {
 911                     int nexceptions = nextChar();
 912                     List<Type> thrown = List.nil();
 913                     for (int j = 0; j < nexceptions; j++)
 914                         thrown = thrown.prepend(readClassSymbol(nextChar()).type);
 915                     if (sym.type.getThrownTypes().isEmpty())
 916                         sym.type.asMethodType().thrown = thrown.reverse();
 917                 }
 918             },
 919 
 920             new AttributeReader(names.InnerClasses, V45_3, CLASS_ATTRIBUTE) {
 921                 void read(Symbol sym, int attrLen) {
 922                     ClassSymbol c = (ClassSymbol) sym;
 923                     readInnerClasses(c);
 924                 }
 925             },
 926 
 927             new AttributeReader(names.LocalVariableTable, V45_3, CLASS_OR_MEMBER_ATTRIBUTE) {
 928                 void read(Symbol sym, int attrLen) {
 929                     int newbp = bp + attrLen;
 930                     if (saveParameterNames) {
 931                         // pick up parameter names from the variable table
 932                         int numEntries = nextChar();
 933                         for (int i = 0; i < numEntries; i++) {
 934                             int start_pc = nextChar();
 935                             int length = nextChar();
 936                             int nameIndex = nextChar();
 937                             int sigIndex = nextChar();
 938                             int register = nextChar();
 939                             if (start_pc == 0) {
 940                                 // ensure array large enough
 941                                 if (register >= parameterNameIndices.length) {
 942                                     int newSize = Math.max(register, parameterNameIndices.length + 8);
 943                                     parameterNameIndices =
 944                                             Arrays.copyOf(parameterNameIndices, newSize);
 945                                 }
 946                                 parameterNameIndices[register] = nameIndex;
 947                             }
 948                         }
 949                     }
 950                     bp = newbp;
 951                 }
 952             },
 953 
 954             new AttributeReader(names.SourceFile, V45_3, CLASS_ATTRIBUTE) {
 955                 void read(Symbol sym, int attrLen) {
 956                     ClassSymbol c = (ClassSymbol) sym;
 957                     Name n = readName(nextChar());
 958                     c.sourcefile = new SourceFileObject(n, c.flatname);
 959                 }
 960             },
 961 
 962             new AttributeReader(names.Synthetic, V45_3, CLASS_OR_MEMBER_ATTRIBUTE) {
 963                 void read(Symbol sym, int attrLen) {
 964                     // bridge methods are visible when generics not enabled
 965                     if (allowGenerics || (sym.flags_field & BRIDGE) == 0)
 966                         sym.flags_field |= SYNTHETIC;
 967                 }
 968             },
 969 
 970             // standard v49 attributes
 971 
 972             new AttributeReader(names.EnclosingMethod, V49, CLASS_ATTRIBUTE) {
 973                 void read(Symbol sym, int attrLen) {
 974                     int newbp = bp + attrLen;
 975                     readEnclosingMethodAttr(sym);
 976                     bp = newbp;
 977                 }
 978             },
 979 
 980             new AttributeReader(names.Signature, V49, CLASS_OR_MEMBER_ATTRIBUTE) {
 981                 @Override
 982                 boolean accepts(AttributeKind kind) {
 983                     return super.accepts(kind) && allowGenerics;
 984                 }
 985 
 986                 void read(Symbol sym, int attrLen) {
 987                     if (sym.kind == TYP) {
 988                         ClassSymbol c = (ClassSymbol) sym;
 989                         readingClassAttr = true;
 990                         try {
 991                             ClassType ct1 = (ClassType)c.type;
 992                             assert c == currentOwner;
 993                             ct1.typarams_field = readTypeParams(nextChar());
 994                             ct1.supertype_field = sigToType();
 995                             ListBuffer<Type> is = new ListBuffer<Type>();
 996                             while (sigp != siglimit) is.append(sigToType());
 997                             ct1.interfaces_field = is.toList();
 998                         } finally {
 999                             readingClassAttr = false;
1000                         }
1001                     } else {
1002                         List<Type> thrown = sym.type.getThrownTypes();
1003                         sym.type = readType(nextChar());
1004                         //- System.err.println(" # " + sym.type);
1005                         if (sym.kind == MTH && sym.type.getThrownTypes().isEmpty())
1006                             sym.type.asMethodType().thrown = thrown;
1007 
1008                     }
1009                 }
1010             },
1011 
1012             // v49 annotation attributes
1013 
1014             new AttributeReader(names.AnnotationDefault, V49, CLASS_OR_MEMBER_ATTRIBUTE) {
1015                 void read(Symbol sym, int attrLen) {
1016                     attachAnnotationDefault(sym);
1017                 }
1018             },
1019 
1020             new AttributeReader(names.RuntimeInvisibleAnnotations, V49, CLASS_OR_MEMBER_ATTRIBUTE) {
1021                 void read(Symbol sym, int attrLen) {
1022                     attachAnnotations(sym);
1023                 }
1024             },
1025 
1026             new AttributeReader(names.RuntimeInvisibleParameterAnnotations, V49, CLASS_OR_MEMBER_ATTRIBUTE) {
1027                 void read(Symbol sym, int attrLen) {
1028                     attachParameterAnnotations(sym);
1029                 }
1030             },
1031 
1032             new AttributeReader(names.RuntimeVisibleAnnotations, V49, CLASS_OR_MEMBER_ATTRIBUTE) {
1033                 void read(Symbol sym, int attrLen) {
1034                     attachAnnotations(sym);
1035                 }
1036             },
1037 
1038             new AttributeReader(names.RuntimeVisibleParameterAnnotations, V49, CLASS_OR_MEMBER_ATTRIBUTE) {
1039                 void read(Symbol sym, int attrLen) {
1040                     attachParameterAnnotations(sym);
1041                 }
1042             },
1043 
1044             // additional "legacy" v49 attributes, superceded by flags
1045 
1046             new AttributeReader(names.Annotation, V49, CLASS_OR_MEMBER_ATTRIBUTE) {
1047                 void read(Symbol sym, int attrLen) {
1048                     if (allowAnnotations)
1049                         sym.flags_field |= ANNOTATION;
1050                 }
1051             },
1052 
1053             new AttributeReader(names.Bridge, V49, MEMBER_ATTRIBUTE) {
1054                 void read(Symbol sym, int attrLen) {
1055                     sym.flags_field |= BRIDGE;
1056                     if (!allowGenerics)
1057                         sym.flags_field &= ~SYNTHETIC;
1058                 }
1059             },
1060 
1061             new AttributeReader(names.Enum, V49, CLASS_OR_MEMBER_ATTRIBUTE) {
1062                 void read(Symbol sym, int attrLen) {
1063                     sym.flags_field |= ENUM;
1064                 }
1065             },
1066 
1067             new AttributeReader(names.Varargs, V49, CLASS_OR_MEMBER_ATTRIBUTE) {
1068                 void read(Symbol sym, int attrLen) {
1069                     if (allowVarargs)
1070                         sym.flags_field |= VARARGS;
1071                 }
1072             },
1073 
1074             // v51 attributes
1075             new AttributeReader(names.RuntimeVisibleTypeAnnotations, V51, CLASS_OR_MEMBER_ATTRIBUTE) {
1076                 void read(Symbol sym, int attrLen) {
1077                     attachTypeAnnotations(sym);
1078                 }
1079             },
1080 
1081             new AttributeReader(names.RuntimeInvisibleTypeAnnotations, V51, CLASS_OR_MEMBER_ATTRIBUTE) {
1082                 void read(Symbol sym, int attrLen) {
1083                     attachTypeAnnotations(sym);
1084                 }
1085             },
1086 
1087 
1088             // The following attributes for a Code attribute are not currently handled
1089             // StackMapTable
1090             // SourceDebugExtension
1091             // LineNumberTable
1092             // LocalVariableTypeTable
1093         };
1094 
1095         for (AttributeReader r: readers)
1096             attributeReaders.put(r.name, r);
1097     }
1098 
1099     /** Report unrecognized attribute.
1100      */
1101     void unrecognized(Name attrName) {
1102         if (checkClassFile)
1103             printCCF("ccf.unrecognized.attribute", attrName);
1104     }
1105 
1106 
1107 
1108     void readEnclosingMethodAttr(Symbol sym) {
1109         // sym is a nested class with an "Enclosing Method" attribute
1110         // remove sym from it's current owners scope and place it in
1111         // the scope specified by the attribute
1112         sym.owner.members().remove(sym);
1113         ClassSymbol self = (ClassSymbol)sym;
1114         ClassSymbol c = readClassSymbol(nextChar());
1115         NameAndType nt = (NameAndType)readPool(nextChar());
1116 
1117         MethodSymbol m = findMethod(nt, c.members_field, self.flags());
1118         if (nt != null && m == null)
1119             throw badClassFile("bad.enclosing.method", self);
1120 
1121         self.name = simpleBinaryName(self.flatname, c.flatname) ;
1122         self.owner = m != null ? m : c;
1123         if (self.name.isEmpty())
1124             self.fullname = null;
1125         else
1126             self.fullname = ClassSymbol.formFullName(self.name, self.owner);
1127 
1128         if (m != null) {
1129             ((ClassType)sym.type).setEnclosingType(m.type);
1130         } else if ((self.flags_field & STATIC) == 0) {
1131             ((ClassType)sym.type).setEnclosingType(c.type);
1132         } else {
1133             ((ClassType)sym.type).setEnclosingType(Type.noType);
1134         }
1135         enterTypevars(self);
1136         if (!missingTypeVariables.isEmpty()) {
1137             ListBuffer<Type> typeVars =  new ListBuffer<Type>();
1138             for (Type typevar : missingTypeVariables) {
1139                 typeVars.append(findTypeVar(typevar.tsym.name));
1140             }
1141             foundTypeVariables = typeVars.toList();
1142         } else {
1143             foundTypeVariables = List.nil();
1144         }
1145     }
1146 
1147     // See java.lang.Class
1148     private Name simpleBinaryName(Name self, Name enclosing) {
1149         String simpleBinaryName = self.toString().substring(enclosing.toString().length());
1150         if (simpleBinaryName.length() < 1 || simpleBinaryName.charAt(0) != '$')
1151             throw badClassFile("bad.enclosing.method", self);
1152         int index = 1;
1153         while (index < simpleBinaryName.length() &&
1154                isAsciiDigit(simpleBinaryName.charAt(index)))
1155             index++;
1156         return names.fromString(simpleBinaryName.substring(index));
1157     }
1158 
1159     private MethodSymbol findMethod(NameAndType nt, Scope scope, long flags) {
1160         if (nt == null)
1161             return null;
1162 
1163         MethodType type = nt.type.asMethodType();
1164 
1165         for (Scope.Entry e = scope.lookup(nt.name); e.scope != null; e = e.next())
1166             if (e.sym.kind == MTH && isSameBinaryType(e.sym.type.asMethodType(), type))
1167                 return (MethodSymbol)e.sym;
1168 
1169         if (nt.name != names.init)
1170             // not a constructor
1171             return null;
1172         if ((flags & INTERFACE) != 0)
1173             // no enclosing instance
1174             return null;
1175         if (nt.type.getParameterTypes().isEmpty())
1176             // no parameters
1177             return null;
1178 
1179         // A constructor of an inner class.
1180         // Remove the first argument (the enclosing instance)
1181         nt.type = new MethodType(nt.type.getParameterTypes().tail,
1182                                  nt.type.getReturnType(),
1183                                  nt.type.getThrownTypes(),
1184                                  syms.methodClass);
1185         // Try searching again
1186         return findMethod(nt, scope, flags);
1187     }
1188 
1189     /** Similar to Types.isSameType but avoids completion */
1190     private boolean isSameBinaryType(MethodType mt1, MethodType mt2) {
1191         List<Type> types1 = types.erasure(mt1.getParameterTypes())
1192             .prepend(types.erasure(mt1.getReturnType()));
1193         List<Type> types2 = mt2.getParameterTypes().prepend(mt2.getReturnType());
1194         while (!types1.isEmpty() && !types2.isEmpty()) {
1195             if (types1.head.tsym != types2.head.tsym)
1196                 return false;
1197             types1 = types1.tail;
1198             types2 = types2.tail;
1199         }
1200         return types1.isEmpty() && types2.isEmpty();
1201     }
1202 
1203     /**
1204      * Character.isDigit answers <tt>true</tt> to some non-ascii
1205      * digits.  This one does not.  <b>copied from java.lang.Class</b>
1206      */
1207     private static boolean isAsciiDigit(char c) {
1208         return '0' <= c && c <= '9';
1209     }
1210 
1211     /** Read member attributes.
1212      */
1213     void readMemberAttrs(Symbol sym) {
1214         readAttrs(sym, AttributeKind.MEMBER);
1215     }
1216 
1217     void readAttrs(Symbol sym, AttributeKind kind) {
1218         char ac = nextChar();
1219         for (int i = 0; i < ac; i++) {
1220             Name attrName = readName(nextChar());
1221             int attrLen = nextInt();
1222             AttributeReader r = attributeReaders.get(attrName);
1223             if (r != null && r.accepts(kind))
1224                 r.read(sym, attrLen);
1225             else  {
1226                 unrecognized(attrName);
1227                 bp = bp + attrLen;
1228             }
1229         }
1230     }
1231 
1232     private boolean readingClassAttr = false;
1233     private List<Type> missingTypeVariables = List.nil();
1234     private List<Type> foundTypeVariables = List.nil();
1235 
1236     /** Read class attributes.
1237      */
1238     void readClassAttrs(ClassSymbol c) {
1239         readAttrs(c, AttributeKind.CLASS);
1240     }
1241 
1242     /** Read code block.
1243      */
1244     Code readCode(Symbol owner) {
1245         nextChar(); // max_stack
1246         nextChar(); // max_locals
1247         final int  code_length = nextInt();
1248         bp += code_length;
1249         final char exception_table_length = nextChar();
1250         bp += exception_table_length * 8;
1251         readMemberAttrs(owner);
1252         return null;
1253     }
1254 
1255 /************************************************************************
1256  * Reading Java-language annotations
1257  ***********************************************************************/
1258 
1259     /** Attach annotations.
1260      */
1261     void attachAnnotations(final Symbol sym) {
1262         int numAttributes = nextChar();
1263         if (numAttributes != 0) {
1264             ListBuffer<CompoundAnnotationProxy> proxies =
1265                 new ListBuffer<CompoundAnnotationProxy>();
1266             for (int i = 0; i<numAttributes; i++) {
1267                 CompoundAnnotationProxy proxy = readCompoundAnnotation();
1268                 if (proxy.type.tsym == syms.proprietaryType.tsym)
1269                     sym.flags_field |= PROPRIETARY;
1270                 else
1271                     proxies.append(proxy);
1272             }
1273             annotate.later(new AnnotationCompleter(sym, proxies.toList()));
1274         }
1275     }
1276 
1277     /** Attach parameter annotations.
1278      */
1279     void attachParameterAnnotations(final Symbol method) {
1280         final MethodSymbol meth = (MethodSymbol)method;
1281         int numParameters = buf[bp++] & 0xFF;
1282         List<VarSymbol> parameters = meth.params();
1283         int pnum = 0;
1284         while (parameters.tail != null) {
1285             attachAnnotations(parameters.head);
1286             parameters = parameters.tail;
1287             pnum++;
1288         }
1289         if (pnum != numParameters) {
1290             throw badClassFile("bad.runtime.invisible.param.annotations", meth);
1291         }
1292     }
1293 
1294     void attachTypeAnnotations(final Symbol sym) {
1295         int numAttributes = nextChar();
1296         if (numAttributes != 0) {
1297             ListBuffer<TypeAnnotationProxy> proxies =
1298                 ListBuffer.lb();
1299             for (int i = 0; i < numAttributes; i++)
1300                 proxies.append(readTypeAnnotation());
1301             annotate.later(new TypeAnnotationCompleter(sym, proxies.toList()));
1302         }
1303     }
1304 
1305     /** Attach the default value for an annotation element.
1306      */
1307     void attachAnnotationDefault(final Symbol sym) {
1308         final MethodSymbol meth = (MethodSymbol)sym; // only on methods
1309         final Attribute value = readAttributeValue();
1310         annotate.later(new AnnotationDefaultCompleter(meth, value));
1311     }
1312 
1313     Type readTypeOrClassSymbol(int i) {
1314         // support preliminary jsr175-format class files
1315         if (buf[poolIdx[i]] == CONSTANT_Class)
1316             return readClassSymbol(i).type;
1317         return readType(i);
1318     }
1319     Type readEnumType(int i) {
1320         // support preliminary jsr175-format class files
1321         int index = poolIdx[i];
1322         int length = getChar(index + 1);
1323         if (buf[index + length + 2] != ';')
1324             return enterClass(readName(i)).type;
1325         return readType(i);
1326     }
1327 
1328     CompoundAnnotationProxy readCompoundAnnotation() {
1329         Type t = readTypeOrClassSymbol(nextChar());
1330         int numFields = nextChar();
1331         ListBuffer<Pair<Name,Attribute>> pairs =
1332             new ListBuffer<Pair<Name,Attribute>>();
1333         for (int i=0; i<numFields; i++) {
1334             Name name = readName(nextChar());
1335             Attribute value = readAttributeValue();
1336             pairs.append(new Pair<Name,Attribute>(name, value));
1337         }
1338         return new CompoundAnnotationProxy(t, pairs.toList());
1339     }
1340 
1341     TypeAnnotationProxy readTypeAnnotation() {
1342         CompoundAnnotationProxy proxy = readCompoundAnnotation();
1343         TypeAnnotationPosition position = readPosition();
1344 
1345         if (debugJSR308)
1346             System.out.println("TA: reading: " + proxy + " @ " + position
1347                     + " in " + log.currentSourceFile());
1348 
1349         return new TypeAnnotationProxy(proxy, position);
1350     }
1351 
1352     TypeAnnotationPosition readPosition() {
1353         byte tag = nextByte();
1354 
1355         if (!TargetType.isValidTargetTypeValue(tag))
1356             throw this.badClassFile("bad.type.annotation.value", tag);
1357 
1358         TypeAnnotationPosition position = new TypeAnnotationPosition();
1359         TargetType type = TargetType.fromTargetTypeValue(tag);
1360 
1361         position.type = type;
1362 
1363         switch (type) {
1364         // type case
1365         case TYPECAST:
1366         case TYPECAST_GENERIC_OR_ARRAY:
1367         // object creation
1368         case INSTANCEOF:
1369         case INSTANCEOF_GENERIC_OR_ARRAY:
1370         // new expression
1371         case NEW:
1372         case NEW_GENERIC_OR_ARRAY:
1373             position.offset = nextChar();
1374             break;
1375          // local variable
1376         case LOCAL_VARIABLE:
1377         case LOCAL_VARIABLE_GENERIC_OR_ARRAY:
1378             int table_length = nextChar();
1379             position.lvarOffset = new int[table_length];
1380             position.lvarLength = new int[table_length];
1381             position.lvarIndex = new int[table_length];
1382 
1383             for (int i = 0; i < table_length; ++i) {
1384                 position.lvarOffset[i] = nextChar();
1385                 position.lvarLength[i] = nextChar();
1386                 position.lvarIndex[i] = nextChar();
1387             }
1388             break;
1389          // method receiver
1390         case METHOD_RECEIVER:
1391             // Do nothing
1392             break;
1393         // type parameters
1394         case CLASS_TYPE_PARAMETER:
1395         case METHOD_TYPE_PARAMETER:
1396             position.parameter_index = nextByte();
1397             break;
1398         // type parameter bounds
1399         case CLASS_TYPE_PARAMETER_BOUND:
1400         case CLASS_TYPE_PARAMETER_BOUND_GENERIC_OR_ARRAY:
1401         case METHOD_TYPE_PARAMETER_BOUND:
1402         case METHOD_TYPE_PARAMETER_BOUND_GENERIC_OR_ARRAY:
1403             position.parameter_index = nextByte();
1404             position.bound_index = nextByte();
1405             break;
1406          // wildcard
1407         case WILDCARD_BOUND:
1408         case WILDCARD_BOUND_GENERIC_OR_ARRAY:
1409             position.wildcard_position = readPosition();
1410             break;
1411          // Class extends and implements clauses
1412         case CLASS_EXTENDS:
1413         case CLASS_EXTENDS_GENERIC_OR_ARRAY:
1414             position.type_index = nextByte();
1415             break;
1416         // throws
1417         case THROWS:
1418             position.type_index = nextByte();
1419             break;
1420         case CLASS_LITERAL:
1421         case CLASS_LITERAL_GENERIC_OR_ARRAY:
1422             position.offset = nextChar();
1423             break;
1424         // method parameter: not specified
1425         case METHOD_PARAMETER_GENERIC_OR_ARRAY:
1426             position.parameter_index = nextByte();
1427             break;
1428         // method type argument: wasn't specified
1429         case NEW_TYPE_ARGUMENT:
1430         case NEW_TYPE_ARGUMENT_GENERIC_OR_ARRAY:
1431         case METHOD_TYPE_ARGUMENT:
1432         case METHOD_TYPE_ARGUMENT_GENERIC_OR_ARRAY:
1433             position.offset = nextChar();
1434             position.type_index = nextByte();
1435             break;
1436         // We don't need to worry abut these
1437         case METHOD_RETURN_GENERIC_OR_ARRAY:
1438         case FIELD_GENERIC_OR_ARRAY:
1439             break;
1440         case UNKNOWN:
1441             break;
1442         default:
1443             throw new AssertionError("unknown type: " + position);
1444         }
1445 
1446         if (type.hasLocation()) {
1447             int len = nextChar();
1448             ListBuffer<Integer> loc = ListBuffer.lb();
1449             for (int i = 0; i < len; i++)
1450                 loc = loc.append((int)nextByte());
1451             position.location = loc.toList();
1452         }
1453 
1454         return position;
1455     }
1456     Attribute readAttributeValue() {
1457         char c = (char) buf[bp++];
1458         switch (c) {
1459         case 'B':
1460             return new Attribute.Constant(syms.byteType, readPool(nextChar()));
1461         case 'C':
1462             return new Attribute.Constant(syms.charType, readPool(nextChar()));
1463         case 'D':
1464             return new Attribute.Constant(syms.doubleType, readPool(nextChar()));
1465         case 'F':
1466             return new Attribute.Constant(syms.floatType, readPool(nextChar()));
1467         case 'I':
1468             return new Attribute.Constant(syms.intType, readPool(nextChar()));
1469         case 'J':
1470             return new Attribute.Constant(syms.longType, readPool(nextChar()));
1471         case 'S':
1472             return new Attribute.Constant(syms.shortType, readPool(nextChar()));
1473         case 'Z':
1474             return new Attribute.Constant(syms.booleanType, readPool(nextChar()));
1475         case 's':
1476             return new Attribute.Constant(syms.stringType, readPool(nextChar()).toString());
1477         case 'e':
1478             return new EnumAttributeProxy(readEnumType(nextChar()), readName(nextChar()));
1479         case 'c':
1480             return new Attribute.Class(types, readTypeOrClassSymbol(nextChar()));
1481         case '[': {
1482             int n = nextChar();
1483             ListBuffer<Attribute> l = new ListBuffer<Attribute>();
1484             for (int i=0; i<n; i++)
1485                 l.append(readAttributeValue());
1486             return new ArrayAttributeProxy(l.toList());
1487         }
1488         case '@':
1489             return readCompoundAnnotation();
1490         default:
1491             throw new AssertionError("unknown annotation tag '" + c + "'");
1492         }
1493     }
1494 
1495     interface ProxyVisitor extends Attribute.Visitor {
1496         void visitEnumAttributeProxy(EnumAttributeProxy proxy);
1497         void visitArrayAttributeProxy(ArrayAttributeProxy proxy);
1498         void visitCompoundAnnotationProxy(CompoundAnnotationProxy proxy);
1499     }
1500 
1501     static class EnumAttributeProxy extends Attribute {
1502         Type enumType;
1503         Name enumerator;
1504         public EnumAttributeProxy(Type enumType, Name enumerator) {
1505             super(null);
1506             this.enumType = enumType;
1507             this.enumerator = enumerator;
1508         }
1509         public void accept(Visitor v) { ((ProxyVisitor)v).visitEnumAttributeProxy(this); }
1510         @Override
1511         public String toString() {
1512             return "/*proxy enum*/" + enumType + "." + enumerator;
1513         }
1514     }
1515 
1516     static class ArrayAttributeProxy extends Attribute {
1517         List<Attribute> values;
1518         ArrayAttributeProxy(List<Attribute> values) {
1519             super(null);
1520             this.values = values;
1521         }
1522         public void accept(Visitor v) { ((ProxyVisitor)v).visitArrayAttributeProxy(this); }
1523         @Override
1524         public String toString() {
1525             return "{" + values + "}";
1526         }
1527     }
1528 
1529     /** A temporary proxy representing a compound attribute.
1530      */
1531     static class CompoundAnnotationProxy extends Attribute {
1532         final List<Pair<Name,Attribute>> values;
1533         public CompoundAnnotationProxy(Type type,
1534                                       List<Pair<Name,Attribute>> values) {
1535             super(type);
1536             this.values = values;
1537         }
1538         public void accept(Visitor v) { ((ProxyVisitor)v).visitCompoundAnnotationProxy(this); }
1539         @Override
1540         public String toString() {
1541             StringBuffer buf = new StringBuffer();
1542             buf.append("@");
1543             buf.append(type.tsym.getQualifiedName());
1544             buf.append("/*proxy*/{");
1545             boolean first = true;
1546             for (List<Pair<Name,Attribute>> v = values;
1547                  v.nonEmpty(); v = v.tail) {
1548                 Pair<Name,Attribute> value = v.head;
1549                 if (!first) buf.append(",");
1550                 first = false;
1551                 buf.append(value.fst);
1552                 buf.append("=");
1553                 buf.append(value.snd);
1554             }
1555             buf.append("}");
1556             return buf.toString();
1557         }
1558     }
1559 
1560     /** A temporary proxy representing a type annotation.
1561      */
1562     static class TypeAnnotationProxy {
1563         final CompoundAnnotationProxy compound;
1564         final TypeAnnotationPosition position;
1565         public TypeAnnotationProxy(CompoundAnnotationProxy compound,
1566                 TypeAnnotationPosition position) {
1567             this.compound = compound;
1568             this.position = position;
1569         }
1570     }
1571 
1572     class AnnotationDeproxy implements ProxyVisitor {
1573         private ClassSymbol requestingOwner = currentOwner.kind == MTH
1574             ? currentOwner.enclClass() : (ClassSymbol)currentOwner;
1575 
1576         List<Attribute.Compound> deproxyCompoundList(List<CompoundAnnotationProxy> pl) {
1577             // also must fill in types!!!!
1578             ListBuffer<Attribute.Compound> buf =
1579                 new ListBuffer<Attribute.Compound>();
1580             for (List<CompoundAnnotationProxy> l = pl; l.nonEmpty(); l=l.tail) {
1581                 buf.append(deproxyCompound(l.head));
1582             }
1583             return buf.toList();
1584         }
1585 
1586         Attribute.Compound deproxyCompound(CompoundAnnotationProxy a) {
1587             ListBuffer<Pair<Symbol.MethodSymbol,Attribute>> buf =
1588                 new ListBuffer<Pair<Symbol.MethodSymbol,Attribute>>();
1589             for (List<Pair<Name,Attribute>> l = a.values;
1590                  l.nonEmpty();
1591                  l = l.tail) {
1592                 MethodSymbol meth = findAccessMethod(a.type, l.head.fst);
1593                 buf.append(new Pair<Symbol.MethodSymbol,Attribute>
1594                            (meth, deproxy(meth.type.getReturnType(), l.head.snd)));
1595             }
1596             return new Attribute.Compound(a.type, buf.toList());
1597         }
1598 
1599         MethodSymbol findAccessMethod(Type container, Name name) {
1600             CompletionFailure failure = null;
1601             try {
1602                 for (Scope.Entry e = container.tsym.members().lookup(name);
1603                      e.scope != null;
1604                      e = e.next()) {
1605                     Symbol sym = e.sym;
1606                     if (sym.kind == MTH && sym.type.getParameterTypes().length() == 0)
1607                         return (MethodSymbol) sym;
1608                 }
1609             } catch (CompletionFailure ex) {
1610                 failure = ex;
1611             }
1612             // The method wasn't found: emit a warning and recover
1613             JavaFileObject prevSource = log.useSource(requestingOwner.classfile);
1614             try {
1615                 if (failure == null) {
1616                     log.warning("annotation.method.not.found",
1617                                 container,
1618                                 name);
1619                 } else {
1620                     log.warning("annotation.method.not.found.reason",
1621                                 container,
1622                                 name,
1623                                 failure.getDetailValue());//diagnostic, if present
1624                 }
1625             } finally {
1626                 log.useSource(prevSource);
1627             }
1628             // Construct a new method type and symbol.  Use bottom
1629             // type (typeof null) as return type because this type is
1630             // a subtype of all reference types and can be converted
1631             // to primitive types by unboxing.
1632             MethodType mt = new MethodType(List.<Type>nil(),
1633                                            syms.botType,
1634                                            List.<Type>nil(),
1635                                            syms.methodClass);
1636             return new MethodSymbol(PUBLIC | ABSTRACT, name, mt, container.tsym);
1637         }
1638 
1639         Attribute result;
1640         Type type;
1641         Attribute deproxy(Type t, Attribute a) {
1642             Type oldType = type;
1643             try {
1644                 type = t;
1645                 a.accept(this);
1646                 return result;
1647             } finally {
1648                 type = oldType;
1649             }
1650         }
1651 
1652         // implement Attribute.Visitor below
1653 
1654         public void visitConstant(Attribute.Constant value) {
1655             // assert value.type == type;
1656             result = value;
1657         }
1658 
1659         public void visitClass(Attribute.Class clazz) {
1660             result = clazz;
1661         }
1662 
1663         public void visitEnum(Attribute.Enum e) {
1664             throw new AssertionError(); // shouldn't happen
1665         }
1666 
1667         public void visitCompound(Attribute.Compound compound) {
1668             throw new AssertionError(); // shouldn't happen
1669         }
1670 
1671         public void visitArray(Attribute.Array array) {
1672             throw new AssertionError(); // shouldn't happen
1673         }
1674 
1675         public void visitError(Attribute.Error e) {
1676             throw new AssertionError(); // shouldn't happen
1677         }
1678 
1679         public void visitEnumAttributeProxy(EnumAttributeProxy proxy) {
1680             // type.tsym.flatName() should == proxy.enumFlatName
1681             TypeSymbol enumTypeSym = proxy.enumType.tsym;
1682             VarSymbol enumerator = null;
1683             for (Scope.Entry e = enumTypeSym.members().lookup(proxy.enumerator);
1684                  e.scope != null;
1685                  e = e.next()) {
1686                 if (e.sym.kind == VAR) {
1687                     enumerator = (VarSymbol)e.sym;
1688                     break;
1689                 }
1690             }
1691             if (enumerator == null) {
1692                 log.error("unknown.enum.constant",
1693                           currentClassFile, enumTypeSym, proxy.enumerator);
1694                 result = new Attribute.Error(enumTypeSym.type);
1695             } else {
1696                 result = new Attribute.Enum(enumTypeSym.type, enumerator);
1697             }
1698         }
1699 
1700         public void visitArrayAttributeProxy(ArrayAttributeProxy proxy) {
1701             int length = proxy.values.length();
1702             Attribute[] ats = new Attribute[length];
1703             Type elemtype = types.elemtype(type);
1704             int i = 0;
1705             for (List<Attribute> p = proxy.values; p.nonEmpty(); p = p.tail) {
1706                 ats[i++] = deproxy(elemtype, p.head);
1707             }
1708             result = new Attribute.Array(type, ats);
1709         }
1710 
1711         public void visitCompoundAnnotationProxy(CompoundAnnotationProxy proxy) {
1712             result = deproxyCompound(proxy);
1713         }
1714     }
1715 
1716     class AnnotationDefaultCompleter extends AnnotationDeproxy implements Annotate.Annotator {
1717         final MethodSymbol sym;
1718         final Attribute value;
1719         final JavaFileObject classFile = currentClassFile;
1720         @Override
1721         public String toString() {
1722             return " ClassReader store default for " + sym.owner + "." + sym + " is " + value;
1723         }
1724         AnnotationDefaultCompleter(MethodSymbol sym, Attribute value) {
1725             this.sym = sym;
1726             this.value = value;
1727         }
1728         // implement Annotate.Annotator.enterAnnotation()
1729         public void enterAnnotation() {
1730             JavaFileObject previousClassFile = currentClassFile;
1731             try {
1732                 currentClassFile = classFile;
1733                 sym.defaultValue = deproxy(sym.type.getReturnType(), value);
1734             } finally {
1735                 currentClassFile = previousClassFile;
1736             }
1737         }
1738     }
1739 
1740     class AnnotationCompleter extends AnnotationDeproxy implements Annotate.Annotator {
1741         final Symbol sym;
1742         final List<CompoundAnnotationProxy> l;
1743         final JavaFileObject classFile;
1744         @Override
1745         public String toString() {
1746             return " ClassReader annotate " + sym.owner + "." + sym + " with " + l;
1747         }
1748         AnnotationCompleter(Symbol sym, List<CompoundAnnotationProxy> l) {
1749             this.sym = sym;
1750             this.l = l;
1751             this.classFile = currentClassFile;
1752         }
1753         // implement Annotate.Annotator.enterAnnotation()
1754         public void enterAnnotation() {
1755             JavaFileObject previousClassFile = currentClassFile;
1756             try {
1757                 currentClassFile = classFile;
1758                 List<Attribute.Compound> newList = deproxyCompoundList(l);
1759                 sym.attributes_field = ((sym.attributes_field == null)
1760                                         ? newList
1761                                         : newList.prependList(sym.attributes_field));
1762             } finally {
1763                 currentClassFile = previousClassFile;
1764             }
1765         }
1766     }
1767 
1768     class TypeAnnotationCompleter extends AnnotationCompleter {
1769 
1770         List<TypeAnnotationProxy> proxies;
1771 
1772         TypeAnnotationCompleter(Symbol sym,
1773                 List<TypeAnnotationProxy> proxies) {
1774             super(sym, List.<CompoundAnnotationProxy>nil());
1775             this.proxies = proxies;
1776         }
1777 
1778         List<Attribute.TypeCompound> deproxyTypeCompoundList(List<TypeAnnotationProxy> proxies) {
1779             ListBuffer<Attribute.TypeCompound> buf = ListBuffer.lb();
1780             for (TypeAnnotationProxy proxy: proxies) {
1781                 Attribute.Compound compound = deproxyCompound(proxy.compound);
1782                 Attribute.TypeCompound typeCompound = new Attribute.TypeCompound(compound, proxy.position);
1783                 buf.add(typeCompound);
1784             }
1785             return buf.toList();
1786         }
1787 
1788         @Override
1789         public void enterAnnotation() {
1790             JavaFileObject previousClassFile = currentClassFile;
1791             try {
1792                 currentClassFile = classFile;
1793                 List<Attribute.TypeCompound> newList = deproxyTypeCompoundList(proxies);
1794               if (debugJSR308)
1795               System.out.println("TA: reading: adding " + newList
1796                       + " to symbol " + sym + " in " + log.currentSourceFile());
1797                 sym.typeAnnotations = ((sym.typeAnnotations == null)
1798                                         ? newList
1799                                         : newList.prependList(sym.typeAnnotations));
1800 
1801             } finally {
1802                 currentClassFile = previousClassFile;
1803             }
1804         }
1805     }
1806 
1807 
1808 /************************************************************************
1809  * Reading Symbols
1810  ***********************************************************************/
1811 
1812     /** Read a field.
1813      */
1814     VarSymbol readField() {
1815         long flags = adjustFieldFlags(nextChar());
1816         Name name = readName(nextChar());
1817         Type type = readType(nextChar());
1818         VarSymbol v = new VarSymbol(flags, name, type, currentOwner);
1819         readMemberAttrs(v);
1820         return v;
1821     }
1822 
1823     /** Read a method.
1824      */
1825     MethodSymbol readMethod() {
1826         long flags = adjustMethodFlags(nextChar());
1827         Name name = readName(nextChar());
1828         Type type = readType(nextChar());
1829         if (name == names.init && currentOwner.hasOuterInstance()) {
1830             // Sometimes anonymous classes don't have an outer
1831             // instance, however, there is no reliable way to tell so
1832             // we never strip this$n
1833             if (!currentOwner.name.isEmpty())
1834                 type = new MethodType(type.getParameterTypes().tail,
1835                                       type.getReturnType(),
1836                                       type.getThrownTypes(),
1837                                       syms.methodClass);
1838         }
1839         MethodSymbol m = new MethodSymbol(flags, name, type, currentOwner);
1840         if (saveParameterNames)
1841             initParameterNames(m);
1842         Symbol prevOwner = currentOwner;
1843         currentOwner = m;
1844         try {
1845             readMemberAttrs(m);
1846         } finally {
1847             currentOwner = prevOwner;
1848         }
1849         if (saveParameterNames)
1850             setParameterNames(m, type);
1851         return m;
1852     }
1853 
1854     void initParameterNames(MethodSymbol sym) {
1855         // make allowance for synthetic parameters.
1856         final int excessSlots = 4;
1857         int expectedParameterSlots =
1858                 Code.width(sym.type.getParameterTypes()) + excessSlots;
1859         if (parameterNameIndices == null
1860                 || parameterNameIndices.length < expectedParameterSlots) {
1861             parameterNameIndices = new int[expectedParameterSlots];
1862         } else
1863             Arrays.fill(parameterNameIndices, 0);
1864     }
1865 
1866     void setParameterNames(MethodSymbol sym, Type jvmType) {
1867         int firstParam = ((sym.flags() & STATIC) == 0) ? 1 : 0;
1868         // the code in readMethod may have skipped the first parameter when
1869         // setting up the MethodType. If so, we make a corresponding allowance
1870         // here for the position of the first parameter.  Note that this
1871         // assumes the skipped parameter has a width of 1 -- i.e. it is not
1872         // a double width type (long or double.)
1873         if (sym.name == names.init && currentOwner.hasOuterInstance()) {
1874             // Sometimes anonymous classes don't have an outer
1875             // instance, however, there is no reliable way to tell so
1876             // we never strip this$n
1877             if (!currentOwner.name.isEmpty())
1878                 firstParam += 1;
1879         }
1880 
1881         if (sym.type != jvmType) {
1882             // reading the method attributes has caused the symbol's type to
1883             // be changed. (i.e. the Signature attribute.)  This may happen if
1884             // there are hidden (synthetic) parameters in the descriptor, but
1885             // not in the Signature.  The position of these hidden parameters
1886             // is unspecified; for now, assume they are at the beginning, and
1887             // so skip over them. The primary case for this is two hidden
1888             // parameters passed into Enum constructors.
1889             int skip = Code.width(jvmType.getParameterTypes())
1890                     - Code.width(sym.type.getParameterTypes());
1891             firstParam += skip;
1892         }
1893         List<Name> paramNames = List.nil();
1894         int index = firstParam;
1895         for (Type t: sym.type.getParameterTypes()) {
1896             int nameIdx = (index < parameterNameIndices.length
1897                     ? parameterNameIndices[index] : 0);
1898             Name name = nameIdx == 0 ? names.empty : readName(nameIdx);
1899             paramNames = paramNames.prepend(name);
1900             index += Code.width(t);
1901         }
1902         sym.savedParameterNames = paramNames.reverse();
1903     }
1904 
1905     /** Skip a field or method
1906      */
1907     void skipMember() {
1908         bp = bp + 6;
1909         char ac = nextChar();
1910         for (int i = 0; i < ac; i++) {
1911             bp = bp + 2;
1912             int attrLen = nextInt();
1913             bp = bp + attrLen;
1914         }
1915     }
1916 
1917     /** Enter type variables of this classtype and all enclosing ones in
1918      *  `typevars'.
1919      */
1920     protected void enterTypevars(Type t) {
1921         if (t.getEnclosingType() != null && t.getEnclosingType().tag == CLASS)
1922             enterTypevars(t.getEnclosingType());
1923         for (List<Type> xs = t.getTypeArguments(); xs.nonEmpty(); xs = xs.tail)
1924             typevars.enter(xs.head.tsym);
1925     }
1926 
1927     protected void enterTypevars(Symbol sym) {
1928         if (sym.owner.kind == MTH) {
1929             enterTypevars(sym.owner);
1930             enterTypevars(sym.owner.owner);
1931         }
1932         enterTypevars(sym.type);
1933     }
1934 
1935     /** Read contents of a given class symbol `c'. Both external and internal
1936      *  versions of an inner class are read.
1937      */
1938     void readClass(ClassSymbol c) {
1939         ClassType ct = (ClassType)c.type;
1940 
1941         // allocate scope for members
1942         c.members_field = new Scope(c);
1943 
1944         // prepare type variable table
1945         typevars = typevars.dup(currentOwner);
1946         if (ct.getEnclosingType().tag == CLASS)
1947             enterTypevars(ct.getEnclosingType());
1948 
1949         // read flags, or skip if this is an inner class
1950         long flags = adjustClassFlags(nextChar());
1951         if (c.owner.kind == PCK) c.flags_field = flags;
1952 
1953         // read own class name and check that it matches
1954         ClassSymbol self = readClassSymbol(nextChar());
1955         if (c != self)
1956             throw badClassFile("class.file.wrong.class",
1957                                self.flatname);
1958 
1959         // class attributes must be read before class
1960         // skip ahead to read class attributes
1961         int startbp = bp;
1962         nextChar();
1963         char interfaceCount = nextChar();
1964         bp += interfaceCount * 2;
1965         char fieldCount = nextChar();
1966         for (int i = 0; i < fieldCount; i++) skipMember();
1967         char methodCount = nextChar();
1968         for (int i = 0; i < methodCount; i++) skipMember();
1969         readClassAttrs(c);
1970 
1971         if (readAllOfClassFile) {
1972             for (int i = 1; i < poolObj.length; i++) readPool(i);
1973             c.pool = new Pool(poolObj.length, poolObj);
1974         }
1975 
1976         // reset and read rest of classinfo
1977         bp = startbp;
1978         int n = nextChar();
1979         if (ct.supertype_field == null)
1980             ct.supertype_field = (n == 0)
1981                 ? Type.noType
1982                 : readClassSymbol(n).erasure(types);
1983         n = nextChar();
1984         List<Type> is = List.nil();
1985         for (int i = 0; i < n; i++) {
1986             Type _inter = readClassSymbol(nextChar()).erasure(types);
1987             is = is.prepend(_inter);
1988         }
1989         if (ct.interfaces_field == null)
1990             ct.interfaces_field = is.reverse();
1991 
1992         if (fieldCount != nextChar()) assert false;
1993         for (int i = 0; i < fieldCount; i++) enterMember(c, readField());
1994         if (methodCount != nextChar()) assert false;
1995         for (int i = 0; i < methodCount; i++) enterMember(c, readMethod());
1996 
1997         typevars = typevars.leave();
1998     }
1999 
2000     /** Read inner class info. For each inner/outer pair allocate a
2001      *  member class.
2002      */
2003     void readInnerClasses(ClassSymbol c) {
2004         int n = nextChar();
2005         for (int i = 0; i < n; i++) {
2006             nextChar(); // skip inner class symbol
2007             ClassSymbol outer = readClassSymbol(nextChar());
2008             Name name = readName(nextChar());
2009             if (name == null) name = names.empty;
2010             long flags = adjustClassFlags(nextChar());
2011             if (outer != null) { // we have a member class
2012                 if (name == names.empty)
2013                     name = names.one;
2014                 ClassSymbol member = enterClass(name, outer);
2015                 if ((flags & STATIC) == 0) {
2016                     ((ClassType)member.type).setEnclosingType(outer.type);
2017                     if (member.erasure_field != null)
2018                         ((ClassType)member.erasure_field).setEnclosingType(types.erasure(outer.type));
2019                 }
2020                 if (c == outer) {
2021                     member.flags_field = flags;
2022                     enterMember(c, member);
2023                 }
2024             }
2025         }
2026     }
2027 
2028     /** Read a class file.
2029      */
2030     private void readClassFile(ClassSymbol c) throws IOException {
2031         int magic = nextInt();
2032         if (magic != JAVA_MAGIC)
2033             throw badClassFile("illegal.start.of.class.file");
2034 
2035         minorVersion = nextChar();
2036         majorVersion = nextChar();
2037         int maxMajor = Target.MAX().majorVersion;
2038         int maxMinor = Target.MAX().minorVersion;
2039         if (majorVersion > maxMajor ||
2040             majorVersion * 1000 + minorVersion <
2041             Target.MIN().majorVersion * 1000 + Target.MIN().minorVersion)
2042         {
2043             if (majorVersion == (maxMajor + 1))
2044                 log.warning("big.major.version",
2045                             currentClassFile,
2046                             majorVersion,
2047                             maxMajor);
2048             else
2049                 throw badClassFile("wrong.version",
2050                                    Integer.toString(majorVersion),
2051                                    Integer.toString(minorVersion),
2052                                    Integer.toString(maxMajor),
2053                                    Integer.toString(maxMinor));
2054         }
2055         else if (checkClassFile &&
2056                  majorVersion == maxMajor &&
2057                  minorVersion > maxMinor)
2058         {
2059             printCCF("found.later.version",
2060                      Integer.toString(minorVersion));
2061         }
2062         indexPool();
2063         if (signatureBuffer.length < bp) {
2064             int ns = Integer.highestOneBit(bp) << 1;
2065             signatureBuffer = new byte[ns];
2066         }
2067         readClass(c);
2068     }
2069 
2070 /************************************************************************
2071  * Adjusting flags
2072  ***********************************************************************/
2073 
2074     long adjustFieldFlags(long flags) {
2075         return flags;
2076     }
2077     long adjustMethodFlags(long flags) {
2078         if ((flags & ACC_BRIDGE) != 0) {
2079             flags &= ~ACC_BRIDGE;
2080             flags |= BRIDGE;
2081             if (!allowGenerics)
2082                 flags &= ~SYNTHETIC;
2083         }
2084         if ((flags & ACC_VARARGS) != 0) {
2085             flags &= ~ACC_VARARGS;
2086             flags |= VARARGS;
2087         }
2088         return flags;
2089     }
2090     long adjustClassFlags(long flags) {
2091         return flags & ~ACC_SUPER; // SUPER and SYNCHRONIZED bits overloaded
2092     }
2093 
2094 /************************************************************************
2095  * Loading Classes
2096  ***********************************************************************/
2097 
2098     /** Define a new class given its name and owner.
2099      */
2100     public ClassSymbol defineClass(Name name, Symbol owner) {
2101         ClassSymbol c = new ClassSymbol(0, name, owner);
2102         if (owner.kind == PCK)
2103             assert classes.get(c.flatname) == null : c;
2104         c.completer = this;
2105         return c;
2106     }
2107 
2108     /** Create a new toplevel or member class symbol with given name
2109      *  and owner and enter in `classes' unless already there.
2110      */
2111     public ClassSymbol enterClass(Name name, TypeSymbol owner) {
2112         Name flatname = TypeSymbol.formFlatName(name, owner);
2113         ClassSymbol c = classes.get(flatname);
2114         if (c == null) {
2115             c = defineClass(name, owner);
2116             classes.put(flatname, c);
2117         } else if ((c.name != name || c.owner != owner) && owner.kind == TYP && c.owner.kind == PCK) {
2118             // reassign fields of classes that might have been loaded with
2119             // their flat names.
2120             c.owner.members().remove(c);
2121             c.name = name;
2122             c.owner = owner;
2123             c.fullname = ClassSymbol.formFullName(name, owner);
2124         }
2125         return c;
2126     }
2127 
2128     /**
2129      * Creates a new toplevel class symbol with given flat name and
2130      * given class (or source) file.
2131      *
2132      * @param flatName a fully qualified binary class name
2133      * @param classFile the class file or compilation unit defining
2134      * the class (may be {@code null})
2135      * @return a newly created class symbol
2136      * @throws AssertionError if the class symbol already exists
2137      */
2138     public ClassSymbol enterClass(Name flatName, JavaFileObject classFile) {
2139         ClassSymbol cs = classes.get(flatName);
2140         if (cs != null) {
2141             String msg = Log.format("%s: completer = %s; class file = %s; source file = %s",
2142                                     cs.fullname,
2143                                     cs.completer,
2144                                     cs.classfile,
2145                                     cs.sourcefile);
2146             throw new AssertionError(msg);
2147         }
2148         Name packageName = Convert.packagePart(flatName);
2149         PackageSymbol owner = packageName.isEmpty()
2150                                 ? syms.unnamedPackage
2151                                 : enterPackage(packageName);
2152         cs = defineClass(Convert.shortName(flatName), owner);
2153         cs.classfile = classFile;
2154         classes.put(flatName, cs);
2155         return cs;
2156     }
2157 
2158     /** Create a new member or toplevel class symbol with given flat name
2159      *  and enter in `classes' unless already there.
2160      */
2161     public ClassSymbol enterClass(Name flatname) {
2162         ClassSymbol c = classes.get(flatname);
2163         if (c == null)
2164             return enterClass(flatname, (JavaFileObject)null);
2165         else
2166             return c;
2167     }
2168 
2169     private boolean suppressFlush = false;
2170 
2171     /** Completion for classes to be loaded. Before a class is loaded
2172      *  we make sure its enclosing class (if any) is loaded.
2173      */
2174     public void complete(Symbol sym) throws CompletionFailure {
2175         if (sym.kind == TYP) {
2176             ClassSymbol c = (ClassSymbol)sym;
2177             c.members_field = new Scope.ErrorScope(c); // make sure it's always defined
2178             boolean saveSuppressFlush = suppressFlush;
2179             suppressFlush = true;
2180             try {
2181                 completeOwners(c.owner);
2182                 completeEnclosing(c);
2183             } finally {
2184                 suppressFlush = saveSuppressFlush;
2185             }
2186             fillIn(c);
2187         } else if (sym.kind == PCK) {
2188             PackageSymbol p = (PackageSymbol)sym;
2189             try {
2190                 fillIn(p);
2191             } catch (IOException ex) {
2192                 throw new CompletionFailure(sym, ex.getLocalizedMessage()).initCause(ex);
2193             }
2194         }
2195         if (!filling && !suppressFlush)
2196             annotate.flush(); // finish attaching annotations
2197     }
2198 
2199     /** complete up through the enclosing package. */
2200     private void completeOwners(Symbol o) {
2201         if (o.kind != PCK) completeOwners(o.owner);
2202         o.complete();
2203     }
2204 
2205     /**
2206      * Tries to complete lexically enclosing classes if c looks like a
2207      * nested class.  This is similar to completeOwners but handles
2208      * the situation when a nested class is accessed directly as it is
2209      * possible with the Tree API or javax.lang.model.*.
2210      */
2211     private void completeEnclosing(ClassSymbol c) {
2212         if (c.owner.kind == PCK) {
2213             Symbol owner = c.owner;
2214             for (Name name : Convert.enclosingCandidates(Convert.shortName(c.name))) {
2215                 Symbol encl = owner.members().lookup(name).sym;
2216                 if (encl == null)
2217                     encl = classes.get(TypeSymbol.formFlatName(name, owner));
2218                 if (encl != null)
2219                     encl.complete();
2220             }
2221         }
2222     }
2223 
2224     /** We can only read a single class file at a time; this
2225      *  flag keeps track of when we are currently reading a class
2226      *  file.
2227      */
2228     private boolean filling = false;
2229 
2230     /** Fill in definition of class `c' from corresponding class or
2231      *  source file.
2232      */
2233     private void fillIn(ClassSymbol c) {
2234         if (completionFailureName == c.fullname) {
2235             throw new CompletionFailure(c, "user-selected completion failure by class name");
2236         }
2237         currentOwner = c;
2238         JavaFileObject classfile = c.classfile;
2239         if (classfile != null) {
2240             JavaFileObject previousClassFile = currentClassFile;
2241             try {
2242                 assert !filling :
2243                     "Filling " + classfile.toUri() +
2244                     " during " + previousClassFile;
2245                 currentClassFile = classfile;
2246                 if (verbose) {
2247                     printVerbose("loading", currentClassFile.toString());
2248                 }
2249                 if (classfile.getKind() == JavaFileObject.Kind.CLASS) {
2250                     filling = true;
2251                     try {
2252                         bp = 0;
2253                         buf = readInputStream(buf, classfile.openInputStream());
2254                         readClassFile(c);
2255                         if (!missingTypeVariables.isEmpty() && !foundTypeVariables.isEmpty()) {
2256                             List<Type> missing = missingTypeVariables;
2257                             List<Type> found = foundTypeVariables;
2258                             missingTypeVariables = List.nil();
2259                             foundTypeVariables = List.nil();
2260                             filling = false;
2261                             ClassType ct = (ClassType)currentOwner.type;
2262                             ct.supertype_field =
2263                                 types.subst(ct.supertype_field, missing, found);
2264                             ct.interfaces_field =
2265                                 types.subst(ct.interfaces_field, missing, found);
2266                         } else if (missingTypeVariables.isEmpty() !=
2267                                    foundTypeVariables.isEmpty()) {
2268                             Name name = missingTypeVariables.head.tsym.name;
2269                             throw badClassFile("undecl.type.var", name);
2270                         }
2271                     } finally {
2272                         missingTypeVariables = List.nil();
2273                         foundTypeVariables = List.nil();
2274                         filling = false;
2275                     }
2276                 } else {
2277                     if (sourceCompleter != null) {
2278                         sourceCompleter.complete(c);
2279                     } else {
2280                         throw new IllegalStateException("Source completer required to read "
2281                                                         + classfile.toUri());
2282                     }
2283                 }
2284                 return;
2285             } catch (IOException ex) {
2286                 throw badClassFile("unable.to.access.file", ex.getMessage());
2287             } finally {
2288                 currentClassFile = previousClassFile;
2289             }
2290         } else {
2291             JCDiagnostic diag =
2292                 diagFactory.fragment("class.file.not.found", c.flatname);
2293             throw
2294                 newCompletionFailure(c, diag);
2295         }
2296     }
2297     // where
2298         private static byte[] readInputStream(byte[] buf, InputStream s) throws IOException {
2299             try {
2300                 buf = ensureCapacity(buf, s.available());
2301                 int r = s.read(buf);
2302                 int bp = 0;
2303                 while (r != -1) {
2304                     bp += r;
2305                     buf = ensureCapacity(buf, bp);
2306                     r = s.read(buf, bp, buf.length - bp);
2307                 }
2308                 return buf;
2309             } finally {
2310                 try {
2311                     s.close();
2312                 } catch (IOException e) {
2313                     /* Ignore any errors, as this stream may have already
2314                      * thrown a related exception which is the one that
2315                      * should be reported.
2316                      */
2317                 }
2318             }
2319         }
2320         private static byte[] ensureCapacity(byte[] buf, int needed) {
2321             if (buf.length < needed) {
2322                 byte[] old = buf;
2323                 buf = new byte[Integer.highestOneBit(needed) << 1];
2324                 System.arraycopy(old, 0, buf, 0, old.length);
2325             }
2326             return buf;
2327         }
2328         /** Static factory for CompletionFailure objects.
2329          *  In practice, only one can be used at a time, so we share one
2330          *  to reduce the expense of allocating new exception objects.
2331          */
2332         private CompletionFailure newCompletionFailure(TypeSymbol c,
2333                                                        JCDiagnostic diag) {
2334             if (!cacheCompletionFailure) {
2335                 // log.warning("proc.messager",
2336                 //             Log.getLocalizedString("class.file.not.found", c.flatname));
2337                 // c.debug.printStackTrace();
2338                 return new CompletionFailure(c, diag);
2339             } else {
2340                 CompletionFailure result = cachedCompletionFailure;
2341                 result.sym = c;
2342                 result.diag = diag;
2343                 return result;
2344             }
2345         }
2346         private CompletionFailure cachedCompletionFailure =
2347             new CompletionFailure(null, (JCDiagnostic) null);
2348         {
2349             cachedCompletionFailure.setStackTrace(new StackTraceElement[0]);
2350         }
2351 
2352     /** Load a toplevel class with given fully qualified name
2353      *  The class is entered into `classes' only if load was successful.
2354      */
2355     public ClassSymbol loadClass(Name flatname) throws CompletionFailure {
2356         boolean absent = classes.get(flatname) == null;
2357         ClassSymbol c = enterClass(flatname);
2358         if (c.members_field == null && c.completer != null) {
2359             try {
2360                 c.complete();
2361             } catch (CompletionFailure ex) {
2362                 if (absent) classes.remove(flatname);
2363                 throw ex;
2364             }
2365         }
2366         return c;
2367     }
2368 
2369 /************************************************************************
2370  * Loading Packages
2371  ***********************************************************************/
2372 
2373     /** Check to see if a package exists, given its fully qualified name.
2374      */
2375     public boolean packageExists(Name fullname) {
2376         return enterPackage(fullname).exists();
2377     }
2378 
2379     /** Make a package, given its fully qualified name.
2380      */
2381     public PackageSymbol enterPackage(Name fullname) {
2382         PackageSymbol p = packages.get(fullname);
2383         if (p == null) {
2384             assert !fullname.isEmpty() : "rootPackage missing!";
2385             p = new PackageSymbol(
2386                 Convert.shortName(fullname),
2387                 enterPackage(Convert.packagePart(fullname)));
2388             p.completer = this;
2389             packages.put(fullname, p);
2390         }
2391         return p;
2392     }
2393 
2394     /** Make a package, given its unqualified name and enclosing package.
2395      */
2396     public PackageSymbol enterPackage(Name name, PackageSymbol owner) {
2397         return enterPackage(TypeSymbol.formFullName(name, owner));
2398     }
2399 
2400     /** Include class corresponding to given class file in package,
2401      *  unless (1) we already have one the same kind (.class or .java), or
2402      *         (2) we have one of the other kind, and the given class file
2403      *             is older.
2404      */
2405     protected void includeClassFile(PackageSymbol p, JavaFileObject file) {
2406         if ((p.flags_field & EXISTS) == 0)
2407             for (Symbol q = p; q != null && q.kind == PCK; q = q.owner)
2408                 q.flags_field |= EXISTS;
2409         JavaFileObject.Kind kind = file.getKind();
2410         int seen;
2411         if (kind == JavaFileObject.Kind.CLASS)
2412             seen = CLASS_SEEN;
2413         else
2414             seen = SOURCE_SEEN;
2415         String binaryName = fileManager.inferBinaryName(currentLoc, file);
2416         int lastDot = binaryName.lastIndexOf(".");
2417         Name classname = names.fromString(binaryName.substring(lastDot + 1));
2418         boolean isPkgInfo = classname == names.package_info;
2419         ClassSymbol c = isPkgInfo
2420             ? p.package_info
2421             : (ClassSymbol) p.members_field.lookup(classname).sym;
2422         if (c == null) {
2423             c = enterClass(classname, p);
2424             if (c.classfile == null) // only update the file if's it's newly created
2425                 c.classfile = file;
2426             if (isPkgInfo) {
2427                 p.package_info = c;
2428             } else {
2429                 if (c.owner == p)  // it might be an inner class
2430                     p.members_field.enter(c);
2431             }
2432         } else if (c.classfile != null && (c.flags_field & seen) == 0) {
2433             // if c.classfile == null, we are currently compiling this class
2434             // and no further action is necessary.
2435             // if (c.flags_field & seen) != 0, we have already encountered
2436             // a file of the same kind; again no further action is necessary.
2437             if ((c.flags_field & (CLASS_SEEN | SOURCE_SEEN)) != 0)
2438                 c.classfile = preferredFileObject(file, c.classfile);
2439         }
2440         c.flags_field |= seen;
2441     }
2442 
2443     /** Implement policy to choose to derive information from a source
2444      *  file or a class file when both are present.  May be overridden
2445      *  by subclasses.
2446      */
2447     protected JavaFileObject preferredFileObject(JavaFileObject a,
2448                                            JavaFileObject b) {
2449 
2450         if (preferSource)
2451             return (a.getKind() == JavaFileObject.Kind.SOURCE) ? a : b;
2452         else {
2453             long adate = a.getLastModified();
2454             long bdate = b.getLastModified();
2455             // 6449326: policy for bad lastModifiedTime in ClassReader
2456             //assert adate >= 0 && bdate >= 0;
2457             return (adate > bdate) ? a : b;
2458         }
2459     }
2460 
2461     /**
2462      * specifies types of files to be read when filling in a package symbol
2463      */
2464     protected EnumSet<JavaFileObject.Kind> getPackageFileKinds() {
2465         return EnumSet.of(JavaFileObject.Kind.CLASS, JavaFileObject.Kind.SOURCE);
2466     }
2467 
2468     /**
2469      * this is used to support javadoc
2470      */
2471     protected void extraFileActions(PackageSymbol pack, JavaFileObject fe) {
2472     }
2473 
2474     protected Location currentLoc; // FIXME
2475 
2476     private boolean verbosePath = true;
2477 
2478     /** Load directory of package into members scope.
2479      */
2480     private void fillIn(PackageSymbol p) throws IOException {
2481         if (p.members_field == null) p.members_field = new Scope(p);
2482         String packageName = p.fullname.toString();
2483 
2484         Set<JavaFileObject.Kind> kinds = getPackageFileKinds();
2485 
2486         fillIn(p, PLATFORM_CLASS_PATH,
2487                fileManager.list(PLATFORM_CLASS_PATH,
2488                                 packageName,
2489                                 EnumSet.of(JavaFileObject.Kind.CLASS),
2490                                 false));
2491 
2492         Set<JavaFileObject.Kind> classKinds = EnumSet.copyOf(kinds);
2493         classKinds.remove(JavaFileObject.Kind.SOURCE);
2494         boolean wantClassFiles = !classKinds.isEmpty();
2495 
2496         Set<JavaFileObject.Kind> sourceKinds = EnumSet.copyOf(kinds);
2497         sourceKinds.remove(JavaFileObject.Kind.CLASS);
2498         boolean wantSourceFiles = !sourceKinds.isEmpty();
2499 
2500         boolean haveSourcePath = fileManager.hasLocation(SOURCE_PATH);
2501 
2502         if (verbose && verbosePath) {
2503             if (fileManager instanceof StandardJavaFileManager) {
2504                 StandardJavaFileManager fm = (StandardJavaFileManager)fileManager;
2505                 if (haveSourcePath && wantSourceFiles) {
2506                     List<File> path = List.nil();
2507                     for (File file : fm.getLocation(SOURCE_PATH)) {
2508                         path = path.prepend(file);
2509                     }
2510                     printVerbose("sourcepath", path.reverse().toString());
2511                 } else if (wantSourceFiles) {
2512                     List<File> path = List.nil();
2513                     for (File file : fm.getLocation(CLASS_PATH)) {
2514                         path = path.prepend(file);
2515                     }
2516                     printVerbose("sourcepath", path.reverse().toString());
2517                 }
2518                 if (wantClassFiles) {
2519                     List<File> path = List.nil();
2520                     for (File file : fm.getLocation(PLATFORM_CLASS_PATH)) {
2521                         path = path.prepend(file);
2522                     }
2523                     for (File file : fm.getLocation(CLASS_PATH)) {
2524                         path = path.prepend(file);
2525                     }
2526                     printVerbose("classpath",  path.reverse().toString());
2527                 }
2528             }
2529         }
2530 
2531         if (wantSourceFiles && !haveSourcePath) {
2532             fillIn(p, CLASS_PATH,
2533                    fileManager.list(CLASS_PATH,
2534                                     packageName,
2535                                     kinds,
2536                                     false));
2537         } else {
2538             if (wantClassFiles)
2539                 fillIn(p, CLASS_PATH,
2540                        fileManager.list(CLASS_PATH,
2541                                         packageName,
2542                                         classKinds,
2543                                         false));
2544             if (wantSourceFiles)
2545                 fillIn(p, SOURCE_PATH,
2546                        fileManager.list(SOURCE_PATH,
2547                                         packageName,
2548                                         sourceKinds,
2549                                         false));
2550         }
2551         verbosePath = false;
2552     }
2553     // where
2554         private void fillIn(PackageSymbol p,
2555                             Location location,
2556                             Iterable<JavaFileObject> files)
2557         {
2558             currentLoc = location;
2559             for (JavaFileObject fo : files) {
2560                 switch (fo.getKind()) {
2561                 case CLASS:
2562                 case SOURCE: {
2563                     // TODO pass binaryName to includeClassFile
2564                     String binaryName = fileManager.inferBinaryName(currentLoc, fo);
2565                     String simpleName = binaryName.substring(binaryName.lastIndexOf(".") + 1);
2566                     if (SourceVersion.isIdentifier(simpleName) ||
2567                         fo.getKind() == JavaFileObject.Kind.CLASS ||
2568                         simpleName.equals("package-info"))
2569                         includeClassFile(p, fo);
2570                     break;
2571                 }
2572                 default:
2573                     extraFileActions(p, fo);
2574                 }
2575             }
2576         }
2577 
2578     /** Output for "-verbose" option.
2579      *  @param key The key to look up the correct internationalized string.
2580      *  @param arg An argument for substitution into the output string.
2581      */
2582     private void printVerbose(String key, CharSequence arg) {
2583         Log.printLines(log.noticeWriter, Log.getLocalizedString("verbose." + key, arg));
2584     }
2585 
2586     /** Output for "-checkclassfile" option.
2587      *  @param key The key to look up the correct internationalized string.
2588      *  @param arg An argument for substitution into the output string.
2589      */
2590     private void printCCF(String key, Object arg) {
2591         Log.printLines(log.noticeWriter, Log.getLocalizedString(key, arg));
2592     }
2593 
2594 
2595     public interface SourceCompleter {
2596         void complete(ClassSymbol sym)
2597             throws CompletionFailure;
2598     }
2599 
2600     /**
2601      * A subclass of JavaFileObject for the sourcefile attribute found in a classfile.
2602      * The attribute is only the last component of the original filename, so is unlikely
2603      * to be valid as is, so operations other than those to access the name throw
2604      * UnsupportedOperationException
2605      */
2606     private static class SourceFileObject extends BaseFileObject {
2607 
2608         /** The file's name.
2609          */
2610         private Name name;
2611         private Name flatname;
2612 
2613         public SourceFileObject(Name name, Name flatname) {
2614             super(null); // no file manager; never referenced for this file object
2615             this.name = name;
2616             this.flatname = flatname;
2617         }
2618 
2619         @Override
2620         public URI toUri() {
2621             try {
2622                 return new URI(null, name.toString(), null);
2623             } catch (URISyntaxException e) {
2624                 throw new CannotCreateUriError(name.toString(), e);
2625             }
2626         }
2627 
2628         @Override
2629         public String getName() {
2630             return name.toString();
2631         }
2632 
2633         @Override
2634         public String getShortName() {
2635             return getName();
2636         }
2637 
2638         @Override
2639         public JavaFileObject.Kind getKind() {
2640             return getKind(getName());
2641         }
2642 
2643         @Override
2644         public InputStream openInputStream() {
2645             throw new UnsupportedOperationException();
2646         }
2647 
2648         @Override
2649         public OutputStream openOutputStream() {
2650             throw new UnsupportedOperationException();
2651         }
2652 
2653         @Override
2654         public CharBuffer getCharContent(boolean ignoreEncodingErrors) {
2655             throw new UnsupportedOperationException();
2656         }
2657 
2658         @Override
2659         public Reader openReader(boolean ignoreEncodingErrors) {
2660             throw new UnsupportedOperationException();
2661         }
2662 
2663         @Override
2664         public Writer openWriter() {
2665             throw new UnsupportedOperationException();
2666         }
2667 
2668         @Override
2669         public long getLastModified() {
2670             throw new UnsupportedOperationException();
2671         }
2672 
2673         @Override
2674         public boolean delete() {
2675             throw new UnsupportedOperationException();
2676         }
2677 
2678         @Override
2679         protected String inferBinaryName(Iterable<? extends File> path) {
2680             return flatname.toString();
2681         }
2682 
2683         @Override
2684         public boolean isNameCompatible(String simpleName, JavaFileObject.Kind kind) {
2685             return true; // fail-safe mode
2686         }
2687 
2688         @Override
2689         public boolean equals(Object other) {
2690             if (!(other instanceof SourceFileObject))
2691                 return false;
2692             SourceFileObject o = (SourceFileObject) other;
2693             return name.equals(o.name);
2694         }
2695 
2696         @Override
2697         public int hashCode() {
2698             return name.hashCode();
2699         }
2700     }
2701 }