47 * If you write code that depends on this, you do so at your own risk. |
47 * If you write code that depends on this, you do so at your own risk. |
48 * This code and its internal interfaces are subject to change or |
48 * This code and its internal interfaces are subject to change or |
49 * deletion without notice.</b> |
49 * deletion without notice.</b> |
50 */ |
50 */ |
51 public class Annotate { |
51 public class Annotate { |
52 protected static final Context.Key<Annotate> annotateKey = |
52 protected static final Context.Key<Annotate> annotateKey = new Context.Key<>(); |
53 new Context.Key<Annotate>(); |
|
54 |
53 |
55 public static Annotate instance(Context context) { |
54 public static Annotate instance(Context context) { |
56 Annotate instance = context.get(annotateKey); |
55 Annotate instance = context.get(annotateKey); |
57 if (instance == null) |
56 if (instance == null) |
58 instance = new Annotate(context); |
57 instance = new Annotate(context); |
86 * Queue maintenance |
85 * Queue maintenance |
87 *********************************************************************/ |
86 *********************************************************************/ |
88 |
87 |
89 private int enterCount = 0; |
88 private int enterCount = 0; |
90 |
89 |
91 ListBuffer<Worker> q = new ListBuffer<Worker>(); |
90 ListBuffer<Worker> q = new ListBuffer<>(); |
92 ListBuffer<Worker> typesQ = new ListBuffer<Worker>(); |
91 ListBuffer<Worker> typesQ = new ListBuffer<>(); |
93 ListBuffer<Worker> repeatedQ = new ListBuffer<Worker>(); |
92 ListBuffer<Worker> repeatedQ = new ListBuffer<>(); |
94 ListBuffer<Worker> afterRepeatedQ = new ListBuffer<Worker>(); |
93 ListBuffer<Worker> afterRepeatedQ = new ListBuffer<>(); |
95 ListBuffer<Worker> validateQ = new ListBuffer<Worker>(); |
94 ListBuffer<Worker> validateQ = new ListBuffer<>(); |
96 |
95 |
97 public void earlier(Worker a) { |
96 public void earlier(Worker a) { |
98 q.prepend(a); |
97 q.prepend(a); |
99 } |
98 } |
100 |
99 |
350 } |
349 } |
351 JCNewArray na = (JCNewArray)tree; |
350 JCNewArray na = (JCNewArray)tree; |
352 if (na.elemtype != null) { |
351 if (na.elemtype != null) { |
353 log.error(na.elemtype.pos(), "new.not.allowed.in.annotation"); |
352 log.error(na.elemtype.pos(), "new.not.allowed.in.annotation"); |
354 } |
353 } |
355 ListBuffer<Attribute> buf = new ListBuffer<Attribute>(); |
354 ListBuffer<Attribute> buf = new ListBuffer<>(); |
356 for (List<JCExpression> l = na.elems; l.nonEmpty(); l=l.tail) { |
355 for (List<JCExpression> l = na.elems; l.nonEmpty(); l=l.tail) { |
357 buf.append(enterAttributeValue(types.elemtype(expected), |
356 buf.append(enterAttributeValue(types.elemtype(expected), |
358 l.head, |
357 l.head, |
359 env)); |
358 env)); |
360 } |
359 } |
507 |
506 |
508 if (!repeated.isEmpty()) { |
507 if (!repeated.isEmpty()) { |
509 repeated = repeated.reverse(); |
508 repeated = repeated.reverse(); |
510 TreeMaker m = make.at(ctx.pos.get(firstOccurrence)); |
509 TreeMaker m = make.at(ctx.pos.get(firstOccurrence)); |
511 Pair<MethodSymbol, Attribute> p = |
510 Pair<MethodSymbol, Attribute> p = |
512 new Pair<MethodSymbol, Attribute>(containerValueSymbol, |
511 new Pair<>(containerValueSymbol, |
513 new Attribute.Array(arrayOfOrigAnnoType, repeated)); |
512 new Attribute.Array(arrayOfOrigAnnoType, repeated)); |
514 if (ctx.isTypeCompound) { |
513 if (ctx.isTypeCompound) { |
515 /* TODO: the following code would be cleaner: |
514 /* TODO: the following code would be cleaner: |
516 Attribute.TypeCompound at = new Attribute.TypeCompound(targetContainerType, List.of(p), |
515 Attribute.TypeCompound at = new Attribute.TypeCompound(targetContainerType, List.of(p), |
517 ((Attribute.TypeCompound)annotations.head).position); |
516 ((Attribute.TypeCompound)annotations.head).position); |
518 JCTypeAnnotation annoTree = m.TypeAnnotation(at); |
517 JCTypeAnnotation annoTree = m.TypeAnnotation(at); |