221 return; |
221 return; |
222 } |
222 } |
223 |
223 |
224 s.resetAnnotations(); // mark Annotations as incomplete for now |
224 s.resetAnnotations(); // mark Annotations as incomplete for now |
225 |
225 |
226 normal(new Runnable() { |
226 normal(() -> { |
227 @Override |
227 Assert.check(s.annotationsPendingCompletion()); |
228 public String toString() { |
228 JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile); |
229 return "Annotate " + annotations + " onto " + s + " in " + s.owner; |
229 DiagnosticPosition prevLintPos = |
230 } |
230 deferPos != null |
231 |
231 ? deferredLintHandler.setPos(deferPos) |
232 @Override |
232 : deferredLintHandler.immediate(); |
233 public void run() { |
233 Lint prevLint = deferPos != null ? null : chk.setLint(lint); |
234 Assert.check(s.annotationsPendingCompletion()); |
234 try { |
235 JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile); |
235 if (s.hasAnnotations() && annotations.nonEmpty()) |
236 DiagnosticPosition prevLintPos = |
236 log.error(annotations.head.pos, "already.annotated", Kinds.kindName(s), s); |
237 deferPos != null |
237 |
238 ? deferredLintHandler.setPos(deferPos) |
238 Assert.checkNonNull(s, "Symbol argument to actualEnterAnnotations is null"); |
239 : deferredLintHandler.immediate(); |
239 |
240 Lint prevLint = deferPos != null ? null : chk.setLint(lint); |
240 // false is passed as fifth parameter since annotateLater is |
241 try { |
241 // never called for a type parameter |
242 if (s.hasAnnotations() && annotations.nonEmpty()) |
242 annotateNow(s, annotations, localEnv, false, false); |
243 log.error(annotations.head.pos, "already.annotated", Kinds.kindName(s), s); |
243 } finally { |
244 |
244 if (prevLint != null) |
245 Assert.checkNonNull(s, "Symbol argument to actualEnterAnnotations is null"); |
245 chk.setLint(prevLint); |
246 |
246 deferredLintHandler.setPos(prevLintPos); |
247 // false is passed as fifth parameter since annotateLater is |
247 log.useSource(prev); |
248 // never called for a type parameter |
|
249 annotateNow(s, annotations, localEnv, false, false); |
|
250 } finally { |
|
251 if (prevLint != null) |
|
252 chk.setLint(prevLint); |
|
253 deferredLintHandler.setPos(prevLintPos); |
|
254 log.useSource(prev); |
|
255 } |
|
256 } |
248 } |
257 }); |
249 }); |
258 |
250 |
259 validate(new Runnable() { //validate annotations |
251 validate(() -> { //validate annotations |
260 @Override |
252 JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile); |
261 public void run() { |
253 try { |
262 JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile); |
254 chk.validateAnnotations(annotations, s); |
263 try { |
255 } finally { |
264 chk.validateAnnotations(annotations, s); |
256 log.useSource(prev); |
265 } finally { |
|
266 log.useSource(prev); |
|
267 } |
|
268 } |
|
269 |
|
270 @Override |
|
271 public String toString() { |
|
272 return "validate annotations: " + annotations + " on " + s; |
|
273 } |
257 } |
274 }); |
258 }); |
275 } |
259 } |
276 |
260 |
277 |
261 |
278 /** Queue processing of an attribute default value. */ |
262 /** Queue processing of an attribute default value. */ |
279 public void annotateDefaultValueLater(JCExpression defaultValue, Env<AttrContext> localEnv, |
263 public void annotateDefaultValueLater(JCExpression defaultValue, Env<AttrContext> localEnv, |
280 MethodSymbol m, DiagnosticPosition deferPos) |
264 MethodSymbol m, DiagnosticPosition deferPos) |
281 { |
265 { |
282 normal(new Runnable() { |
266 normal(() -> { |
283 @Override |
267 JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile); |
284 public void run() { |
268 DiagnosticPosition prevLintPos = deferredLintHandler.setPos(deferPos); |
285 JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile); |
269 try { |
286 DiagnosticPosition prevLintPos = deferredLintHandler.setPos(deferPos); |
270 enterDefaultValue(defaultValue, localEnv, m); |
287 try { |
271 } finally { |
288 enterDefaultValue(defaultValue, localEnv, m); |
272 deferredLintHandler.setPos(prevLintPos); |
289 } finally { |
273 log.useSource(prev); |
290 deferredLintHandler.setPos(prevLintPos); |
|
291 log.useSource(prev); |
|
292 } |
|
293 } |
|
294 |
|
295 @Override |
|
296 public String toString() { |
|
297 return "Annotate " + m.owner + "." + |
|
298 m + " default " + defaultValue; |
|
299 } |
274 } |
300 }); |
275 }); |
301 |
276 |
302 validate(new Runnable() { //validate annotations |
277 validate(() -> { //validate annotations |
303 @Override |
278 JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile); |
304 public void run() { |
279 try { |
305 JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile); |
280 // if default value is an annotation, check it is a well-formed |
306 try { |
281 // annotation value (e.g. no duplicate values, no missing values, etc.) |
307 // if default value is an annotation, check it is a well-formed |
282 chk.validateAnnotationTree(defaultValue); |
308 // annotation value (e.g. no duplicate values, no missing values, etc.) |
283 } finally { |
309 chk.validateAnnotationTree(defaultValue); |
284 log.useSource(prev); |
310 } finally { |
|
311 log.useSource(prev); |
|
312 } |
|
313 } |
|
314 |
|
315 @Override |
|
316 public String toString() { |
|
317 return "Validate default value " + m.owner + "." + m + " default " + defaultValue; |
|
318 } |
285 } |
319 }); |
286 }); |
320 } |
287 } |
321 |
288 |
322 /** Enter a default value for an annotation element. */ |
289 /** Enter a default value for an annotation element. */ |
990 */ |
957 */ |
991 public void queueScanTreeAndTypeAnnotate(JCTree tree, Env<AttrContext> env, Symbol sym, |
958 public void queueScanTreeAndTypeAnnotate(JCTree tree, Env<AttrContext> env, Symbol sym, |
992 DiagnosticPosition deferPos) |
959 DiagnosticPosition deferPos) |
993 { |
960 { |
994 Assert.checkNonNull(sym); |
961 Assert.checkNonNull(sym); |
995 normal(new Runnable() { |
962 normal(() -> tree.accept(new TypeAnnotate(env, sym, deferPos))); |
996 @Override |
|
997 public String toString() { |
|
998 return "type annotate " + tree + " onto " + sym + " in " + sym.owner; |
|
999 } |
|
1000 |
|
1001 @Override |
|
1002 public void run() { |
|
1003 tree.accept(new TypeAnnotate(env, sym, deferPos)); |
|
1004 } |
|
1005 }); |
|
1006 } |
963 } |
1007 |
964 |
1008 /** |
965 /** |
1009 * Apply the annotations to the particular type. |
966 * Apply the annotations to the particular type. |
1010 */ |
967 */ |
1011 public void annotateTypeSecondStage(JCTree tree, List<JCAnnotation> annotations, Type storeAt) { |
968 public void annotateTypeSecondStage(JCTree tree, List<JCAnnotation> annotations, Type storeAt) { |
1012 typeAnnotation(new Runnable() { |
969 typeAnnotation(() -> { |
1013 @Override |
970 List<Attribute.TypeCompound> compounds = fromAnnotations(annotations); |
1014 public String toString() { |
971 Assert.check(annotations.size() == compounds.size()); |
1015 return "Type annotate 2:nd stage " + annotations + " onto " + tree; |
972 storeAt.getMetadataOfKind(Kind.ANNOTATIONS).combine(new TypeMetadata.Annotations(compounds)); |
1016 } |
|
1017 |
|
1018 @Override |
|
1019 public void run() { |
|
1020 List<Attribute.TypeCompound> compounds = fromAnnotations(annotations); |
|
1021 Assert.check(annotations.size() == compounds.size()); |
|
1022 storeAt.getMetadataOfKind(Kind.ANNOTATIONS).combine(new TypeMetadata.Annotations(compounds)); |
|
1023 } |
|
1024 }); |
973 }); |
1025 } |
974 } |
1026 |
975 |
1027 /** |
976 /** |
1028 * Apply the annotations to the particular type. |
977 * Apply the annotations to the particular type. |
1029 */ |
978 */ |
1030 public void annotateTypeParameterSecondStage(JCTree tree, List<JCAnnotation> annotations) { |
979 public void annotateTypeParameterSecondStage(JCTree tree, List<JCAnnotation> annotations) { |
1031 typeAnnotation(new Runnable() { |
980 typeAnnotation(() -> { |
1032 @Override |
981 List<Attribute.TypeCompound> compounds = fromAnnotations(annotations); |
1033 public String toString() { |
982 Assert.check(annotations.size() == compounds.size()); |
1034 return "Type annotate 2:nd stage " + annotations + " onto " + tree; |
|
1035 } |
|
1036 |
|
1037 @Override |
|
1038 public void run() { |
|
1039 List<Attribute.TypeCompound> compounds = fromAnnotations(annotations); |
|
1040 Assert.check(annotations.size() == compounds.size()); |
|
1041 } |
|
1042 }); |
983 }); |
1043 } |
984 } |
1044 |
985 |
1045 /** |
986 /** |
1046 * We need to use a TreeScanner, because it is not enough to visit the top-level |
987 * We need to use a TreeScanner, because it is not enough to visit the top-level |