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