src/share/classes/com/sun/tools/javac/jvm/ClassReader.java

Mon, 21 Jan 2013 01:27:42 -0500

author
jjg
date
Mon, 21 Jan 2013 01:27:42 -0500
changeset 1569
475eb15dfdad
parent 1473
31780dd06ec7
child 1570
f91144b7da75
permissions
-rw-r--r--

8004182: Add support for profiles in javac
Reviewed-by: mcimadamore

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

mercurial