Packages

t

scala.reflect.api

Annotations

trait Annotations extends AnyRef

EXPERIMENTAL

This trait provides annotation support for the reflection API.

In Scala, annotations belong to one of the two categories:

  • Java annotations: annotations on definitions produced by the Java compiler, i.e., subtypes of java.lang.annotation.Annotation attached to program definitions.
  • Scala annotations: annotations on definitions or types produced by the Scala compiler.

When a Scala annotation that inherits from scala.annotation.StaticAnnotation is compiled, it is stored as special attributes in the corresponding classfile, and not as a Java annotation. Note that subclassing just scala.annotation.Annotation is not enough to have the corresponding metadata persisted for runtime reflection.

Both Java and Scala annotations are represented as typed trees carrying constructor invocations corresponding to the annotation. For instance, the annotation in @ann(1, 2) class C is represented as q"@new ann(1, 2)".

Unlike Java reflection, Scala reflection does not support evaluation of constructor invocations stored in annotations into underlying objects. For instance it's impossible to go from @ann(1, 2) class C to ann(1, 2), so one has to analyze trees representing annotation arguments to manually extract corresponding values. Towards that end, arguments of an annotation can be obtained via annotation.tree.children.tail.

For more information about Annotations, see the Reflection Guide: Annotations, Names, Scopes, and More

Self Type
Universe
Source
Annotations.scala
Linear Supertypes
Known Subclasses
Type Hierarchy
Ordering
  1. Grouped
  2. Alphabetic
  3. By Inheritance
Inherited
  1. Annotations
  2. AnyRef
  3. Any
Implicitly
  1. by any2stringadd
  2. by StringFormat
  3. by Ensuring
  4. by ArrowAssoc
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Annotations

  1. abstract type Annotation >: Null <: Universe.AnnotationApi

    Information about an annotation.

API

The methods available for each reflection entity, without the implementation. Since the reflection entities are later overridden by runtime reflection and macros, their API counterparts guarantee a minimum set of methods that are implemented.

  1. trait AnnotationApi extends AnyRef

    The API of Annotation instances.

    The API of Annotation instances. The main source of information about annotations is the scala.reflect.api.Annotations page.

Extractors

Extractors provide the machinery necessary to allow pattern matching and construction of reflection entities that is similar to case classes, although the entities are only abstract types that are later overridden.

  1. abstract class AnnotationExtractor extends AnyRef

    An extractor class to create and pattern match with syntax Annotation(tpe, scalaArgs, javaArgs).

    An extractor class to create and pattern match with syntax Annotation(tpe, scalaArgs, javaArgs). Here, tpe is the annotation type, scalaArgs the payload of Scala annotations, and javaArgs the payload of Java annotations.

  1. abstract val Annotation: Universe.AnnotationExtractor

    The constructor/extractor for Annotation instances.