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