langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java
author jlahoda
Wed, 27 Aug 2014 07:44:00 +0200
changeset 26266 2d24bda701dc
parent 25874 83c19f00452c
child 26532 aa84b6606229
permissions -rw-r--r--
8056061: Mark implementations of public interfaces with an annotation Summary: Adding @DefinedBy annotation to mark methods that implement public API methods; annotating the methods; adding a coding rules analyzer to enforce all such methods are annotated. Reviewed-by: jjg, mcimadamore, jfranck Contributed-by: jan.lahoda@oracle.com, jonathan.gibbons@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
22442
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22167
diff changeset
     2
 * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5012
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5012
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5012
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5012
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5012
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.javac.jvm;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import java.io.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
import java.net.URI;
3782
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents: 3149
diff changeset
    30
import java.net.URISyntaxException;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import java.nio.CharBuffer;
4077
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
    32
import java.util.Arrays;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
import java.util.EnumSet;
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
import java.util.HashMap;
7624
c31b0ea95b37 6999210: javac should be able to warn of anomalous conditions in classfiles
jjg
parents: 7330
diff changeset
    35
import java.util.HashSet;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
import java.util.Map;
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
import java.util.Set;
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
import javax.tools.JavaFileObject;
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
import javax.tools.JavaFileManager;
2513
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
    40
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
import com.sun.tools.javac.comp.Annotate;
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
import com.sun.tools.javac.code.*;
7624
c31b0ea95b37 6999210: javac should be able to warn of anomalous conditions in classfiles
jjg
parents: 7330
diff changeset
    43
import com.sun.tools.javac.code.Lint.LintCategory;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
import com.sun.tools.javac.code.Type.*;
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 24895
diff changeset
    45
import com.sun.tools.javac.code.Scope.WriteableScope;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
import com.sun.tools.javac.code.Symbol.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
import com.sun.tools.javac.code.Symtab;
731
1dd22bdb9ca5 6714364: refactor javac File handling code into new javac.file package
jjg
parents: 169
diff changeset
    48
import com.sun.tools.javac.file.BaseFileObject;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
import com.sun.tools.javac.util.*;
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
    50
import com.sun.tools.javac.util.DefinedBy.Api;
7624
c31b0ea95b37 6999210: javac should be able to warn of anomalous conditions in classfiles
jjg
parents: 7330
diff changeset
    51
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
import static com.sun.tools.javac.code.Flags.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
import static com.sun.tools.javac.code.Kinds.*;
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 13689
diff changeset
    55
import static com.sun.tools.javac.code.TypeTag.CLASS;
20242
11fa75a0b9fb 8024437: Inferring the exception thrown: sometimes fails to compile
vromero
parents: 19921
diff changeset
    56
import static com.sun.tools.javac.code.TypeTag.TYPEVAR;
2513
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
    57
import static com.sun.tools.javac.jvm.ClassFile.*;
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
    58
import static com.sun.tools.javac.jvm.ClassFile.Version.*;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
11314
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 11053
diff changeset
    60
import static com.sun.tools.javac.main.Option.*;
6721
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6709
diff changeset
    61
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
/** This class provides operations to read a classfile into an internal
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
 *  representation. The internal representation is anchored in a
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
 *  ClassSymbol which contains in its scope symbol representations
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
 *  for all other definitions in the classfile. Top-level Classes themselves
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
 *  appear as members of the scopes of PackageSymbols.
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    68
 *  <p><b>This is NOT part of any supported API.
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    69
 *  If you write code that depends on this, you do so at your own risk.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
 */
19921
58bcbe156057 8023974: Drop 'implements Completer' and 'implements SourceCompleter' from ClassReader resp. JavaCompiler.
jfranck
parents: 19915
diff changeset
    73
