diff options
author | Kevin Wright <kevin.wright@bradyplc.com> | 2018-02-01 14:42:05 +0000 |
---|---|---|
committer | Kevin Wright <kevin.wright@bradyplc.com> | 2018-02-01 14:42:05 +0000 |
commit | 6660480a75b240b7ac613ed308e5b7f7ddfc6459 (patch) | |
tree | 2c85897a2ab4010438538351340f89356a28ad6a /core/shared/src/main/scala/interface.scala | |
parent | bd1ca071286987bc148fda830aa3141f56891efb (diff) | |
download | magnolia-6660480a75b240b7ac613ed308e5b7f7ddfc6459.tar.gz magnolia-6660480a75b240b7ac613ed308e5b7f7ddfc6459.tar.bz2 magnolia-6660480a75b240b7ac613ed308e5b7f7ddfc6459.zip |
Added top-level annotation capture
Diffstat (limited to 'core/shared/src/main/scala/interface.scala')
-rw-r--r-- | core/shared/src/main/scala/interface.scala | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/core/shared/src/main/scala/interface.scala b/core/shared/src/main/scala/interface.scala index 427c84c..97ea5b7 100644 --- a/core/shared/src/main/scala/interface.scala +++ b/core/shared/src/main/scala/interface.scala @@ -92,7 +92,13 @@ trait Param[Typeclass[_], Type] { * @return the parameter value */ def dereference(param: Type): PType - def annotations: Seq[Any] + def annotationsArray: Array[Any] + + /** a sequence of objects representing all of the annotations on the case class + * + * For efficiency, this sequence is implemented by an `Array`, but upcast to a + * [[scala.collection.Seq]] to hide the mutable collection API. */ + final def annotations: Seq[Any] = annotationsArray override def toString: String = s"Param($label)" } @@ -113,7 +119,8 @@ abstract class CaseClass[Typeclass[_], Type] private[magnolia] ( val typeName: TypeName, val isObject: Boolean, val isValueClass: Boolean, - parametersArray: Array[Param[Typeclass, Type]] + parametersArray: Array[Param[Typeclass, Type]], + annotationsArray: Array[Any] ) { override def toString: String = s"CaseClass(${typeName.full}, ${parameters.mkString(",")})" @@ -152,6 +159,12 @@ abstract class CaseClass[Typeclass[_], Type] private[magnolia] ( * For efficiency, this sequence is implemented by an `Array`, but upcast to a * [[scala.collection.Seq]] to hide the mutable collection API. */ final def parameters: Seq[Param[Typeclass, Type]] = parametersArray + + /** a sequence of objects representing all of the annotations on the case class + * + * For efficiency, this sequence is implemented by an `Array`, but upcast to a + * [[scala.collection.Seq]] to hide the mutable collection API. */ + final def annotations: Seq[Any] = annotationsArray } /** represents a sealed trait and the context required to construct a new typeclass instance @@ -163,8 +176,11 @@ abstract class CaseClass[Typeclass[_], Type] private[magnolia] ( * @param subtypesArray an array of [[Subtype]] instances for each subtype in the sealed trait * @tparam Typeclass type constructor for the typeclass being derived * @tparam Type generic type of this parameter */ -final class SealedTrait[Typeclass[_], Type](val typeName: TypeName, - subtypesArray: Array[Subtype[Typeclass, Type]]) { +final class SealedTrait[Typeclass[_], Type]( + val typeName: TypeName, + subtypesArray: Array[Subtype[Typeclass, Type]], + annotationsArray: Array[Any] +) { override def toString: String = s"SealedTrait($typeName, Array[${subtypes.mkString(",")}])" @@ -192,6 +208,12 @@ final class SealedTrait[Typeclass[_], Type](val typeName: TypeName, ) rec(0) } + + /** a sequence of objects representing all of the annotations on the topmost trait + * + * For efficiency, this sequence is implemented by an `Array`, but upcast to a + * [[scala.collection.Seq]] to hide the mutable collection API. */ + final def annotations: Seq[Any] = annotationsArray } /** |