author | emc |
Fri, 09 May 2014 09:28:47 -0400 | |
changeset 24396 | 3c36c6afcbca |
parent 22702 | 1297fbaf34fa |
permissions | -rw-r--r-- |
15385 | 1 |
/* |
2 |
* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved. |
|
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 |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
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 |
* |
|
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. |
|
24 |
*/ |
|
25 |
||
26 |
package com.sun.tools.javac.code; |
|
27 |
||
28 |
import javax.lang.model.element.Element; |
|
29 |
import javax.lang.model.element.ElementKind; |
|
30 |
import javax.lang.model.type.TypeKind; |
|
31 |
||
19651 | 32 |
import javax.tools.JavaFileObject; |
33 |
||
15385 | 34 |
import com.sun.tools.javac.code.Attribute.TypeCompound; |
35 |
import com.sun.tools.javac.code.Type.ArrayType; |
|
36 |
import com.sun.tools.javac.code.Type.CapturedType; |
|
37 |
import com.sun.tools.javac.code.Type.ClassType; |
|
38 |
import com.sun.tools.javac.code.Type.ErrorType; |
|
39 |
import com.sun.tools.javac.code.Type.ForAll; |
|
40 |
import com.sun.tools.javac.code.Type.MethodType; |
|
41 |
import com.sun.tools.javac.code.Type.PackageType; |
|
42 |
import com.sun.tools.javac.code.Type.TypeVar; |
|
43 |
import com.sun.tools.javac.code.Type.UndetVar; |
|
44 |
import com.sun.tools.javac.code.Type.Visitor; |
|
45 |
import com.sun.tools.javac.code.Type.WildcardType; |
|
46 |
import com.sun.tools.javac.code.TypeAnnotationPosition.TypePathEntry; |
|
47 |
import com.sun.tools.javac.code.TypeAnnotationPosition.TypePathEntryKind; |
|
48 |
import com.sun.tools.javac.code.Symbol.VarSymbol; |
|
17578 | 49 |
import com.sun.tools.javac.code.Symbol.MethodSymbol; |
50 |
import com.sun.tools.javac.comp.Annotate; |
|
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
51 |
import com.sun.tools.javac.comp.Annotate.Worker; |
21018
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21010
diff
changeset
|
52 |
import com.sun.tools.javac.comp.Attr; |
19651 | 53 |
import com.sun.tools.javac.comp.AttrContext; |
54 |
import com.sun.tools.javac.comp.Env; |
|
15385 | 55 |
import com.sun.tools.javac.tree.JCTree; |
19651 | 56 |
import com.sun.tools.javac.tree.TreeInfo; |
15385 | 57 |
import com.sun.tools.javac.tree.JCTree.JCBlock; |
58 |
import com.sun.tools.javac.tree.JCTree.JCClassDecl; |
|
59 |
import com.sun.tools.javac.tree.JCTree.JCExpression; |
|
17578 | 60 |
import com.sun.tools.javac.tree.JCTree.JCLambda; |
15385 | 61 |
import com.sun.tools.javac.tree.JCTree.JCMethodDecl; |
19651 | 62 |
import com.sun.tools.javac.tree.JCTree.JCMethodInvocation; |
17578 | 63 |
import com.sun.tools.javac.tree.JCTree.JCNewClass; |
15385 | 64 |
import com.sun.tools.javac.tree.JCTree.JCTypeApply; |
65 |
import com.sun.tools.javac.tree.JCTree.JCVariableDecl; |
|
66 |
import com.sun.tools.javac.tree.TreeScanner; |
|
67 |
import com.sun.tools.javac.tree.JCTree.*; |
|
68 |
import com.sun.tools.javac.util.Assert; |
|
20258 | 69 |
import com.sun.tools.javac.util.Context; |
15385 | 70 |
import com.sun.tools.javac.util.List; |
71 |
import com.sun.tools.javac.util.ListBuffer; |
|
72 |
import com.sun.tools.javac.util.Log; |
|
73 |
import com.sun.tools.javac.util.Names; |
|
21010
5ffe0d8a5e24
8008762: Type annotation on inner class in anonymous class show up as regular type annotations
emc
parents:
20258
diff
changeset
|
74 |
import com.sun.tools.javac.util.Options; |
15385 | 75 |
|
76 |
/** |
|
77 |
* Contains operations specific to processing type annotations. |
|
78 |
* This class has two functions: |
|
79 |
* separate declaration from type annotations and insert the type |
|
80 |
* annotations to their types; |
|
81 |
* and determine the TypeAnnotationPositions for all type annotations. |
|
82 |
*/ |
|
83 |
public class TypeAnnotations { |
|
22163 | 84 |
protected static final Context.Key<TypeAnnotations> typeAnnosKey = new Context.Key<>(); |
20258 | 85 |
|
86 |
public static TypeAnnotations instance(Context context) { |
|
87 |
TypeAnnotations instance = context.get(typeAnnosKey); |
|
88 |
if (instance == null) |
|
89 |
instance = new TypeAnnotations(context); |
|
90 |
return instance; |
|
91 |
} |
|
92 |
||
93 |
final Log log; |
|
94 |
final Names names; |
|
95 |
final Symtab syms; |
|
96 |
final Annotate annotate; |
|
21018
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21010
diff
changeset
|
97 |
final Attr attr; |
20258 | 98 |
|
99 |
protected TypeAnnotations(Context context) { |
|
100 |
context.put(typeAnnosKey, this); |
|
101 |
names = Names.instance(context); |
|
102 |
log = Log.instance(context); |
|
103 |
syms = Symtab.instance(context); |
|
104 |
annotate = Annotate.instance(context); |
|
21018
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21010
diff
changeset
|
105 |
attr = Attr.instance(context); |
21010
5ffe0d8a5e24
8008762: Type annotation on inner class in anonymous class show up as regular type annotations
emc
parents:
20258
diff
changeset
|
106 |
Options options = Options.instance(context); |
20258 | 107 |
} |
15385 | 108 |
|
109 |
/** |
|
110 |
* Separate type annotations from declaration annotations and |
|
111 |
* determine the correct positions for type annotations. |
|
112 |
* This version only visits types in signatures and should be |
|
113 |
* called from MemberEnter. |
|
17578 | 114 |
* The method takes the Annotate object as parameter and |
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
115 |
* adds an Annotate.Worker to the correct Annotate queue for |
17578 | 116 |
* later processing. |
15385 | 117 |
*/ |
20258 | 118 |
public void organizeTypeAnnotationsSignatures(final Env<AttrContext> env, final JCClassDecl tree) { |
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
119 |
annotate.afterRepeated( new Worker() { |
15385 | 120 |
@Override |
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
121 |
public void run() { |
19651 | 122 |
JavaFileObject oldSource = log.useSource(env.toplevel.sourcefile); |
123 |
||
124 |
try { |
|
20258 | 125 |
new TypeAnnotationPositions(true).scan(tree); |
19651 | 126 |
} finally { |
127 |
log.useSource(oldSource); |
|
128 |
} |
|
15385 | 129 |
} |
17578 | 130 |
} ); |
15385 | 131 |
} |
132 |
||
21018
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21010
diff
changeset
|
133 |
public void validateTypeAnnotationsSignatures(final Env<AttrContext> env, final JCClassDecl tree) { |
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
134 |
annotate.validate(new Worker() { //validate annotations |
21018
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21010
diff
changeset
|
135 |
@Override |
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
136 |
public void run() { |
21018
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21010
diff
changeset
|
137 |
JavaFileObject oldSource = log.useSource(env.toplevel.sourcefile); |
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21010
diff
changeset
|
138 |
|
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21010
diff
changeset
|
139 |
try { |
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21010
diff
changeset
|
140 |
attr.validateTypeAnnotations(tree, true); |
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21010
diff
changeset
|
141 |
} finally { |
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21010
diff
changeset
|
142 |
log.useSource(oldSource); |
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21010
diff
changeset
|
143 |
} |
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21010
diff
changeset
|
144 |
} |
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21010
diff
changeset
|
145 |
} ); |
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21010
diff
changeset
|
146 |
} |
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21010
diff
changeset
|
147 |
|
15385 | 148 |
/** |
149 |
* This version only visits types in bodies, that is, field initializers, |
|
150 |
* top-level blocks, and method bodies, and should be called from Attr. |
|
151 |
*/ |
|
20258 | 152 |
public void organizeTypeAnnotationsBodies(JCClassDecl tree) { |
153 |
new TypeAnnotationPositions(false).scan(tree); |
|
15385 | 154 |
} |
155 |
||
22163 | 156 |
public enum AnnotationType { DECLARATION, TYPE, BOTH } |
15385 | 157 |
|
17578 | 158 |
/** |
159 |
* Determine whether an annotation is a declaration annotation, |
|
160 |
* a type annotation, or both. |
|
161 |
*/ |
|
20258 | 162 |
public AnnotationType annotationType(Attribute.Compound a, Symbol s) { |
17578 | 163 |
Attribute.Compound atTarget = |
164 |
a.type.tsym.attribute(syms.annotationTargetType.tsym); |
|
165 |
if (atTarget == null) { |
|
166 |
return inferTargetMetaInfo(a, s); |
|
167 |
} |
|
168 |
Attribute atValue = atTarget.member(names.value); |
|
169 |
if (!(atValue instanceof Attribute.Array)) { |
|
170 |
Assert.error("annotationType(): bad @Target argument " + atValue + |
|
171 |
" (" + atValue.getClass() + ")"); |
|
172 |
return AnnotationType.DECLARATION; // error recovery |
|
173 |
} |
|
174 |
Attribute.Array arr = (Attribute.Array) atValue; |
|
175 |
boolean isDecl = false, isType = false; |
|
176 |
for (Attribute app : arr.values) { |
|
177 |
if (!(app instanceof Attribute.Enum)) { |
|
178 |
Assert.error("annotationType(): unrecognized Attribute kind " + app + |
|
179 |
" (" + app.getClass() + ")"); |
|
180 |
isDecl = true; |
|
181 |
continue; |
|
182 |
} |
|
183 |
Attribute.Enum e = (Attribute.Enum) app; |
|
184 |
if (e.value.name == names.TYPE) { |
|
185 |
if (s.kind == Kinds.TYP) |
|
186 |
isDecl = true; |
|
187 |
} else if (e.value.name == names.FIELD) { |
|
188 |
if (s.kind == Kinds.VAR && |
|
189 |
s.owner.kind != Kinds.MTH) |
|
190 |
isDecl = true; |
|
191 |
} else if (e.value.name == names.METHOD) { |
|
192 |
if (s.kind == Kinds.MTH && |
|
193 |
!s.isConstructor()) |
|
194 |
isDecl = true; |
|
195 |
} else if (e.value.name == names.PARAMETER) { |
|
196 |
if (s.kind == Kinds.VAR && |
|
197 |
s.owner.kind == Kinds.MTH && |
|
198 |
(s.flags() & Flags.PARAMETER) != 0) |
|
199 |
isDecl = true; |
|
200 |
} else if (e.value.name == names.CONSTRUCTOR) { |
|
201 |
if (s.kind == Kinds.MTH && |
|
202 |
s.isConstructor()) |
|
203 |
isDecl = true; |
|
204 |
} else if (e.value.name == names.LOCAL_VARIABLE) { |
|
205 |
if (s.kind == Kinds.VAR && |
|
206 |
s.owner.kind == Kinds.MTH && |
|
207 |
(s.flags() & Flags.PARAMETER) == 0) |
|
208 |
isDecl = true; |
|
209 |
} else if (e.value.name == names.ANNOTATION_TYPE) { |
|
210 |
if (s.kind == Kinds.TYP && |
|
211 |
(s.flags() & Flags.ANNOTATION) != 0) |
|
212 |
isDecl = true; |
|
213 |
} else if (e.value.name == names.PACKAGE) { |
|
214 |
if (s.kind == Kinds.PCK) |
|
215 |
isDecl = true; |
|
216 |
} else if (e.value.name == names.TYPE_USE) { |
|
217 |
if (s.kind == Kinds.TYP || |
|
218 |
s.kind == Kinds.VAR || |
|
219 |
(s.kind == Kinds.MTH && !s.isConstructor() && |
|
220 |
!s.type.getReturnType().hasTag(TypeTag.VOID)) || |
|
221 |
(s.kind == Kinds.MTH && s.isConstructor())) |
|
222 |
isType = true; |
|
223 |
} else if (e.value.name == names.TYPE_PARAMETER) { |
|
224 |
/* Irrelevant in this case */ |
|
225 |
// TYPE_PARAMETER doesn't aid in distinguishing between |
|
226 |
// Type annotations and declaration annotations on an |
|
227 |
// Element |
|
228 |
} else { |
|
229 |
Assert.error("annotationType(): unrecognized Attribute name " + e.value.name + |
|
230 |
" (" + e.value.name.getClass() + ")"); |
|
231 |
isDecl = true; |
|
232 |
} |
|
233 |
} |
|
234 |
if (isDecl && isType) { |
|
235 |
return AnnotationType.BOTH; |
|
236 |
} else if (isType) { |
|
237 |
return AnnotationType.TYPE; |
|
238 |
} else { |
|
239 |
return AnnotationType.DECLARATION; |
|
240 |
} |
|
241 |
} |
|
242 |
||
243 |
/** Infer the target annotation kind, if none is give. |
|
244 |
* We only infer declaration annotations. |
|
245 |
*/ |
|
246 |
private static AnnotationType inferTargetMetaInfo(Attribute.Compound a, Symbol s) { |
|
247 |
return AnnotationType.DECLARATION; |
|
248 |
} |
|
249 |
||
250 |
||
20258 | 251 |
private class TypeAnnotationPositions extends TreeScanner { |
15385 | 252 |
|
253 |
private final boolean sigOnly; |
|
254 |
||
20258 | 255 |
TypeAnnotationPositions(boolean sigOnly) { |
15385 | 256 |
this.sigOnly = sigOnly; |
257 |
} |
|
258 |
||
259 |
/* |
|
260 |
* When traversing the AST we keep the "frames" of visited |
|
261 |
* trees in order to determine the position of annotations. |
|
262 |
*/ |
|
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19651
diff
changeset
|
263 |
private ListBuffer<JCTree> frames = new ListBuffer<>(); |
15385 | 264 |
|
265 |
protected void push(JCTree t) { frames = frames.prepend(t); } |
|
266 |
protected JCTree pop() { return frames.next(); } |
|
267 |
// could this be frames.elems.tail.head? |
|
268 |
private JCTree peek2() { return frames.toList().tail.head; } |
|
269 |
||
270 |
@Override |
|
271 |
public void scan(JCTree tree) { |
|
272 |
push(tree); |
|
273 |
super.scan(tree); |
|
274 |
pop(); |
|
275 |
} |
|
276 |
||
277 |
/** |
|
278 |
* Separates type annotations from declaration annotations. |
|
279 |
* This step is needed because in certain locations (where declaration |
|
280 |
* and type annotations can be mixed, e.g. the type of a field) |
|
281 |
* we never build an JCAnnotatedType. This step finds these |
|
282 |
* annotations and marks them as if they were part of the type. |
|
283 |
*/ |
|
284 |
private void separateAnnotationsKinds(JCTree typetree, Type type, Symbol sym, |
|
285 |
TypeAnnotationPosition pos) { |
|
286 |
List<Attribute.Compound> annotations = sym.getRawAttributes(); |
|
22163 | 287 |
ListBuffer<Attribute.Compound> declAnnos = new ListBuffer<>(); |
288 |
ListBuffer<Attribute.TypeCompound> typeAnnos = new ListBuffer<>(); |
|
289 |
ListBuffer<Attribute.TypeCompound> onlyTypeAnnos = new ListBuffer<>(); |
|
15385 | 290 |
|
291 |
for (Attribute.Compound a : annotations) { |
|
20258 | 292 |
switch (annotationType(a, sym)) { |
15385 | 293 |
case DECLARATION: |
294 |
declAnnos.append(a); |
|
295 |
break; |
|
296 |
case BOTH: { |
|
297 |
declAnnos.append(a); |
|
298 |
Attribute.TypeCompound ta = toTypeCompound(a, pos); |
|
299 |
typeAnnos.append(ta); |
|
300 |
break; |
|
301 |
} |
|
302 |
case TYPE: { |
|
303 |
Attribute.TypeCompound ta = toTypeCompound(a, pos); |
|
304 |
typeAnnos.append(ta); |
|
21041 | 305 |
// Also keep track which annotations are only type annotations |
306 |
onlyTypeAnnos.append(ta); |
|
15385 | 307 |
break; |
308 |
} |
|
309 |
} |
|
310 |
} |
|
311 |
||
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17578
diff
changeset
|
312 |
sym.resetAnnotations(); |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17578
diff
changeset
|
313 |
sym.setDeclarationAttributes(declAnnos.toList()); |
15385 | 314 |
|
17578 | 315 |
if (typeAnnos.isEmpty()) { |
316 |
return; |
|
317 |
} |
|
318 |
||
15385 | 319 |
List<Attribute.TypeCompound> typeAnnotations = typeAnnos.toList(); |
320 |
||
321 |
if (type == null) { |
|
322 |
// When type is null, put the type annotations to the symbol. |
|
323 |
// This is used for constructor return annotations, for which |
|
21481
f0aeb1da97bd
8026791: wrong type_path encoded for method_return on an inner class constructor
jjg
parents:
21480
diff
changeset
|
324 |
// we use the type of the enclosing class. |
f0aeb1da97bd
8026791: wrong type_path encoded for method_return on an inner class constructor
jjg
parents:
21480
diff
changeset
|
325 |
type = sym.getEnclosingElement().asType(); |
f0aeb1da97bd
8026791: wrong type_path encoded for method_return on an inner class constructor
jjg
parents:
21480
diff
changeset
|
326 |
|
f0aeb1da97bd
8026791: wrong type_path encoded for method_return on an inner class constructor
jjg
parents:
21480
diff
changeset
|
327 |
// Declaration annotations are always allowed on constructor returns. |
f0aeb1da97bd
8026791: wrong type_path encoded for method_return on an inner class constructor
jjg
parents:
21480
diff
changeset
|
328 |
// Therefore, use typeAnnotations instead of onlyTypeAnnos. |
f0aeb1da97bd
8026791: wrong type_path encoded for method_return on an inner class constructor
jjg
parents:
21480
diff
changeset
|
329 |
type = typeWithAnnotations(typetree, type, typeAnnotations, typeAnnotations); |
f0aeb1da97bd
8026791: wrong type_path encoded for method_return on an inner class constructor
jjg
parents:
21480
diff
changeset
|
330 |
// Note that we don't use the result, the call to |
f0aeb1da97bd
8026791: wrong type_path encoded for method_return on an inner class constructor
jjg
parents:
21480
diff
changeset
|
331 |
// typeWithAnnotations side-effects the type annotation positions. |
f0aeb1da97bd
8026791: wrong type_path encoded for method_return on an inner class constructor
jjg
parents:
21480
diff
changeset
|
332 |
// This is important for constructors of nested classes. |
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17578
diff
changeset
|
333 |
sym.appendUniqueTypeAttributes(typeAnnotations); |
15385 | 334 |
return; |
335 |
} |
|
336 |
||
337 |
// type is non-null and annotations are added to that type |
|
21041 | 338 |
type = typeWithAnnotations(typetree, type, typeAnnotations, onlyTypeAnnos.toList()); |
15385 | 339 |
|
340 |
if (sym.getKind() == ElementKind.METHOD) { |
|
341 |
sym.type.asMethodType().restype = type; |
|
17578 | 342 |
} else if (sym.getKind() == ElementKind.PARAMETER) { |
343 |
sym.type = type; |
|
344 |
if (sym.getQualifiedName().equals(names._this)) { |
|
345 |
sym.owner.type.asMethodType().recvtype = type; |
|
346 |
// note that the typeAnnotations will also be added to the owner below. |
|
347 |
} else { |
|
348 |
MethodType methType = sym.owner.type.asMethodType(); |
|
349 |
List<VarSymbol> params = ((MethodSymbol)sym.owner).params; |
|
350 |
List<Type> oldArgs = methType.argtypes; |
|
22163 | 351 |
ListBuffer<Type> newArgs = new ListBuffer<>(); |
17578 | 352 |
while (params.nonEmpty()) { |
353 |
if (params.head == sym) { |
|
354 |
newArgs.add(type); |
|
355 |
} else { |
|
356 |
newArgs.add(oldArgs.head); |
|
357 |
} |
|
358 |
oldArgs = oldArgs.tail; |
|
359 |
params = params.tail; |
|
360 |
} |
|
361 |
methType.argtypes = newArgs.toList(); |
|
362 |
} |
|
15385 | 363 |
} else { |
364 |
sym.type = type; |
|
365 |
} |
|
366 |
||
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17578
diff
changeset
|
367 |
sym.appendUniqueTypeAttributes(typeAnnotations); |
17578 | 368 |
|
15385 | 369 |
if (sym.getKind() == ElementKind.PARAMETER || |
21499
203cfd174518
8023682: Incorrect attributes emitted for anonymous class declaration
emc
parents:
21481
diff
changeset
|
370 |
sym.getKind() == ElementKind.LOCAL_VARIABLE || |
203cfd174518
8023682: Incorrect attributes emitted for anonymous class declaration
emc
parents:
21481
diff
changeset
|
371 |
sym.getKind() == ElementKind.RESOURCE_VARIABLE || |
203cfd174518
8023682: Incorrect attributes emitted for anonymous class declaration
emc
parents:
21481
diff
changeset
|
372 |
sym.getKind() == ElementKind.EXCEPTION_PARAMETER) { |
15385 | 373 |
// Make sure all type annotations from the symbol are also |
374 |
// on the owner. |
|
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17578
diff
changeset
|
375 |
sym.owner.appendUniqueTypeAttributes(sym.getRawTypeAttributes()); |
15385 | 376 |
} |
377 |
} |
|
378 |
||
379 |
// This method has a similar purpose as |
|
380 |
// {@link com.sun.tools.javac.parser.JavacParser.insertAnnotationsToMostInner(JCExpression, List<JCTypeAnnotation>, boolean)} |
|
381 |
// We found a type annotation in a declaration annotation position, |
|
382 |
// for example, on the return type. |
|
383 |
// Such an annotation is _not_ part of an JCAnnotatedType tree and we therefore |
|
384 |
// need to set its position explicitly. |
|
385 |
// The method returns a copy of type that contains these annotations. |
|
15718 | 386 |
// |
387 |
// As a side effect the method sets the type annotation position of "annotations". |
|
388 |
// Note that it is assumed that all annotations share the same position. |
|
20258 | 389 |
private Type typeWithAnnotations(final JCTree typetree, final Type type, |
21041 | 390 |
final List<Attribute.TypeCompound> annotations, |
391 |
final List<Attribute.TypeCompound> onlyTypeAnnotations) { |
|
24396 | 392 |
//System.err.printf("typeWithAnnotations(typetree: %s, type: %s, annotations: %s, onlyTypeAnnotations: %s)%n", |
21041 | 393 |
// typetree, type, annotations, onlyTypeAnnotations); |
15385 | 394 |
if (annotations.isEmpty()) { |
395 |
return type; |
|
396 |
} |
|
397 |
if (type.hasTag(TypeTag.ARRAY)) { |
|
24396 | 398 |
Type.ArrayType arType = (Type.ArrayType) type; |
399 |
Type.ArrayType tomodify = new Type.ArrayType(null, arType.tsym, |
|
400 |
Type.noAnnotations); |
|
15385 | 401 |
Type toreturn; |
21041 | 402 |
if (type.isAnnotated()) { |
403 |
toreturn = tomodify.annotatedType(type.getAnnotationMirrors()); |
|
404 |
} else { |
|
405 |
toreturn = tomodify; |
|
15385 | 406 |
} |
21041 | 407 |
|
15385 | 408 |
JCArrayTypeTree arTree = arrayTypeTree(typetree); |
409 |
||
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19651
diff
changeset
|
410 |
ListBuffer<TypePathEntry> depth = new ListBuffer<>(); |
15385 | 411 |
depth = depth.append(TypePathEntry.ARRAY); |
412 |
while (arType.elemtype.hasTag(TypeTag.ARRAY)) { |
|
16556
f4adc5bb4652
8008425: Remove interim new javax.lang.model API for type-annotations
jjg
parents:
15718
diff
changeset
|
413 |
if (arType.elemtype.isAnnotated()) { |
21480 | 414 |
Type aelemtype = arType.elemtype; |
24396 | 415 |
arType = (Type.ArrayType) aelemtype; |
21041 | 416 |
ArrayType prevToMod = tomodify; |
24396 | 417 |
tomodify = new Type.ArrayType(null, arType.tsym, |
418 |
Type.noAnnotations); |
|
21480 | 419 |
prevToMod.elemtype = tomodify.annotatedType(arType.elemtype.getAnnotationMirrors()); |
15385 | 420 |
} else { |
421 |
arType = (Type.ArrayType) arType.elemtype; |
|
24396 | 422 |
tomodify.elemtype = new Type.ArrayType(null, arType.tsym, |
423 |
Type.noAnnotations); |
|
15385 | 424 |
tomodify = (Type.ArrayType) tomodify.elemtype; |
425 |
} |
|
426 |
arTree = arrayTypeTree(arTree.elemtype); |
|
427 |
depth = depth.append(TypePathEntry.ARRAY); |
|
428 |
} |
|
21041 | 429 |
Type arelemType = typeWithAnnotations(arTree.elemtype, arType.elemtype, annotations, onlyTypeAnnotations); |
15385 | 430 |
tomodify.elemtype = arelemType; |
15718 | 431 |
{ |
432 |
// All annotations share the same position; modify the first one. |
|
433 |
Attribute.TypeCompound a = annotations.get(0); |
|
15385 | 434 |
TypeAnnotationPosition p = a.position; |
435 |
p.location = p.location.prependList(depth.toList()); |
|
436 |
} |
|
17578 | 437 |
typetree.type = toreturn; |
15385 | 438 |
return toreturn; |
439 |
} else if (type.hasTag(TypeTag.TYPEVAR)) { |
|
440 |
// Nothing to do for type variables. |
|
441 |
return type; |
|
17578 | 442 |
} else if (type.getKind() == TypeKind.UNION) { |
443 |
// There is a TypeKind, but no TypeTag. |
|
444 |
JCTypeUnion tutree = (JCTypeUnion) typetree; |
|
445 |
JCExpression fst = tutree.alternatives.get(0); |
|
21041 | 446 |
Type res = typeWithAnnotations(fst, fst.type, annotations, onlyTypeAnnotations); |
17578 | 447 |
fst.type = res; |
448 |
// TODO: do we want to set res as first element in uct.alternatives? |
|
449 |
// UnionClassType uct = (com.sun.tools.javac.code.Type.UnionClassType)type; |
|
450 |
// Return the un-annotated union-type. |
|
451 |
return type; |
|
15385 | 452 |
} else { |
453 |
Type enclTy = type; |
|
454 |
Element enclEl = type.asElement(); |
|
455 |
JCTree enclTr = typetree; |
|
456 |
||
457 |
while (enclEl != null && |
|
458 |
enclEl.getKind() != ElementKind.PACKAGE && |
|
459 |
enclTy != null && |
|
460 |
enclTy.getKind() != TypeKind.NONE && |
|
461 |
enclTy.getKind() != TypeKind.ERROR && |
|
462 |
(enclTr.getKind() == JCTree.Kind.MEMBER_SELECT || |
|
463 |
enclTr.getKind() == JCTree.Kind.PARAMETERIZED_TYPE || |
|
464 |
enclTr.getKind() == JCTree.Kind.ANNOTATED_TYPE)) { |
|
465 |
// Iterate also over the type tree, not just the type: the type is already |
|
466 |
// completely resolved and we cannot distinguish where the annotation |
|
467 |
// belongs for a nested type. |
|
468 |
if (enclTr.getKind() == JCTree.Kind.MEMBER_SELECT) { |
|
469 |
// only change encl in this case. |
|
470 |
enclTy = enclTy.getEnclosingType(); |
|
471 |
enclEl = enclEl.getEnclosingElement(); |
|
472 |
enclTr = ((JCFieldAccess)enclTr).getExpression(); |
|
473 |
} else if (enclTr.getKind() == JCTree.Kind.PARAMETERIZED_TYPE) { |
|
474 |
enclTr = ((JCTypeApply)enclTr).getType(); |
|
475 |
} else { |
|
476 |
// only other option because of while condition |
|
477 |
enclTr = ((JCAnnotatedType)enclTr).getUnderlyingType(); |
|
478 |
} |
|
479 |
} |
|
480 |
||
481 |
/** We are trying to annotate some enclosing type, |
|
482 |
* but nothing more exists. |
|
483 |
*/ |
|
484 |
if (enclTy != null && |
|
21041 | 485 |
enclTy.hasTag(TypeTag.NONE)) { |
486 |
switch (onlyTypeAnnotations.size()) { |
|
487 |
case 0: |
|
488 |
// Don't issue an error if all type annotations are |
|
489 |
// also declaration annotations. |
|
490 |
// If the annotations are also declaration annotations, they are |
|
491 |
// illegal as type annotations but might be legal as declaration annotations. |
|
492 |
// The normal declaration annotation checks make sure that the use is valid. |
|
493 |
break; |
|
494 |
case 1: |
|
495 |
log.error(typetree.pos(), "cant.type.annotate.scoping.1", |
|
496 |
onlyTypeAnnotations); |
|
497 |
break; |
|
498 |
default: |
|
499 |
log.error(typetree.pos(), "cant.type.annotate.scoping", |
|
500 |
onlyTypeAnnotations); |
|
501 |
} |
|
15385 | 502 |
return type; |
503 |
} |
|
504 |
||
505 |
// At this point we have visited the part of the nested |
|
506 |
// type that is written in the source code. |
|
507 |
// Now count from here to the actual top-level class to determine |
|
508 |
// the correct nesting. |
|
509 |
||
510 |
// The genericLocation for the annotation. |
|
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19651
diff
changeset
|
511 |
ListBuffer<TypePathEntry> depth = new ListBuffer<>(); |
15385 | 512 |
|
513 |
Type topTy = enclTy; |
|
514 |
while (enclEl != null && |
|
515 |
enclEl.getKind() != ElementKind.PACKAGE && |
|
516 |
topTy != null && |
|
517 |
topTy.getKind() != TypeKind.NONE && |
|
518 |
topTy.getKind() != TypeKind.ERROR) { |
|
519 |
topTy = topTy.getEnclosingType(); |
|
520 |
enclEl = enclEl.getEnclosingElement(); |
|
521 |
||
522 |
if (topTy != null && topTy.getKind() != TypeKind.NONE) { |
|
523 |
// Only count enclosing types. |
|
524 |
depth = depth.append(TypePathEntry.INNER_TYPE); |
|
525 |
} |
|
526 |
} |
|
527 |
||
528 |
if (depth.nonEmpty()) { |
|
529 |
// Only need to change the annotation positions |
|
530 |
// if they are on an enclosed type. |
|
15718 | 531 |
// All annotations share the same position; modify the first one. |
532 |
Attribute.TypeCompound a = annotations.get(0); |
|
533 |
TypeAnnotationPosition p = a.position; |
|
534 |
p.location = p.location.appendList(depth.toList()); |
|
15385 | 535 |
} |
536 |
||
537 |
Type ret = typeWithAnnotations(type, enclTy, annotations); |
|
17578 | 538 |
typetree.type = ret; |
15385 | 539 |
return ret; |
540 |
} |
|
541 |
} |
|
542 |
||
20258 | 543 |
private JCArrayTypeTree arrayTypeTree(JCTree typetree) { |
15385 | 544 |
if (typetree.getKind() == JCTree.Kind.ARRAY_TYPE) { |
545 |
return (JCArrayTypeTree) typetree; |
|
546 |
} else if (typetree.getKind() == JCTree.Kind.ANNOTATED_TYPE) { |
|
547 |
return (JCArrayTypeTree) ((JCAnnotatedType)typetree).underlyingType; |
|
548 |
} else { |
|
549 |
Assert.error("Could not determine array type from type tree: " + typetree); |
|
550 |
return null; |
|
551 |
} |
|
552 |
} |
|
553 |
||
554 |
/** Return a copy of the first type that only differs by |
|
555 |
* inserting the annotations to the left-most/inner-most type |
|
556 |
* or the type given by stopAt. |
|
557 |
* |
|
558 |
* We need the stopAt parameter to know where on a type to |
|
559 |
* put the annotations. |
|
560 |
* If we have nested classes Outer > Middle > Inner, and we |
|
561 |
* have the source type "@A Middle.Inner", we will invoke |
|
562 |
* this method with type = Outer.Middle.Inner, |
|
563 |
* stopAt = Middle.Inner, and annotations = @A. |
|
564 |
* |
|
565 |
* @param type The type to copy. |
|
566 |
* @param stopAt The type to stop at. |
|
567 |
* @param annotations The annotations to insert. |
|
568 |
* @return A copy of type that contains the annotations. |
|
569 |
*/ |
|
20258 | 570 |
private Type typeWithAnnotations(final Type type, |
15385 | 571 |
final Type stopAt, |
572 |
final List<Attribute.TypeCompound> annotations) { |
|
24396 | 573 |
//System.err.println("typeWithAnnotations " + type + " " + annotations + " stopAt " + stopAt); |
15385 | 574 |
Visitor<Type, List<TypeCompound>> visitor = |
575 |
new Type.Visitor<Type, List<Attribute.TypeCompound>>() { |
|
576 |
@Override |
|
577 |
public Type visitClassType(ClassType t, List<TypeCompound> s) { |
|
578 |
// assert that t.constValue() == null? |
|
579 |
if (t == stopAt || |
|
580 |
t.getEnclosingType() == Type.noType) { |
|
21041 | 581 |
return t.annotatedType(s); |
15385 | 582 |
} else { |
583 |
ClassType ret = new ClassType(t.getEnclosingType().accept(this, s), |
|
24396 | 584 |
t.typarams_field, t.tsym, |
585 |
t.getAnnotationMirrors()); |
|
15385 | 586 |
ret.all_interfaces_field = t.all_interfaces_field; |
587 |
ret.allparams_field = t.allparams_field; |
|
588 |
ret.interfaces_field = t.interfaces_field; |
|
589 |
ret.rank_field = t.rank_field; |
|
590 |
ret.supertype_field = t.supertype_field; |
|
591 |
return ret; |
|
592 |
} |
|
593 |
} |
|
594 |
||
595 |
@Override |
|
596 |
public Type visitWildcardType(WildcardType t, List<TypeCompound> s) { |
|
21041 | 597 |
return t.annotatedType(s); |
15385 | 598 |
} |
599 |
||
600 |
@Override |
|
601 |
public Type visitArrayType(ArrayType t, List<TypeCompound> s) { |
|
24396 | 602 |
ArrayType ret = new ArrayType(t.elemtype.accept(this, s), t.tsym, |
603 |
t.getAnnotationMirrors()); |
|
15385 | 604 |
return ret; |
605 |
} |
|
606 |
||
607 |
@Override |
|
608 |
public Type visitMethodType(MethodType t, List<TypeCompound> s) { |
|
609 |
// Impossible? |
|
610 |
return t; |
|
611 |
} |
|
612 |
||
613 |
@Override |
|
614 |
public Type visitPackageType(PackageType t, List<TypeCompound> s) { |
|
615 |
// Impossible? |
|
616 |
return t; |
|
617 |
} |
|
618 |
||
619 |
@Override |
|
620 |
public Type visitTypeVar(TypeVar t, List<TypeCompound> s) { |
|
21041 | 621 |
return t.annotatedType(s); |
15385 | 622 |
} |
623 |
||
624 |
@Override |
|
625 |
public Type visitCapturedType(CapturedType t, List<TypeCompound> s) { |
|
21041 | 626 |
return t.annotatedType(s); |
15385 | 627 |
} |
628 |
||
629 |
@Override |
|
630 |
public Type visitForAll(ForAll t, List<TypeCompound> s) { |
|
631 |
// Impossible? |
|
632 |
return t; |
|
633 |
} |
|
634 |
||
635 |
@Override |
|
636 |
public Type visitUndetVar(UndetVar t, List<TypeCompound> s) { |
|
637 |
// Impossible? |
|
638 |
return t; |
|
639 |
} |
|
640 |
||
641 |
@Override |
|
642 |
public Type visitErrorType(ErrorType t, List<TypeCompound> s) { |
|
21041 | 643 |
return t.annotatedType(s); |
15385 | 644 |
} |
645 |
||
646 |
@Override |
|
647 |
public Type visitType(Type t, List<TypeCompound> s) { |
|
21041 | 648 |
return t.annotatedType(s); |
15385 | 649 |
} |
650 |
}; |
|
651 |
||
652 |
return type.accept(visitor, annotations); |
|
653 |
} |
|
654 |
||
20258 | 655 |
private Attribute.TypeCompound toTypeCompound(Attribute.Compound a, TypeAnnotationPosition p) { |
15385 | 656 |
// It is safe to alias the position. |
657 |
return new Attribute.TypeCompound(a, p); |
|
658 |
} |
|
659 |
||
660 |
||
661 |
/* This is the beginning of the second part of organizing |
|
662 |
* type annotations: determine the type annotation positions. |
|
663 |
*/ |
|
664 |
||
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
665 |
// This method is considered deprecated, and will be removed |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
666 |
// in the near future. Don't use it for anything new. |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
667 |
private TypeAnnotationPosition |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
668 |
resolveFrame(JCTree tree, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
669 |
JCTree frame, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
670 |
List<JCTree> path, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
671 |
JCLambda currentLambda, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
672 |
int outer_type_index, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
673 |
ListBuffer<TypePathEntry> location) { |
15385 | 674 |
/* |
675 |
System.out.println("Resolving tree: " + tree + " kind: " + tree.getKind()); |
|
676 |
System.out.println(" Framing tree: " + frame + " kind: " + frame.getKind()); |
|
677 |
*/ |
|
15718 | 678 |
|
679 |
// Note that p.offset is set in |
|
680 |
// com.sun.tools.javac.jvm.Gen.setTypeAnnotationPositions(int) |
|
681 |
||
15385 | 682 |
switch (frame.getKind()) { |
683 |
case TYPE_CAST: |
|
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
684 |
return TypeAnnotationPosition.typeCast(location.toList(), |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
685 |
currentLambda, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
686 |
outer_type_index, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
687 |
frame.pos); |
15385 | 688 |
|
689 |
case INSTANCE_OF: |
|
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
690 |
return TypeAnnotationPosition.instanceOf(location.toList(), |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
691 |
currentLambda, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
692 |
frame.pos); |
15385 | 693 |
|
694 |
case NEW_CLASS: |
|
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
695 |
final JCNewClass frameNewClass = (JCNewClass) frame; |
17578 | 696 |
if (frameNewClass.def != null) { |
697 |
// Special handling for anonymous class instantiations |
|
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
698 |
final JCClassDecl frameClassDecl = frameNewClass.def; |
17578 | 699 |
if (frameClassDecl.extending == tree) { |
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
700 |
return TypeAnnotationPosition |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
701 |
.classExtends(location.toList(), currentLambda, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
702 |
frame.pos); |
17578 | 703 |
} else if (frameClassDecl.implementing.contains(tree)) { |
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
704 |
final int type_index = |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
705 |
frameClassDecl.implementing.indexOf(tree); |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
706 |
return TypeAnnotationPosition |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
707 |
.classExtends(location.toList(), currentLambda, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
708 |
type_index, frame.pos); |
17578 | 709 |
} else { |
710 |
// In contrast to CLASS below, typarams cannot occur here. |
|
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
711 |
throw new AssertionError("Could not determine position of tree " + tree + |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
712 |
" within frame " + frame); |
17578 | 713 |
} |
714 |
} else if (frameNewClass.typeargs.contains(tree)) { |
|
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
715 |
final int type_index = |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
716 |
frameNewClass.typeargs.indexOf(tree); |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
717 |
return TypeAnnotationPosition |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
718 |
.constructorInvocationTypeArg(location.toList(), |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
719 |
currentLambda, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
720 |
type_index, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
721 |
frame.pos); |
15385 | 722 |
} else { |
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
723 |
return TypeAnnotationPosition |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
724 |
.newObj(location.toList(), currentLambda, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
725 |
frame.pos); |
15385 | 726 |
} |
727 |
||
728 |
case NEW_ARRAY: |
|
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
729 |
return TypeAnnotationPosition |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
730 |
.newObj(location.toList(), currentLambda, frame.pos); |
15385 | 731 |
|
732 |
case ANNOTATION_TYPE: |
|
733 |
case CLASS: |
|
734 |
case ENUM: |
|
735 |
case INTERFACE: |
|
736 |
if (((JCClassDecl)frame).extending == tree) { |
|
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
737 |
return TypeAnnotationPosition |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
738 |
.classExtends(location.toList(), currentLambda, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
739 |
frame.pos); |
15385 | 740 |
} else if (((JCClassDecl)frame).implementing.contains(tree)) { |
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
741 |
final int type_index = |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
742 |
((JCClassDecl)frame).implementing.indexOf(tree); |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
743 |
return TypeAnnotationPosition |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
744 |
.classExtends(location.toList(), currentLambda, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
745 |
type_index, frame.pos); |
15385 | 746 |
} else if (((JCClassDecl)frame).typarams.contains(tree)) { |
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
747 |
final int parameter_index = |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
748 |
((JCClassDecl)frame).typarams.indexOf(tree); |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
749 |
return TypeAnnotationPosition |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
750 |
.typeParameter(location.toList(), currentLambda, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
751 |
parameter_index, frame.pos); |
15385 | 752 |
} else { |
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
753 |
throw new AssertionError("Could not determine position of tree " + |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
754 |
tree + " within frame " + frame); |
15385 | 755 |
} |
756 |
||
757 |
case METHOD: { |
|
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
758 |
final JCMethodDecl frameMethod = (JCMethodDecl) frame; |
15385 | 759 |
if (frameMethod.thrown.contains(tree)) { |
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
760 |
final int type_index = frameMethod.thrown.indexOf(tree); |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
761 |
return TypeAnnotationPosition |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
762 |
.methodThrows(location.toList(), currentLambda, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
763 |
type_index, frame.pos); |
15385 | 764 |
} else if (frameMethod.restype == tree) { |
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
765 |
return TypeAnnotationPosition |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
766 |
.methodReturn(location.toList(), currentLambda, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
767 |
frame.pos); |
15385 | 768 |
} else if (frameMethod.typarams.contains(tree)) { |
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
769 |
final int parameter_index = |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
770 |
frameMethod.typarams.indexOf(tree); |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
771 |
return TypeAnnotationPosition |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
772 |
.methodTypeParameter(location.toList(), |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
773 |
currentLambda, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
774 |
parameter_index, frame.pos); |
15385 | 775 |
} else { |
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
776 |
throw new AssertionError("Could not determine position of tree " + tree + |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
777 |
" within frame " + frame); |
15385 | 778 |
} |
779 |
} |
|
780 |
||
781 |
case PARAMETERIZED_TYPE: { |
|
17578 | 782 |
List<JCTree> newPath = path.tail; |
783 |
||
15385 | 784 |
if (((JCTypeApply)frame).clazz == tree) { |
785 |
// generic: RAW; noop |
|
786 |
} else if (((JCTypeApply)frame).arguments.contains(tree)) { |
|
787 |
JCTypeApply taframe = (JCTypeApply) frame; |
|
788 |
int arg = taframe.arguments.indexOf(tree); |
|
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
789 |
location = location.prepend( |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
790 |
new TypePathEntry(TypePathEntryKind.TYPE_ARGUMENT, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
791 |
arg)); |
15385 | 792 |
|
17578 | 793 |
Type typeToUse; |
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
794 |
if (newPath.tail != null && |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
795 |
newPath.tail.head.hasTag(Tag.NEWCLASS)) { |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
796 |
// If we are within an anonymous class |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
797 |
// instantiation, use its type, because it |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
798 |
// contains a correctly nested type. |
17578 | 799 |
typeToUse = newPath.tail.head.type; |
800 |
} else { |
|
801 |
typeToUse = taframe.type; |
|
802 |
} |
|
803 |
||
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
804 |
location = locateNestedTypes(typeToUse, location); |
15385 | 805 |
} else { |
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
806 |
throw new AssertionError("Could not determine type argument position of tree " + tree + |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
807 |
" within frame " + frame); |
15385 | 808 |
} |
809 |
||
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
810 |
return resolveFrame(newPath.head, newPath.tail.head, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
811 |
newPath, currentLambda, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
812 |
outer_type_index, location); |
15385 | 813 |
} |
814 |
||
15718 | 815 |
case MEMBER_REFERENCE: { |
816 |
JCMemberReference mrframe = (JCMemberReference) frame; |
|
817 |
||
818 |
if (mrframe.expr == tree) { |
|
819 |
switch (mrframe.mode) { |
|
820 |
case INVOKE: |
|
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
821 |
return TypeAnnotationPosition |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
822 |
.methodRef(location.toList(), currentLambda, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
823 |
frame.pos); |
15718 | 824 |
case NEW: |
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
825 |
return TypeAnnotationPosition |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
826 |
.constructorRef(location.toList(), |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
827 |
currentLambda, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
828 |
frame.pos); |
15718 | 829 |
default: |
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
830 |
throw new AssertionError("Unknown method reference mode " + mrframe.mode + |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
831 |
" for tree " + tree + " within frame " + frame); |
15718 | 832 |
} |
833 |
} else if (mrframe.typeargs != null && |
|
834 |
mrframe.typeargs.contains(tree)) { |
|
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
835 |
final int type_index = mrframe.typeargs.indexOf(tree); |
15718 | 836 |
switch (mrframe.mode) { |
837 |
case INVOKE: |
|
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
838 |
return TypeAnnotationPosition |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
839 |
.methodRefTypeArg(location.toList(), |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
840 |
currentLambda, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
841 |
type_index, frame.pos); |
15718 | 842 |
case NEW: |
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
843 |
return TypeAnnotationPosition |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
844 |
.constructorRefTypeArg(location.toList(), |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
845 |
currentLambda, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
846 |
type_index, frame.pos); |
15718 | 847 |
default: |
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
848 |
throw new AssertionError("Unknown method reference mode " + mrframe.mode + |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
849 |
" for tree " + tree + " within frame " + frame); |
15718 | 850 |
} |
851 |
} else { |
|
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
852 |
throw new AssertionError("Could not determine type argument position of tree " + tree + |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
853 |
" within frame " + frame); |
15718 | 854 |
} |
855 |
} |
|
856 |
||
15385 | 857 |
case ARRAY_TYPE: { |
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
858 |
location = location.prepend(TypePathEntry.ARRAY); |
15385 | 859 |
List<JCTree> newPath = path.tail; |
860 |
while (true) { |
|
861 |
JCTree npHead = newPath.tail.head; |
|
862 |
if (npHead.hasTag(JCTree.Tag.TYPEARRAY)) { |
|
863 |
newPath = newPath.tail; |
|
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
864 |
location = location.prepend(TypePathEntry.ARRAY); |
15385 | 865 |
} else if (npHead.hasTag(JCTree.Tag.ANNOTATED_TYPE)) { |
866 |
newPath = newPath.tail; |
|
867 |
} else { |
|
868 |
break; |
|
869 |
} |
|
870 |
} |
|
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
871 |
return resolveFrame(newPath.head, newPath.tail.head, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
872 |
newPath, currentLambda, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
873 |
outer_type_index, location); |
15385 | 874 |
} |
875 |
||
876 |
case TYPE_PARAMETER: |
|
877 |
if (path.tail.tail.head.hasTag(JCTree.Tag.CLASSDEF)) { |
|
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
878 |
final JCClassDecl clazz = |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
879 |
(JCClassDecl)path.tail.tail.head; |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
880 |
final int parameter_index = |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
881 |
clazz.typarams.indexOf(path.tail.head); |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
882 |
final int bound_index = |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
883 |
((JCTypeParameter)frame).bounds.get(0) |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
884 |
.type.isInterface() ? |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
885 |
((JCTypeParameter)frame).bounds.indexOf(tree) + 1: |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
886 |
((JCTypeParameter)frame).bounds.indexOf(tree); |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
887 |
return TypeAnnotationPosition |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
888 |
.typeParameterBound(location.toList(), |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
889 |
currentLambda, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
890 |
parameter_index, bound_index, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
891 |
frame.pos); |
15385 | 892 |
} else if (path.tail.tail.head.hasTag(JCTree.Tag.METHODDEF)) { |
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
893 |
final JCMethodDecl method = |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
894 |
(JCMethodDecl)path.tail.tail.head; |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
895 |
final int parameter_index = |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
896 |
method.typarams.indexOf(path.tail.head); |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
897 |
final int bound_index = |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
898 |
((JCTypeParameter)frame).bounds.get(0) |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
899 |
.type.isInterface() ? |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
900 |
((JCTypeParameter)frame).bounds.indexOf(tree) + 1: |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
901 |
((JCTypeParameter)frame).bounds.indexOf(tree); |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
902 |
return TypeAnnotationPosition |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
903 |
.methodTypeParameterBound(location.toList(), |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
904 |
currentLambda, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
905 |
parameter_index, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
906 |
bound_index, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
907 |
frame.pos); |
15385 | 908 |
} else { |
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
909 |
throw new AssertionError("Could not determine position of tree " + tree + |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
910 |
" within frame " + frame); |
15385 | 911 |
} |
912 |
||
913 |
case VARIABLE: |
|
914 |
VarSymbol v = ((JCVariableDecl)frame).sym; |
|
17578 | 915 |
if (v.getKind() != ElementKind.FIELD) { |
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17578
diff
changeset
|
916 |
v.owner.appendUniqueTypeAttributes(v.getRawTypeAttributes()); |
17578 | 917 |
} |
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
918 |
switch (v.getKind()) { |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
919 |
case LOCAL_VARIABLE: |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
920 |
return TypeAnnotationPosition |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
921 |
.localVariable(location.toList(), currentLambda, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
922 |
frame.pos); |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
923 |
case FIELD: |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
924 |
return TypeAnnotationPosition.field(location.toList(), |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
925 |
currentLambda, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
926 |
frame.pos); |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
927 |
case PARAMETER: |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
928 |
if (v.getQualifiedName().equals(names._this)) { |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
929 |
return TypeAnnotationPosition |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
930 |
.methodReceiver(location.toList(), |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
931 |
currentLambda, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
932 |
frame.pos); |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
933 |
} else { |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
934 |
final int parameter_index = |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
935 |
methodParamIndex(path, frame); |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
936 |
return TypeAnnotationPosition |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
937 |
.methodParameter(location.toList(), |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
938 |
currentLambda, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
939 |
parameter_index, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
940 |
frame.pos); |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
941 |
} |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
942 |
case EXCEPTION_PARAMETER: |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
943 |
return TypeAnnotationPosition |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
944 |
.exceptionParameter(location.toList(), |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
945 |
currentLambda, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
946 |
frame.pos); |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
947 |
case RESOURCE_VARIABLE: |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
948 |
return TypeAnnotationPosition |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
949 |
.resourceVariable(location.toList(), |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
950 |
currentLambda, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
951 |
frame.pos); |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
952 |
default: |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
953 |
throw new AssertionError("Found unexpected type annotation for variable: " + v + " with kind: " + v.getKind()); |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
954 |
} |
15385 | 955 |
|
956 |
case ANNOTATED_TYPE: { |
|
957 |
if (frame == tree) { |
|
958 |
// This is only true for the first annotated type we see. |
|
959 |
// For any other annotated types along the path, we do |
|
960 |
// not care about inner types. |
|
961 |
JCAnnotatedType atypetree = (JCAnnotatedType) frame; |
|
962 |
final Type utype = atypetree.underlyingType.type; |
|
22699
3b17c61ad5a1
8033218: Silent failure in TypeAnnotations.resolveFrame
emc
parents:
22163
diff
changeset
|
963 |
Assert.checkNonNull(utype); |
15385 | 964 |
Symbol tsym = utype.tsym; |
965 |
if (tsym.getKind().equals(ElementKind.TYPE_PARAMETER) || |
|
966 |
utype.getKind().equals(TypeKind.WILDCARD) || |
|
967 |
utype.getKind().equals(TypeKind.ARRAY)) { |
|
968 |
// Type parameters, wildcards, and arrays have the declaring |
|
969 |
// class/method as enclosing elements. |
|
970 |
// There is actually nothing to do for them. |
|
971 |
} else { |
|
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
972 |
location = locateNestedTypes(utype, location); |
15385 | 973 |
} |
974 |
} |
|
975 |
List<JCTree> newPath = path.tail; |
|
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
976 |
return resolveFrame(newPath.head, newPath.tail.head, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
977 |
newPath, currentLambda, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
978 |
outer_type_index, location); |
15385 | 979 |
} |
980 |
||
981 |
case UNION_TYPE: { |
|
982 |
List<JCTree> newPath = path.tail; |
|
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
983 |
return resolveFrame(newPath.head, newPath.tail.head, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
984 |
newPath, currentLambda, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
985 |
outer_type_index, location); |
15385 | 986 |
} |
987 |
||
15718 | 988 |
case INTERSECTION_TYPE: { |
989 |
JCTypeIntersection isect = (JCTypeIntersection)frame; |
|
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
990 |
final List<JCTree> newPath = path.tail; |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
991 |
return resolveFrame(newPath.head, newPath.tail.head, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
992 |
newPath, currentLambda, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
993 |
isect.bounds.indexOf(tree), location); |
15718 | 994 |
} |
995 |
||
15385 | 996 |
case METHOD_INVOCATION: { |
997 |
JCMethodInvocation invocation = (JCMethodInvocation)frame; |
|
998 |
if (!invocation.typeargs.contains(tree)) { |
|
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
999 |
throw new AssertionError("{" + tree + "} is not an argument in the invocation: " + invocation); |
15385 | 1000 |
} |
19651 | 1001 |
MethodSymbol exsym = (MethodSymbol) TreeInfo.symbol(invocation.getMethodSelect()); |
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1002 |
final int type_index = invocation.typeargs.indexOf(tree); |
19651 | 1003 |
if (exsym == null) { |
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1004 |
throw new AssertionError("could not determine symbol for {" + invocation + "}"); |
19651 | 1005 |
} else if (exsym.isConstructor()) { |
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1006 |
return TypeAnnotationPosition |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1007 |
.constructorInvocationTypeArg(location.toList(), |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1008 |
currentLambda, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1009 |
type_index, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1010 |
invocation.pos); |
19651 | 1011 |
} else { |
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1012 |
return TypeAnnotationPosition |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1013 |
.methodInvocationTypeArg(location.toList(), |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1014 |
currentLambda, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1015 |
type_index, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1016 |
invocation.pos); |
19651 | 1017 |
} |
15385 | 1018 |
} |
1019 |
||
1020 |
case EXTENDS_WILDCARD: |
|
1021 |
case SUPER_WILDCARD: { |
|
1022 |
// Annotations in wildcard bounds |
|
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1023 |
final List<JCTree> newPath = path.tail; |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1024 |
return resolveFrame(newPath.head, newPath.tail.head, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1025 |
newPath, currentLambda, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1026 |
outer_type_index, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1027 |
location.prepend(TypePathEntry.WILDCARD)); |
15385 | 1028 |
} |
1029 |
||
1030 |
case MEMBER_SELECT: { |
|
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1031 |
final List<JCTree> newPath = path.tail; |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1032 |
return resolveFrame(newPath.head, newPath.tail.head, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1033 |
newPath, currentLambda, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1034 |
outer_type_index, location); |
15385 | 1035 |
} |
1036 |
||
1037 |
default: |
|
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1038 |
throw new AssertionError("Unresolved frame: " + frame + |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1039 |
" of kind: " + frame.getKind() + |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1040 |
"\n Looking for tree: " + tree); |
15385 | 1041 |
} |
1042 |
} |
|
1043 |
||
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1044 |
private ListBuffer<TypePathEntry> |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1045 |
locateNestedTypes(Type type, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1046 |
ListBuffer<TypePathEntry> depth) { |
15385 | 1047 |
Type encl = type.getEnclosingType(); |
1048 |
while (encl != null && |
|
1049 |
encl.getKind() != TypeKind.NONE && |
|
1050 |
encl.getKind() != TypeKind.ERROR) { |
|
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1051 |
depth = depth.prepend(TypePathEntry.INNER_TYPE); |
15385 | 1052 |
encl = encl.getEnclosingType(); |
1053 |
} |
|
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1054 |
return depth; |
15385 | 1055 |
} |
1056 |
||
20258 | 1057 |
private int methodParamIndex(List<JCTree> path, JCTree param) { |
15385 | 1058 |
List<JCTree> curr = path; |
17578 | 1059 |
while (curr.head.getTag() != Tag.METHODDEF && |
1060 |
curr.head.getTag() != Tag.LAMBDA) { |
|
15385 | 1061 |
curr = curr.tail; |
1062 |
} |
|
17578 | 1063 |
if (curr.head.getTag() == Tag.METHODDEF) { |
1064 |
JCMethodDecl method = (JCMethodDecl)curr.head; |
|
1065 |
return method.params.indexOf(param); |
|
1066 |
} else if (curr.head.getTag() == Tag.LAMBDA) { |
|
1067 |
JCLambda lambda = (JCLambda)curr.head; |
|
1068 |
return lambda.params.indexOf(param); |
|
1069 |
} else { |
|
1070 |
Assert.error("methodParamIndex expected to find method or lambda for param: " + param); |
|
1071 |
return -1; |
|
1072 |
} |
|
15385 | 1073 |
} |
1074 |
||
1075 |
// Each class (including enclosed inner classes) is visited separately. |
|
1076 |
// This flag is used to prevent from visiting inner classes. |
|
1077 |
private boolean isInClass = false; |
|
1078 |
||
1079 |
@Override |
|
1080 |
public void visitClassDef(JCClassDecl tree) { |
|
1081 |
if (isInClass) |
|
1082 |
return; |
|
1083 |
isInClass = true; |
|
17578 | 1084 |
|
15385 | 1085 |
if (sigOnly) { |
1086 |
scan(tree.mods); |
|
1087 |
scan(tree.typarams); |
|
1088 |
scan(tree.extending); |
|
1089 |
scan(tree.implementing); |
|
1090 |
} |
|
1091 |
scan(tree.defs); |
|
1092 |
} |
|
1093 |
||
1094 |
/** |
|
1095 |
* Resolve declaration vs. type annotations in methods and |
|
1096 |
* then determine the positions. |
|
1097 |
*/ |
|
1098 |
@Override |
|
1099 |
public void visitMethodDef(final JCMethodDecl tree) { |
|
1100 |
if (tree.sym == null) { |
|
21043
3b000be15694
8026286: Improper locking of annotation queues causes assertion failures.
emc
parents:
21041
diff
changeset
|
1101 |
Assert.error("Visiting tree node before memberEnter"); |
21010
5ffe0d8a5e24
8008762: Type annotation on inner class in anonymous class show up as regular type annotations
emc
parents:
20258
diff
changeset
|
1102 |
} |
15385 | 1103 |
if (sigOnly) { |
17578 | 1104 |
if (!tree.mods.annotations.isEmpty()) { |
15385 | 1105 |
if (tree.sym.isConstructor()) { |
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1106 |
final TypeAnnotationPosition pos = |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1107 |
TypeAnnotationPosition.methodReturn(tree.pos); |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1108 |
// Use null to mark that the annotations go |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1109 |
// with the symbol. |
15385 | 1110 |
separateAnnotationsKinds(tree, null, tree.sym, pos); |
1111 |
} else { |
|
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1112 |
final TypeAnnotationPosition pos = |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1113 |
TypeAnnotationPosition.methodReturn(tree.restype.pos); |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1114 |
separateAnnotationsKinds(tree.restype, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1115 |
tree.sym.type.getReturnType(), |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1116 |
tree.sym, pos); |
15385 | 1117 |
} |
1118 |
} |
|
17578 | 1119 |
if (tree.recvparam != null && tree.recvparam.sym != null && |
1120 |
!tree.recvparam.mods.annotations.isEmpty()) { |
|
1121 |
// Nothing to do for separateAnnotationsKinds if |
|
1122 |
// there are no annotations of either kind. |
|
15385 | 1123 |
// TODO: make sure there are no declaration annotations. |
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1124 |
final TypeAnnotationPosition pos = |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1125 |
TypeAnnotationPosition.methodReceiver(tree.recvparam.vartype.pos); |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1126 |
separateAnnotationsKinds(tree.recvparam.vartype, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1127 |
tree.recvparam.sym.type, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1128 |
tree.recvparam.sym, pos); |
15385 | 1129 |
} |
1130 |
int i = 0; |
|
1131 |
for (JCVariableDecl param : tree.params) { |
|
17578 | 1132 |
if (!param.mods.annotations.isEmpty()) { |
1133 |
// Nothing to do for separateAnnotationsKinds if |
|
1134 |
// there are no annotations of either kind. |
|
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1135 |
final TypeAnnotationPosition pos = |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1136 |
TypeAnnotationPosition.methodParameter(i, param.vartype.pos); |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1137 |
separateAnnotationsKinds(param.vartype, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1138 |
param.sym.type, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1139 |
param.sym, pos); |
17578 | 1140 |
} |
15385 | 1141 |
++i; |
1142 |
} |
|
1143 |
} |
|
1144 |
||
1145 |
push(tree); |
|
1146 |
// super.visitMethodDef(tree); |
|
1147 |
if (sigOnly) { |
|
1148 |
scan(tree.mods); |
|
1149 |
scan(tree.restype); |
|
1150 |
scan(tree.typarams); |
|
1151 |
scan(tree.recvparam); |
|
1152 |
scan(tree.params); |
|
1153 |
scan(tree.thrown); |
|
1154 |
} else { |
|
1155 |
scan(tree.defaultValue); |
|
1156 |
scan(tree.body); |
|
1157 |
} |
|
1158 |
pop(); |
|
1159 |
} |
|
1160 |
||
17578 | 1161 |
/* Store a reference to the current lambda expression, to |
1162 |
* be used by all type annotations within this expression. |
|
1163 |
*/ |
|
1164 |
private JCLambda currentLambda = null; |
|
1165 |
||
1166 |
public void visitLambda(JCLambda tree) { |
|
1167 |
JCLambda prevLambda = currentLambda; |
|
1168 |
try { |
|
1169 |
currentLambda = tree; |
|
1170 |
||
1171 |
int i = 0; |
|
1172 |
for (JCVariableDecl param : tree.params) { |
|
1173 |
if (!param.mods.annotations.isEmpty()) { |
|
1174 |
// Nothing to do for separateAnnotationsKinds if |
|
1175 |
// there are no annotations of either kind. |
|
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1176 |
final TypeAnnotationPosition pos = |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1177 |
TypeAnnotationPosition.methodParameter(tree, i, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1178 |
param.vartype.pos); |
17578 | 1179 |
separateAnnotationsKinds(param.vartype, param.sym.type, param.sym, pos); |
1180 |
} |
|
1181 |
++i; |
|
1182 |
} |
|
1183 |
||
1184 |
push(tree); |
|
1185 |
scan(tree.body); |
|
1186 |
scan(tree.params); |
|
1187 |
pop(); |
|
1188 |
} finally { |
|
1189 |
currentLambda = prevLambda; |
|
1190 |
} |
|
1191 |
} |
|
1192 |
||
15385 | 1193 |
/** |
1194 |
* Resolve declaration vs. type annotations in variable declarations and |
|
1195 |
* then determine the positions. |
|
1196 |
*/ |
|
1197 |
@Override |
|
1198 |
public void visitVarDef(final JCVariableDecl tree) { |
|
17578 | 1199 |
if (tree.mods.annotations.isEmpty()) { |
1200 |
// Nothing to do for separateAnnotationsKinds if |
|
1201 |
// there are no annotations of either kind. |
|
1202 |
} else if (tree.sym == null) { |
|
21043
3b000be15694
8026286: Improper locking of annotation queues causes assertion failures.
emc
parents:
21041
diff
changeset
|
1203 |
Assert.error("Visiting tree node before memberEnter"); |
15718 | 1204 |
} else if (tree.sym.getKind() == ElementKind.PARAMETER) { |
17578 | 1205 |
// Parameters are handled in visitMethodDef or visitLambda. |
15385 | 1206 |
} else if (tree.sym.getKind() == ElementKind.FIELD) { |
1207 |
if (sigOnly) { |
|
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1208 |
TypeAnnotationPosition pos = |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1209 |
TypeAnnotationPosition.field(tree.pos); |
15385 | 1210 |
separateAnnotationsKinds(tree.vartype, tree.sym.type, tree.sym, pos); |
1211 |
} |
|
1212 |
} else if (tree.sym.getKind() == ElementKind.LOCAL_VARIABLE) { |
|
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1213 |
final TypeAnnotationPosition pos = |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1214 |
TypeAnnotationPosition.localVariable(currentLambda, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1215 |
tree.pos); |
15385 | 1216 |
separateAnnotationsKinds(tree.vartype, tree.sym.type, tree.sym, pos); |
1217 |
} else if (tree.sym.getKind() == ElementKind.EXCEPTION_PARAMETER) { |
|
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1218 |
final TypeAnnotationPosition pos = |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1219 |
TypeAnnotationPosition.exceptionParameter(currentLambda, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1220 |
tree.pos); |
15385 | 1221 |
separateAnnotationsKinds(tree.vartype, tree.sym.type, tree.sym, pos); |
1222 |
} else if (tree.sym.getKind() == ElementKind.RESOURCE_VARIABLE) { |
|
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1223 |
final TypeAnnotationPosition pos = |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1224 |
TypeAnnotationPosition.resourceVariable(currentLambda, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1225 |
tree.pos); |
15385 | 1226 |
separateAnnotationsKinds(tree.vartype, tree.sym.type, tree.sym, pos); |
15718 | 1227 |
} else if (tree.sym.getKind() == ElementKind.ENUM_CONSTANT) { |
1228 |
// No type annotations can occur here. |
|
15385 | 1229 |
} else { |
1230 |
// There is nothing else in a variable declaration that needs separation. |
|
15718 | 1231 |
Assert.error("Unhandled variable kind: " + tree + " of kind: " + tree.sym.getKind()); |
15385 | 1232 |
} |
1233 |
||
1234 |
push(tree); |
|
1235 |
// super.visitVarDef(tree); |
|
1236 |
scan(tree.mods); |
|
1237 |
scan(tree.vartype); |
|
1238 |
if (!sigOnly) { |
|
1239 |
scan(tree.init); |
|
1240 |
} |
|
1241 |
pop(); |
|
1242 |
} |
|
1243 |
||
1244 |
@Override |
|
1245 |
public void visitBlock(JCBlock tree) { |
|
1246 |
// Do not descend into top-level blocks when only interested |
|
1247 |
// in the signature. |
|
1248 |
if (!sigOnly) { |
|
1249 |
scan(tree.stats); |
|
1250 |
} |
|
1251 |
} |
|
1252 |
||
1253 |
@Override |
|
1254 |
public void visitAnnotatedType(JCAnnotatedType tree) { |
|
1255 |
push(tree); |
|
1256 |
findPosition(tree, tree, tree.annotations); |
|
1257 |
pop(); |
|
1258 |
super.visitAnnotatedType(tree); |
|
1259 |
} |
|
1260 |
||
1261 |
@Override |
|
1262 |
public void visitTypeParameter(JCTypeParameter tree) { |
|
1263 |
findPosition(tree, peek2(), tree.annotations); |
|
1264 |
super.visitTypeParameter(tree); |
|
1265 |
} |
|
1266 |
||
21499
203cfd174518
8023682: Incorrect attributes emitted for anonymous class declaration
emc
parents:
21481
diff
changeset
|
1267 |
private void copyNewClassAnnotationsToOwner(JCNewClass tree) { |
203cfd174518
8023682: Incorrect attributes emitted for anonymous class declaration
emc
parents:
21481
diff
changeset
|
1268 |
Symbol sym = tree.def.sym; |
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1269 |
final TypeAnnotationPosition pos = |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1270 |
TypeAnnotationPosition.newObj(tree.pos); |
22163 | 1271 |
ListBuffer<Attribute.TypeCompound> newattrs = new ListBuffer<>(); |
21499
203cfd174518
8023682: Incorrect attributes emitted for anonymous class declaration
emc
parents:
21481
diff
changeset
|
1272 |
|
203cfd174518
8023682: Incorrect attributes emitted for anonymous class declaration
emc
parents:
21481
diff
changeset
|
1273 |
for (Attribute.TypeCompound old : sym.getRawTypeAttributes()) { |
203cfd174518
8023682: Incorrect attributes emitted for anonymous class declaration
emc
parents:
21481
diff
changeset
|
1274 |
newattrs.append(new Attribute.TypeCompound(old.type, old.values, |
203cfd174518
8023682: Incorrect attributes emitted for anonymous class declaration
emc
parents:
21481
diff
changeset
|
1275 |
pos)); |
203cfd174518
8023682: Incorrect attributes emitted for anonymous class declaration
emc
parents:
21481
diff
changeset
|
1276 |
} |
203cfd174518
8023682: Incorrect attributes emitted for anonymous class declaration
emc
parents:
21481
diff
changeset
|
1277 |
|
203cfd174518
8023682: Incorrect attributes emitted for anonymous class declaration
emc
parents:
21481
diff
changeset
|
1278 |
sym.owner.appendUniqueTypeAttributes(newattrs.toList()); |
203cfd174518
8023682: Incorrect attributes emitted for anonymous class declaration
emc
parents:
21481
diff
changeset
|
1279 |
} |
203cfd174518
8023682: Incorrect attributes emitted for anonymous class declaration
emc
parents:
21481
diff
changeset
|
1280 |
|
15385 | 1281 |
@Override |
17578 | 1282 |
public void visitNewClass(JCNewClass tree) { |
1283 |
if (tree.def != null && |
|
1284 |
!tree.def.mods.annotations.isEmpty()) { |
|
1285 |
JCClassDecl classdecl = tree.def; |
|
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1286 |
TypeAnnotationPosition pos; |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1287 |
|
17578 | 1288 |
if (classdecl.extending == tree.clazz) { |
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1289 |
pos = TypeAnnotationPosition.classExtends(tree.pos); |
17578 | 1290 |
} else if (classdecl.implementing.contains(tree.clazz)) { |
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1291 |
final int index = classdecl.implementing.indexOf(tree.clazz); |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1292 |
pos = TypeAnnotationPosition.classExtends(index, tree.pos); |
17578 | 1293 |
} else { |
1294 |
// In contrast to CLASS elsewhere, typarams cannot occur here. |
|
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1295 |
throw new AssertionError("Could not determine position of tree " + tree); |
17578 | 1296 |
} |
1297 |
Type before = classdecl.sym.type; |
|
1298 |
separateAnnotationsKinds(classdecl, tree.clazz.type, classdecl.sym, pos); |
|
21499
203cfd174518
8023682: Incorrect attributes emitted for anonymous class declaration
emc
parents:
21481
diff
changeset
|
1299 |
copyNewClassAnnotationsToOwner(tree); |
17578 | 1300 |
// classdecl.sym.type now contains an annotated type, which |
1301 |
// is not what we want there. |
|
1302 |
// TODO: should we put this type somewhere in the superclass/interface? |
|
1303 |
classdecl.sym.type = before; |
|
1304 |
} |
|
1305 |
||
1306 |
scan(tree.encl); |
|
1307 |
scan(tree.typeargs); |
|
1308 |
scan(tree.clazz); |
|
1309 |
scan(tree.args); |
|
1310 |
||
1311 |
// The class body will already be scanned. |
|
1312 |
// scan(tree.def); |
|
1313 |
} |
|
1314 |
||
1315 |
@Override |
|
15385 | 1316 |
public void visitNewArray(JCNewArray tree) { |
1317 |
findPosition(tree, tree, tree.annotations); |
|
1318 |
int dimAnnosCount = tree.dimAnnotations.size(); |
|
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19651
diff
changeset
|
1319 |
ListBuffer<TypePathEntry> depth = new ListBuffer<>(); |
15385 | 1320 |
|
1321 |
// handle annotations associated with dimensions |
|
1322 |
for (int i = 0; i < dimAnnosCount; ++i) { |
|
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1323 |
ListBuffer<TypePathEntry> location = |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1324 |
new ListBuffer<TypePathEntry>(); |
15385 | 1325 |
if (i != 0) { |
1326 |
depth = depth.append(TypePathEntry.ARRAY); |
|
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1327 |
location = location.appendList(depth.toList()); |
15385 | 1328 |
} |
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1329 |
final TypeAnnotationPosition p = |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1330 |
TypeAnnotationPosition.newObj(location.toList(), |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1331 |
currentLambda, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1332 |
tree.pos); |
15385 | 1333 |
|
1334 |
setTypeAnnotationPos(tree.dimAnnotations.get(i), p); |
|
1335 |
} |
|
1336 |
||
1337 |
// handle "free" annotations |
|
1338 |
// int i = dimAnnosCount == 0 ? 0 : dimAnnosCount - 1; |
|
1339 |
// TODO: is depth.size == i here? |
|
1340 |
JCExpression elemType = tree.elemtype; |
|
17578 | 1341 |
depth = depth.append(TypePathEntry.ARRAY); |
15385 | 1342 |
while (elemType != null) { |
1343 |
if (elemType.hasTag(JCTree.Tag.ANNOTATED_TYPE)) { |
|
1344 |
JCAnnotatedType at = (JCAnnotatedType)elemType; |
|
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1345 |
final ListBuffer<TypePathEntry> locationbuf = |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1346 |
locateNestedTypes(elemType.type, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1347 |
new ListBuffer<TypePathEntry>()); |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1348 |
final List<TypePathEntry> location = |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1349 |
locationbuf.toList().prependList(depth.toList()); |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1350 |
final TypeAnnotationPosition p = |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1351 |
TypeAnnotationPosition.newObj(location, currentLambda, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1352 |
tree.pos); |
15385 | 1353 |
setTypeAnnotationPos(at.annotations, p); |
1354 |
elemType = at.underlyingType; |
|
1355 |
} else if (elemType.hasTag(JCTree.Tag.TYPEARRAY)) { |
|
1356 |
depth = depth.append(TypePathEntry.ARRAY); |
|
1357 |
elemType = ((JCArrayTypeTree)elemType).elemtype; |
|
17578 | 1358 |
} else if (elemType.hasTag(JCTree.Tag.SELECT)) { |
1359 |
elemType = ((JCFieldAccess)elemType).selected; |
|
15385 | 1360 |
} else { |
1361 |
break; |
|
1362 |
} |
|
1363 |
} |
|
1364 |
scan(tree.elems); |
|
1365 |
} |
|
1366 |
||
1367 |
private void findPosition(JCTree tree, JCTree frame, List<JCAnnotation> annotations) { |
|
1368 |
if (!annotations.isEmpty()) { |
|
1369 |
/* |
|
21010
5ffe0d8a5e24
8008762: Type annotation on inner class in anonymous class show up as regular type annotations
emc
parents:
20258
diff
changeset
|
1370 |
System.err.println("Finding pos for: " + annotations); |
5ffe0d8a5e24
8008762: Type annotation on inner class in anonymous class show up as regular type annotations
emc
parents:
20258
diff
changeset
|
1371 |
System.err.println(" tree: " + tree + " kind: " + tree.getKind()); |
5ffe0d8a5e24
8008762: Type annotation on inner class in anonymous class show up as regular type annotations
emc
parents:
20258
diff
changeset
|
1372 |
System.err.println(" frame: " + frame + " kind: " + frame.getKind()); |
15385 | 1373 |
*/ |
22702
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1374 |
final TypeAnnotationPosition p = |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1375 |
resolveFrame(tree, frame, frames.toList(), currentLambda, 0, |
1297fbaf34fa
8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents:
22699
diff
changeset
|
1376 |
new ListBuffer<TypePathEntry>()); |
15385 | 1377 |
setTypeAnnotationPos(annotations, p); |
1378 |
} |
|
1379 |
} |
|
1380 |
||
20258 | 1381 |
private void setTypeAnnotationPos(List<JCAnnotation> annotations, |
15385 | 1382 |
TypeAnnotationPosition position) { |
1383 |
for (JCAnnotation anno : annotations) { |
|
17578 | 1384 |
// attribute might be null during DeferredAttr; |
1385 |
// we will be back later. |
|
1386 |
if (anno.attribute != null) { |
|
1387 |
((Attribute.TypeCompound) anno.attribute).position = position; |
|
1388 |
} |
|
15385 | 1389 |
} |
1390 |
} |
|
17578 | 1391 |
|
1392 |
@Override |
|
1393 |
public String toString() { |
|
1394 |
return super.toString() + ": sigOnly: " + sigOnly; |
|
1395 |
} |
|
15385 | 1396 |
} |
1397 |
} |