You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/reflect/scala/reflect/api/Annotations.scala
+53-21Lines changed: 53 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -3,52 +3,58 @@ package api
3
3
4
4
importscala.collection.immutable.ListMap
5
5
6
-
/** This trait provides annotation support for the reflection API.
6
+
/** This trait provides annotation support for the reflection API.
7
7
*
8
8
* The API distinguishes between two kinds of annotations:
9
-
* 1. ''Java annotations'': annotations on definitions produced by the Java compiler, i.e., subtypes of [[java.lang.annotation.Annotation]]
10
-
* attached to program definitions. When read by Scala reflection, the [[scala.annotation.ClassfileAnnotation]] trait
11
-
* is automatically added as a subclass to every Java annotation.
12
-
* 2. ''Scala annotations'': annotations on definitions or types produced by the Scala compiler.
13
-
*
14
-
* When a Scala annotation that inherits from [[scala.annotation.StaticAnnotation]] or [[scala.annotation.ClassfileAnnotation]] is compiled,
15
-
* it is stored as special attributes in the corresponding classfile, and not as a Java annotation. Note that subclassing
9
+
* 1. ''Java annotations'': annotations on definitions produced by the Java compiler, i.e., subtypes of `java.lang.annotation.Annotation` attached to program definitions. When read by Scala reflection, the [[scala.annotation.ClassfileAnnotation]] trait is automatically added as a subclass to every Java annotation.
10
+
* 1. ''Scala annotations'': annotations on definitions or types produced by the Scala compiler.
11
+
*
12
+
* When a Scala annotation that inherits from [[scala.annotation.StaticAnnotation]] or [[scala.annotation.ClassfileAnnotation]] is compiled,
13
+
* it is stored as special attributes in the corresponding classfile, and not as a Java annotation. Note that subclassing
16
14
* just [[scala.annotation.Annotation]] is not enough to have the corresponding metadata persisted for runtime reflection.
17
-
*
15
+
*
18
16
* The distinction between Java and Scala annotations is manifested in the contract of [[scala.reflect.api.Annotations#Annotation]], which exposes
19
-
* both `scalaArgs` and `javaArgs`. For Scala or Java annotations extending [[scala.annotation.ClassfileAnnotation]] `scalaArgs` is empty
17
+
* both `scalaArgs` and `javaArgs`. For Scala or Java annotations extending [[scala.annotation.ClassfileAnnotation]] `scalaArgs` is empty
20
18
* and arguments are stored in `javaArgs`. For all other Scala annotations, arguments are stored in `scalaArgs` and `javaArgs` is empty.
21
-
*
19
+
*
22
20
* Arguments in `scalaArgs` are represented as typed trees. Note that these trees are not transformed by any phases
23
21
* following the type-checker. Arguments in `javaArgs` are repesented as a map from [[scala.reflect.api.Names#Name]] to
24
-
* [[scala.reflect.api.Annotations#JavaArgument]]. Instances of `JavaArgument` represent different kinds of Java annotation arguments:
22
+
* [[scala.reflect.api.Annotations#JavaArgument]]. Instances of `JavaArgument` represent different kinds of Java annotation arguments:
25
23
* - literals (primitive and string constants),
26
-
* - arrays and
24
+
* - arrays and
27
25
* - nested annotations.
28
26
*/
29
27
traitAnnotations { self: Universe=>
30
28
31
-
/** Information about an annotation. */
29
+
/** Information about an annotation.
30
+
* @template
31
+
* @group Annotations
32
+
*/
32
33
typeAnnotation>:Null<:AnyRefwithAnnotationApi
33
34
34
35
/** A tag that preserves the identity of the `Annotation` abstract type from erasure.
35
36
* Can be used for pattern matching, instance tests, serialization and likes.
37
+
* @group Tags
36
38
*/
37
39
implicitvalAnnotationTag:ClassTag[Annotation]
38
40
39
-
/** The constructor/deconstructor for `Annotation` instances. */
41
+
/** The constructor/deconstructor for `Annotation` instances.
42
+
* @group Extractors
43
+
*/
40
44
valAnnotation:AnnotationExtractor
41
45
42
46
/** An extractor class to create and pattern match with syntax `Annotation(tpe, scalaArgs, javaArgs)`.
43
47
* Here, `tpe` is the annotation type, `scalaArgs` the payload of Scala annotations, and `javaArgs` the payload of Java annotations.
0 commit comments