1 package annotations.field;
2 
3 /*>>>
4 import org.checkerframework.checker.nullness.qual.*;
5 */
6 
7 import annotations.Annotation;
8 import annotations.el.AnnotationDef;
9 
10 /**
11  * An {@link AnnotationAFT} represents a subannotation as the type of an
12  * annotation field and contains the definition of the subannotation.
13  */
14 public final class AnnotationAFT extends ScalarAFT {
15 
16     /**
17      * The definition of the subannotation.
18      */
19     public final AnnotationDef annotationDef;
20 
21     /**
22      * Constructs a new {@link AnnotationAFT} for a subannotation of the
23      * given definition.
24      */
25     public AnnotationAFT(AnnotationDef annotationDef) {
26         this.annotationDef = annotationDef;
27     }
28 
29     /**
30      * {@inheritDoc}
31      */
32     @Override
33     public boolean isValidValue(Object o) {
34         return o instanceof Annotation;
35     }
36 
37     /**
38      * The string representation of an {@link AnnotationAFT} looks like
39      * <code>&#64;Foo</code> even though the subannotation definition is
40      * logically part of the {@link AnnotationAFT}.  This is because the
41      * subannotation field type appears as <code>&#64;Foo</code> in an
42      * index file and the subannotation definition is written separately.
43      */
44     @Override
45     public  String toString() {
46         return "annotation-field " + annotationDef.name;
47     }
48 
49     /**
50      * {@inheritDoc}
51      */
52     @Override
53     public String format(Object o) {
54         return o.toString();
55     }
56 
57     @Override
58     public <R, T> R accept(AFTVisitor<R, T> v, T arg) {
59         return v.visitAnnotationAFT(this, arg);
60     }
61 }
62