@@ -3,42 +3,103 @@ package base
3
3
4
4
import scala .collection .immutable .ListMap
5
5
6
+ /**
7
+ * Defines the type hierarchy for annotations.
8
+ */
6
9
trait Annotations { self : Universe =>
7
10
11
+ /** Typed information about an annotation. It can be attached to either a symbol or an annotated type.
12
+ *
13
+ * Annotations are either ''Scala annotations'', which conform to [[scala.annotation.Annotation ]] or [[scala.annotation.StaticAnnotation ]]
14
+ * but not [[scala.annotation.ClassfileAnnotation ]] or ''Java annotations'', which conform to [[scala.annotation.ClassfileAnnotation ]].
15
+ * Trait `ClassfileAnnotation` is automatically added to every Java annotation by the scalac classfile parser.
16
+ */
8
17
type Annotation >: Null <: AnyRef
18
+
19
+ /** A tag that preserves the identity of the `Annotation` abstract type from erasure.
20
+ * Can be used for pattern matching, instance tests, serialization and likes.
21
+ */
9
22
implicit val AnnotationTag : ClassTag [Annotation ]
10
- val Annotation : AnnotationExtractor
11
23
24
+ /** The constructor/deconstructor for `Annotation` instances. */
25
+ val Annotation : AnnotationExtractor
26
+
27
+ /** An extractor class to create and pattern match with syntax `Annotation(atp, args, javaArgs)`.
28
+ * Here, `atp` is the annotation type, `args` the arguments, and `javaArgs` the annotation's key-value
29
+ * pairs.
30
+ *
31
+ * Annotations are written to the classfile as Java annotations if `atp` conforms to
32
+ * `ClassfileAnnotation`. Annotations are pickled, i.e., written to scala symtab attribute in the classfile,
33
+ * if `atp` inherits from `StaticAnnotation` but not `ClassfileAnnotation`.
34
+ *
35
+ * For Scala annotations, arguments are stored in `args` and `javaArgs` is empty. Arguments in
36
+ * `args` are represented as typed trees. Note that these trees are not transformed by any phases
37
+ * following the type-checker. For Java annotations, `args` is empty and arguments are stored in
38
+ * `javaArgs`.
39
+ */
12
40
abstract class AnnotationExtractor {
13
41
def apply (tpe : Type , scalaArgs : List [Tree ], javaArgs : ListMap [Name , JavaArgument ]): Annotation
14
42
def unapply (ann : Annotation ): Option [(Type , List [Tree ], ListMap [Name , JavaArgument ])]
15
43
}
16
44
45
+ /** A Java annotation argument */
17
46
type JavaArgument >: Null <: AnyRef
18
47
implicit val JavaArgumentTag : ClassTag [JavaArgument ]
19
48
49
+ /** A literal argument to a Java annotation as `"Use X instead"` in `@Deprecated("Use X instead")`*/
20
50
type LiteralArgument >: Null <: AnyRef with JavaArgument
51
+
52
+ /** A tag that preserves the identity of the `LiteralArgument` abstract type from erasure.
53
+ * Can be used for pattern matching, instance tests, serialization and likes.
54
+ */
21
55
implicit val LiteralArgumentTag : ClassTag [LiteralArgument ]
56
+
57
+ /** The constructor/deconstructor for `LiteralArgument` instances. */
22
58
val LiteralArgument : LiteralArgumentExtractor
23
59
60
+ /** An extractor class to create and pattern match with syntax `LiteralArgument(value)`
61
+ * where `value` is the constant argument.
62
+ */
24
63
abstract class LiteralArgumentExtractor {
25
64
def apply (value : Constant ): LiteralArgument
26
65
def unapply (arg : LiteralArgument ): Option [Constant ]
27
66
}
28
67
68
+ /** An array argument to a Java annotation as in `@Target(value={TYPE,FIELD,METHOD,PARAMETER})`
69
+ */
29
70
type ArrayArgument >: Null <: AnyRef with JavaArgument
71
+
72
+ /** A tag that preserves the identity of the `ArrayArgument` abstract type from erasure.
73
+ * Can be used for pattern matching, instance tests, serialization and likes.
74
+ */
30
75
implicit val ArrayArgumentTag : ClassTag [ArrayArgument ]
76
+
77
+ /** The constructor/deconstructor for `ArrayArgument` instances. */
31
78
val ArrayArgument : ArrayArgumentExtractor
32
79
80
+ /** An extractor class to create and pattern match with syntax `ArrayArgument(args)`
81
+ * where `args` is the argument array.
82
+ */
33
83
abstract class ArrayArgumentExtractor {
34
84
def apply (args : Array [JavaArgument ]): ArrayArgument
35
85
def unapply (arg : ArrayArgument ): Option [Array [JavaArgument ]]
36
86
}
37
87
88
+ /** A nested argument to a Java annotation as `@Nested` in `@Outer(@Nested)`.
89
+ */
38
90
type NestedArgument >: Null <: AnyRef with JavaArgument
91
+
92
+ /** A tag that preserves the identity of the `NestedArgument` abstract type from erasure.
93
+ * Can be used for pattern matching, instance tests, serialization and likes.
94
+ */
39
95
implicit val NestedArgumentTag : ClassTag [NestedArgument ]
96
+
97
+ /** The constructor/deconstructor for `NestedArgument` instances. */
40
98
val NestedArgument : NestedArgumentExtractor
41
99
100
+ /** An extractor class to create and pattern match with syntax `NestedArgument(annotation)`
101
+ * where `annotation` is the nested annotation.
102
+ */
42
103
abstract class NestedArgumentExtractor {
43
104
def apply (annotation : Annotation ): NestedArgument
44
105
def unapply (arg : NestedArgument ): Option [Annotation ]
0 commit comments