814N/A * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 553N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 553N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 553N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 553N/A * or visit www.oracle.com if you need additional information or have any 0N/A/** This class provides operations to read a classfile into an internal 0N/A * representation. The internal representation is anchored in a 0N/A * ClassSymbol which contains in its scope symbol representations 0N/A * for all other definitions in the classfile. Top-level Classes themselves 0N/A * appear as members of the scopes of PackageSymbols. 580N/A * <p><b>This is NOT part of any supported API. 580N/A * If you write code that depends on this, you do so at your own risk. 0N/A * This code and its internal interfaces are subject to change or 0N/A * deletion without notice.</b> 0N/A /** The context key for the class reader. */ 0N/A /** Switch: verbose output. 0N/A /** Switch: check class file for correct minor version, unrecognized 0N/A /** Switch: read constant pool and code sections. This switch is initially 0N/A * set to false but can be turned on from outside. 0N/A /** Switch: read GJ signature information. 0N/A /** Switch: read varargs attribute. 0N/A /** Switch: allow annotations. 794N/A /** Switch: allow simplified varargs. 794N/A /** Lint option: warn about classfile issues 0N/A /** Switch: preserve parameter names from the variable table. 0N/A * Switch: cache completion failures unless -XDdev is used 0N/A * Switch: prefer source files instead of newer when both source 0N/A * and class are available 0N/A /** The log to use for verbose output 0N/A /** The symbol table. */ 0N/A /** The name table. */ 0N/A /** Force a completion failure on this name 11N/A /** Factory for diagnostics 0N/A /** Can be reassigned from outside: 0N/A * the completer to be used for ".java" files. If this remains unassigned 0N/A * ".java" files will not be loaded. 0N/A /** A hashtable containing the encountered top-level and member classes, 0N/A * indexed by flat names. The table does not contain local classes. 0N/A /** A hashtable containing the encountered packages. 0N/A /** The current scope where type variables are entered. 0N/A /** The path name of the class file currently being read. 0N/A /** The class or method currently being read. 0N/A /** The buffer containing the currently read class file. 0N/A /** The current input pointer. 0N/A /** The objects of the constant pool. 0N/A /** For every constant pool entry, an index into buf where the 0N/A * defining section of the entry is found. 255N/A /** The major version number of the class file being read. */ 255N/A /** The minor version number of the class file being read. */ 427N/A /** A table to hold the constant pool indices for method parameter 427N/A * names, as given in LocalVariableTable attributes. 427N/A * Whether or not any parameter names have been found. 775N/A * The set of attribute names for which warnings have been generated for the current class 0N/A /** Get the ClassReader instance for this invocation. */ 0N/A /** Initialize classes and packages, treating this as the definitive classreader. */ 0N/A /** Initialize classes and packages, optionally treating this as 0N/A * the definitive classreader. 0N/A /** Construct a new class reader, optionally treated as the 0N/A * definitive classreader for this invocation. 0N/A /** Add member to class unless it is synthetic. 0N/A/************************************************************************ 0N/A ***********************************************************************/ 11N/A ?
"bad.source.file.header" :
"bad.class.file.header");
0N/A/************************************************************************ 0N/A ***********************************************************************/ 0N/A /** Read a character. 0N/A /** Read an integer. 0N/A /** Extract a character at position bp from buf. 0N/A /** Extract an integer at position bp from buf. 0N/A /** Extract a long integer at position bp from buf. 0N/A /** Extract a float at position bp from buf. 0N/A /** Extract a double at position bp from buf. 0N/A/************************************************************************ 0N/A * Constant Pool Access 0N/A ***********************************************************************/ 0N/A /** Index all constant pool entries, writing their start addresses into 0N/A /** Read constant pool entry at start address i, use pool as a cache. 0N/A // FIXME: (footprint) do not use toString here 0N/A /** Read signature and convert to type. 0N/A /** If name is an array type or class signature, return the 0N/A * corresponding type; otherwise return a ClassSymbol with given name. 0N/A // by the above assertion, the following test can be 0N/A // simplified to (buf[start] == '[') 0N/A /** Read signature and convert to type parameters. 0N/A /** Read class entry. 0N/A/************************************************************************ 0N/A ***********************************************************************/ 0N/A /** The unread portion of the currently read type is 0N/A * signature[sigp..siglimit-1]. 0N/A /** Convert signature to type, where signature is a byte array segment. 0N/A /** Convert signature to type, where signature is implicit. 0N/A // int oldsigp = sigp; 0N/A "(please recompile from source)");
0N/A System.err.println(" decoded " + 0N/A new String(signature, oldsigp, sigp-oldsigp) + 0N/A " => " + t + " outer " + t.outer()); 0N/A /** Convert class signature to type, where signature is implicit. 0N/A case '<':
// generic arguments 0N/A // support old-style GJC signatures 0N/A // The signature produced was 0N/A /** Convert (implicit) signature to list of types 0N/A * until `terminator' is encountered. 0N/A /** Convert signature to type parameters, where signature is a byte 0N/A /** Convert signature to type parameters, where signature is implicit. 0N/A /** Convert (implicit) signature to type parameter. 0N/A /** Find type variable with given name in `typevars' scope. 0N/A // While reading the class attribute, the supertypes 0N/A // might refer to a type variable from an enclosing element 0N/A // (method or class). 0N/A // If the type variable is defined in the enclosing class, 0N/A // we can actually find it in 0N/A // currentOwner.owner.type.getTypeArguments() 0N/A // However, until we have read the enclosing method attribute 0N/A // we don't know for sure if this owner is correct. It could 0N/A // be a method and there is no way to tell before reading the 0N/A // enclosing method attribute. 0N/A // System.err.println("Missing type var " + name); 0N/A/************************************************************************ 0N/A * Reading Attributes 0N/A ***********************************************************************/ 255N/A // Ignore ConstantValue attribute if field not final. 427N/A // Pick up parameter names from the variable table. 427N/A // Parameter names are not explicitly identified as such, 427N/A // but all parameter name entries in the LocalVariableTable 427N/A // have a start_pc of 0. Therefore, we record the name 427N/A // indicies of all slots with a start_pc of zero in the 427N/A // parameterNameIndicies array. 427N/A // Note that this implicitly honors the JVMS spec that 427N/A // there may be more than one LocalVariableTable, and that 427N/A // there is no specified ordering for the entries. 427N/A // ensure array large enough 255N/A // bridge methods are visible when generics not enabled 255N/A // standard v49 attributes 255N/A //- System.err.println(" # " + sym.type); 255N/A // v49 annotation attributes 255N/A // additional "legacy" v49 attributes, superceded by flags 255N/A // The following attributes for a Code attribute are not currently handled 255N/A // SourceDebugExtension 255N/A // LocalVariableTypeTable 0N/A /** Report unrecognized attribute. 0N/A // sym is a nested class with an "Enclosing Method" attribute 0N/A // remove sym from it's current owners scope and place it in 0N/A // the scope specified by the attribute 0N/A // See java.lang.Class 0N/A // not a constructor 0N/A // no enclosing instance 0N/A // A constructor of an inner class. 0N/A // Remove the first argument (the enclosing instance) 0N/A // Try searching again 0N/A /** Similar to Types.isSameType but avoids completion */ 0N/A * Character.isDigit answers <tt>true</tt> to some non-ascii 0N/A * digits. This one does not. <b>copied from java.lang.Class</b> 0N/A return '0' <= c && c <=
'9';
0N/A /** Read member attributes. 0N/A for (
int i =
0; i <
ac; i++) {
0N/A /** Read class attributes. 0N/A /** Read code block. 0N/A/************************************************************************ 0N/A * Reading Java-language annotations 0N/A ***********************************************************************/ 0N/A /** Attach annotations. 0N/A /** Attach parameter annotations. 0N/A /** Attach the default value for an annotation element. 0N/A // support preliminary jsr175-format class files 0N/A // support preliminary jsr175-format class files 0N/A for (
int i=
0; i<n; i++)
0N/A /** A temporary proxy representing a compound attribute. 307N/A /** A temporary proxy representing a type annotation. 0N/A // also must fill in types!!!! 0N/A // The method wasn't found: emit a warning and recover 0N/A // Construct a new method type and symbol. Use bottom 0N/A // type (typeof null) as return type because this type is 0N/A // a subtype of all reference types and can be converted 0N/A // to primitive types by unboxing. 0N/A // implement Attribute.Visitor below 0N/A // assert value.type == type; 0N/A // type.tsym.flatName() should == proxy.enumFlatName 0N/A // implement Annotate.Annotator.enterAnnotation() 0N/A return " ClassReader annotate " +
sym.
owner +
"." +
sym +
" with " + l;
0N/A // implement Annotate.Annotator.enterAnnotation() 0N/A/************************************************************************ 0N/A ***********************************************************************/ 0N/A // Sometimes anonymous classes don't have an outer 0N/A // instance, however, there is no reliable way to tell so 0N/A // we never strip this$n 427N/A * Init the parameter names array. 427N/A * Parameter names are currently inferred from the names in the 427N/A * LocalVariableTable attributes of a Code attribute. 427N/A * (Note: this means parameter names are currently not available for 427N/A * methods without a Code attribute.) 427N/A * This method initializes an array in which to store the name indexes 427N/A * of parameter names found in LocalVariableTable attributes. It is 427N/A * slightly supersized to allow for additional slots with a start_pc of 0. 427N/A // make allowance for synthetic parameters. 427N/A * Set the parameter names for a symbol from the name index in the 427N/A * parameterNameIndicies array. The type of the symbol may have changed 427N/A * while reading the method attributes (see the Signature attribute). 427N/A * This may be because of generic information or because anonymous 427N/A * synthetic parameters were added. The original type (as read from 427N/A * the method descriptor) is used to help guess the existence of 427N/A * anonymous synthetic parameters. 427N/A * On completion, sym.savedParameter names will either be null (if 427N/A * no parameter names were found in the class file) or will be set to a 427N/A * list of names, one per entry in sym.type.getParameterTypes, with 427N/A * any missing names represented by the empty name. 427N/A // if no names were found in the class file, there's nothing more to do 427N/A // the code in readMethod may have skipped the first parameter when 427N/A // setting up the MethodType. If so, we make a corresponding allowance 427N/A // here for the position of the first parameter. Note that this 427N/A // assumes the skipped parameter has a width of 1 -- i.e. it is not 427N/A // a double width type (long or double.) 427N/A // Sometimes anonymous classes don't have an outer 427N/A // instance, however, there is no reliable way to tell so 427N/A // we never strip this$n 427N/A // reading the method attributes has caused the symbol's type to 427N/A // be changed. (i.e. the Signature attribute.) This may happen if 427N/A // there are hidden (synthetic) parameters in the descriptor, but 427N/A // not in the Signature. The position of these hidden parameters 427N/A // is unspecified; for now, assume they are at the beginning, and 427N/A // so skip over them. The primary case for this is two hidden 427N/A // parameters passed into Enum constructors. 0N/A /** Skip a field or method 0N/A for (
int i =
0; i <
ac; i++) {
0N/A /** Enter type variables of this classtype and all enclosing ones in 0N/A /** Read contents of a given class symbol `c'. Both external and internal 0N/A * versions of an inner class are read. 0N/A // allocate scope for members 0N/A // prepare type variable table 0N/A // read flags, or skip if this is an inner class 0N/A // read own class name and check that it matches 0N/A // class attributes must be read before class 0N/A // skip ahead to read class attributes 0N/A // reset and read rest of classinfo 0N/A for (
int i =
0; i < n; i++) {
0N/A for (
int i =
0; i < n; i++) {
0N/A /** Read a class file. 0N/A/************************************************************************ 0N/A ***********************************************************************/ 0N/A/************************************************************************ 0N/A ***********************************************************************/ 0N/A /** Define a new class given its name and owner. 0N/A /** Create a new toplevel or member class symbol with given name 0N/A * and owner and enter in `classes' unless already there. 0N/A // reassign fields of classes that might have been loaded with 0N/A // their flat names. 0N/A * Creates a new toplevel class symbol with given flat name and 0N/A * given class (or source) file. 0N/A * @param flatName a fully qualified binary class name 0N/A * @param classFile the class file or compilation unit defining 0N/A * the class (may be {@code null}) 0N/A * @return a newly created class symbol 0N/A * @throws AssertionError if the class symbol already exists 0N/A /** Create a new member or toplevel class symbol with given flat name 0N/A * and enter in `classes' unless already there. 0N/A /** Completion for classes to be loaded. Before a class is loaded 0N/A * we make sure its enclosing class (if any) is loaded. 0N/A /** complete up through the enclosing package. */ 0N/A * Tries to complete lexically enclosing classes if c looks like a 0N/A * nested class. This is similar to completeOwners but handles 0N/A * the situation when a nested class is accessed directly as it is 0N/A * possible with the Tree API or javax.lang.model.*. 0N/A /** We can only read a single class file at a time; this 0N/A * flag keeps track of when we are currently reading a class 0N/A /** Fill in definition of class `c' from corresponding class or 0N/A /* Ignore any errors, as this stream may have already 0N/A * thrown a related exception which is the one that 0N/A * should be reported. 803N/A * ensureCapacity will increase the buffer as needed, taking note that 803N/A * the new buffer will always be greater than the needed and never 803N/A * exactly equal to the needed size or bp. If equal then the read (above) 803N/A * will infinitely loop as buf.length - bp == 0. 0N/A /** Static factory for CompletionFailure objects. 0N/A * In practice, only one can be used at a time, so we share one 0N/A * to reduce the expense of allocating new exception objects. 0N/A // log.warning("proc.messager", 0N/A // Log.getLocalizedString("class.file.not.found", c.flatname)); 0N/A // c.debug.printStackTrace(); 0N/A /** Load a toplevel class with given fully qualified name 0N/A * The class is entered into `classes' only if load was successful. 0N/A/************************************************************************ 0N/A ***********************************************************************/ 0N/A /** Check to see if a package exists, given its fully qualified name. 0N/A /** Make a package, given its fully qualified name. 0N/A /** Make a package, given its unqualified name and enclosing package. 0N/A /** Include class corresponding to given class file in package, 0N/A * unless (1) we already have one the same kind (.class or .java), or 0N/A * (2) we have one of the other kind, and the given class file 0N/A if (c.
owner == p)
// it might be an inner class 0N/A // if c.classfile == null, we are currently compiling this class 0N/A // and no further action is necessary. 0N/A // if (c.flags_field & seen) != 0, we have already encountered 0N/A // a file of the same kind; again no further action is necessary. 0N/A /** Implement policy to choose to derive information from a source 0N/A * file or a class file when both are present. May be overridden 0N/A // 6449326: policy for bad lastModifiedTime in ClassReader 0N/A //assert adate >= 0 && bdate >= 0; 0N/A * specifies types of files to be read when filling in a package symbol 0N/A * this is used to support javadoc 0N/A /** Load directory of package into members scope. 0N/A // TODO pass binaryName to includeClassFile 0N/A /** Output for "-checkclassfile" option. 0N/A * @param key The key to look up the correct internationalized string. 0N/A * @param arg An argument for substitution into the output string. 0N/A * A subclass of JavaFileObject for the sourcefile attribute found in a classfile. 0N/A * The attribute is only the last component of the original filename, so is unlikely 0N/A * to be valid as is, so operations other than those to access the name throw 0N/A * UnsupportedOperationException 0N/A /** The file's name. 56N/A super(
null);
// no file manager; never referenced for this file object 414N/A return true;
// fail-safe mode 423N/A * Check if two file objects are equal. 423N/A * SourceFileObjects are just placeholder objects for the value of a 423N/A * SourceFile attribute, and do not directly represent specific files. 423N/A * Two SourceFileObjects are equal if their names are equal.