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