public class ClassReader {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
    /** The context key for the class reader. */
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21043
diff changeset
    75
    protected static final Context.Key<ClassReader> classReaderKey = new Context.Key<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
7842
5de9ea98089d 6567415: Neverending loop in ClassReader
ksrini
parents: 7643
diff changeset
    77
    public static final int INITIAL_BUFFER_SIZE = 0x0fff0;
5de9ea98089d 6567415: Neverending loop in ClassReader
ksrini
parents: 7643
diff changeset
    78
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
    Annotate annotate;
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
    /** Switch: verbose output.
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
    boolean verbose;
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
    /** Switch: check class file for correct minor version, unrecognized
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
     *  attributes.
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
    boolean checkClassFile;
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
    /** Switch: read constant pool and code sections. This switch is initially
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
     *  set to false but can be turned on from outside.
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
    public boolean readAllOfClassFile = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
7643
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7632
diff changeset
    95
    /** Switch: allow simplified varargs.
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7632
diff changeset
    96
     */
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7632
diff changeset
    97
    boolean allowSimplifiedVarargs;
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7632
diff changeset
    98
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7632
diff changeset
    99
   /** Lint option: warn about classfile issues
7624
c31b0ea95b37 6999210: javac should be able to warn of anomalous conditions in classfiles
jjg
parents: 7330
diff changeset
   100
     */
c31b0ea95b37 6999210: javac should be able to warn of anomalous conditions in classfiles
jjg
parents: 7330
diff changeset
   101
    boolean lintClassfile;
c31b0ea95b37 6999210: javac should be able to warn of anomalous conditions in classfiles
jjg
parents: 7330
diff changeset
   102
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
    /** Switch: preserve parameter names from the variable table.
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
    public boolean saveParameterNames;
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
    /**
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 15031
diff changeset
   108
     * The currently selected profile.
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 15031
diff changeset
   109
     */
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 15031
diff changeset
   110
    public final Profile profile;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 15031
diff changeset
   111
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
    /** The log to use for verbose output
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
    final Log log;
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
    /** The symbol table. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
    Symtab syms;
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
    Types types;
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
    /** The name table. */
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 939
diff changeset
   122
    final Names names;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
    /** Access to files
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
    private final JavaFileManager fileManager;
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
169
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
   128
    /** Factory for diagnostics
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
   129
     */
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
   130
    JCDiagnostic.Factory diagFactory;
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
   131
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
    /** The current scope where type variables are entered.
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
     */
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 24895
diff changeset
   134
    protected WriteableScope typevars;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
    /** The path name of the class file currently being read.
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
    protected JavaFileObject currentClassFile = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
    /** The class or method currently being read.
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
    protected Symbol currentOwner = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
    /** The buffer containing the currently read class file.
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
     */
7842
5de9ea98089d 6567415: Neverending loop in ClassReader
ksrini
parents: 7643
diff changeset
   146
    byte[] buf = new byte[INITIAL_BUFFER_SIZE];
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
    /** The current input pointer.
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
     */
13635
5c742eabba7c 7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents: 12335
diff changeset
   150
    protected int bp;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
    /** The objects of the constant pool.
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
    Object[] poolObj;
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
    /** For every constant pool entry, an index into buf where the
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
     *  defining section of the entry is found.
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
    int[] poolIdx;
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
2513
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   161
    /** The major version number of the class file being read. */
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   162
    int majorVersion;
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   163
    /** The minor version number of the class file being read. */
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   164
    int minorVersion;
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   165
4077
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
   166
    /** A table to hold the constant pool indices for method parameter
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
   167
     * names, as given in LocalVariableTable attributes.
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
   168
     */
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
   169
    int[] parameterNameIndices;
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
   170
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
   171
    /**
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
   172
     * Whether or not any parameter names have been found.
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
   173
     */
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
   174
    boolean haveParameterNameIndices;
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
   175
15031
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14949
diff changeset
   176
    /** Set this to false every time we start reading a method
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14949
diff changeset
   177
     * and are saving parameter names.  Set it to true when we see
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14949
diff changeset
   178
     * MethodParameters, if it's set when we see a LocalVariableTable,
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14949
diff changeset
   179
     * then we ignore the parameter names from the LVT.
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14949
diff changeset
   180
     */
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14949
diff changeset
   181
    boolean sawMethodParameters;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14949
diff changeset
   182
7624
c31b0ea95b37 6999210: javac should be able to warn of anomalous conditions in classfiles
jjg
parents: 7330
diff changeset
   183
    /**
c31b0ea95b37 6999210: javac should be able to warn of anomalous conditions in classfiles
jjg
parents: 7330
diff changeset
   184
     * The set of attribute names for which warnings have been generated for the current class
c31b0ea95b37 6999210: javac should be able to warn of anomalous conditions in classfiles
jjg
parents: 7330
diff changeset
   185
     */
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21043
diff changeset
   186
    Set<Name> warnedAttrs = new HashSet<>();
7624
c31b0ea95b37 6999210: javac should be able to warn of anomalous conditions in classfiles
jjg
parents: 7330
diff changeset
   187
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
    /** Get the ClassReader instance for this invocation. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
    public static ClassReader instance(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
        ClassReader instance = context.get(classReaderKey);
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
        if (instance == null)
22442
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22167
diff changeset
   192
            instance = new ClassReader(context);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
        return instance;
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
22442
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22167
diff changeset
   196
    /** Construct a new class reader. */
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22167
diff changeset
   197
    protected ClassReader(Context context) {
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22167
diff changeset
   198
        context.put(classReaderKey, this);
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 939
diff changeset
   199
        names = Names.instance(context);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
        syms = Symtab.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
        types = Types.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
        fileManager = context.get(JavaFileManager.class);
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
        if (fileManager == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
            throw new AssertionError("FileManager initialization error");
169
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
   205
        diagFactory = JCDiagnostic.Factory.instance(context);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
        log = Log.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
        Options options = Options.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
        annotate = Annotate.instance(context);
6721
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6709
diff changeset
   211
        verbose        = options.isSet(VERBOSE);
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6709
diff changeset
   212
        checkClassFile = options.isSet("-checkclassfile");
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 15031
diff changeset
   213
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
        Source source = Source.instance(context);
7643
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7632
diff changeset
   215
        allowSimplifiedVarargs = source.allowSimplifiedVarargs();
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 15031
diff changeset
   216
6721
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6709
diff changeset
   217
        saveParameterNames = options.isSet("save-parameter-names");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 15031
diff changeset
   219
        profile = Profile.instance(context);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 15031
diff changeset
   220
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 24895
diff changeset
   221
        typevars = WriteableScope.create(syms.noSymbol);
2513
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   222
7624
c31b0ea95b37 6999210: javac should be able to warn of anomalous conditions in classfiles
jjg
parents: 7330
diff changeset
   223
        lintClassfile = Lint.instance(context).isEnabled(LintCategory.CLASSFILE);
c31b0ea95b37 6999210: javac should be able to warn of anomalous conditions in classfiles
jjg
parents: 7330
diff changeset
   224
2513
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   225
        initAttributeReaders();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
    /** Add member to class unless it is synthetic.
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
    private void enterMember(ClassSymbol c, Symbol sym) {
16300
7cf27559c8df 8004969: Generate $deserializeLambda$ method
rfield
parents: 15718
diff changeset
   231
        // Synthetic members are not entered -- reason lost to history (optimization?).
7cf27559c8df 8004969: Generate $deserializeLambda$ method
rfield
parents: 15718
diff changeset
   232
        // Lambda methods must be entered because they may have inner classes (which reference them)
7cf27559c8df 8004969: Generate $deserializeLambda$ method
rfield
parents: 15718
diff changeset
   233
        if ((sym.flags_field & (SYNTHETIC|BRIDGE)) != SYNTHETIC || sym.name.startsWith(names.lambda))
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
            c.members_field.enter(sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
/************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
 * Error Diagnoses
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
 ***********************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
   241
    public ClassFinder.BadClassFile badClassFile(String key, Object... args) {
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
   242
        return new ClassFinder.BadClassFile (
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
            currentOwner.enclClass(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
            currentClassFile,
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
   245
            diagFactory.fragment(key, args),
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
   246
            diagFactory);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
/************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
 * Buffer Access
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
 ***********************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
    /** Read a character.
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
    char nextChar() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
        return (char)(((buf[bp++] & 0xFF) << 8) + (buf[bp++] & 0xFF));
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
3149
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 2723
diff changeset
   259
    /** Read a byte.
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 2723
diff changeset
   260
     */
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   261
    int nextByte() {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   262
        return buf[bp++] & 0xFF;
3149
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 2723
diff changeset
   263
    }
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 2723
diff changeset
   264
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
    /** Read an integer.
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
    int nextInt() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
        return
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
            ((buf[bp++] & 0xFF) << 24) +
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
            ((buf[bp++] & 0xFF) << 16) +
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
            ((buf[bp++] & 0xFF) << 8) +
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
            (buf[bp++] & 0xFF);
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
    /** Extract a character at position bp from buf.
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
    char getChar(int bp) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
        return
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
            (char)(((buf[bp] & 0xFF) << 8) + (buf[bp+1] & 0xFF));
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
    /** Extract an integer at position bp from buf.
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
    int getInt(int bp) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
        return
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
            ((buf[bp] & 0xFF) << 24) +
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
            ((buf[bp+1] & 0xFF) << 16) +
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
            ((buf[bp+2] & 0xFF) << 8) +
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
            (buf[bp+3] & 0xFF);
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
    /** Extract a long integer at position bp from buf.
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
    long getLong(int bp) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
        DataInputStream bufin =
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
            new DataInputStream(new ByteArrayInputStream(buf, bp, 8));
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
            return bufin.readLong();
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
            throw new AssertionError(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
    /** Extract a float at position bp from buf.
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
    float getFloat(int bp) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
        DataInputStream bufin =
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
            new DataInputStream(new ByteArrayInputStream(buf, bp, 4));
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
            return bufin.readFloat();
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
            throw new AssertionError(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
    /** Extract a double at position bp from buf.
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
    double getDouble(int bp) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
        DataInputStream bufin =
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
            new DataInputStream(new ByteArrayInputStream(buf, bp, 8));
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
            return bufin.readDouble();
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
            throw new AssertionError(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
/************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
 * Constant Pool Access
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
 ***********************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
    /** Index all constant pool entries, writing their start addresses into
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
     *  poolIdx.
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
    void indexPool() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
        poolIdx = new int[nextChar()];
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
        poolObj = new Object[poolIdx.length];
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
        int i = 1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
        while (i < poolIdx.length) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
            poolIdx[i++] = bp;
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
            byte tag = buf[bp++];
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
            switch (tag) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
            case CONSTANT_Utf8: case CONSTANT_Unicode: {
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
                int len = nextChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
                bp = bp + len;
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
            case CONSTANT_Class:
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
            case CONSTANT_String:
8042
d534dd80da9f 6982999: tools must support -target 7 bytecodes
ksrini
parents: 8032
diff changeset
   351
            case CONSTANT_MethodType:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
                bp = bp + 2;
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
                break;
8042
d534dd80da9f 6982999: tools must support -target 7 bytecodes
ksrini
parents: 8032
diff changeset
   354
            case CONSTANT_MethodHandle:
d534dd80da9f 6982999: tools must support -target 7 bytecodes
ksrini
parents: 8032
diff changeset
   355
                bp = bp + 3;
d534dd80da9f 6982999: tools must support -target 7 bytecodes
ksrini
parents: 8032
diff changeset
   356
                break;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
            case CONSTANT_Fieldref:
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
            case CONSTANT_Methodref:
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
            case CONSTANT_InterfaceMethodref:
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
            case CONSTANT_NameandType:
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
            case CONSTANT_Integer:
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
            case CONSTANT_Float:
8042
d534dd80da9f 6982999: tools must support -target 7 bytecodes
ksrini
parents: 8032
diff changeset
   363
            case CONSTANT_InvokeDynamic:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   364
                bp = bp + 4;
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
            case CONSTANT_Long:
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
            case CONSTANT_Double:
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
                bp = bp + 8;
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
                i++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
            default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
                throw badClassFile("bad.const.pool.tag.at",
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
                                   Byte.toString(tag),
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
                                   Integer.toString(bp -1));
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
    /** Read constant pool entry at start address i, use pool as a cache.
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   381
    Object readPool(int i) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
        Object result = poolObj[i];
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
        if (result != null) return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
        int index = poolIdx[i];
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
        if (index == 0) return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   387
06bc494ca11e Initial load
duke
parents:
diff changeset
   388
        byte tag = buf[index];
06bc494ca11e Initial load
duke
parents:
diff changeset
   389
        switch (tag) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   390
        case CONSTANT_Utf8:
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
            poolObj[i] = names.fromUtf(buf, index + 3, getChar(index + 1));
06bc494ca11e Initial load
duke
parents:
diff changeset
   392
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   393
        case CONSTANT_Unicode:
06bc494ca11e Initial load
duke
parents:
diff changeset
   394
            throw badClassFile("unicode.str.not.supported");
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
        case CONSTANT_Class:
06bc494ca11e Initial load
duke
parents:
diff changeset
   396
            poolObj[i] = readClassOrType(getChar(index + 1));
06bc494ca11e Initial load
duke
parents:
diff changeset
   397
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   398
        case CONSTANT_String:
06bc494ca11e Initial load
duke
parents:
diff changeset
   399
            // FIXME: (footprint) do not use toString here
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
            poolObj[i] = readName(getChar(index + 1)).toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   401
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   402
        case CONSTANT_Fieldref: {
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
            ClassSymbol owner = readClassSymbol(getChar(index + 1));
24068
d8a1180faaa9 8038023: Compiler crash ClassCastException
pgovereau
parents: 23975
diff changeset
   404
            NameAndType nt = readNameAndType(getChar(index + 3));
14949
45f43822bbde 8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents: 14804
diff changeset
   405
            poolObj[i] = new VarSymbol(0, nt.name, nt.uniqueType.type, owner);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
        case CONSTANT_Methodref:
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
        case CONSTANT_InterfaceMethodref: {
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
            ClassSymbol owner = readClassSymbol(getChar(index + 1));
24068
d8a1180faaa9 8038023: Compiler crash ClassCastException
pgovereau
parents: 23975
diff changeset
   411
            NameAndType nt = readNameAndType(getChar(index + 3));
14949
45f43822bbde 8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents: 14804
diff changeset
   412
            poolObj[i] = new MethodSymbol(0, nt.name, nt.uniqueType.type, owner);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   413
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   415
        case CONSTANT_NameandType:
06bc494ca11e Initial load
duke
parents:
diff changeset
   416
            poolObj[i] = new NameAndType(
06bc494ca11e Initial load
duke
parents:
diff changeset
   417
                readName(getChar(index + 1)),
14949
45f43822bbde 8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents: 14804
diff changeset
   418
                readType(getChar(index + 3)), types);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   419
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   420
        case CONSTANT_Integer:
06bc494ca11e Initial load
duke
parents:
diff changeset
   421
            poolObj[i] = getInt(index + 1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   422
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   423
        case CONSTANT_Float:
06bc494ca11e Initial load
duke
parents:
diff changeset
   424
            poolObj[i] = new Float(getFloat(index + 1));
06bc494ca11e Initial load
duke
parents:
diff changeset
   425
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   426
        case CONSTANT_Long:
06bc494ca11e Initial load
duke
parents:
diff changeset
   427
            poolObj[i] = new Long(getLong(index + 1));
06bc494ca11e Initial load
duke
parents:
diff changeset
   428
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   429
        case CONSTANT_Double:
06bc494ca11e Initial load
duke
parents:
diff changeset
   430
            poolObj[i] = new Double(getDouble(index + 1));
06bc494ca11e Initial load
duke
parents:
diff changeset
   431
            break;
8042
d534dd80da9f 6982999: tools must support -target 7 bytecodes
ksrini
parents: 8032
diff changeset
   432
        case CONSTANT_MethodHandle:
d534dd80da9f 6982999: tools must support -target 7 bytecodes
ksrini
parents: 8032
diff changeset
   433
            skipBytes(4);
d534dd80da9f 6982999: tools must support -target 7 bytecodes
ksrini
parents: 8032
diff changeset
   434
            break;
d534dd80da9f 6982999: tools must support -target 7 bytecodes
ksrini
parents: 8032
diff changeset
   435
        case CONSTANT_MethodType:
d534dd80da9f 6982999: tools must support -target 7 bytecodes
ksrini
parents: 8032
diff changeset
   436
            skipBytes(3);
d534dd80da9f 6982999: tools must support -target 7 bytecodes
ksrini
parents: 8032
diff changeset
   437
            break;
d534dd80da9f 6982999: tools must support -target 7 bytecodes
ksrini
parents: 8032
diff changeset
   438
        case CONSTANT_InvokeDynamic:
d534dd80da9f 6982999: tools must support -target 7 bytecodes
ksrini
parents: 8032
diff changeset
   439
            skipBytes(5);
d534dd80da9f 6982999: tools must support -target 7 bytecodes
ksrini
parents: 8032
diff changeset
   440
            break;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   441
        default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   442
            throw badClassFile("bad.const.pool.tag", Byte.toString(tag));
06bc494ca11e Initial load
duke
parents:
diff changeset
   443
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   444
        return poolObj[i];
06bc494ca11e Initial load
duke
parents:
diff changeset
   445
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   446
06bc494ca11e Initial load
duke
parents:
diff changeset
   447
    /** Read signature and convert to type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   448
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   449
    Type readType(int i) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   450
        int index = poolIdx[i];
06bc494ca11e Initial load
duke
parents:
diff changeset
   451
        return sigToType(buf, index + 3, getChar(index + 1));
06bc494ca11e Initial load
duke
parents:
diff changeset
   452
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   453
06bc494ca11e Initial load
duke
parents:
diff changeset
   454
    /** If name is an array type or class signature, return the
06bc494ca11e Initial load
duke
parents:
diff changeset
   455
     *  corresponding type; otherwise return a ClassSymbol with given name.
06bc494ca11e Initial load
duke
parents:
diff changeset
   456
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   457
    Object readClassOrType(int i) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   458
        int index =  poolIdx[i];
06bc494ca11e Initial load
duke
parents:
diff changeset
   459
        int len = getChar(index + 1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   460
        int start = index + 3;
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 8031
diff changeset
   461
        Assert.check(buf[start] == '[' || buf[start + len - 1] != ';');
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   462
        // by the above assertion, the following test can be
06bc494ca11e Initial load
duke
parents:
diff changeset
   463
        // simplified to (buf[start] == '[')
06bc494ca11e Initial load
duke
parents:
diff changeset
   464
        return (buf[start] == '[' || buf[start + len - 1] == ';')
06bc494ca11e Initial load
duke
parents:
diff changeset
   465
            ? (Object)sigToType(buf, start, len)
22442
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22167
diff changeset
   466
            : (Object)syms.enterClass(names.fromUtf(internalize(buf, start,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   467
                                                           len)));
06bc494ca11e Initial load
duke
parents:
diff changeset
   468
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   469
06bc494ca11e Initial load
duke
parents:
diff changeset
   470
    /** Read signature and convert to type parameters.
06bc494ca11e Initial load
duke
parents:
diff changeset
   471
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   472
    List<Type> readTypeParams(int i) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   473
        int index = poolIdx[i];
06bc494ca11e Initial load
duke
parents:
diff changeset
   474
        return sigToTypeParams(buf, index + 3, getChar(index + 1));
06bc494ca11e Initial load
duke
parents:
diff changeset
   475
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   476
06bc494ca11e Initial load
duke
parents:
diff changeset
   477
    /** Read class entry.
06bc494ca11e Initial load
duke
parents:
diff changeset
   478
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   479
    ClassSymbol readClassSymbol(int i) {
24068
d8a1180faaa9 8038023: Compiler crash ClassCastException
pgovereau
parents: 23975
diff changeset
   480
        Object obj = readPool(i);
d8a1180faaa9 8038023: Compiler crash ClassCastException
pgovereau
parents: 23975
diff changeset
   481
        if (obj != null && !(obj instanceof ClassSymbol))
d8a1180faaa9 8038023: Compiler crash ClassCastException
pgovereau
parents: 23975
diff changeset
   482
            throw badClassFile("bad.const.pool.entry",
d8a1180faaa9 8038023: Compiler crash ClassCastException
pgovereau
parents: 23975
diff changeset
   483
                               currentClassFile.toString(),
d8a1180faaa9 8038023: Compiler crash ClassCastException
pgovereau
parents: 23975
diff changeset
   484
                               "CONSTANT_Class_info", i);
d8a1180faaa9 8038023: Compiler crash ClassCastException
pgovereau
parents: 23975
diff changeset
   485
        return (ClassSymbol)obj;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   486
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   487
06bc494ca11e Initial load
duke
parents:
diff changeset
   488
    /** Read name.
06bc494ca11e Initial load
duke
parents:
diff changeset
   489
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   490
    Name readName(int i) {
24068
d8a1180faaa9 8038023: Compiler crash ClassCastException
pgovereau
parents: 23975
diff changeset
   491
        Object obj = readPool(i);
d8a1180faaa9 8038023: Compiler crash ClassCastException
pgovereau
parents: 23975
diff changeset
   492
        if (obj != null && !(obj instanceof Name))
d8a1180faaa9 8038023: Compiler crash ClassCastException
pgovereau
parents: 23975
diff changeset
   493
            throw badClassFile("bad.const.pool.entry",
d8a1180faaa9 8038023: Compiler crash ClassCastException
pgovereau
parents: 23975
diff changeset
   494
                               currentClassFile.toString(),
d8a1180faaa9 8038023: Compiler crash ClassCastException
pgovereau
parents: 23975
diff changeset
   495
                               "CONSTANT_Utf8_info or CONSTANT_String_info", i);
d8a1180faaa9 8038023: Compiler crash ClassCastException
pgovereau
parents: 23975
diff changeset
   496
        return (Name)obj;
d8a1180faaa9 8038023: Compiler crash ClassCastException
pgovereau
parents: 23975
diff changeset
   497
    }
d8a1180faaa9 8038023: Compiler crash ClassCastException
pgovereau
parents: 23975
diff changeset
   498
d8a1180faaa9 8038023: Compiler crash ClassCastException
pgovereau
parents: 23975
diff changeset
   499
    /** Read name and type.
d8a1180faaa9 8038023: Compiler crash ClassCastException
pgovereau
parents: 23975
diff changeset
   500
     */
d8a1180faaa9 8038023: Compiler crash ClassCastException
pgovereau
parents: 23975
diff changeset
   501
    NameAndType readNameAndType(int i) {
d8a1180faaa9 8038023: Compiler crash ClassCastException
pgovereau
parents: 23975
diff changeset
   502
        Object obj = readPool(i);
d8a1180faaa9 8038023: Compiler crash ClassCastException
pgovereau
parents: 23975
diff changeset
   503
        if (obj != null && !(obj instanceof NameAndType))
d8a1180faaa9 8038023: Compiler crash ClassCastException
pgovereau
parents: 23975
diff changeset
   504
            throw badClassFile("bad.const.pool.entry",
d8a1180faaa9 8038023: Compiler crash ClassCastException
pgovereau
parents: 23975
diff changeset
   505
                               currentClassFile.toString(),
d8a1180faaa9 8038023: Compiler crash ClassCastException
pgovereau
parents: 23975
diff changeset
   506
                               "CONSTANT_NameAndType_info", i);
d8a1180faaa9 8038023: Compiler crash ClassCastException
pgovereau
parents: 23975
diff changeset
   507
        return (NameAndType)obj;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   508
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   509
06bc494ca11e Initial load
duke
parents:
diff changeset
   510
/************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
   511
 * Reading Types
06bc494ca11e Initial load
duke
parents:
diff changeset
   512
 ***********************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
   513
06bc494ca11e Initial load
duke
parents:
diff changeset
   514
    /** The unread portion of the currently read type is
06bc494ca11e Initial load
duke
parents:
diff changeset
   515
     *  signature[sigp..siglimit-1].
06bc494ca11e Initial load
duke
parents:
diff changeset
   516
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   517
    byte[] signature;
06bc494ca11e Initial load
duke
parents:
diff changeset
   518
    int sigp;
06bc494ca11e Initial load
duke
parents:
diff changeset
   519
    int siglimit;
06bc494ca11e Initial load
duke
parents:
diff changeset
   520
    boolean sigEnterPhase = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   521
06bc494ca11e Initial load
duke
parents:
diff changeset
   522
    /** Convert signature to type, where signature is a byte array segment.
06bc494ca11e Initial load
duke
parents:
diff changeset
   523
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   524
    Type sigToType(byte[] sig, int offset, int len) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   525
        signature = sig;
06bc494ca11e Initial load
duke
parents:
diff changeset
   526
        sigp = offset;
06bc494ca11e Initial load
duke
parents:
diff changeset
   527
        siglimit = offset + len;
06bc494ca11e Initial load
duke
parents:
diff changeset
   528
        return sigToType();
06bc494ca11e Initial load
duke
parents:
diff changeset
   529
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   530
06bc494ca11e Initial load
duke
parents:
diff changeset
   531
    /** Convert signature to type, where signature is implicit.
06bc494ca11e Initial load
duke
parents:
diff changeset
   532
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   533
    Type sigToType() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   534
        switch ((char) signature[sigp]) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   535
        case 'T':
06bc494ca11e Initial load
duke
parents:
diff changeset
   536
            sigp++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   537
            int start = sigp;
06bc494ca11e Initial load
duke
parents:
diff changeset
   538
            while (signature[sigp] != ';') sigp++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   539
            sigp++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   540
            return sigEnterPhase
06bc494ca11e Initial load
duke
parents:
diff changeset
   541
                ? Type.noType
06bc494ca11e Initial load
duke
parents:
diff changeset
   542
                : findTypeVar(names.fromUtf(signature, start, sigp - 1 - start));
06bc494ca11e Initial load
duke
parents:
diff changeset
   543
        case '+': {
06bc494ca11e Initial load
duke
parents:
diff changeset
   544
            sigp++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   545
            Type t = sigToType();
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24298
diff changeset
   546
            return new WildcardType(t, BoundKind.EXTENDS, syms.boundClass,
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24298
diff changeset
   547
                                    Type.noAnnotations);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   548
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   549
        case '*':
06bc494ca11e Initial load
duke
parents:
diff changeset
   550
            sigp++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   551
            return new WildcardType(syms.objectType, BoundKind.UNBOUND,
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24298
diff changeset
   552
                                    syms.boundClass, Type.noAnnotations);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   553
        case '-': {
06bc494ca11e Initial load
duke
parents:
diff changeset
   554
            sigp++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   555
            Type t = sigToType();
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24298
diff changeset
   556
            return new WildcardType(t, BoundKind.SUPER, syms.boundClass,
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24298
diff changeset
   557
                                    Type.noAnnotations);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   558
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   559
        case 'B':
06bc494ca11e Initial load
duke
parents:
diff changeset
   560
            sigp++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   561
            return syms.byteType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   562
        case 'C':
06bc494ca11e Initial load
duke
parents:
diff changeset
   563
            sigp++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   564
            return syms.charType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   565
        case 'D':
06bc494ca11e Initial load
duke
parents:
diff changeset
   566
            sigp++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   567
            return syms.doubleType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   568
        case 'F':
06bc494ca11e Initial load
duke
parents:
diff changeset
   569
            sigp++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   570
            return syms.floatType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   571
        case 'I':
06bc494ca11e Initial load
duke
parents:
diff changeset
   572
            sigp++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   573
            return syms.intType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   574
        case 'J':
06bc494ca11e Initial load
duke
parents:
diff changeset
   575
            sigp++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   576
            return syms.longType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   577
        case 'L':
06bc494ca11e Initial load
duke
parents:
diff changeset
   578
            {
06bc494ca11e Initial load
duke
parents:
diff changeset
   579
                // int oldsigp = sigp;
06bc494ca11e Initial load
duke
parents:
diff changeset
   580
                Type t = classSigToType();
06bc494ca11e Initial load
duke
parents:
diff changeset
   581
                if (sigp < siglimit && signature[sigp] == '.')
06bc494ca11e Initial load
duke
parents:
diff changeset
   582
                    throw badClassFile("deprecated inner class signature syntax " +
06bc494ca11e Initial load
duke
parents:
diff changeset
   583
                                       "(please recompile from source)");
06bc494ca11e Initial load
duke
parents:
diff changeset
   584
                /*
06bc494ca11e Initial load
duke
parents:
diff changeset
   585
                System.err.println(" decoded " +
06bc494ca11e Initial load
duke
parents:
diff changeset
   586
                                   new String(signature, oldsigp, sigp-oldsigp) +
06bc494ca11e Initial load
duke
parents:
diff changeset
   587
                                   " => " + t + " outer " + t.outer());
06bc494ca11e Initial load
duke
parents:
diff changeset
   588
                */
06bc494ca11e Initial load
duke
parents:
diff changeset
   589
                return t;
06bc494ca11e Initial load
duke
parents:
diff changeset
   590
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   591
        case 'S':
06bc494ca11e Initial load
duke
parents:
diff changeset
   592
            sigp++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   593
            return syms.shortType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   594
        case 'V':
06bc494ca11e Initial load
duke
parents:
diff changeset
   595
            sigp++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   596
            return syms.voidType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   597
        case 'Z':
06bc494ca11e Initial load
duke
parents:
diff changeset
   598
            sigp++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   599
            return syms.booleanType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   600
        case '[':
06bc494ca11e Initial load
duke
parents:
diff changeset
   601
            sigp++;
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24298
diff changeset
   602
            return new ArrayType(sigToType(), syms.arrayClass,
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24298
diff changeset
   603
                                 Type.noAnnotations);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   604
        case '(':
06bc494ca11e Initial load
duke
parents:
diff changeset
   605
            sigp++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   606
            List<Type> argtypes = sigToTypes(')');
06bc494ca11e Initial load
duke
parents:
diff changeset
   607
            Type restype = sigToType();
06bc494ca11e Initial load
duke
parents:
diff changeset
   608
            List<Type> thrown = List.nil();
06bc494ca11e Initial load
duke
parents:
diff changeset
   609
            while (signature[sigp] == '^') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   610
                sigp++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   611
                thrown = thrown.prepend(sigToType());
06bc494ca11e Initial load
duke
parents:
diff changeset
   612
            }
20242
11fa75a0b9fb 8024437: Inferring the exception thrown: sometimes fails to compile
vromero
parents: 19921
diff changeset
   613
            // if there is a typevar in the throws clause we should state it.
11fa75a0b9fb 8024437: Inferring the exception thrown: sometimes fails to compile
vromero
parents: 19921
diff changeset
   614
            for (List<Type> l = thrown; l.nonEmpty(); l = l.tail) {
11fa75a0b9fb 8024437: Inferring the exception thrown: sometimes fails to compile
vromero
parents: 19921
diff changeset
   615
                if (l.head.hasTag(TYPEVAR)) {
11fa75a0b9fb 8024437: Inferring the exception thrown: sometimes fails to compile
vromero
parents: 19921
diff changeset
   616
                    l.head.tsym.flags_field |= THROWS;
11fa75a0b9fb 8024437: Inferring the exception thrown: sometimes fails to compile
vromero
parents: 19921
diff changeset
   617
                }
11fa75a0b9fb 8024437: Inferring the exception thrown: sometimes fails to compile
vromero
parents: 19921
diff changeset
   618
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   619
            return new MethodType(argtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
   620
                                  restype,
06bc494ca11e Initial load
duke
parents:
diff changeset
   621
                                  thrown.reverse(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   622
                                  syms.methodClass);
06bc494ca11e Initial load
duke
parents:
diff changeset
   623
        case '<':
06bc494ca11e Initial load
duke
parents:
diff changeset
   624
            typevars = typevars.dup(currentOwner);
06bc494ca11e Initial load
duke
parents:
diff changeset
   625
            Type poly = new ForAll(sigToTypeParams(), sigToType());
06bc494ca11e Initial load
duke
parents:
diff changeset
   626
            typevars = typevars.leave();
06bc494ca11e Initial load
duke
parents:
diff changeset
   627
            return poly;
06bc494ca11e Initial load
duke
parents:
diff changeset
   628
        default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   629
            throw badClassFile("bad.signature",
06bc494ca11e Initial load
duke
parents:
diff changeset
   630
                               Convert.utf2string(signature, sigp, 10));
06bc494ca11e Initial load
duke
parents:
diff changeset
   631
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   632
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   633
06bc494ca11e Initial load
duke
parents:
diff changeset
   634
    byte[] signatureBuffer = new byte[0];
06bc494ca11e Initial load
duke
parents:
diff changeset
   635
    int sbp = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   636
    /** Convert class signature to type, where signature is implicit.
06bc494ca11e Initial load
duke
parents:
diff changeset
   637
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   638
    Type classSigToType() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   639
        if (signature[sigp] != 'L')
06bc494ca11e Initial load
duke
parents:
diff changeset
   640
            throw badClassFile("bad.class.signature",
06bc494ca11e Initial load
duke
parents:
diff changeset
   641
                               Convert.utf2string(signature, sigp, 10));
06bc494ca11e Initial load
duke
parents:
diff changeset
   642
        sigp++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   643
        Type outer = Type.noType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   644
        int startSbp = sbp;
06bc494ca11e Initial load
duke
parents:
diff changeset
   645
06bc494ca11e Initial load
duke
parents:
diff changeset
   646
        while (true) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   647
            final byte c = signature[sigp++];
06bc494ca11e Initial load
duke
parents:
diff changeset
   648
            switch (c) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   649
06bc494ca11e Initial load
duke
parents:
diff changeset
   650
            case ';': {         // end
22442
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22167
diff changeset
   651
                ClassSymbol t = syms.enterClass(names.fromUtf(signatureBuffer,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   652
                                                         startSbp,
06bc494ca11e Initial load
duke
parents:
diff changeset
   653
                                                         sbp - startSbp));
19915
8a6dae12e4bd 8022162: Incorrect signature determination for certain inner class generics
vromero
parents: 18389
diff changeset
   654
8a6dae12e4bd 8022162: Incorrect signature determination for certain inner class generics
vromero
parents: 18389
diff changeset
   655
                try {
8a6dae12e4bd 8022162: Incorrect signature determination for certain inner class generics
vromero
parents: 18389
diff changeset
   656
                    return (outer == Type.noType) ?
8a6dae12e4bd 8022162: Incorrect signature determination for certain inner class generics
vromero
parents: 18389
diff changeset
   657
                            t.erasure(types) :
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24298
diff changeset
   658
                        new ClassType(outer, List.<Type>nil(), t,
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24298
diff changeset
   659
                                      Type.noAnnotations);
19915
8a6dae12e4bd 8022162: Incorrect signature determination for certain inner class generics
vromero
parents: 18389
diff changeset
   660
                } finally {
8a6dae12e4bd 8022162: Incorrect signature determination for certain inner class generics
vromero
parents: 18389
diff changeset
   661
                    sbp = startSbp;
8a6dae12e4bd 8022162: Incorrect signature determination for certain inner class generics
vromero
parents: 18389
diff changeset
   662
                }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   663
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   664
06bc494ca11e Initial load
duke
parents:
diff changeset
   665
            case '<':           // generic arguments
22442
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22167
diff changeset
   666
                ClassSymbol t = syms.enterClass(names.fromUtf(signatureBuffer,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   667
                                                         startSbp,
06bc494ca11e Initial load
duke
parents:
diff changeset
   668
                                                         sbp - startSbp));
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24298
diff changeset
   669
                outer = new ClassType(outer, sigToTypes('>'), t,
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24298
diff changeset
   670
                                      Type.noAnnotations) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   671
                        boolean completed = false;
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   672
                        @Override @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   673
                        public Type getEnclosingType() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   674
                            if (!completed) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   675
                                completed = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   676
                                tsym.complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
   677
                                Type enclosingType = tsym.type.getEnclosingType();
06bc494ca11e Initial load
duke
parents:
diff changeset
   678
                                if (enclosingType != Type.noType) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   679
                                    List<Type> typeArgs =
06bc494ca11e Initial load
duke
parents:
diff changeset
   680
                                        super.getEnclosingType().allparams();
06bc494ca11e Initial load
duke
parents:
diff changeset
   681
                                    List<Type> typeParams =
06bc494ca11e Initial load
duke
parents:
diff changeset
   682
                                        enclosingType.allparams();
06bc494ca11e Initial load
duke
parents:
diff changeset
   683
                                    if (typeParams.length() != typeArgs.length()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   684
                                        // no "rare" types
06bc494ca11e Initial load
duke
parents:
diff changeset
   685
                                        super.setEnclosingType(types.erasure(enclosingType));
06bc494ca11e Initial load
duke
parents:
diff changeset
   686
                                    } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   687
                                        super.setEnclosingType(types.subst(enclosingType,
06bc494ca11e Initial load
duke
parents:
diff changeset
   688
                                                                           typeParams,
06bc494ca11e Initial load
duke
parents:
diff changeset
   689
                                                                           typeArgs));
06bc494ca11e Initial load
duke
parents:
diff changeset
   690
                                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   691
                                } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   692
                                    super.setEnclosingType(Type.noType);
06bc494ca11e Initial load
duke
parents:
diff changeset
   693
                                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   694
                            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   695
                            return super.getEnclosingType();
06bc494ca11e Initial load
duke
parents:
diff changeset
   696
                        }
2513
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   697
                        @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   698
                        public void setEnclosingType(Type outer) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   699
                            throw new UnsupportedOperationException();
06bc494ca11e Initial load
duke
parents:
diff changeset
   700
                        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   701
                    };
06bc494ca11e Initial load
duke
parents:
diff changeset
   702
                switch (signature[sigp++]) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   703
                case ';':
06bc494ca11e Initial load
duke
parents:
diff changeset
   704
                    if (sigp < signature.length && signature[sigp] == '.') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   705
                        // support old-style GJC signatures
06bc494ca11e Initial load
duke
parents:
diff changeset
   706
                        // The signature produced was
06bc494ca11e Initial load
duke
parents:
diff changeset
   707
                        // Lfoo/Outer<Lfoo/X;>;.Lfoo/Outer$Inner<Lfoo/Y;>;
06bc494ca11e Initial load
duke
parents:
diff changeset
   708
                        // rather than say
06bc494ca11e Initial load
duke
parents:
diff changeset
   709
                        // Lfoo/Outer<Lfoo/X;>.Inner<Lfoo/Y;>;
06bc494ca11e Initial load
duke
parents:
diff changeset
   710
                        // so we skip past ".Lfoo/Outer$"
06bc494ca11e Initial load
duke
parents:
diff changeset
   711
                        sigp += (sbp - startSbp) + // "foo/Outer"
06bc494ca11e Initial load
duke
parents:
diff changeset
   712
                            3;  // ".L" and "$"
06bc494ca11e Initial load
duke
parents:
diff changeset
   713
                        signatureBuffer[sbp++] = (byte)'$';
06bc494ca11e Initial load
duke
parents:
diff changeset
   714
                        break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   715
                    } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   716
                        sbp = startSbp;
06bc494ca11e Initial load
duke
parents:
diff changeset
   717
                        return outer;
06bc494ca11e Initial load
duke
parents:
diff changeset
   718
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   719
                case '.':
06bc494ca11e Initial load
duke
parents:
diff changeset
   720
                    signatureBuffer[sbp++] = (byte)'$';
06bc494ca11e Initial load
duke
parents:
diff changeset
   721
                    break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   722
                default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   723
                    throw new AssertionError(signature[sigp-1]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   724
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   725
                continue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   726
06bc494ca11e Initial load
duke
parents:
diff changeset
   727
            case '.':
19915
8a6dae12e4bd 8022162: Incorrect signature determination for certain inner class generics
vromero
parents: 18389
diff changeset
   728
                //we have seen an enclosing non-generic class
8a6dae12e4bd 8022162: Incorrect signature determination for certain inner class generics
vromero
parents: 18389
diff changeset
   729
                if (outer != Type.noType) {
22442
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22167
diff changeset
   730
                    t = syms.enterClass(names.fromUtf(signatureBuffer,
19915
8a6dae12e4bd 8022162: Incorrect signature determination for certain inner class generics
vromero
parents: 18389
diff changeset
   731
                                                 startSbp,
8a6dae12e4bd 8022162: Incorrect signature determination for certain inner class generics
vromero
parents: 18389
diff changeset
   732
                                                 sbp - startSbp));
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24298
diff changeset
   733
                    outer = new ClassType(outer, List.<Type>nil(), t,
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24298
diff changeset
   734
                                          Type.noAnnotations);
19915
8a6dae12e4bd 8022162: Incorrect signature determination for certain inner class generics
vromero
parents: 18389
diff changeset
   735
                }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   736
                signatureBuffer[sbp++] = (byte)'$';
06bc494ca11e Initial load
duke
parents:
diff changeset
   737
                continue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   738
            case '/':
06bc494ca11e Initial load
duke
parents:
diff changeset
   739
                signatureBuffer[sbp++] = (byte)'.';
06bc494ca11e Initial load
duke
parents:
diff changeset
   740
                continue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   741
            default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   742
                signatureBuffer[sbp++] = c;
06bc494ca11e Initial load
duke
parents:
diff changeset
   743
                continue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   744
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   745
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   746
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   747
06bc494ca11e Initial load
duke
parents:
diff changeset
   748
    /** Convert (implicit) signature to list of types
06bc494ca11e Initial load
duke
parents:
diff changeset
   749
     *  until `terminator' is encountered.
06bc494ca11e Initial load
duke
parents:
diff changeset
   750
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   751
    List<Type> sigToTypes(char terminator) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   752
        List<Type> head = List.of(null);
06bc494ca11e Initial load
duke
parents:
diff changeset
   753
        List<Type> tail = head;
06bc494ca11e Initial load
duke
parents:
diff changeset
   754
        while (signature[sigp] != terminator)
06bc494ca11e Initial load
duke
parents:
diff changeset
   755
            tail = tail.setTail(List.of(sigToType()));
06bc494ca11e Initial load
duke
parents:
diff changeset
   756
        sigp++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   757
        return head.tail;
06bc494ca11e Initial load
duke
parents:
diff changeset
   758
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   759
06bc494ca11e Initial load
duke
parents:
diff changeset
   760
    /** Convert signature to type parameters, where signature is a byte
06bc494ca11e Initial load
duke
parents:
diff changeset
   761
     *  array segment.
06bc494ca11e Initial load
duke
parents:
diff changeset
   762
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   763
    List<Type> sigToTypeParams(byte[] sig, int offset, int len) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   764
        signature = sig;
06bc494ca11e Initial load
duke
parents:
diff changeset
   765
        sigp = offset;
06bc494ca11e Initial load
duke
parents:
diff changeset
   766
        siglimit = offset + len;
06bc494ca11e Initial load
duke
parents:
diff changeset
   767
        return sigToTypeParams();
06bc494ca11e Initial load
duke
parents:
diff changeset
   768
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   769
06bc494ca11e Initial load
duke
parents:
diff changeset
   770
    /** Convert signature to type parameters, where signature is implicit.
06bc494ca11e Initial load
duke
parents:
diff changeset
   771
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   772
    List<Type> sigToTypeParams() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   773
        List<Type> tvars = List.nil();
06bc494ca11e Initial load
duke
parents:
diff changeset
   774
        if (signature[sigp] == '<') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   775
            sigp++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   776
            int start = sigp;
06bc494ca11e Initial load
duke
parents:
diff changeset
   777
            sigEnterPhase = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   778
            while (signature[sigp] != '>')
06bc494ca11e Initial load
duke
parents:
diff changeset
   779
                tvars = tvars.prepend(sigToTypeParam());
06bc494ca11e Initial load
duke
parents:
diff changeset
   780
            sigEnterPhase = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   781
            sigp = start;
06bc494ca11e Initial load
duke
parents:
diff changeset
   782
            while (signature[sigp] != '>')
06bc494ca11e Initial load
duke
parents:
diff changeset
   783
                sigToTypeParam();
06bc494ca11e Initial load
duke
parents:
diff changeset
   784
            sigp++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   785
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   786
        return tvars.reverse();
06bc494ca11e Initial load
duke
parents:
diff changeset
   787
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   788
06bc494ca11e Initial load
duke
parents:
diff changeset
   789
    /** Convert (implicit) signature to type parameter.
06bc494ca11e Initial load
duke
parents:
diff changeset
   790
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   791
    Type sigToTypeParam() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   792
        int start = sigp;
06bc494ca11e Initial load
duke
parents:
diff changeset
   793
        while (signature[sigp] != ':') sigp++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   794
        Name name = names.fromUtf(signature, start, sigp - start);
06bc494ca11e Initial load
duke
parents:
diff changeset
   795
        TypeVar tvar;
06bc494ca11e Initial load
duke
parents:
diff changeset
   796
        if (sigEnterPhase) {
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24298
diff changeset
   797
            tvar = new TypeVar(name, currentOwner, syms.botType,
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24298
diff changeset
   798
                               Type.noAnnotations);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   799
            typevars.enter(tvar.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   800
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   801
            tvar = (TypeVar)findTypeVar(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   802
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   803
        List<Type> bounds = List.nil();
14725
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14547
diff changeset
   804
        boolean allInterfaces = false;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   805
        if (signature[sigp] == ':' && signature[sigp+1] == ':') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   806
            sigp++;
14725
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14547
diff changeset
   807
            allInterfaces = true;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   808
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   809
        while (signature[sigp] == ':') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   810
            sigp++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   811
            bounds = bounds.prepend(sigToType());
06bc494ca11e Initial load
duke
parents:
diff changeset
   812
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   813
        if (!sigEnterPhase) {
14725
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14547
diff changeset
   814
            types.setBounds(tvar, bounds.reverse(), allInterfaces);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   815
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   816
        return tvar;
06bc494ca11e Initial load
duke
parents:
diff changeset
   817
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   818
06bc494ca11e Initial load
duke
parents:
diff changeset
   819
    /** Find type variable with given name in `typevars' scope.
06bc494ca11e Initial load
duke
parents:
diff changeset
   820
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   821
    Type findTypeVar(Name name) {
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 24895
diff changeset
   822
        Symbol s = typevars.findFirst(name);
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 24895
diff changeset
   823
        if (s != null) {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 24895
diff changeset
   824
            return s.type;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   825
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   826
            if (readingClassAttr) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   827
                // While reading the class attribute, the supertypes
06bc494ca11e Initial load
duke
parents:
diff changeset
   828
                // might refer to a type variable from an enclosing element
06bc494ca11e Initial load
duke
parents:
diff changeset
   829
                // (method or class).
06bc494ca11e Initial load
duke
parents:
diff changeset
   830
                // If the type variable is defined in the enclosing class,
06bc494ca11e Initial load
duke
parents:
diff changeset
   831
                // we can actually find it in
06bc494ca11e Initial load
duke
parents:
diff changeset
   832
                // currentOwner.owner.type.getTypeArguments()
06bc494ca11e Initial load
duke
parents:
diff changeset
   833
                // However, until we have read the enclosing method attribute
06bc494ca11e Initial load
duke
parents:
diff changeset
   834
                // we don't know for sure if this owner is correct.  It could
06bc494ca11e Initial load
duke
parents:
diff changeset
   835
                // be a method and there is no way to tell before reading the
06bc494ca11e Initial load
duke
parents:
diff changeset
   836
                // enclosing method attribute.
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24298
diff changeset
   837
                TypeVar t = new TypeVar(name, currentOwner, syms.botType,
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24298
diff changeset
   838
                                        Type.noAnnotations);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   839
                missingTypeVariables = missingTypeVariables.prepend(t);
06bc494ca11e Initial load
duke
parents:
diff changeset
   840
                // System.err.println("Missing type var " + name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   841
                return t;
06bc494ca11e Initial load
duke
parents:
diff changeset
   842
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   843
            throw badClassFile("undecl.type.var", name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   844
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   845
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   846
06bc494ca11e Initial load
duke
parents:
diff changeset
   847
/************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
   848
 * Reading Attributes
06bc494ca11e Initial load
duke
parents:
diff changeset
   849
 ***********************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
   850
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21043
diff changeset
   851
    protected enum AttributeKind { CLASS, MEMBER }
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21043
diff changeset
   852
2513
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   853
    protected abstract class AttributeReader {
13635
5c742eabba7c 7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents: 12335
diff changeset
   854
        protected AttributeReader(Name name, ClassFile.Version version, Set<AttributeKind> kinds) {
2513
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   855
            this.name = name;
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   856
            this.version = version;
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   857
            this.kinds = kinds;
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   858
        }
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   859
13635
5c742eabba7c 7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents: 12335
diff changeset
   860
        protected boolean accepts(AttributeKind kind) {
7624
c31b0ea95b37 6999210: javac should be able to warn of anomalous conditions in classfiles
jjg
parents: 7330
diff changeset
   861
            if (kinds.contains(kind)) {
c31b0ea95b37 6999210: javac should be able to warn of anomalous conditions in classfiles
jjg
parents: 7330
diff changeset
   862
                if (majorVersion > version.major || (majorVersion == version.major && minorVersion >= version.minor))
c31b0ea95b37 6999210: javac should be able to warn of anomalous conditions in classfiles
jjg
parents: 7330
diff changeset
   863
                    return true;
c31b0ea95b37 6999210: javac should be able to warn of anomalous conditions in classfiles
jjg
parents: 7330
diff changeset
   864
c31b0ea95b37 6999210: javac should be able to warn of anomalous conditions in classfiles
jjg
parents: 7330
diff changeset
   865
                if (lintClassfile && !warnedAttrs.contains(name)) {
c31b0ea95b37 6999210: javac should be able to warn of anomalous conditions in classfiles
jjg
parents: 7330
diff changeset
   866
                    JavaFileObject prev = log.useSource(currentClassFile);
c31b0ea95b37 6999210: javac should be able to warn of anomalous conditions in classfiles
jjg
parents: 7330
diff changeset
   867
                    try {
c31b0ea95b37 6999210: javac should be able to warn of anomalous conditions in classfiles
jjg
parents: 7330
diff changeset
   868
                        log.warning(LintCategory.CLASSFILE, (DiagnosticPosition) null, "future.attr",
c31b0ea95b37 6999210: javac should be able to warn of anomalous conditions in classfiles
jjg
parents: 7330
diff changeset
   869
                                name, version.major, version.minor, majorVersion, minorVersion);
c31b0ea95b37 6999210: javac should be able to warn of anomalous conditions in classfiles
jjg
parents: 7330
diff changeset
   870
                    } finally {
c31b0ea95b37 6999210: javac should be able to warn of anomalous conditions in classfiles
jjg
parents: 7330
diff changeset
   871
                        log.useSource(prev);
c31b0ea95b37 6999210: javac should be able to warn of anomalous conditions in classfiles
jjg
parents: 7330
diff changeset
   872
                    }
c31b0ea95b37 6999210: javac should be able to warn of anomalous conditions in classfiles
jjg
parents: 7330
diff changeset
   873
                    warnedAttrs.add(name);
c31b0ea95b37 6999210: javac should be able to warn of anomalous conditions in classfiles
jjg
parents: 7330
diff changeset
   874
                }
c31b0ea95b37 6999210: javac should be able to warn of anomalous conditions in classfiles
jjg
parents: 7330
diff changeset
   875
            }
c31b0ea95b37 6999210: javac should be able to warn of anomalous conditions in classfiles
jjg
parents: 7330
diff changeset
   876
            return false;
2513
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   877
        }
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   878
13635
5c742eabba7c 7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents: 12335
diff changeset
   879
        protected abstract void read(Symbol sym, int attrLen);
2513
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   880
13635
5c742eabba7c 7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents: 12335
diff changeset
   881
        protected final Name name;
5c742eabba7c 7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents: 12335
diff changeset
   882
        protected final ClassFile.Version version;
5c742eabba7c 7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents: 12335
diff changeset
   883
        protected final Set<AttributeKind> kinds;
2513
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   884
    }
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   885
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   886
    protected Set<AttributeKind> CLASS_ATTRIBUTE =
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   887
            EnumSet.of(AttributeKind.CLASS);
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   888
    protected Set<AttributeKind> MEMBER_ATTRIBUTE =
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   889
            EnumSet.of(AttributeKind.MEMBER);
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   890
    protected Set<AttributeKind> CLASS_OR_MEMBER_ATTRIBUTE =
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   891
            EnumSet.of(AttributeKind.CLASS, AttributeKind.MEMBER);
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   892
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21043
diff changeset
   893
    protected Map<Name, AttributeReader> attributeReaders = new HashMap<>();
2513
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   894
7624
c31b0ea95b37 6999210: javac should be able to warn of anomalous conditions in classfiles
jjg
parents: 7330
diff changeset
   895
    private void initAttributeReaders() {
2513
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   896
        AttributeReader[] readers = {
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   897
            // v45.3 attributes
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   898
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   899
            new AttributeReader(names.Code, V45_3, MEMBER_ATTRIBUTE) {
13635
5c742eabba7c 7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents: 12335
diff changeset
   900
                protected void read(Symbol sym, int attrLen) {
2513
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   901
                    if (readAllOfClassFile || saveParameterNames)
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   902
                        ((MethodSymbol)sym).code = readCode(sym);
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   903
                    else
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   904
                        bp = bp + attrLen;
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   905
                }
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   906
            },
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   907
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   908
            new AttributeReader(names.ConstantValue, V45_3, MEMBER_ATTRIBUTE) {
13635
5c742eabba7c 7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents: 12335
diff changeset
   909
                protected void read(Symbol sym, int attrLen) {
2513
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   910
                    Object v = readPool(nextChar());
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   911
                    // Ignore ConstantValue attribute if field not final.
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   912
                    if ((sym.flags() & FINAL) != 0)
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   913
                        ((VarSymbol) sym).setData(v);
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   914
                }
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   915
            },
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   916
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   917
            new AttributeReader(names.Deprecated, V45_3, CLASS_OR_MEMBER_ATTRIBUTE) {
13635
5c742eabba7c 7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents: 12335
diff changeset
   918
                protected void read(Symbol sym, int attrLen) {
2513
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   919
                    sym.flags_field |= DEPRECATED;
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   920
                }
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   921
            },
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   922
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   923
            new AttributeReader(names.Exceptions, V45_3, CLASS_OR_MEMBER_ATTRIBUTE) {
13635
5c742eabba7c 7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents: 12335
diff changeset
   924
                protected void read(Symbol sym, int attrLen) {
2513
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   925
                    int nexceptions = nextChar();
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   926
                    List<Type> thrown = List.nil();
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   927
                    for (int j = 0; j < nexceptions; j++)
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   928
                        thrown = thrown.prepend(readClassSymbol(nextChar()).type);
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   929
                    if (sym.type.getThrownTypes().isEmpty())
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   930
                        sym.type.asMethodType().thrown = thrown.reverse();
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   931
                }
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   932
            },
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   933
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   934
            new AttributeReader(names.InnerClasses, V45_3, CLASS_ATTRIBUTE) {
13635
5c742eabba7c 7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents: 12335
diff changeset
   935
                protected void read(Symbol sym, int attrLen) {
2513
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   936
                    ClassSymbol c = (ClassSymbol) sym;
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   937
                    readInnerClasses(c);
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   938
                }
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   939
            },
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   940
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   941
            new AttributeReader(names.LocalVariableTable, V45_3, CLASS_OR_MEMBER_ATTRIBUTE) {
13635
5c742eabba7c 7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents: 12335
diff changeset
   942
                protected void read(Symbol sym, int attrLen) {
2513
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   943
                    int newbp = bp + attrLen;
15031
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14949
diff changeset
   944
                    if (saveParameterNames && !sawMethodParameters) {
4077
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
   945
                        // Pick up parameter names from the variable table.
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
   946
                        // Parameter names are not explicitly identified as such,
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
   947
                        // but all parameter name entries in the LocalVariableTable
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
   948
                        // have a start_pc of 0.  Therefore, we record the name
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
   949
                        // indicies of all slots with a start_pc of zero in the
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
   950
                        // parameterNameIndicies array.
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
   951
                        // Note that this implicitly honors the JVMS spec that
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
   952
                        // there may be more than one LocalVariableTable, and that
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
   953
                        // there is no specified ordering for the entries.
2513
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   954
                        int numEntries = nextChar();
4077
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
   955
                        for (int i = 0; i < numEntries; i++) {
2513
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   956
                            int start_pc = nextChar();
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   957
                            int length = nextChar();
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   958
                            int nameIndex = nextChar();
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   959
                            int sigIndex = nextChar();
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   960
                            int register = nextChar();
4077
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
   961
                            if (start_pc == 0) {
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
   962
                                // ensure array large enough
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
   963
                                if (register >= parameterNameIndices.length) {
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
   964
                                    int newSize = Math.max(register, parameterNameIndices.length + 8);
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
   965
                                    parameterNameIndices =
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
   966
                                            Arrays.copyOf(parameterNameIndices, newSize);
2513
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   967
                                }
4077
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
   968
                                parameterNameIndices[register] = nameIndex;
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
   969
                                haveParameterNameIndices = true;
2513
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   970
                            }
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   971
                        }
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   972
                    }
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   973
                    bp = newbp;
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   974
                }
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   975
            },
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   976
15031
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14949
diff changeset
   977
            new AttributeReader(names.MethodParameters, V52, MEMBER_ATTRIBUTE) {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14949
diff changeset
   978
                protected void read(Symbol sym, int attrlen) {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14949
diff changeset
   979
                    int newbp = bp + attrlen;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14949
diff changeset
   980
                    if (saveParameterNames) {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14949
diff changeset
   981
                        sawMethodParameters = true;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14949
diff changeset
   982
                        int numEntries = nextByte();
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14949
diff changeset
   983
                        parameterNameIndices = new int[numEntries];
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14949
diff changeset
   984
                        haveParameterNameIndices = true;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14949
diff changeset
   985
                        for (int i = 0; i < numEntries; i++) {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14949
diff changeset
   986
                            int nameIndex = nextChar();
16305
ee7f13d9d434 8006948: Update javac for MethodParameters format change
ksrini
parents: 16300
diff changeset
   987
                            int flags = nextChar();
15031
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14949
diff changeset
   988
                            parameterNameIndices[i] = nameIndex;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14949
diff changeset
   989
                        }
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14949
diff changeset
   990
                    }
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14949
diff changeset
   991
                    bp = newbp;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14949
diff changeset
   992
                }
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14949
diff changeset
   993
            },
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14949
diff changeset
   994
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14949
diff changeset
   995
2513
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   996
            new AttributeReader(names.SourceFile, V45_3, CLASS_ATTRIBUTE) {
13635
5c742eabba7c 7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents: 12335
diff changeset
   997
                protected void read(Symbol sym, int attrLen) {
2513
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   998
                    ClassSymbol c = (ClassSymbol) sym;
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
   999
                    Name n = readName(nextChar());
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1000
                    c.sourcefile = new SourceFileObject(n, c.flatname);
14369
3d660d08d1f7 7153951: Add new lint option -Xlint:auxiliaryclass
ohrstrom
parents: 14359
diff changeset
  1001
                    // If the class is a toplevel class, originating from a Java source file,
3d660d08d1f7 7153951: Add new lint option -Xlint:auxiliaryclass
ohrstrom
parents: 14359
diff changeset
  1002
                    // but the class name does not match the file name, then it is
3d660d08d1f7 7153951: Add new lint option -Xlint:auxiliaryclass
ohrstrom
parents: 14359
diff changeset
  1003
                    // an auxiliary class.
3d660d08d1f7 7153951: Add new lint option -Xlint:auxiliaryclass
ohrstrom
parents: 14359
diff changeset
  1004
                    String sn = n.toString();
3d660d08d1f7 7153951: Add new lint option -Xlint:auxiliaryclass
ohrstrom
parents: 14359
diff changeset
  1005
                    if (c.owner.kind == Kinds.PCK &&
3d660d08d1f7 7153951: Add new lint option -Xlint:auxiliaryclass
ohrstrom
parents: 14359
diff changeset
  1006
                        sn.endsWith(".java") &&
3d660d08d1f7 7153951: Add new lint option -Xlint:auxiliaryclass
ohrstrom
parents: 14359
diff changeset
  1007
                        !sn.equals(c.name.toString()+".java")) {
3d660d08d1f7 7153951: Add new lint option -Xlint:auxiliaryclass
ohrstrom
parents: 14359
diff changeset
  1008
                        c.flags_field |= AUXILIARY;
3d660d08d1f7 7153951: Add new lint option -Xlint:auxiliaryclass
ohrstrom
parents: 14359
diff changeset
  1009
                    }
2513
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1010
                }
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1011
            },
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1012
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1013
            new AttributeReader(names.Synthetic, V45_3, CLASS_OR_MEMBER_ATTRIBUTE) {
13635
5c742eabba7c 7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents: 12335
diff changeset
  1014
                protected void read(Symbol sym, int attrLen) {
25445
603f0c93d5c9 8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents: 25443
diff changeset
  1015
                    sym.flags_field |= SYNTHETIC;
2513
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1016
                }
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1017
            },
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1018
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1019
            // standard v49 attributes
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1020
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1021
            new AttributeReader(names.EnclosingMethod, V49, CLASS_ATTRIBUTE) {
13635
5c742eabba7c 7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents: 12335
diff changeset
  1022
                protected void read(Symbol sym, int attrLen) {
2513
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1023
                    int newbp = bp + attrLen;
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1024
                    readEnclosingMethodAttr(sym);
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1025
                    bp = newbp;
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1026
                }
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1027
            },
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1028
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1029
            new AttributeReader(names.Signature, V49, CLASS_OR_MEMBER_ATTRIBUTE) {
13635
5c742eabba7c 7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents: 12335
diff changeset
  1030
                protected void read(Symbol sym, int attrLen) {
2513
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1031
                    if (sym.kind == TYP) {
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1032
                        ClassSymbol c = (ClassSymbol) sym;
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1033
                        readingClassAttr = true;
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1034
                        try {
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1035
                            ClassType ct1 = (ClassType)c.type;
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 8031
diff changeset
  1036
                            Assert.check(c == currentOwner);
2513
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1037
                            ct1.typarams_field = readTypeParams(nextChar());
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1038
                            ct1.supertype_field = sigToType();
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21043
diff changeset
  1039
                            ListBuffer<Type> is = new ListBuffer<>();
2513
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1040
                            while (sigp != siglimit) is.append(sigToType());
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1041
                            ct1.interfaces_field = is.toList();
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1042
                        } finally {
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1043
                            readingClassAttr = false;
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1044
                        }
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1045
                    } else {
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1046
                        List<Type> thrown = sym.type.getThrownTypes();
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1047
                        sym.type = readType(nextChar());
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1048
                        //- System.err.println(" # " + sym.type);
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1049
                        if (sym.kind == MTH && sym.type.getThrownTypes().isEmpty())
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1050
                            sym.type.asMethodType().thrown = thrown;
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1051
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1052
                    }
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1053
                }
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1054
            },
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1055
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1056
            // v49 annotation attributes
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1057
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1058
            new AttributeReader(names.AnnotationDefault, V49, CLASS_OR_MEMBER_ATTRIBUTE) {
13635
5c742eabba7c 7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents: 12335
diff changeset
  1059
                protected void read(Symbol sym, int attrLen) {
2513
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1060
                    attachAnnotationDefault(sym);
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1061
                }
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1062
            },
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1063
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1064
            new AttributeReader(names.RuntimeInvisibleAnnotations, V49, CLASS_OR_MEMBER_ATTRIBUTE) {
13635
5c742eabba7c 7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents: 12335
diff changeset
  1065
                protected void read(Symbol sym, int attrLen) {
2513
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1066
                    attachAnnotations(sym);
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1067
                }
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1068
            },
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1069
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1070
            new AttributeReader(names.RuntimeInvisibleParameterAnnotations, V49, CLASS_OR_MEMBER_ATTRIBUTE) {
13635
5c742eabba7c 7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents: 12335
diff changeset
  1071
                protected void read(Symbol sym, int attrLen) {
2513
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1072
                    attachParameterAnnotations(sym);
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1073
                }
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1074
            },
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1075
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1076
            new AttributeReader(names.RuntimeVisibleAnnotations, V49, CLASS_OR_MEMBER_ATTRIBUTE) {
13635
5c742eabba7c 7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents: 12335
diff changeset
  1077
                protected void read(Symbol sym, int attrLen) {
2513
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1078
                    attachAnnotations(sym);
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1079
                }
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1080
            },
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1081
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1082
            new AttributeReader(names.RuntimeVisibleParameterAnnotations, V49, CLASS_OR_MEMBER_ATTRIBUTE) {
13635
5c742eabba7c 7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents: 12335
diff changeset
  1083
                protected void read(Symbol sym, int attrLen) {
2513
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1084
                    attachParameterAnnotations(sym);
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1085
                }
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1086
            },
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1087
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1088
            // additional "legacy" v49 attributes, superceded by flags
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1089
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1090
            new AttributeReader(names.Annotation, V49, CLASS_OR_MEMBER_ATTRIBUTE) {
13635
5c742eabba7c 7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents: 12335
diff changeset
  1091
                protected void read(Symbol sym, int attrLen) {
25445
603f0c93d5c9 8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents: 25443
diff changeset
  1092
                    sym.flags_field |= ANNOTATION;
2513
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1093
                }
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1094
            },
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1095
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1096
            new AttributeReader(names.Bridge, V49, MEMBER_ATTRIBUTE) {
13635
5c742eabba7c 7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents: 12335
diff changeset
  1097
                protected void read(Symbol sym, int attrLen) {
2513
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1098
                    sym.flags_field |= BRIDGE;
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1099
                }
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1100
            },
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1101
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1102
            new AttributeReader(names.Enum, V49, CLASS_OR_MEMBER_ATTRIBUTE) {
13635
5c742eabba7c 7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents: 12335
diff changeset
  1103
                protected void read(Symbol sym, int attrLen) {
2513
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1104
                    sym.flags_field |= ENUM;
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1105
                }
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1106
            },
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1107
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1108
            new AttributeReader(names.Varargs, V49, CLASS_OR_MEMBER_ATTRIBUTE) {
13635
5c742eabba7c 7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents: 12335
diff changeset
  1109
                protected void read(Symbol sym, int attrLen) {
25445
603f0c93d5c9 8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents: 25443
diff changeset
  1110
                    sym.flags_field |= VARARGS;
2513
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1111
                }
3149
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 2723
diff changeset
  1112
            },
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 2723
diff changeset
  1113
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1114
            new AttributeReader(names.RuntimeVisibleTypeAnnotations, V52, CLASS_OR_MEMBER_ATTRIBUTE) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1115
                protected void read(Symbol sym, int attrLen) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1116
                    attachTypeAnnotations(sym);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1117
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1118
            },
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1119
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1120
            new AttributeReader(names.RuntimeInvisibleTypeAnnotations, V52, CLASS_OR_MEMBER_ATTRIBUTE) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1121
                protected void read(Symbol sym, int attrLen) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1122
                    attachTypeAnnotations(sym);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1123
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1124
            },
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1125
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1126
2513
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1127
            // The following attributes for a Code attribute are not currently handled
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1128
            // StackMapTable
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1129
            // SourceDebugExtension
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1130
            // LineNumberTable
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1131
            // LocalVariableTypeTable
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1132
        };
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1133
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1134
        for (AttributeReader r: readers)
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1135
            attributeReaders.put(r.name, r);
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1136
    }
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1137
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1138
    /** Report unrecognized attribute.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1139
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1140
    void unrecognized(Name attrName) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1141
        if (checkClassFile)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1142
            printCCF("ccf.unrecognized.attribute", attrName);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1143
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1144
2513
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1145
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1146
13635
5c742eabba7c 7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents: 12335
diff changeset
  1147
    protected void readEnclosingMethodAttr(Symbol sym) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1148
        // sym is a nested class with an "Enclosing Method" attribute
06bc494ca11e Initial load
duke
parents:
diff changeset
  1149
        // remove sym from it's current owners scope and place it in
06bc494ca11e Initial load
duke
parents:
diff changeset
  1150
        // the scope specified by the attribute
06bc494ca11e Initial load
duke
parents:
diff changeset
  1151
        sym.owner.members().remove(sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1152
        ClassSymbol self = (ClassSymbol)sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1153
        ClassSymbol c = readClassSymbol(nextChar());
24068
d8a1180faaa9 8038023: Compiler crash ClassCastException
pgovereau
parents: 23975
diff changeset
  1154
        NameAndType nt = readNameAndType(nextChar());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1155
9077
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents: 8630
diff changeset
  1156
        if (c.members_field == null)
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents: 8630
diff changeset
  1157
            throw badClassFile("bad.enclosing.class", self, c);
6ee59e40b258 7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents: 8630
diff changeset
  1158
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1159
        MethodSymbol m = findMethod(nt, c.members_field, self.flags());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1160
        if (nt != null && m == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1161
            throw badClassFile("bad.enclosing.method", self);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1162
06bc494ca11e Initial load
duke
parents:
diff changeset
  1163
        self.name = simpleBinaryName(self.flatname, c.flatname) ;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1164
        self.owner = m != null ? m : c;
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 939
diff changeset
  1165
        if (self.name.isEmpty())
5012
405341b6e9c5 6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents: 4872
diff changeset
  1166
            self.fullname = names.empty;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1167
        else
06bc494ca11e Initial load
duke
parents:
diff changeset
  1168
            self.fullname = ClassSymbol.formFullName(self.name, self.owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1169
06bc494ca11e Initial load
duke
parents:
diff changeset
  1170
        if (m != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1171
            ((ClassType)sym.type).setEnclosingType(m.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1172
        } else if ((self.flags_field & STATIC) == 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1173
            ((ClassType)sym.type).setEnclosingType(c.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1174
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1175
            ((ClassType)sym.type).setEnclosingType(Type.noType);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1176
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1177
        enterTypevars(self);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1178
        if (!missingTypeVariables.isEmpty()) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21043
diff changeset
  1179
            ListBuffer<Type> typeVars =  new ListBuffer<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1180
            for (Type typevar : missingTypeVariables) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1181
                typeVars.append(findTypeVar(typevar.tsym.name));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1182
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1183
            foundTypeVariables = typeVars.toList();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1184
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1185
            foundTypeVariables = List.nil();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1186
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1187
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1188
06bc494ca11e Initial load
duke
parents:
diff changeset
  1189
    // See java.lang.Class
06bc494ca11e Initial load
duke
parents:
diff changeset
  1190
    private Name simpleBinaryName(Name self, Name enclosing) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1191
        String simpleBinaryName = self.toString().substring(enclosing.toString().length());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1192
        if (simpleBinaryName.length() < 1 || simpleBinaryName.charAt(0) != '$')
06bc494ca11e Initial load
duke
parents:
diff changeset
  1193
            throw badClassFile("bad.enclosing.method", self);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1194
        int index = 1;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1195
        while (index < simpleBinaryName.length() &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1196
               isAsciiDigit(simpleBinaryName.charAt(index)))
06bc494ca11e Initial load
duke
parents:
diff changeset
  1197
            index++;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1198
        return names.fromString(simpleBinaryName.substring(index));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1199
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1200
06bc494ca11e Initial load
duke
parents:
diff changeset
  1201
    private MethodSymbol findMethod(NameAndType nt, Scope scope, long flags) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1202
        if (nt == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1203
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1204
14949
45f43822bbde 8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents: 14804
diff changeset
  1205
        MethodType type = nt.uniqueType.type.asMethodType();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1206
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 24895
diff changeset
  1207
        for (Symbol sym : scope.getSymbolsByName(nt.name)) {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 24895
diff changeset
  1208
            if (sym.kind == MTH && isSameBinaryType(sym.type.asMethodType(), type))
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 24895
diff changeset
  1209
                return (MethodSymbol)sym;
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 24895
diff changeset
  1210
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1211
06bc494ca11e Initial load
duke
parents:
diff changeset
  1212
        if (nt.name != names.init)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1213
            // not a constructor
06bc494ca11e Initial load
duke
parents:
diff changeset
  1214
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1215
        if ((flags & INTERFACE) != 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1216
            // no enclosing instance
06bc494ca11e Initial load
duke
parents:
diff changeset
  1217
            return null;
14949
45f43822bbde 8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents: 14804
diff changeset
  1218
        if (nt.uniqueType.type.getParameterTypes().isEmpty())
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1219
            // no parameters
06bc494ca11e Initial load
duke
parents:
diff changeset
  1220
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1221
06bc494ca11e Initial load
duke
parents:
diff changeset
  1222
        // A constructor of an inner class.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1223
        // Remove the first argument (the enclosing instance)
14949
45f43822bbde 8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents: 14804
diff changeset
  1224
        nt.setType(new MethodType(nt.uniqueType.type.getParameterTypes().tail,
45f43822bbde 8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents: 14804
diff changeset
  1225
                                 nt.uniqueType.type.getReturnType(),
45f43822bbde 8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents: 14804
diff changeset
  1226
                                 nt.uniqueType.type.getThrownTypes(),
45f43822bbde 8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents: 14804
diff changeset
  1227
                                 syms.methodClass));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1228
        // Try searching again
06bc494ca11e Initial load
duke
parents:
diff changeset
  1229
        return findMethod(nt, scope, flags);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1230
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1231
06bc494ca11e Initial load
duke
parents:
diff changeset
  1232
    /** Similar to Types.isSameType but avoids completion */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1233
    private boolean isSameBinaryType(MethodType mt1, MethodType mt2) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1234
        List<Type> types1 = types.erasure(mt1.getParameterTypes())
06bc494ca11e Initial load
duke
parents:
diff changeset
  1235
            .prepend(types.erasure(mt1.getReturnType()));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1236
        List<Type> types2 = mt2.getParameterTypes().prepend(mt2.getReturnType());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1237
        while (!types1.isEmpty() && !types2.isEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1238
            if (types1.head.tsym != types2.head.tsym)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1239
                return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1240
            types1 = types1.tail;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1241
            types2 = types2.tail;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1242
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1243
        return types1.isEmpty() && types2.isEmpty();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1244
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1245
06bc494ca11e Initial load
duke
parents:
diff changeset
  1246
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  1247
     * Character.isDigit answers <tt>true</tt> to some non-ascii
06bc494ca11e Initial load
duke
parents:
diff changeset
  1248
     * digits.  This one does not.  <b>copied from java.lang.Class</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
  1249
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1250
    private static boolean isAsciiDigit(char c) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1251
        return '0' <= c && c <= '9';
06bc494ca11e Initial load
duke
parents:
diff changeset
  1252
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1253
06bc494ca11e Initial load
duke
parents:
diff changeset
  1254
    /** Read member attributes.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1255
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1256
    void readMemberAttrs(Symbol sym) {
2513
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1257
        readAttrs(sym, AttributeKind.MEMBER);
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1258
    }
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1259
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1260
    void readAttrs(Symbol sym, AttributeKind kind) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1261
        char ac = nextChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1262
        for (int i = 0; i < ac; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1263
            Name attrName = readName(nextChar());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1264
            int attrLen = nextInt();
2513
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1265
            AttributeReader r = attributeReaders.get(attrName);
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1266
            if (r != null && r.accepts(kind))
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1267
                r.read(sym, attrLen);
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1268
            else  {
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1269
                unrecognized(attrName);
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1270
                bp = bp + attrLen;
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1271
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1272
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1273
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1274
06bc494ca11e Initial load
duke
parents:
diff changeset
  1275
    private boolean readingClassAttr = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1276
    private List<Type> missingTypeVariables = List.nil();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1277
    private List<Type> foundTypeVariables = List.nil();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1278
06bc494ca11e Initial load
duke
parents:
diff changeset
  1279
    /** Read class attributes.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1280
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1281
    void readClassAttrs(ClassSymbol c) {
2513
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1282
        readAttrs(c, AttributeKind.CLASS);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1283
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1284
06bc494ca11e Initial load
duke
parents:
diff changeset
  1285
    /** Read code block.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1286
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1287
    Code readCode(Symbol owner) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1288
        nextChar(); // max_stack
06bc494ca11e Initial load
duke
parents:
diff changeset
  1289
        nextChar(); // max_locals
06bc494ca11e Initial load
duke
parents:
diff changeset
  1290
        final int  code_length = nextInt();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1291
        bp += code_length;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1292
        final char exception_table_length = nextChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1293
        bp += exception_table_length * 8;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1294
        readMemberAttrs(owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1295
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1296
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1297
06bc494ca11e Initial load
duke
parents:
diff changeset
  1298
/************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
  1299
 * Reading Java-language annotations
06bc494ca11e Initial load
duke
parents:
diff changeset
  1300
 ***********************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
  1301
06bc494ca11e Initial load
duke
parents:
diff changeset
  1302
    /** Attach annotations.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1303
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1304
    void attachAnnotations(final Symbol sym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1305
        int numAttributes = nextChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1306
        if (numAttributes != 0) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21043
diff changeset
  1307
            ListBuffer<CompoundAnnotationProxy> proxies = new ListBuffer<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1308
            for (int i = 0; i<numAttributes; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1309
                CompoundAnnotationProxy proxy = readCompoundAnnotation();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1310
                if (proxy.type.tsym == syms.proprietaryType.tsym)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1311
                    sym.flags_field |= PROPRIETARY;
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 15031
diff changeset
  1312
                else if (proxy.type.tsym == syms.profileType.tsym) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 15031
diff changeset
  1313
                    if (profile != Profile.DEFAULT) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 15031
diff changeset
  1314
                        for (Pair<Name,Attribute> v: proxy.values) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 15031
diff changeset
  1315
                            if (v.fst == names.value && v.snd instanceof Attribute.Constant) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 15031
diff changeset
  1316
                                Attribute.Constant c = (Attribute.Constant) v.snd;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 15031
diff changeset
  1317
                                if (c.type == syms.intType && ((Integer) c.value) > profile.value) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 15031
diff changeset
  1318
                                    sym.flags_field |= NOT_IN_PROFILE;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 15031
diff changeset
  1319
                                }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 15031
diff changeset
  1320
                            }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 15031
diff changeset
  1321
                        }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 15031
diff changeset
  1322
                    }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 15031
diff changeset
  1323
                } else
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1324
                    proxies.append(proxy);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1325
            }
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 13635
diff changeset
  1326
            annotate.normal(new AnnotationCompleter(sym, proxies.toList()));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1327
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1328
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1329
06bc494ca11e Initial load
duke
parents:
diff changeset
  1330
    /** Attach parameter annotations.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1331
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1332
    void attachParameterAnnotations(final Symbol method) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1333
        final MethodSymbol meth = (MethodSymbol)method;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1334
        int numParameters = buf[bp++] & 0xFF;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1335
        List<VarSymbol> parameters = meth.params();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1336
        int pnum = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1337
        while (parameters.tail != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1338
            attachAnnotations(parameters.head);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1339
            parameters = parameters.tail;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1340
            pnum++;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1341
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1342
        if (pnum != numParameters) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1343
            throw badClassFile("bad.runtime.invisible.param.annotations", meth);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1344
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1345
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1346
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1347
    void attachTypeAnnotations(final Symbol sym) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1348
        int numAttributes = nextChar();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1349
        if (numAttributes != 0) {
20249
93f8eae31092 6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents: 20242
diff changeset
  1350
            ListBuffer<TypeAnnotationProxy> proxies = new ListBuffer<>();
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1351
            for (int i = 0; i < numAttributes; i++)
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1352
                proxies.append(readTypeAnnotation());
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1353
            annotate.normal(new TypeAnnotationCompleter(sym, proxies.toList()));
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1354
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1355
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1356
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1357
    /** Attach the default value for an annotation element.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1358
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1359
    void attachAnnotationDefault(final Symbol sym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1360
        final MethodSymbol meth = (MethodSymbol)sym; // only on methods
06bc494ca11e Initial load
duke
parents:
diff changeset
  1361
        final Attribute value = readAttributeValue();
14804
f93a8d60b9a4 8001114: Container annotation is not checked for semantic correctness
jfranck
parents: 14725
diff changeset
  1362
f93a8d60b9a4 8001114: Container annotation is not checked for semantic correctness
jfranck
parents: 14725
diff changeset
  1363
        // The default value is set later during annotation. It might
f93a8d60b9a4 8001114: Container annotation is not checked for semantic correctness
jfranck
parents: 14725
diff changeset
  1364
        // be the case that the Symbol sym is annotated _after_ the
f93a8d60b9a4 8001114: Container annotation is not checked for semantic correctness
jfranck
parents: 14725
diff changeset
  1365
        // repeating instances that depend on this default value,
f93a8d60b9a4 8001114: Container annotation is not checked for semantic correctness
jfranck
parents: 14725
diff changeset
  1366
        // because of this we set an interim value that tells us this
f93a8d60b9a4 8001114: Container annotation is not checked for semantic correctness
jfranck
parents: 14725
diff changeset
  1367
        // element (most likely) has a default.
f93a8d60b9a4 8001114: Container annotation is not checked for semantic correctness
jfranck
parents: 14725
diff changeset
  1368
        //
f93a8d60b9a4 8001114: Container annotation is not checked for semantic correctness
jfranck
parents: 14725
diff changeset
  1369
        // Set interim value for now, reset just before we do this
f93a8d60b9a4 8001114: Container annotation is not checked for semantic correctness
jfranck
parents: 14725
diff changeset
  1370
        // properly at annotate time.
f93a8d60b9a4 8001114: Container annotation is not checked for semantic correctness
jfranck
parents: 14725
diff changeset
  1371
        meth.defaultValue = value;
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 13635
diff changeset
  1372
        annotate.normal(new AnnotationDefaultCompleter(meth, value));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1373
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1374
06bc494ca11e Initial load
duke
parents:
diff changeset
  1375
    Type readTypeOrClassSymbol(int i) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1376
        // support preliminary jsr175-format class files
06bc494ca11e Initial load
duke
parents:
diff changeset
  1377
        if (buf[poolIdx[i]] == CONSTANT_Class)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1378
            return readClassSymbol(i).type;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1379
        return readType(i);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1380
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1381
    Type readEnumType(int i) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1382
        // support preliminary jsr175-format class files
06bc494ca11e Initial load
duke
parents:
diff changeset
  1383
        int index = poolIdx[i];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1384
        int length = getChar(index + 1);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1385
        if (buf[index + length + 2] != ';')
22442
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22167
diff changeset
  1386
            return syms.enterClass(readName(i)).type;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1387
        return readType(i);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1388
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1389
06bc494ca11e Initial load
duke
parents:
diff changeset
  1390
    CompoundAnnotationProxy readCompoundAnnotation() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1391
        Type t = readTypeOrClassSymbol(nextChar());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1392
        int numFields = nextChar();
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21043
diff changeset
  1393
        ListBuffer<Pair<Name,Attribute>> pairs = new ListBuffer<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1394
        for (int i=0; i<numFields; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1395
            Name name = readName(nextChar());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1396
            Attribute value = readAttributeValue();
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21043
diff changeset
  1397
            pairs.append(new Pair<>(name, value));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1398
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1399
        return new CompoundAnnotationProxy(t, pairs.toList());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1400
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1401
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1402
    TypeAnnotationProxy readTypeAnnotation() {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1403
        TypeAnnotationPosition position = readPosition();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1404
        CompoundAnnotationProxy proxy = readCompoundAnnotation();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1405
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1406
        return new TypeAnnotationProxy(proxy, position);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1407
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1408
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1409
    TypeAnnotationPosition readPosition() {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1410
        int tag = nextByte(); // TargetType tag is a byte
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1411
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1412
        if (!TargetType.isValidTargetTypeValue(tag))
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  1413
            throw badClassFile("bad.type.annotation.value", String.format("0x%02X", tag));
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1414
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1415
        TargetType type = TargetType.fromTargetTypeValue(tag);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1416
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1417
        switch (type) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1418
        // instanceof
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1419
        case INSTANCEOF: {
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1420
            final int offset = nextChar();
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1421
            final TypeAnnotationPosition position =
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1422
                TypeAnnotationPosition.instanceOf(readTypePath());
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1423
            position.offset = offset;
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1424
            return position;
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1425
        }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1426
        // new expression
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1427
        case NEW: {
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1428
            final int offset = nextChar();
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1429
            final TypeAnnotationPosition position =
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1430
                TypeAnnotationPosition.newObj(readTypePath());
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1431
            position.offset = offset;
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1432
            return position;
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1433
        }
15718
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
  1434
        // constructor/method reference receiver
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1435
        case CONSTRUCTOR_REFERENCE: {
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1436
            final int offset = nextChar();
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1437
            final TypeAnnotationPosition position =
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1438
                TypeAnnotationPosition.constructorRef(readTypePath());
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1439
            position.offset = offset;
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1440
            return position;
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1441
        }
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1442
        case METHOD_REFERENCE: {
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1443
            final int offset = nextChar();
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1444
            final TypeAnnotationPosition position =
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1445
                TypeAnnotationPosition.methodRef(readTypePath());
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1446
            position.offset = offset;
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1447
            return position;
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1448
        }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1449
        // local variable
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1450
        case LOCAL_VARIABLE: {
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1451
            final int table_length = nextChar();
24403
f2ce14657001 8035763: Error parsing binary type annotations data in javac
emc
parents: 24396
diff changeset
  1452
            final int[] newLvarOffset = new int[table_length];
f2ce14657001 8035763: Error parsing binary type annotations data in javac
emc
parents: 24396
diff changeset
  1453
            final int[] newLvarLength = new int[table_length];
f2ce14657001 8035763: Error parsing binary type annotations data in javac
emc
parents: 24396
diff changeset
  1454
            final int[] newLvarIndex = new int[table_length];
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1455
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1456
            for (int i = 0; i < table_length; ++i) {
24403
f2ce14657001 8035763: Error parsing binary type annotations data in javac
emc
parents: 24396
diff changeset
  1457
                newLvarOffset[i] = nextChar();
f2ce14657001 8035763: Error parsing binary type annotations data in javac
emc
parents: 24396
diff changeset
  1458
                newLvarLength[i] = nextChar();
f2ce14657001 8035763: Error parsing binary type annotations data in javac
emc
parents: 24396
diff changeset
  1459
                newLvarIndex[i] = nextChar();
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1460
            }
24403
f2ce14657001 8035763: Error parsing binary type annotations data in javac
emc
parents: 24396
diff changeset
  1461
f2ce14657001 8035763: Error parsing binary type annotations data in javac
emc
parents: 24396
diff changeset
  1462
            final TypeAnnotationPosition position =
f2ce14657001 8035763: Error parsing binary type annotations data in javac
emc
parents: 24396
diff changeset
  1463
                    TypeAnnotationPosition.localVariable(readTypePath());
f2ce14657001 8035763: Error parsing binary type annotations data in javac
emc
parents: 24396
diff changeset
  1464
            position.lvarOffset = newLvarOffset;
f2ce14657001 8035763: Error parsing binary type annotations data in javac
emc
parents: 24396
diff changeset
  1465
            position.lvarLength = newLvarLength;
f2ce14657001 8035763: Error parsing binary type annotations data in javac
emc
parents: 24396
diff changeset
  1466
            position.lvarIndex = newLvarIndex;
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1467
            return position;
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1468
        }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1469
        // resource variable
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1470
        case RESOURCE_VARIABLE: {
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1471
            final int table_length = nextChar();
24403
f2ce14657001 8035763: Error parsing binary type annotations data in javac
emc
parents: 24396
diff changeset
  1472
            final int[] newLvarOffset = new int[table_length];
f2ce14657001 8035763: Error parsing binary type annotations data in javac
emc
parents: 24396
diff changeset
  1473
            final int[] newLvarLength = new int[table_length];
f2ce14657001 8035763: Error parsing binary type annotations data in javac
emc
parents: 24396
diff changeset
  1474
            final int[] newLvarIndex = new int[table_length];
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1475
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1476
            for (int i = 0; i < table_length; ++i) {
24403
f2ce14657001 8035763: Error parsing binary type annotations data in javac
emc
parents: 24396
diff changeset
  1477
                newLvarOffset[i] = nextChar();
f2ce14657001 8035763: Error parsing binary type annotations data in javac
emc
parents: 24396
diff changeset
  1478
                newLvarLength[i] = nextChar();
f2ce14657001 8035763: Error parsing binary type annotations data in javac
emc
parents: 24396
diff changeset
  1479
                newLvarIndex[i] = nextChar();
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1480
            }
24403
f2ce14657001 8035763: Error parsing binary type annotations data in javac
emc
parents: 24396
diff changeset
  1481
f2ce14657001 8035763: Error parsing binary type annotations data in javac
emc
parents: 24396
diff changeset
  1482
            final TypeAnnotationPosition position =
f2ce14657001 8035763: Error parsing binary type annotations data in javac
emc
parents: 24396
diff changeset
  1483
                    TypeAnnotationPosition.resourceVariable(readTypePath());
f2ce14657001 8035763: Error parsing binary type annotations data in javac
emc
parents: 24396
diff changeset
  1484
            position.lvarOffset = newLvarOffset;
f2ce14657001 8035763: Error parsing binary type annotations data in javac
emc
parents: 24396
diff changeset
  1485
            position.lvarLength = newLvarLength;
f2ce14657001 8035763: Error parsing binary type annotations data in javac
emc
parents: 24396
diff changeset
  1486
            position.lvarIndex = newLvarIndex;
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1487
            return position;
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1488
        }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1489
        // exception parameter
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1490
        case EXCEPTION_PARAMETER: {
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1491
            final int exception_index = nextChar();
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1492
            final TypeAnnotationPosition position =
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1493
                TypeAnnotationPosition.exceptionParameter(readTypePath());
23975
c7c81595aea9 8040319: Clean up type annotation exception index generating code in Code.java
emc
parents: 23790
diff changeset
  1494
            position.setExceptionIndex(exception_index);
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1495
            return position;
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1496
        }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1497
        // method receiver
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1498
        case METHOD_RECEIVER:
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1499
            return TypeAnnotationPosition.methodReceiver(readTypePath());
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1500
        // type parameter
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1501
        case CLASS_TYPE_PARAMETER: {
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1502
            final int parameter_index = nextByte();
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1503
            return TypeAnnotationPosition
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1504
                .typeParameter(readTypePath(), parameter_index);
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1505
        }
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1506
        case METHOD_TYPE_PARAMETER: {
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1507
            final int parameter_index = nextByte();
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1508
            return TypeAnnotationPosition
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1509
                .methodTypeParameter(readTypePath(), parameter_index);
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1510
        }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1511
        // type parameter bound
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1512
        case CLASS_TYPE_PARAMETER_BOUND: {
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1513
            final int parameter_index = nextByte();
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1514
            final int bound_index = nextByte();
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1515
            return TypeAnnotationPosition
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1516
                .typeParameterBound(readTypePath(), parameter_index,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1517
                                    bound_index);
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1518
        }
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1519
        case METHOD_TYPE_PARAMETER_BOUND: {
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1520
            final int parameter_index = nextByte();
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1521
            final int bound_index = nextByte();
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1522
            return TypeAnnotationPosition
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1523
                .methodTypeParameterBound(readTypePath(), parameter_index,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1524
                                          bound_index);
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1525
        }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1526
        // class extends or implements clause
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1527
        case CLASS_EXTENDS: {
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1528
            final int type_index = nextChar();
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1529
            return TypeAnnotationPosition.classExtends(readTypePath(),
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1530
                                                       type_index);
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1531
        }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1532
        // throws
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1533
        case THROWS: {
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1534
            final int type_index = nextChar();
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1535
            return TypeAnnotationPosition.methodThrows(readTypePath(),
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1536
                                                       type_index);
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1537
        }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1538
        // method parameter
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1539
        case METHOD_FORMAL_PARAMETER: {
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1540
            final int parameter_index = nextByte();
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1541
            return TypeAnnotationPosition.methodParameter(readTypePath(),
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1542
                                                          parameter_index);
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1543
        }
15718
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
  1544
        // type cast
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1545
        case CAST: {
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1546
            final int offset = nextChar();
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1547
            final int type_index = nextByte();
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1548
            final TypeAnnotationPosition position =
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1549
                TypeAnnotationPosition.typeCast(readTypePath(), type_index);
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1550
            position.offset = offset;
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1551
            return position;
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1552
        }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1553
        // method/constructor/reference type argument
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1554
        case CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT: {
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1555
            final int offset = nextChar();
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1556
            final int type_index = nextByte();
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1557
            final TypeAnnotationPosition position = TypeAnnotationPosition
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1558
                .constructorInvocationTypeArg(readTypePath(), type_index);
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1559
            position.offset = offset;
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1560
            return position;
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1561
        }
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1562
        case METHOD_INVOCATION_TYPE_ARGUMENT: {
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1563
            final int offset = nextChar();
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1564
            final int type_index = nextByte();
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1565
            final TypeAnnotationPosition position = TypeAnnotationPosition
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1566
                .methodInvocationTypeArg(readTypePath(), type_index);
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1567
            position.offset = offset;
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1568
            return position;
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1569
        }
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1570
        case CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT: {
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1571
            final int offset = nextChar();
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1572
            final int type_index = nextByte();
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1573
            final TypeAnnotationPosition position = TypeAnnotationPosition
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1574
                .constructorRefTypeArg(readTypePath(), type_index);
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1575
            position.offset = offset;
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1576
            return position;
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1577
        }
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1578
        case METHOD_REFERENCE_TYPE_ARGUMENT: {
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1579
            final int offset = nextChar();
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1580
            final int type_index = nextByte();
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1581
            final TypeAnnotationPosition position = TypeAnnotationPosition
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1582
                .methodRefTypeArg(readTypePath(), type_index);
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1583
            position.offset = offset;
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1584
            return position;
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1585
        }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1586
        // We don't need to worry about these
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1587
        case METHOD_RETURN:
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1588
            return TypeAnnotationPosition.methodReturn(readTypePath());
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1589
        case FIELD:
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1590
            return TypeAnnotationPosition.field(readTypePath());
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1591
        default:
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1592
            throw new AssertionError("jvm.ClassReader: Unknown target type for position: " + type);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1593
        }
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1594
    }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1595
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1596
    List<TypeAnnotationPosition.TypePathEntry> readTypePath() {
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1597
        int len = nextByte();
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1598
        ListBuffer<Integer> loc = new ListBuffer<>();
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1599
        for (int i = 0; i < len * TypeAnnotationPosition.TypePathEntry.bytesPerEntry; ++i)
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1600
            loc = loc.append(nextByte());
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1601
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1602
        return TypeAnnotationPosition.getTypePathFromBinary(loc.toList());
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22442
diff changeset
  1603
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1604
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1605
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1606
    Attribute readAttributeValue() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1607
        char c = (char) buf[bp++];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1608
        switch (c) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1609
        case 'B':
06bc494ca11e Initial load
duke
parents:
diff changeset
  1610
            return new Attribute.Constant(syms.byteType, readPool(nextChar()));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1611
        case 'C':
06bc494ca11e Initial load
duke
parents:
diff changeset
  1612
            return new Attribute.Constant(syms.charType, readPool(nextChar()));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1613
        case 'D':
06bc494ca11e Initial load
duke
parents:
diff changeset
  1614
            return new Attribute.Constant(syms.doubleType, readPool(nextChar()));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1615
        case 'F':
06bc494ca11e Initial load
duke
parents:
diff changeset
  1616
            return new Attribute.Constant(syms.floatType, readPool(nextChar()));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1617
        case 'I':
06bc494ca11e Initial load
duke
parents:
diff changeset
  1618
            return new Attribute.Constant(syms.intType, readPool(nextChar()));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1619
        case 'J':
06bc494ca11e Initial load
duke
parents:
diff changeset
  1620
            return new Attribute.Constant(syms.longType, readPool(nextChar()));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1621
        case 'S':
06bc494ca11e Initial load
duke
parents:
diff changeset
  1622
            return new Attribute.Constant(syms.shortType, readPool(nextChar()));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1623
        case 'Z':
06bc494ca11e Initial load
duke
parents:
diff changeset
  1624
            return new Attribute.Constant(syms.booleanType, readPool(nextChar()));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1625
        case 's':
06bc494ca11e Initial load
duke
parents:
diff changeset
  1626
            return new Attribute.Constant(syms.stringType, readPool(nextChar()).toString());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1627
        case 'e':
06bc494ca11e Initial load
duke
parents:
diff changeset
  1628
            return new EnumAttributeProxy(readEnumType(nextChar()), readName(nextChar()));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1629
        case 'c':
06bc494ca11e Initial load
duke
parents:
diff changeset
  1630
            return new Attribute.Class(types, readTypeOrClassSymbol(nextChar()));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1631
        case '[': {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1632
            int n = nextChar();
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21043
diff changeset
  1633
            ListBuffer<Attribute> l = new ListBuffer<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1634
            for (int i=0; i<n; i++)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1635
                l.append(readAttributeValue());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1636
            return new ArrayAttributeProxy(l.toList());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1637
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1638
        case '@':
06bc494ca11e Initial load
duke
parents:
diff changeset
  1639
            return readCompoundAnnotation();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1640
        default:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1641
            throw new AssertionError("unknown annotation tag '" + c + "'");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1642
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1643
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1644
06bc494ca11e Initial load
duke
parents:
diff changeset
  1645
    interface ProxyVisitor extends Attribute.Visitor {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1646
        void visitEnumAttributeProxy(EnumAttributeProxy proxy);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1647
        void visitArrayAttributeProxy(ArrayAttributeProxy proxy);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1648
        void visitCompoundAnnotationProxy(CompoundAnnotationProxy proxy);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1649
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1650
06bc494ca11e Initial load
duke
parents:
diff changeset
  1651
    static class EnumAttributeProxy extends Attribute {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1652
        Type enumType;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1653
        Name enumerator;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1654
        public EnumAttributeProxy(Type enumType, Name enumerator) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1655
            super(null);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1656
            this.enumType = enumType;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1657
            this.enumerator = enumerator;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1658
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1659
        public void accept(Visitor v) { ((ProxyVisitor)v).visitEnumAttributeProxy(this); }
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1660
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1661
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1662
            return "/*proxy enum*/" + enumType + "." + enumerator;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1663
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1664
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1665
06bc494ca11e Initial load
duke
parents:
diff changeset
  1666
    static class ArrayAttributeProxy extends Attribute {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1667
        List<Attribute> values;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1668
        ArrayAttributeProxy(List<Attribute> values) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1669
            super(null);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1670
            this.values = values;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1671
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1672
        public void accept(Visitor v) { ((ProxyVisitor)v).visitArrayAttributeProxy(this); }
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1673
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1674
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1675
            return "{" + values + "}";
06bc494ca11e Initial load
duke
parents:
diff changeset
  1676
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1677
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1678
06bc494ca11e Initial load
duke
parents:
diff changeset
  1679
    /** A temporary proxy representing a compound attribute.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1680
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1681
    static class CompoundAnnotationProxy extends Attribute {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1682
        final List<Pair<Name,Attribute>> values;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1683
        public CompoundAnnotationProxy(Type type,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1684
                                      List<Pair<Name,Attribute>> values) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1685
            super(type);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1686
            this.values = values;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1687
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1688
        public void accept(Visitor v) { ((ProxyVisitor)v).visitCompoundAnnotationProxy(this); }
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1689
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1690
        public String toString() {
7624
c31b0ea95b37 6999210: javac should be able to warn of anomalous conditions in classfiles
jjg
parents: 7330
diff changeset
  1691
            StringBuilder buf = new StringBuilder();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1692
            buf.append("@");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1693
            buf.append(type.tsym.getQualifiedName());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1694
            buf.append("/*proxy*/{");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1695
            boolean first = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1696
            for (List<Pair<Name,Attribute>> v = values;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1697
                 v.nonEmpty(); v = v.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1698
                Pair<Name,Attribute> value = v.head;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1699
                if (!first) buf.append(",");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1700
                first = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1701
                buf.append(value.fst);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1702
                buf.append("=");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1703
                buf.append(value.snd);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1704
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1705
            buf.append("}");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1706
            return buf.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1707
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1708
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1709
3149
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 2723
diff changeset
  1710
    /** A temporary proxy representing a type annotation.
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 2723
diff changeset
  1711
     */
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 2723
diff changeset
  1712
    static class TypeAnnotationProxy {
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 2723
diff changeset
  1713
        final CompoundAnnotationProxy compound;
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 2723
diff changeset
  1714
        final TypeAnnotationPosition position;
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 2723
diff changeset
  1715
        public TypeAnnotationProxy(CompoundAnnotationProxy compound,
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 2723
diff changeset
  1716
                TypeAnnotationPosition position) {
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 2723
diff changeset
  1717
            this.compound = compound;
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 2723
diff changeset
  1718
            this.position = position;
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 2723
diff changeset
  1719
        }
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 2723
diff changeset
  1720
    }
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 2723
diff changeset
  1721
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1722
    class AnnotationDeproxy implements ProxyVisitor {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1723
        private ClassSymbol requestingOwner = currentOwner.kind == MTH
06bc494ca11e Initial load
duke
parents:
diff changeset
  1724
            ? currentOwner.enclClass() : (ClassSymbol)currentOwner;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1725
06bc494ca11e Initial load
duke
parents:
diff changeset
  1726
        List<Attribute.Compound> deproxyCompoundList(List<CompoundAnnotationProxy> pl) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1727
            // also must fill in types!!!!
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21043
diff changeset
  1728
            ListBuffer<Attribute.Compound> buf = new ListBuffer<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1729
            for (List<CompoundAnnotationProxy> l = pl; l.nonEmpty(); l=l.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1730
                buf.append(deproxyCompound(l.head));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1731
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1732
            return buf.toList();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1733
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1734
06bc494ca11e Initial load
duke
parents:
diff changeset
  1735
        Attribute.Compound deproxyCompound(CompoundAnnotationProxy a) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21043
diff changeset
  1736
            ListBuffer<Pair<Symbol.MethodSymbol,Attribute>> buf = new ListBuffer<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1737
            for (List<Pair<Name,Attribute>> l = a.values;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1738
                 l.nonEmpty();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1739
                 l = l.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1740
                MethodSymbol meth = findAccessMethod(a.type, l.head.fst);
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21043
diff changeset
  1741
                buf.append(new Pair<>(meth, deproxy(meth.type.getReturnType(), l.head.snd)));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1742
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1743
            return new Attribute.Compound(a.type, buf.toList());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1744
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1745
06bc494ca11e Initial load
duke
parents:
diff changeset
  1746
        MethodSymbol findAccessMethod(Type container, Name name) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1747
            CompletionFailure failure = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1748
            try {
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 24895
diff changeset
  1749
                for (Symbol sym : container.tsym.members().getSymbolsByName(name)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1750
                    if (sym.kind == MTH && sym.type.getParameterTypes().length() == 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1751
                        return (MethodSymbol) sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1752
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1753
            } catch (CompletionFailure ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1754
                failure = ex;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1755
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1756
            // The method wasn't found: emit a warning and recover
06bc494ca11e Initial load
duke
parents:
diff changeset
  1757
            JavaFileObject prevSource = log.useSource(requestingOwner.classfile);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1758
            try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1759
                if (failure == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1760
                    log.warning("annotation.method.not.found",
06bc494ca11e Initial load
duke
parents:
diff changeset
  1761
                                container,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1762
                                name);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1763
                } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1764
                    log.warning("annotation.method.not.found.reason",
06bc494ca11e Initial load
duke
parents:
diff changeset
  1765
                                container,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1766
                                name,
939
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 815
diff changeset
  1767
                                failure.getDetailValue());//diagnostic, if present
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1768
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1769
            } finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1770
                log.useSource(prevSource);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1771
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1772
            // Construct a new method type and symbol.  Use bottom
06bc494ca11e Initial load
duke
parents:
diff changeset
  1773
            // type (typeof null) as return type because this type is
06bc494ca11e Initial load
duke
parents:
diff changeset
  1774
            // a subtype of all reference types and can be converted
06bc494ca11e Initial load
duke
parents:
diff changeset
  1775
            // to primitive types by unboxing.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1776
            MethodType mt = new MethodType(List.<Type>nil(),
06bc494ca11e Initial load
duke
parents:
diff changeset
  1777
                                           syms.botType,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1778
                                           List.<Type>nil(),
06bc494ca11e Initial load
duke
parents:
diff changeset
  1779
                                           syms.methodClass);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1780
            return new MethodSymbol(PUBLIC | ABSTRACT, name, mt, container.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1781
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1782
06bc494ca11e Initial load
duke
parents:
diff changeset
  1783
        Attribute result;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1784
        Type type;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1785
        Attribute deproxy(Type t, Attribute a) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1786
            Type oldType = type;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1787
            try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1788
                type = t;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1789
                a.accept(this);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1790
                return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1791
            } finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1792
                type = oldType;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1793
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1794
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1795
06bc494ca11e Initial load
duke
parents:
diff changeset
  1796
        // implement Attribute.Visitor below
06bc494ca11e Initial load
duke
parents:
diff changeset
  1797
06bc494ca11e Initial load
duke
parents:
diff changeset
  1798
        public void visitConstant(Attribute.Constant value) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1799
            // assert value.type == type;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1800
            result = value;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1801
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1802
06bc494ca11e Initial load
duke
parents:
diff changeset
  1803
        public void visitClass(Attribute.Class clazz) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1804
            result = clazz;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1805
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1806
06bc494ca11e Initial load
duke
parents:
diff changeset
  1807
        public void visitEnum(Attribute.Enum e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1808
            throw new AssertionError(); // shouldn't happen
06bc494ca11e Initial load
duke
parents:
diff changeset
  1809
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1810
06bc494ca11e Initial load
duke
parents:
diff changeset
  1811
        public void visitCompound(Attribute.Compound compound) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1812
            throw new AssertionError(); // shouldn't happen
06bc494ca11e Initial load
duke
parents:
diff changeset
  1813
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1814
06bc494ca11e Initial load
duke
parents:
diff changeset
  1815
        public void visitArray(Attribute.Array array) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1816
            throw new AssertionError(); // shouldn't happen
06bc494ca11e Initial load
duke
parents:
diff changeset
  1817
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1818
06bc494ca11e Initial load
duke
parents:
diff changeset
  1819
        public void visitError(Attribute.Error e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1820
            throw new AssertionError(); // shouldn't happen
06bc494ca11e Initial load
duke
parents:
diff changeset
  1821
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1822
06bc494ca11e Initial load
duke
parents:
diff changeset
  1823
        public void visitEnumAttributeProxy(EnumAttributeProxy proxy) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1824
            // type.tsym.flatName() should == proxy.enumFlatName
06bc494ca11e Initial load
duke
parents:
diff changeset
  1825
            TypeSymbol enumTypeSym = proxy.enumType.tsym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1826
            VarSymbol enumerator = null;
9603
fa337b87574b 6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents: 9082
diff changeset
  1827
            CompletionFailure failure = null;
fa337b87574b 6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents: 9082
diff changeset
  1828
            try {
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 24895
diff changeset
  1829
                for (Symbol sym : enumTypeSym.members().getSymbolsByName(proxy.enumerator)) {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 24895
diff changeset
  1830
                    if (sym.kind == VAR) {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 24895
diff changeset
  1831
                        enumerator = (VarSymbol)sym;
9603
fa337b87574b 6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents: 9082
diff changeset
  1832
                        break;
fa337b87574b 6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents: 9082
diff changeset
  1833
                    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1834
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1835
            }
9603
fa337b87574b 6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents: 9082
diff changeset
  1836
            catch (CompletionFailure ex) {
fa337b87574b 6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents: 9082
diff changeset
  1837
                failure = ex;
fa337b87574b 6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents: 9082
diff changeset
  1838
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1839
            if (enumerator == null) {
9603
fa337b87574b 6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents: 9082
diff changeset
  1840
                if (failure != null) {
fa337b87574b 6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents: 9082
diff changeset
  1841
                    log.warning("unknown.enum.constant.reason",
fa337b87574b 6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents: 9082
diff changeset
  1842
                              currentClassFile, enumTypeSym, proxy.enumerator,
fa337b87574b 6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents: 9082
diff changeset
  1843
                              failure.getDiagnostic());
fa337b87574b 6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents: 9082
diff changeset
  1844
                } else {
fa337b87574b 6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents: 9082
diff changeset
  1845
                    log.warning("unknown.enum.constant",
fa337b87574b 6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents: 9082
diff changeset
  1846
                              currentClassFile, enumTypeSym, proxy.enumerator);
fa337b87574b 6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents: 9082
diff changeset
  1847
                }
fa337b87574b 6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents: 9082
diff changeset
  1848
                result = new Attribute.Enum(enumTypeSym.type,
fa337b87574b 6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents: 9082
diff changeset
  1849
                        new VarSymbol(0, proxy.enumerator, syms.botType, enumTypeSym));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1850
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1851
                result = new Attribute.Enum(enumTypeSym.type, enumerator);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1852
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1853
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1854
06bc494ca11e Initial load
duke
parents:
diff changeset
  1855
        public void visitArrayAttributeProxy(ArrayAttributeProxy proxy) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1856
            int length = proxy.values.length();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1857
            Attribute[] ats = new Attribute[length];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1858
            Type elemtype = types.elemtype(type);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1859
            int i = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1860
            for (List<Attribute> p = proxy.values; p.nonEmpty(); p = p.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1861
                ats[i++] = deproxy(elemtype, p.head);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1862
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1863
            result = new Attribute.Array(type, ats);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1864
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1865
06bc494ca11e Initial load
duke
parents:
diff changeset
  1866
        public void visitCompoundAnnotationProxy(CompoundAnnotationProxy proxy) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1867
            result = deproxyCompound(proxy);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1868
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1869
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1870
21040
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21006
diff changeset
  1871
    class AnnotationDefaultCompleter extends AnnotationDeproxy implements Annotate.Worker {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1872
        final MethodSymbol sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1873
        final Attribute value;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1874
        final JavaFileObject classFile = currentClassFile;
2513
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1875
        @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1876
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1877
            return " ClassReader store default for " + sym.owner + "." + sym + " is " + value;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1878
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1879
        AnnotationDefaultCompleter(MethodSymbol sym, Attribute value) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1880
            this.sym = sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1881
            this.value = value;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1882
        }
21040
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21006
diff changeset
  1883
        // implement Annotate.Worker.run()
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21006
diff changeset
  1884
        public void run() {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1885
            JavaFileObject previousClassFile = currentClassFile;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1886
            try {
14804
f93a8d60b9a4 8001114: Container annotation is not checked for semantic correctness
jfranck
parents: 14725
diff changeset
  1887
                // Reset the interim value set earlier in
f93a8d60b9a4 8001114: Container annotation is not checked for semantic correctness
jfranck
parents: 14725
diff changeset
  1888
                // attachAnnotationDefault().
f93a8d60b9a4 8001114: Container annotation is not checked for semantic correctness
jfranck
parents: 14725
diff changeset
  1889
                sym.defaultValue = null;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1890
                currentClassFile = classFile;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1891
                sym.defaultValue = deproxy(sym.type.getReturnType(), value);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1892
            } finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1893
                currentClassFile = previousClassFile;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1894
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1895
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1896
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1897
21040
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21006
diff changeset
  1898
    class AnnotationCompleter extends AnnotationDeproxy implements Annotate.Worker {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1899
        final Symbol sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1900
        final List<CompoundAnnotationProxy> l;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1901
        final JavaFileObject classFile;
2513
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  1902
        @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1903
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1904
            return " ClassReader annotate " + sym.owner + "." + sym + " with " + l;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1905
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1906
        AnnotationCompleter(Symbol sym, List<CompoundAnnotationProxy> l) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1907
            this.sym = sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1908
            this.l = l;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1909
            this.classFile = currentClassFile;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1910
        }
21040
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21006
diff changeset
  1911
        // implement Annotate.Worker.run()
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21006
diff changeset
  1912
        public void run() {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1913
            JavaFileObject previousClassFile = currentClassFile;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1914
            try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1915
                currentClassFile = classFile;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1916
                List<Attribute.Compound> newList = deproxyCompoundList(l);
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17578
diff changeset
  1917
                if (sym.annotationsPendingCompletion()) {
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17578
diff changeset
  1918
                    sym.setDeclarationAttributes(newList);
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 13635
diff changeset
  1919
                } else {
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17578
diff changeset
  1920
                    sym.appendAttributes(newList);
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 13635
diff changeset
  1921
                }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1922
            } finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1923
                currentClassFile = previousClassFile;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1924
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1925
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1926
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1927
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1928
    class TypeAnnotationCompleter extends AnnotationCompleter {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1929
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1930
        List<TypeAnnotationProxy> proxies;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1931
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1932
        TypeAnnotationCompleter(Symbol sym,
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1933
                List<TypeAnnotationProxy> proxies) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1934
            super(sym, List.<CompoundAnnotationProxy>nil());
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1935
            this.proxies = proxies;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1936
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1937
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1938
        List<Attribute.TypeCompound> deproxyTypeCompoundList(List<TypeAnnotationProxy> proxies) {
20249
93f8eae31092 6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents: 20242
diff changeset
  1939
            ListBuffer<Attribute.TypeCompound> buf = new ListBuffer<>();
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1940
            for (TypeAnnotationProxy proxy: proxies) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1941
                Attribute.Compound compound = deproxyCompound(proxy.compound);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1942
                Attribute.TypeCompound typeCompound = new Attribute.TypeCompound(compound, proxy.position);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1943
                buf.add(typeCompound);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1944
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1945
            return buf.toList();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1946
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1947
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1948
        @Override
21040
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21006
diff changeset
  1949
        public void run() {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1950
            JavaFileObject previousClassFile = currentClassFile;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1951
            try {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1952
                currentClassFile = classFile;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1953
                List<Attribute.TypeCompound> newList = deproxyTypeCompoundList(proxies);
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17578
diff changeset
  1954
                sym.setTypeAttributes(newList.prependList(sym.getRawTypeAttributes()));
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1955
            } finally {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1956
                currentClassFile = previousClassFile;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1957
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1958
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1959
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1960
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1961
06bc494ca11e Initial load
duke
parents:
diff changeset
  1962
/************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
  1963
 * Reading Symbols
06bc494ca11e Initial load
duke
parents:
diff changeset
  1964
 ***********************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
  1965
06bc494ca11e Initial load
duke
parents:
diff changeset
  1966
    /** Read a field.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1967
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1968
    VarSymbol readField() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1969
        long flags = adjustFieldFlags(nextChar());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1970
        Name name = readName(nextChar());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1971
        Type type = readType(nextChar());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1972
        VarSymbol v = new VarSymbol(flags, name, type, currentOwner);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1973
        readMemberAttrs(v);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1974
        return v;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1975
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1976
06bc494ca11e Initial load
duke
parents:
diff changeset
  1977
    /** Read a method.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1978
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1979
    MethodSymbol readMethod() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1980
        long flags = adjustMethodFlags(nextChar());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1981
        Name name = readName(nextChar());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1982
        Type type = readType(nextChar());
14547
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14443
diff changeset
  1983
        if (currentOwner.isInterface() &&
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14443
diff changeset
  1984
                (flags & ABSTRACT) == 0 && !name.equals(names.clinit)) {
24606
12c0ca21f8dc 8042406: javac.jvm.ClassReader.readClassFile() is using Target to verify valid major versions
ntoda
parents: 24604
diff changeset
  1985
            if (majorVersion > Version.V52.major ||
12c0ca21f8dc 8042406: javac.jvm.ClassReader.readClassFile() is using Target to verify valid major versions
ntoda
parents: 24604
diff changeset
  1986
                    (majorVersion == Version.V52.major && minorVersion >= Version.V52.minor)) {
21006
534673718919 8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents: 20249
diff changeset
  1987
                if ((flags & STATIC) == 0) {
534673718919 8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents: 20249
diff changeset
  1988
                    currentOwner.flags_field |= DEFAULT;
534673718919 8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents: 20249
diff changeset
  1989
                    flags |= DEFAULT | ABSTRACT;
534673718919 8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents: 20249
diff changeset
  1990
                }
14547
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14443
diff changeset
  1991
            } else {
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14443
diff changeset
  1992
                //protect against ill-formed classfiles
21006
534673718919 8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents: 20249
diff changeset
  1993
                throw badClassFile((flags & STATIC) == 0 ? "invalid.default.interface" : "invalid.static.interface",
534673718919 8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents: 20249
diff changeset
  1994
                                   Integer.toString(majorVersion),
534673718919 8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents: 20249
diff changeset
  1995
                                   Integer.toString(minorVersion));
14547
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14443
diff changeset
  1996
            }
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14443
diff changeset
  1997
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1998
        if (name == names.init && currentOwner.hasOuterInstance()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1999
            // Sometimes anonymous classes don't have an outer
06bc494ca11e Initial load
duke
parents:
diff changeset
  2000
            // instance, however, there is no reliable way to tell so
06bc494ca11e Initial load
duke
parents:
diff changeset
  2001
            // we never strip this$n
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 939
diff changeset
  2002
            if (!currentOwner.name.isEmpty())
7643
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7632
diff changeset
  2003
                type = new MethodType(adjustMethodParams(flags, type.getParameterTypes()),
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2004
                                      type.getReturnType(),
06bc494ca11e Initial load
duke
parents:
diff changeset
  2005
                                      type.getThrownTypes(),
06bc494ca11e Initial load
duke
parents:
diff changeset
  2006
                                      syms.methodClass);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2007
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2008
        MethodSymbol m = new MethodSymbol(flags, name, type, currentOwner);
18389
a425d0819f36 8016569: javac, add new flag for polymorphic method signatures
vromero
parents: 18010
diff changeset
  2009
        if (types.isSignaturePolymorphic(m)) {
a425d0819f36 8016569: javac, add new flag for polymorphic method signatures
vromero
parents: 18010
diff changeset
  2010
            m.flags_field |= SIGNATURE_POLYMORPHIC;
a425d0819f36 8016569: javac, add new flag for polymorphic method signatures
vromero
parents: 18010
diff changeset
  2011
        }
4077
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2012
        if (saveParameterNames)
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2013
            initParameterNames(m);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2014
        Symbol prevOwner = currentOwner;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2015
        currentOwner = m;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2016
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2017
            readMemberAttrs(m);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2018
        } finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2019
            currentOwner = prevOwner;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2020
        }
4077
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2021
        if (saveParameterNames)
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2022
            setParameterNames(m, type);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2023
        return m;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2024
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2025
7643
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7632
diff changeset
  2026
    private List<Type> adjustMethodParams(long flags, List<Type> args) {
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7632
diff changeset
  2027
        boolean isVarargs = (flags & VARARGS) != 0;
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7632
diff changeset
  2028
        if (isVarargs) {
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7632
diff changeset
  2029
            Type varargsElem = args.last();
20249
93f8eae31092 6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents: 20242
diff changeset
  2030
            ListBuffer<Type> adjustedArgs = new ListBuffer<>();
7643
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7632
diff changeset
  2031
            for (Type t : args) {
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7632
diff changeset
  2032
                adjustedArgs.append(t != varargsElem ?
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7632
diff changeset
  2033
                    t :
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7632
diff changeset
  2034
                    ((ArrayType)t).makeVarargs());
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7632
diff changeset
  2035
            }
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7632
diff changeset
  2036
            args = adjustedArgs.toList();
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7632
diff changeset
  2037
        }
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7632
diff changeset
  2038
        return args.tail;
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7632
diff changeset
  2039
    }
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7632
diff changeset
  2040
4077
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2041
    /**
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2042
     * Init the parameter names array.
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2043
     * Parameter names are currently inferred from the names in the
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2044
     * LocalVariableTable attributes of a Code attribute.
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2045
     * (Note: this means parameter names are currently not available for
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2046
     * methods without a Code attribute.)
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2047
     * This method initializes an array in which to store the name indexes
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2048
     * of parameter names found in LocalVariableTable attributes. It is
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2049
     * slightly supersized to allow for additional slots with a start_pc of 0.
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2050
     */
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2051
    void initParameterNames(MethodSymbol sym) {
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2052
        // make allowance for synthetic parameters.
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2053
        final int excessSlots = 4;
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2054
        int expectedParameterSlots =
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2055
                Code.width(sym.type.getParameterTypes()) + excessSlots;
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2056
        if (parameterNameIndices == null
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2057
                || parameterNameIndices.length < expectedParameterSlots) {
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2058
            parameterNameIndices = new int[expectedParameterSlots];
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2059
        } else
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2060
            Arrays.fill(parameterNameIndices, 0);
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2061
        haveParameterNameIndices = false;
15031
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14949
diff changeset
  2062
        sawMethodParameters = false;
4077
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2063
    }
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2064
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2065
    /**
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2066
     * Set the parameter names for a symbol from the name index in the
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2067
     * parameterNameIndicies array. The type of the symbol may have changed
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2068
     * while reading the method attributes (see the Signature attribute).
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2069
     * This may be because of generic information or because anonymous
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2070
     * synthetic parameters were added.   The original type (as read from
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2071
     * the method descriptor) is used to help guess the existence of
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2072
     * anonymous synthetic parameters.
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2073
     * On completion, sym.savedParameter names will either be null (if
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2074
     * no parameter names were found in the class file) or will be set to a
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2075
     * list of names, one per entry in sym.type.getParameterTypes, with
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2076
     * any missing names represented by the empty name.
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2077
     */
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2078
    void setParameterNames(MethodSymbol sym, Type jvmType) {
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2079
        // if no names were found in the class file, there's nothing more to do
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2080
        if (!haveParameterNameIndices)
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2081
            return;
15031
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14949
diff changeset
  2082
        // If we get parameter names from MethodParameters, then we
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14949
diff changeset
  2083
        // don't need to skip.
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14949
diff changeset
  2084
        int firstParam = 0;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14949
diff changeset
  2085
        if (!sawMethodParameters) {
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14949
diff changeset
  2086
            firstParam = ((sym.flags() & STATIC) == 0) ? 1 : 0;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14949
diff changeset
  2087
            // the code in readMethod may have skipped the first
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14949
diff changeset
  2088
            // parameter when setting up the MethodType. If so, we
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14949
diff changeset
  2089
            // make a corresponding allowance here for the position of
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14949
diff changeset
  2090
            // the first parameter.  Note that this assumes the
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14949
diff changeset
  2091
            // skipped parameter has a width of 1 -- i.e. it is not
4077
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2092
        // a double width type (long or double.)
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2093
        if (sym.name == names.init && currentOwner.hasOuterInstance()) {
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2094
            // Sometimes anonymous classes don't have an outer
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2095
            // instance, however, there is no reliable way to tell so
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2096
            // we never strip this$n
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2097
            if (!currentOwner.name.isEmpty())
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2098
                firstParam += 1;
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2099
        }
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2100
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2101
        if (sym.type != jvmType) {
15031
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14949
diff changeset
  2102
                // reading the method attributes has caused the
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14949
diff changeset
  2103
                // symbol's type to be changed. (i.e. the Signature
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14949
diff changeset
  2104
                // attribute.)  This may happen if there are hidden
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14949
diff changeset
  2105
                // (synthetic) parameters in the descriptor, but not
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14949
diff changeset
  2106
                // in the Signature.  The position of these hidden
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14949
diff changeset
  2107
                // parameters is unspecified; for now, assume they are
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14949
diff changeset
  2108
                // at the beginning, and so skip over them. The
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14949
diff changeset
  2109
                // primary case for this is two hidden parameters
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14949
diff changeset
  2110
                // passed into Enum constructors.
4077
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2111
            int skip = Code.width(jvmType.getParameterTypes())
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2112
                    - Code.width(sym.type.getParameterTypes());
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2113
            firstParam += skip;
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2114
        }
15031
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14949
diff changeset
  2115
        }
4077
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2116
        List<Name> paramNames = List.nil();
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2117
        int index = firstParam;
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2118
        for (Type t: sym.type.getParameterTypes()) {
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2119
            int nameIdx = (index < parameterNameIndices.length
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2120
                    ? parameterNameIndices[index] : 0);
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2121
            Name name = nameIdx == 0 ? names.empty : readName(nameIdx);
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2122
            paramNames = paramNames.prepend(name);
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2123
            index += Code.width(t);
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2124
        }
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2125
        sym.savedParameterNames = paramNames.reverse();
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2126
    }
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 4073
diff changeset
  2127
8042
d534dd80da9f 6982999: tools must support -target 7 bytecodes
ksrini
parents: 8032
diff changeset
  2128
    /**
d534dd80da9f 6982999: tools must support -target 7 bytecodes
ksrini
parents: 8032
diff changeset
  2129
     * skip n bytes
d534dd80da9f 6982999: tools must support -target 7 bytecodes
ksrini
parents: 8032
diff changeset
  2130
     */
d534dd80da9f 6982999: tools must support -target 7 bytecodes
ksrini
parents: 8032
diff changeset
  2131
    void skipBytes(int n) {
d534dd80da9f 6982999: tools must support -target 7 bytecodes
ksrini
parents: 8032
diff changeset
  2132
        bp = bp + n;
d534dd80da9f 6982999: tools must support -target 7 bytecodes
ksrini
parents: 8032
diff changeset
  2133
    }
d534dd80da9f 6982999: tools must support -target 7 bytecodes
ksrini
parents: 8032
diff changeset
  2134
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2135
    /** Skip a field or method
06bc494ca11e Initial load
duke
parents:
diff changeset
  2136
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2137
    void skipMember() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2138
        bp = bp + 6;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2139
        char ac = nextChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2140
        for (int i = 0; i < ac; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2141
            bp = bp + 2;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2142
            int attrLen = nextInt();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2143
            bp = bp + attrLen;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2144
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2145
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2146
06bc494ca11e Initial load
duke
parents:
diff changeset
  2147
    /** Enter type variables of this classtype and all enclosing ones in
06bc494ca11e Initial load
duke
parents:
diff changeset
  2148
     *  `typevars'.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2149
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2150
    protected void enterTypevars(Type t) {
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 13689
diff changeset
  2151
        if (t.getEnclosingType() != null && t.getEnclosingType().hasTag(CLASS))
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2152
            enterTypevars(t.getEnclosingType());
06bc494ca11e Initial load
duke
parents:
diff changeset
  2153
        for (List<Type> xs = t.getTypeArguments(); xs.nonEmpty(); xs = xs.tail)
06bc494ca11e Initial load
duke
parents:
diff changeset
  2154
            typevars.enter(xs.head.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2155
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2156
06bc494ca11e Initial load
duke
parents:
diff changeset
  2157
    protected void enterTypevars(Symbol sym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2158
        if (sym.owner.kind == MTH) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2159
            enterTypevars(sym.owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2160
            enterTypevars(sym.owner.owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2161
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2162
        enterTypevars(sym.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2163
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2164
06bc494ca11e Initial load
duke
parents:
diff changeset
  2165
    /** Read contents of a given class symbol `c'. Both external and internal
06bc494ca11e Initial load
duke
parents:
diff changeset
  2166
     *  versions of an inner class are read.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2167
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2168
    void readClass(ClassSymbol c) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2169
        ClassType ct = (ClassType)c.type;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2170
06bc494ca11e Initial load
duke
parents:
diff changeset
  2171
        // allocate scope for members
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 24895
diff changeset
  2172
        c.members_field = WriteableScope.create(c);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2173
06bc494ca11e Initial load
duke
parents:
diff changeset
  2174
        // prepare type variable table
06bc494ca11e Initial load
duke
parents:
diff changeset
  2175
        typevars = typevars.dup(currentOwner);
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 13689
diff changeset
  2176
        if (ct.getEnclosingType().hasTag(CLASS))
2513
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  2177
            enterTypevars(ct.getEnclosingType());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2178
06bc494ca11e Initial load
duke
parents:
diff changeset
  2179
        // read flags, or skip if this is an inner class
06bc494ca11e Initial load
duke
parents:
diff changeset
  2180
        long flags = adjustClassFlags(nextChar());
06bc494ca11e Initial load
duke
parents:
diff changeset
  2181
        if (c.owner.kind == PCK) c.flags_field = flags;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2182
06bc494ca11e Initial load
duke
parents:
diff changeset
  2183
        // read own class name and check that it matches
06bc494ca11e Initial load
duke
parents:
diff changeset
  2184
        ClassSymbol self = readClassSymbol(nextChar());
06bc494ca11e Initial load
duke
parents:
diff changeset
  2185
        if (c != self)
06bc494ca11e Initial load
duke
parents:
diff changeset
  2186
            throw badClassFile("class.file.wrong.class",
06bc494ca11e Initial load
duke
parents:
diff changeset
  2187
                               self.flatname);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2188
06bc494ca11e Initial load
duke
parents:
diff changeset
  2189
        // class attributes must be read before class
06bc494ca11e Initial load
duke
parents:
diff changeset
  2190
        // skip ahead to read class attributes
06bc494ca11e Initial load
duke
parents:
diff changeset
  2191
        int startbp = bp;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2192
        nextChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2193
        char interfaceCount = nextChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2194
        bp += interfaceCount * 2;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2195
        char fieldCount = nextChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2196
        for (int i = 0; i < fieldCount; i++) skipMember();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2197
        char methodCount = nextChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2198
        for (int i = 0; i < methodCount; i++) skipMember();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2199
        readClassAttrs(c);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2200
06bc494ca11e Initial load
duke
parents:
diff changeset
  2201
        if (readAllOfClassFile) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2202
            for (int i = 1; i < poolObj.length; i++) readPool(i);
14949
45f43822bbde 8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents: 14804
diff changeset
  2203
            c.pool = new Pool(poolObj.length, poolObj, types);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2204
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2205
06bc494ca11e Initial load
duke
parents:
diff changeset
  2206
        // reset and read rest of classinfo
06bc494ca11e Initial load
duke
parents:
diff changeset
  2207
        bp = startbp;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2208
        int n = nextChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2209
        if (ct.supertype_field == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
  2210
            ct.supertype_field = (n == 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
  2211
                ? Type.noType
06bc494ca11e Initial load
duke
parents:
diff changeset
  2212
                : readClassSymbol(n).erasure(types);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2213
        n = nextChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2214
        List<Type> is = List.nil();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2215
        for (int i = 0; i < n; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2216
            Type _inter = readClassSymbol(nextChar()).erasure(types);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2217
            is = is.prepend(_inter);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2218
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2219
        if (ct.interfaces_field == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
  2220
            ct.interfaces_field = is.reverse();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2221
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 8031
diff changeset
  2222
        Assert.check(fieldCount == nextChar());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2223
        for (int i = 0; i < fieldCount; i++) enterMember(c, readField());
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 8031
diff changeset
  2224
        Assert.check(methodCount == nextChar());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2225
        for (int i = 0; i < methodCount; i++) enterMember(c, readMethod());
06bc494ca11e Initial load
duke
parents:
diff changeset
  2226
06bc494ca11e Initial load
duke
parents:
diff changeset
  2227
        typevars = typevars.leave();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2228
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2229
06bc494ca11e Initial load
duke
parents:
diff changeset
  2230
    /** Read inner class info. For each inner/outer pair allocate a
06bc494ca11e Initial load
duke
parents:
diff changeset
  2231
     *  member class.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2232
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2233
    void readInnerClasses(ClassSymbol c) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2234
        int n = nextChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2235
        for (int i = 0; i < n; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2236
            nextChar(); // skip inner class symbol
06bc494ca11e Initial load
duke
parents:
diff changeset
  2237
            ClassSymbol outer = readClassSymbol(nextChar());
06bc494ca11e Initial load
duke
parents:
diff changeset
  2238
            Name name = readName(nextChar());
06bc494ca11e Initial load
duke
parents:
diff changeset
  2239
            if (name == null) name = names.empty;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2240
            long flags = adjustClassFlags(nextChar());
06bc494ca11e Initial load
duke
parents:
diff changeset
  2241
            if (outer != null) { // we have a member class
06bc494ca11e Initial load
duke
parents:
diff changeset
  2242
                if (name == names.empty)
06bc494ca11e Initial load
duke
parents:
diff changeset
  2243
                    name = names.one;
22442
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22167
diff changeset
  2244
                ClassSymbol member = syms.enterClass(name, outer);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2245
                if ((flags & STATIC) == 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2246
                    ((ClassType)member.type).setEnclosingType(outer.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2247
                    if (member.erasure_field != null)
06bc494ca11e Initial load
duke
parents:
diff changeset
  2248
                        ((ClassType)member.erasure_field).setEnclosingType(types.erasure(outer.type));
06bc494ca11e Initial load
duke
parents:
diff changeset
  2249
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2250
                if (c == outer) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2251
                    member.flags_field = flags;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2252
                    enterMember(c, member);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2253
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2254
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2255
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2256
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2257
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2258
    /** Read a class definition from the bytes in buf.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2259
     */
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2260
    private void readClassBuffer(ClassSymbol c) throws IOException {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2261
        int magic = nextInt();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2262
        if (magic != JAVA_MAGIC)
06bc494ca11e Initial load
duke
parents:
diff changeset
  2263
            throw badClassFile("illegal.start.of.class.file");
06bc494ca11e Initial load
duke
parents:
diff changeset
  2264
2513
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  2265
        minorVersion = nextChar();
1cbbf23b22f9 6817950: refactor ClassReader to improve attribute handling
jjg
parents: 1260
diff changeset
  2266
        majorVersion = nextChar();
24606
12c0ca21f8dc 8042406: javac.jvm.ClassReader.readClassFile() is using Target to verify valid major versions
ntoda
parents: 24604
diff changeset
  2267
        int maxMajor = Version.MAX().major;
12c0ca21f8dc 8042406: javac.jvm.ClassReader.readClassFile() is using Target to verify valid major versions
ntoda
parents: 24604
diff changeset
  2268
        int maxMinor = Version.MAX().minor;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2269
        if (majorVersion > maxMajor ||
06bc494ca11e Initial load
duke
parents:
diff changeset
  2270
            majorVersion * 1000 + minorVersion <
24606
12c0ca21f8dc 8042406: javac.jvm.ClassReader.readClassFile() is using Target to verify valid major versions
ntoda
parents: 24604
diff changeset
  2271
            Version.MIN().major * 1000 + Version.MIN().minor)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2272
        {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2273
            if (majorVersion == (maxMajor + 1))
06bc494ca11e Initial load
duke
parents:
diff changeset
  2274
                log.warning("big.major.version",
06bc494ca11e Initial load
duke
parents:
diff changeset
  2275
                            currentClassFile,
06bc494ca11e Initial load
duke
parents:
diff changeset
  2276
                            majorVersion,
06bc494ca11e Initial load
duke
parents:
diff changeset
  2277
                            maxMajor);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2278
            else
06bc494ca11e Initial load
duke
parents:
diff changeset
  2279
                throw badClassFile("wrong.version",
06bc494ca11e Initial load
duke
parents:
diff changeset
  2280
                                   Integer.toString(majorVersion),
06bc494ca11e Initial load
duke
parents:
diff changeset
  2281
                                   Integer.toString(minorVersion),
06bc494ca11e Initial load
duke
parents:
diff changeset
  2282
                                   Integer.toString(maxMajor),
06bc494ca11e Initial load
duke
parents:
diff changeset
  2283
                                   Integer.toString(maxMinor));
06bc494ca11e Initial load
duke
parents:
diff changeset
  2284
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2285
        else if (checkClassFile &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  2286
                 majorVersion == maxMajor &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  2287
                 minorVersion > maxMinor)
06bc494ca11e Initial load
duke
parents:
diff changeset
  2288
        {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2289
            printCCF("found.later.version",
06bc494ca11e Initial load
duke
parents:
diff changeset
  2290
                     Integer.toString(minorVersion));
06bc494ca11e Initial load
duke
parents:
diff changeset
  2291
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2292
        indexPool();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2293
        if (signatureBuffer.length < bp) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2294
            int ns = Integer.highestOneBit(bp) << 1;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2295
            signatureBuffer = new byte[ns];
06bc494ca11e Initial load
duke
parents:
diff changeset
  2296
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2297
        readClass(c);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2298
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2299
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2300
    public void readClassFile(ClassSymbol c) {
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2301
        currentOwner = c;
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2302
        currentClassFile = c.classfile;
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2303
        warnedAttrs.clear();
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2304
        filling = true;
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2305
        try {
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2306
            bp = 0;
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2307
            buf = readInputStream(buf, c.classfile.openInputStream());
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2308
            readClassBuffer(c);
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2309
            if (!missingTypeVariables.isEmpty() && !foundTypeVariables.isEmpty()) {
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2310
                List<Type> missing = missingTypeVariables;
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2311
                List<Type> found = foundTypeVariables;
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2312
                missingTypeVariables = List.nil();
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2313
                foundTypeVariables = List.nil();
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2314
                filling = false;
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2315
                ClassType ct = (ClassType)currentOwner.type;
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2316
                ct.supertype_field =
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2317
                    types.subst(ct.supertype_field, missing, found);
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2318
                ct.interfaces_field =
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2319
                    types.subst(ct.interfaces_field, missing, found);
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2320
            } else if (missingTypeVariables.isEmpty() !=
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2321
                       foundTypeVariables.isEmpty()) {
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2322
                Name name = missingTypeVariables.head.tsym.name;
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2323
                throw badClassFile("undecl.type.var", name);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2324
            }
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2325
        } catch (IOException ex) {
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2326
            throw badClassFile("unable.to.access.file", ex.getMessage());
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2327
        } catch (ArrayIndexOutOfBoundsException ex) {
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2328
            throw badClassFile("bad.class.file", c.flatname);
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2329
        } finally {
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2330
            missingTypeVariables = List.nil();
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2331
            foundTypeVariables = List.nil();
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2332
            filling = false;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2333
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2334
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2335
    // where
06bc494ca11e Initial load
duke
parents:
diff changeset
  2336
        private static byte[] readInputStream(byte[] buf, InputStream s) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2337
            try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2338
                buf = ensureCapacity(buf, s.available());
06bc494ca11e Initial load
duke
parents:
diff changeset
  2339
                int r = s.read(buf);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2340
                int bp = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2341
                while (r != -1) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2342
                    bp += r;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2343
                    buf = ensureCapacity(buf, bp);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2344
                    r = s.read(buf, bp, buf.length - bp);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2345
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2346
                return buf;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2347
            } finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2348
                try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2349
                    s.close();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2350
                } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2351
                    /* Ignore any errors, as this stream may have already
06bc494ca11e Initial load
duke
parents:
diff changeset
  2352
                     * thrown a related exception which is the one that
06bc494ca11e Initial load
duke
parents:
diff changeset
  2353
                     * should be reported.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2354
                     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2355
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2356
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2357
        }
7842
5de9ea98089d 6567415: Neverending loop in ClassReader
ksrini
parents: 7643
diff changeset
  2358
        /*
5de9ea98089d 6567415: Neverending loop in ClassReader
ksrini
parents: 7643
diff changeset
  2359
         * ensureCapacity will increase the buffer as needed, taking note that
5de9ea98089d 6567415: Neverending loop in ClassReader
ksrini
parents: 7643
diff changeset
  2360
         * the new buffer will always be greater than the needed and never
5de9ea98089d 6567415: Neverending loop in ClassReader
ksrini
parents: 7643
diff changeset
  2361
         * exactly equal to the needed size or bp. If equal then the read (above)
5de9ea98089d 6567415: Neverending loop in ClassReader
ksrini
parents: 7643
diff changeset
  2362
         * will infinitely loop as buf.length - bp == 0.
5de9ea98089d 6567415: Neverending loop in ClassReader
ksrini
parents: 7643
diff changeset
  2363
         */
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2364
        private static byte[] ensureCapacity(byte[] buf, int needed) {
7842
5de9ea98089d 6567415: Neverending loop in ClassReader
ksrini
parents: 7643
diff changeset
  2365
            if (buf.length <= needed) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2366
                byte[] old = buf;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2367
                buf = new byte[Integer.highestOneBit(needed) << 1];
06bc494ca11e Initial load
duke
parents:
diff changeset
  2368
                System.arraycopy(old, 0, buf, 0, old.length);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2369
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2370
            return buf;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2371
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2372
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2373
    /** We can only read a single class file at a time; this
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2374
     *  flag keeps track of when we are currently reading a class
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2375
     *  file.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2376
     */
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2377
    public boolean filling = false;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2378
06bc494ca11e Initial load
duke
parents:
diff changeset
  2379
/************************************************************************
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2380
 * Adjusting flags
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2381
 ***********************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
  2382
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2383
    long adjustFieldFlags(long flags) {
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2384
        return flags;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2385
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2386
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2387
    long adjustMethodFlags(long flags) {
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2388
        if ((flags & ACC_BRIDGE) != 0) {
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2389
            flags &= ~ACC_BRIDGE;
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2390
            flags |= BRIDGE;
24298
cc4f0f71a505 8028196: Javac allows timestamps inside rt.jar to affect compilation when using -sourcepath.
alundblad
parents: 24068
diff changeset
  2391
        }
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2392
        if ((flags & ACC_VARARGS) != 0) {
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2393
            flags &= ~ACC_VARARGS;
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2394
            flags |= VARARGS;
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2395
        }
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2396
        return flags;
24298
cc4f0f71a505 8028196: Javac allows timestamps inside rt.jar to affect compilation when using -sourcepath.
alundblad
parents: 24068
diff changeset
  2397
    }
cc4f0f71a505 8028196: Javac allows timestamps inside rt.jar to affect compilation when using -sourcepath.
alundblad
parents: 24068
diff changeset
  2398
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2399
    long adjustClassFlags(long flags) {
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 24403
diff changeset
  2400
        return flags & ~ACC_SUPER; // SUPER and SYNCHRONIZED bits overloaded
24298
cc4f0f71a505 8028196: Javac allows timestamps inside rt.jar to affect compilation when using -sourcepath.
alundblad
parents: 24068
diff changeset
  2401
    }
cc4f0f71a505 8028196: Javac allows timestamps inside rt.jar to affect compilation when using -sourcepath.
alundblad
parents: 24068
diff changeset
  2402
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2403
    /** Output for "-checkclassfile" option.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2404
     *  @param key The key to look up the correct internationalized string.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2405
     *  @param arg An argument for substitution into the output string.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2406
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2407
    private void printCCF(String key, Object arg) {
11053
48713f779b1d 7108669: cleanup Log methods for direct printing to streams
jjg
parents: 9603
diff changeset
  2408
        log.printLines(key, arg);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2409
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2410
06bc494ca11e Initial load
duke
parents:
diff changeset
  2411
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  2412
     * A subclass of JavaFileObject for the sourcefile attribute found in a classfile.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2413
     * The attribute is only the last component of the original filename, so is unlikely
06bc494ca11e Initial load
duke
parents:
diff changeset
  2414
     * to be valid as is, so operations other than those to access the name throw
06bc494ca11e Initial load
duke
parents:
diff changeset
  2415
     * UnsupportedOperationException
06bc494ca11e Initial load
duke
parents:
diff changeset
  2416
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2417
    private static class SourceFileObject extends BaseFileObject {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2418
06bc494ca11e Initial load
duke
parents:
diff changeset
  2419
        /** The file's name.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2420
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2421
        private Name name;
810
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents: 731
diff changeset
  2422
        private Name flatname;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2423
810
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents: 731
diff changeset
  2424
        public SourceFileObject(Name name, Name flatname) {
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents: 731
diff changeset
  2425
            super(null); // no file manager; never referenced for this file object
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2426
            this.name = name;
810
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents: 731
diff changeset
  2427
            this.flatname = flatname;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2428
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2429
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  2430
        @Override @DefinedBy(Api.COMPILER)
3995
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
  2431
        public URI toUri() {
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
  2432
            try {
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
  2433
                return new URI(null, name.toString(), null);
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
  2434
            } catch (URISyntaxException e) {
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
  2435
                throw new CannotCreateUriError(name.toString(), e);
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
  2436
            }
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
  2437
        }
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
  2438
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  2439
        @Override @DefinedBy(Api.COMPILER)
3995
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
  2440
        public String getName() {
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
  2441
            return name.toString();
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
  2442
        }
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
  2443
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
  2444
        @Override
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
  2445
        public String getShortName() {
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
  2446
            return getName();
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
  2447
        }
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
  2448
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  2449
        @Override @DefinedBy(Api.COMPILER)
3995
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
  2450
        public JavaFileObject.Kind getKind() {
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
  2451
            return getKind(getName());
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
  2452
        }
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
  2453
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  2454
        @Override @DefinedBy(Api.COMPILER)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2455
        public InputStream openInputStream() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2456
            throw new UnsupportedOperationException();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2457
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2458
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  2459
        @Override @DefinedBy(Api.COMPILER)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2460
        public OutputStream openOutputStream() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2461
            throw new UnsupportedOperationException();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2462
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2463
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  2464
        @Override @DefinedBy(Api.COMPILER)
3995
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
  2465
        public CharBuffer getCharContent(boolean ignoreEncodingErrors) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2466
            throw new UnsupportedOperationException();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2467
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2468
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  2469
        @Override @DefinedBy(Api.COMPILER)
3995
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
  2470
        public Reader openReader(boolean ignoreEncodingErrors) {
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
  2471
            throw new UnsupportedOperationException();
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
  2472
        }
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
  2473
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  2474
        @Override @DefinedBy(Api.COMPILER)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2475
        public Writer openWriter() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2476
            throw new UnsupportedOperationException();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2477
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2478
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  2479
        @Override @DefinedBy(Api.COMPILER)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2480
        public long getLastModified() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2481
            throw new UnsupportedOperationException();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2482
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2483
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  2484
        @Override @DefinedBy(Api.COMPILER)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2485
        public boolean delete() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2486
            throw new UnsupportedOperationException();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2487
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2488
3995
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
  2489
        @Override
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
  2490
        protected String inferBinaryName(Iterable<? extends File> path) {
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
  2491
            return flatname.toString();
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
  2492
        }
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
  2493
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  2494
        @Override @DefinedBy(Api.COMPILER)
3995
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
  2495
        public boolean isNameCompatible(String simpleName, JavaFileObject.Kind kind) {
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
  2496
            return true; // fail-safe mode
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2497
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2498
4073
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents: 3998
diff changeset
  2499
        /**
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents: 3998
diff changeset
  2500
         * Check if two file objects are equal.
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents: 3998
diff changeset
  2501
         * SourceFileObjects are just placeholder objects for the value of a
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents: 3998
diff changeset
  2502
         * SourceFile attribute, and do not directly represent specific files.
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents: 3998
diff changeset
  2503
         * Two SourceFileObjects are equal if their names are equal.
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents: 3998
diff changeset
  2504
         */
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2505
        @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
  2506
        public boolean equals(Object other) {
4073
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents: 3998
diff changeset
  2507
            if (this == other)
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents: 3998
diff changeset
  2508
                return true;
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents: 3998
diff changeset
  2509
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2510
            if (!(other instanceof SourceFileObject))
06bc494ca11e Initial load
duke
parents:
diff changeset
  2511
                return false;
4073
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents: 3998
diff changeset
  2512
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2513
            SourceFileObject o = (SourceFileObject) other;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2514
            return name.equals(o.name);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2515
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2516
06bc494ca11e Initial load
duke
parents:
diff changeset
  2517
        @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
  2518
        public int hashCode() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2519
            return name.hashCode();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2520
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2521
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2522
}