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