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