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