Package

com.avsystem.commons

annotation

Permalink

package annotation

Visibility
  1. Public
  2. All

Type Members

  1. trait AnnotationAggregate extends Annotation with StaticAnnotation

    Permalink

    Base trait for annotations which aggregate multiple other annotations.

    Base trait for annotations which aggregate multiple other annotations. This way annotation aggregates work like "annotation functions" - they are annotations that yield more annotations.

    In order to specify aggregated annotations, the class that extends AnnotationAggregate must redefine the Implied dummy type member and apply the aggregated annotations on it. Macro engines used in GenCodec materialization and RPC framework will automatically pick up these annotations.

    import com.avsystem.commons.serialization._
    
    class mongoId extends AnnotationAggregate {
      @name("_id") @outOfOrder
      type Implied
    }
    
    case class SomeMongoEntity(@mongoId id: String, data: String)

    In the above example, applying @mongoId annotation on the id field has the same effect as if annotations @name("_id") @outOfOrder were applied directly on that field.

    NOTE: thanks to the fact that aggregated annotations are applied on a type member you can pass the arguments of original annotation to aggregated annotations, e.g.

    class rpcNameAndDescription(name: String, description: String) extends AnnotationAggregate {
      @rpcName(name) // passing `name` to aggregated annotation
      type Implied
    }
  2. class atLeast extends Annotation with StaticAnnotation

    Permalink

    When applied on varargs parameter, indicates that at least some number of parameters is required.

    When applied on varargs parameter, indicates that at least some number of parameters is required. This is later checked by the static analyzer.
    WARNING: implementation of method which takes a varargs parameter may NOT assume that given number of arguments will always be passed, because it's still possible to pass a Seq where varargs parameter is required using the : _* ascription, e.g.

    varargsMethod(List(): _*)

    and that is not checked by the static analyzer.

  3. class explicitGenerics extends Annotation with StaticAnnotation

    Permalink

    When applied on generic method, requires that all the type parameters are given explicitly (cannot be inferred by the compiler).

    When applied on generic method, requires that all the type parameters are given explicitly (cannot be inferred by the compiler). This is meant primarily for methods whose generics cannot be inferred from method arguments. Requiring that the programmer specifies them explicitly is a protection against the compiler inferring Nothing or Null.

    @explicitGenerics
    def readJson[T: GenCodec](json: String): T = ...
    
    // raise error, because otherwise we have a hidden bug - the compiler infers `Nothing` in place of `T`
    val x: MyType = readJson("{}")
    // ok
    val x = readJson[MyType]("{}")
  4. class macroPrivate extends Annotation with StaticAnnotation

    Permalink

    Symbols annotated with this annotation can only be used in macro-generated code.

Ungrouped