scala.annotation.meta

When defining a field, the Scala compiler creates up to four accessors for it: a getter, a setter, and if the field is annotated with @BeanProperty, a bean getter and a bean setter.

For instance in the following class definition

class C(@myAnnot @BeanProperty var c: Int)

there are six entities which can carry the annotation @myAnnot: the constructor parameter, the generated field and the four accessors.

By default, annotations on (val-, var- or plain) constructor parameters end up on the parameter, not on any other entity. Annotations on fields by default only end up on the field.

The meta-annotations in package scala.annotation.meta are used to control where annotations on fields and class parameters are copied. This is done by annotating either the annotation type or the annotation class with one or several of the meta-annotations in this package.

Annotating the annotation type

The target meta-annotations can be put on the annotation type when instantiating the annotation. In the following example, the annotation @Id will be added only to the bean getter getX.

import javax.persistence.Id
class A {
 @(Id @beanGetter) @BeanProperty val x = 0
}

In order to annotate the field as well, the meta-annotation @field would need to be added.

The syntax can be improved using a type alias:

object ScalaJPA {
 type Id = javax.persistence.Id @beanGetter
}
import ScalaJPA.Id
class A {
 @Id @BeanProperty val x = 0
}

Annotating the annotation class

For annotations defined in Scala, a default target can be specified in the annotation class itself, for example

@getter
class myAnnotation extends Annotation

This only changes the default target for the annotation myAnnotation. When instantiating the annotation, the target can still be specified as described in the last section.

Attributes

Members list

Type members

Classlikes

final class beanGetter extends StaticAnnotation

Consult the documentation in package scala.annotation.meta.

Consult the documentation in package scala.annotation.meta.

Attributes

Source
beanGetter.scala
Supertypes
class Annotation
class Object
trait Matchable
class Any
final class beanSetter extends StaticAnnotation

Consult the documentation in package scala.annotation.meta.

Consult the documentation in package scala.annotation.meta.

Attributes

Source
beanSetter.scala
Supertypes
class Annotation
class Object
trait Matchable
class Any
final class companionClass extends StaticAnnotation

When defining an implicit class, the Scala compiler creates an implicit conversion method for it.

When defining an implicit class, the Scala compiler creates an implicit conversion method for it. Annotations @companionClass and @companionMethod control where an annotation on the implicit class will go. By default, annotations on an implicit class end up only on the class.

Attributes

Source
companionClass.scala
Supertypes
class Annotation
class Object
trait Matchable
class Any
final class companionMethod extends StaticAnnotation

When defining an implicit class, the Scala compiler creates an implicit conversion method for it.

When defining an implicit class, the Scala compiler creates an implicit conversion method for it. Annotations @companionClass and @companionMethod control where an annotation on the implicit class will go. By default, annotations on an implicit class end up only on the class.

Attributes

Source
companionMethod.scala
Supertypes
class Annotation
class Object
trait Matchable
class Any
final class companionObject extends StaticAnnotation

Currently unused; intended as an annotation target for classes such as case classes that automatically generate a companion object

Currently unused; intended as an annotation target for classes such as case classes that automatically generate a companion object

Attributes

Source
companionObject.scala
Supertypes
class Annotation
class Object
trait Matchable
class Any
class defaultArg(arg: Any) extends StaticAnnotation

This internal meta annotation is used by the compiler to support default annotation arguments.

This internal meta annotation is used by the compiler to support default annotation arguments.

For an annotation definition class ann(x: Int = defaultExpr) extends Annotation, the compiler adds @defaultArg(defaultExpr) to the parameter x. This causes the syntax tree of defaultExpr to be stored in the classfile.

When using a default annotation argument, the compiler can recover the syntax tree and insert it in the AnnotationInfo.

For details, see scala.reflect.internal.AnnotationInfos.AnnotationInfo.

Attributes

Source
defaultArg.scala
Supertypes
class Annotation
class Object
trait Matchable
class Any
final class field extends StaticAnnotation

Consult the documentation in package scala.annotation.meta.

Consult the documentation in package scala.annotation.meta.

Attributes

Source
field.scala
Supertypes
class Annotation
class Object
trait Matchable
class Any
final class getter extends StaticAnnotation

Consult the documentation in package scala.annotation.meta.

Consult the documentation in package scala.annotation.meta.

Attributes

Source
getter.scala
Supertypes
class Annotation
class Object
trait Matchable
class Any
final class languageFeature(feature: String, enableRequired: Boolean) extends StaticAnnotation

An annotation giving particulars for a language feature in object scala.language.

An annotation giving particulars for a language feature in object scala.language.

Attributes

Source
languageFeature.scala
Supertypes
class Annotation
class Object
trait Matchable
class Any
final class param extends StaticAnnotation

Consult the documentation in package scala.annotation.meta.

Consult the documentation in package scala.annotation.meta.

Attributes

Source
param.scala
Supertypes
class Annotation
class Object
trait Matchable
class Any
final class setter extends StaticAnnotation

Consult the documentation in package scala.annotation.meta.

Consult the documentation in package scala.annotation.meta.

Attributes

Source
setter.scala
Supertypes
class Annotation
class Object
trait Matchable
class Any
class superArg(p: String, v: Any) extends StaticAnnotation

This internal annotation encodes arguments passed to annotation superclasses.

This internal annotation encodes arguments passed to annotation superclasses. Example:

class a(x: Int) extends Annotation
class b extends a(42) // the compiler adds `@superArg("x", 42)` to class b

Attributes

Source
superArg.scala
Supertypes
class Annotation
class Object
trait Matchable
class Any
class superFwdArg(p: String, n: String) extends StaticAnnotation

This internal annotation encodes arguments passed to annotation superclasses.

This internal annotation encodes arguments passed to annotation superclasses. Example:

class a(x: Int) extends Annotation
class b(y: Int) extends a(y) // the compiler adds `@superFwdArg("x", "y")` to class b

Attributes

Source
superArg.scala
Supertypes
class Annotation
class Object
trait Matchable
class Any