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