From 89426bcfd380ceeb004632ab8b05d8c8dfb0df5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Krenski?= Date: Wed, 31 Jan 2024 11:30:20 +0100 Subject: [PATCH] remove runtime field name resolution which was unsupported by MCc anyway --- .../rogue/cc/macros/NameFieldMacro.scala | 76 ------ .../me/sgrouples/rogue/cc/NamesResolver.scala | 3 - .../rogue/cc/QueryFieldHelpers.scala | 216 +----------------- .../rogue/cc/macros/MacroNamesResolver.scala | 12 - .../me/sgrouples/rogue/cc/TestModels.scala | 53 +++-- 5 files changed, 39 insertions(+), 321 deletions(-) delete mode 100644 bsonmacros/src/main/scala/me/sgrouples/rogue/cc/macros/NameFieldMacro.scala diff --git a/bsonmacros/src/main/scala/me/sgrouples/rogue/cc/macros/NameFieldMacro.scala b/bsonmacros/src/main/scala/me/sgrouples/rogue/cc/macros/NameFieldMacro.scala deleted file mode 100644 index b64bd37..0000000 --- a/bsonmacros/src/main/scala/me/sgrouples/rogue/cc/macros/NameFieldMacro.scala +++ /dev/null @@ -1,76 +0,0 @@ -package me.sgrouples.rogue.cc.macros - -import scala.annotation.StaticAnnotation - -object GenFieldName { - /*def impl(c: whitebox.Context)(annottees: c.Expr[Any]*): c.Expr[Any] = { - import c.universe._ - val result = annottees.map(_.tree).toList match { - case q"$mods val $pat = ClassField[..$tpt]($expr)" :: Nil => - val fname = Constant(pat.toString()) - q"$mods val $pat = ClassField[..$tpt]($fname, $expr)" - - case q"$mods val $pat = OptClassField[..$tpt]($expr)" :: Nil => - val fname = Constant(pat.toString()) - q"$mods val $pat = OptClassField[..$tpt]($fname, $expr)" - - case q"$mods val $pat = ClassRequiredField[..$tpt]($e1, $e2)" :: Nil => - val fname = Constant(pat.toString()) - q"$mods val $pat = ClassRequiredField[..$tpt]($fname, $e1, $e2)" - - case q"$mods val $pat = ClassListField[..$tpt]($expr)" :: Nil => - val fname = Constant(pat.toString()) - q"$mods val $pat = ClassListField[..$tpt]($fname, $expr)" - - case q"$mods val $pat = OptClassListField[..$tpt]($expr)" :: Nil => - val fname = Constant(pat.toString()) - q"$mods val $pat = OptClassListField[..$tpt]($fname, $expr)" - - case q"$mods val $pat = ClassArrayField[..$tpt]($expr)" :: Nil => - val fname = Constant(pat.toString()) - q"$mods val $pat = ClassArrayField[..$tpt]($fname, $expr)" - - case q"$mods val $pat = OptClassArrayField[..$tpt]($expr)" :: Nil => - val fname = Constant(pat.toString()) - q"$mods val $pat = OptClassArrayField[..$tpt]($fname, $expr)" - - case q"$mods val $pat = EnumField($expr)" :: Nil => - val fname = Constant(pat.toString()) - q"$mods val $pat = EnumField($fname, $expr)" - - case q"$mods val $pat = OptEnumField($expr)" :: Nil => - val fname = Constant(pat.toString()) - q"$mods val $pat = OptEnumField($fname, $expr)" - - case q"$mods val $pat = EnumIdField($expr)" :: Nil => - val fname = Constant(pat.toString()) - q"$mods val $pat = EnumIdField($fname, $expr)" - - case q"$mods val $pat = OptEnumIdField($expr)" :: Nil => - val fname = Constant(pat.toString()) - q"$mods val $pat = OptEnumIdField($fname, $expr)" - - case q"$mods val $pat = EnumeratumField($expr)" :: Nil => - val fname = Constant(pat.toString()) - q"$mods val $pat = EnumeratumField($fname, $expr)" - - case q"$mods val $pat = $expr($exp1)" :: Nil => - val r = q"$mods val $pat = $expr($exp1)" - //println(s"No change - let's assume we have name - ${r}") - r - - case q"$mods val $pat = $expr" :: Nil => - val fname = Constant(pat.toString()) - //println(s"Expr ${expr} , fname ${fname}") - val res = q"$mods val $pat = $expr($fname)" - //println(s"rewrote to ${res}") - res - case _ => - c.abort( - c.enclosingPosition, - "@f macro can only annotate val in cc meta" - ) - } - c.Expr[Any](result) - }*/ -} diff --git a/cc/src/main/scala/me/sgrouples/rogue/cc/NamesResolver.scala b/cc/src/main/scala/me/sgrouples/rogue/cc/NamesResolver.scala index e476015..6e07495 100644 --- a/cc/src/main/scala/me/sgrouples/rogue/cc/NamesResolver.scala +++ b/cc/src/main/scala/me/sgrouples/rogue/cc/NamesResolver.scala @@ -4,7 +4,4 @@ trait NamesResolver { protected def named[T <: io.fsq.field.Field[?, ?]](name: String)( func: String => T ): T - protected def named[T <: io.fsq.field.Field[?, ?]]( - func: String => T - ): T } diff --git a/cc/src/main/scala/me/sgrouples/rogue/cc/QueryFieldHelpers.scala b/cc/src/main/scala/me/sgrouples/rogue/cc/QueryFieldHelpers.scala index 994d4d0..e957285 100644 --- a/cc/src/main/scala/me/sgrouples/rogue/cc/QueryFieldHelpers.scala +++ b/cc/src/main/scala/me/sgrouples/rogue/cc/QueryFieldHelpers.scala @@ -17,253 +17,144 @@ import java.util.UUID trait QueryFieldHelpers[Meta] extends NamesResolver { requires: Meta => - protected def IntField: IntField[Meta] = named( - new IntField[Meta](_, this) - ) protected def IntField(name: String): IntField[Meta] = named(name)(new IntField[Meta](_, this)) - protected def OptIntField: OptIntField[Meta] = named( - new OptIntField[Meta](_, this) - ) protected def OptIntField(name: String): OptIntField[Meta] = named(name)(new OptIntField[Meta](_, this)) - protected def IntSubtypeField[T <: Int]: IntSubtypeField[T, Meta] = - named(new IntSubtypeField[T, Meta](_, this)) - protected def IntSubtypeField[T <: Int]( name: String ): IntSubtypeField[T, Meta] = named(name)(new IntSubtypeField[T, Meta](_, this)) - protected def OptIntSubtypeField[T <: Int]: OptIntSubtypeField[T, Meta] = - named(new OptIntSubtypeField[T, Meta](_, this)) - protected def OptIntSubtypeField[T <: Int]( name: String ): OptIntSubtypeField[T, Meta] = named(name)(new OptIntSubtypeField[T, Meta](_, this)) - protected def StringField: StringField[Meta] = named( - new StringField[Meta](_, this) - ) protected def StringField(name: String): StringField[Meta] = named(name)(new StringField[Meta](_, this)) - protected def OptStringField: OptStringField[Meta] = named( - new OptStringField[Meta](_, this) - ) protected def OptStringField(name: String): OptStringField[Meta] = named(name)(new OptStringField[Meta](_, this)) - protected def StringSubtypeField[T <: String]: StringSubtypeField[T, Meta] = - named(new StringSubtypeField[T, Meta](_, this)) protected def StringSubtypeField[T <: String]( name: String ): StringSubtypeField[T, Meta] = named(name)(new StringSubtypeField[T, Meta](_, this)) - - protected def OptStringSubtypeField[T <: String] - : OptStringSubtypeField[T, Meta] = named( - new OptStringSubtypeField[T, Meta](_, this) - ) protected def OptStringSubtypeField[T <: String]( name: String ): OptStringSubtypeField[T, Meta] = named(name)(new OptStringSubtypeField[T, Meta](_, this)) - protected def LongField: LongField[Meta] = named( - new LongField[Meta](_, this) - ) protected def LongField(name: String): LongField[Meta] = named(name)(new LongField[Meta](_, this)) - protected def OptLongField: OptLongField[Meta] = named( - new OptLongField[Meta](_, this) - ) protected def OptLongField(name: String): OptLongField[Meta] = named(name)(new OptLongField[Meta](_, this)) - protected def BigDecimalField: BigDecimalField[Meta] = named( - new BigDecimalField[Meta](_, this) - ) protected def BigDecimalField(name: String): BigDecimalField[Meta] = named(name)(new BigDecimalField[Meta](_, this)) - protected def OptBigDecimalField: OptBigDecimalField[Meta] = named( - new OptBigDecimalField[Meta](_, this) - ) protected def OptBigDecimalField( name: String ): OptBigDecimalField[Meta] = named(name)(new OptBigDecimalField[Meta](_, this)) - protected def LongSubtypeField[T <: Long]: LongSubtypeField[T, Meta] = - named(new LongSubtypeField[T, Meta](_, this)) protected def LongSubtypeField[T <: Long]( name: String ): LongSubtypeField[T, Meta] = named(name)(new LongSubtypeField[T, Meta](_, this)) - protected def OptLongSubtypeField[T <: Long]: OptLongSubtypeField[T, Meta] = - named( - new OptLongSubtypeField[T, Meta](_, this) - ) protected def OptLongSubtypeField[T <: Long]( name: String ): OptLongSubtypeField[T, Meta] = named(name)(new OptLongSubtypeField[T, Meta](_, this)) - protected def DoubleField: DoubleField[Meta] = named( - new DoubleField[Meta](_, this) - ) protected def DoubleField(name: String): DoubleField[Meta] = named(name)(new DoubleField[Meta](_, this)) - protected def OptDoubleField: OptDoubleField[Meta] = named( - new OptDoubleField[Meta](_, this) - ) protected def OptDoubleField(name: String): OptDoubleField[Meta] = named(name)(new OptDoubleField[Meta](_, this)) - protected def ObjectIdField: ObjectIdField[Meta] = named( - new ObjectIdField[Meta](_, this) - ) protected def ObjectIdField(name: String): ObjectIdField[Meta] = named(name)(new ObjectIdField[Meta](_, this)) - protected def ObjectIdTaggedField[Tag]: ObjectIdTaggedField[Tag, Meta] = - named( - new ObjectIdTaggedField[Tag, Meta](_, this) - ) protected def ObjectIdTaggedField[Tag]( name: String ): ObjectIdTaggedField[Tag, Meta] = named(name)(new ObjectIdTaggedField[Tag, Meta](_, this)) - protected def OptObjectIdField: OptObjectIdField[Meta] = named( - new OptObjectIdField[Meta](_, this) - ) protected def OptObjectIdField( name: String ): OptObjectIdField[Meta] = named(name)(new OptObjectIdField[Meta](_, this)) - protected def ObjectIdSubtypeField[T <: ObjectId] - : ObjectIdSubtypeField[T, Meta] = named( - new ObjectIdSubtypeField[T, Meta](_, this) - ) - protected def ObjectIdSubtypeField[T <: ObjectId]( name: String ): ObjectIdSubtypeField[T, Meta] = named(name)(new ObjectIdSubtypeField[T, Meta](_, this)) - protected def OptObjectIdSubtypeField[T <: ObjectId] - : OptObjectIdSubtypeField[T, Meta] = named( - new OptObjectIdSubtypeField[T, Meta](_, this) - ) protected def OptObjectIdSubtypeField[T <: ObjectId]( name: String ): OptObjectIdSubtypeField[T, Meta] = named(name)(new OptObjectIdSubtypeField[T, Meta](_, this)) - protected def UUIdField: UUIDIdField[Meta] = named( - new UUIDIdField[Meta](_, this) - ) protected def UUIdField(name: String): UUIDIdField[Meta] = named(name)(new UUIDIdField[Meta](_, this)) - protected def OptUUIdField: OptUUIDIdField[Meta] = named( - new OptUUIDIdField[Meta](_, this) - ) protected def OptUUIdField(name: String): OptUUIDIdField[Meta] = named(name)(new OptUUIDIdField[Meta](_, this)) - protected def UUIdSubtypeField[T <: UUID]: UUIDIdSubtypeField[T, Meta] = - named(new UUIDIdSubtypeField[T, Meta](_, this)) protected def UUIdSubtypeField[T <: UUID]( name: String ): UUIDIdSubtypeField[T, Meta] = named(name)(new UUIDIdSubtypeField[T, Meta](_, this)) - protected def OptUUIdSubtypeField[T <: UUID]: OptUUIDIdSubtypeField[T, Meta] = - named( - new OptUUIDIdSubtypeField[T, Meta](_, this) - ) protected def OptUUIdSubtypeField[T <: UUID]( name: String ): OptUUIDIdSubtypeField[T, Meta] = named(name)(new OptUUIDIdSubtypeField[T, Meta](_, this)) - protected def LocalDateTimeField: LocalDateTimeField[Meta] = named( - new LocalDateTimeField[Meta](_, this) - ) protected def LocalDateTimeField( name: String ): LocalDateTimeField[Meta] = named(name)(new LocalDateTimeField[Meta](_, this)) - protected def OptLocalDateTimeField: OptLocalDateTimeField[Meta] = - named(new OptLocalDateTimeField[Meta](_, this)) protected def OptLocalDateTimeField( name: String ): OptLocalDateTimeField[Meta] = named(name)(new OptLocalDateTimeField[Meta](_, this)) - protected def CurrencyField: CurrencyField[Meta] = named( - new CurrencyField[Meta](_, this) - ) protected def CurrencyField(name: String): CurrencyField[Meta] = named(name)(new CurrencyField[Meta](_, this)) - protected def OptCurrencyField: OptCurrencyField[Meta] = named( - new OptCurrencyField[Meta](_, this) - ) protected def OptCurrencyField( name: String ): OptCurrencyField[Meta] = named(name)(new OptCurrencyField[Meta](_, this)) - protected def InstantField: InstantField[Meta] = named( - new InstantField[Meta](_, this) - ) protected def InstantField(name: String): InstantField[Meta] = named(name)(new InstantField[Meta](_, this)) - protected def OptInstantField: OptInstantField[Meta] = named( - new OptInstantField[Meta](_, this) - ) protected def OptInstantField(name: String): OptInstantField[Meta] = named(name)(new OptInstantField[Meta](_, this)) - protected def BooleanField: BooleanField[Meta] = named( - new BooleanField[Meta](_, this) - ) protected def BooleanField(name: String): BooleanField[Meta] = named(name)(new BooleanField[Meta](_, this)) - protected def OptBooleanField: OptBooleanField[Meta] = named( - new OptBooleanField[Meta](_, this) - ) protected def OptBooleanField(name: String): OptBooleanField[Meta] = named(name)(new OptBooleanField[Meta](_, this)) /** This version of the EnumField method accepts e: E as a param to avoid ugly * type parameters like [MyEnum.type] So instead of writing val myEnum = * EnumField[MyEnum.type, MyMeta] we can simply write val myEnum = - * EnumField(MyEnum) + * EnumField("name", MyEnum) * @param e * @tparam E * @return */ - protected def EnumField[E <: Enumeration]( - e: E - ): EnumField[e.Value, Meta] = named( - new EnumField[e.Value, Meta](_, this, e(0)) - ) - protected def EnumField[E <: Enumeration]( name: String, e: E @@ -272,16 +163,12 @@ trait QueryFieldHelpers[Meta] extends NamesResolver { /** This version of the EnumField method accepts e: E as a param to avoid ugly * type parameters like [MyEnum.type] So instead of writting val myEnum = - * EnumField[MyEnum.type, MyMeta] we can simply write val myEnum = - * EnumField(MyEnum) + * OptEnumField[MyEnum.type, MyMeta] we can simply write val myEnum = + * OptEnumField("name", MyEnum) * @param e * @tparam E * @return */ - protected def OptEnumField[E <: Enumeration]( - e: E - ): OptEnumField[E, Meta] = named(new OptEnumField[E, Meta](_, this, e)) - protected def OptEnumField[E <: Enumeration]( name: String, e: E @@ -290,15 +177,12 @@ trait QueryFieldHelpers[Meta] extends NamesResolver { /** This version of the EnumField method accepts e: E as a param to avoid ugly * type parameters like [MyEnum.type] So instead of writting val myEnum = - * EnumField[MyEnum.type, MyMeta] we can simply write val myEnum = - * EnumField(MyEnum) + * EnumIdField[MyEnum.type, MyMeta] we can simply write val myEnum = + * EnumIdField("name", MyEnum) * @param e * @tparam E * @return */ - protected def EnumIdField[E <: Enumeration]( - e: E - ): EnumIdField[E, Meta] = named(new EnumIdField[E, Meta](_, this, e)) protected def EnumIdField[E <: Enumeration]( name: String, e: E @@ -307,104 +191,60 @@ trait QueryFieldHelpers[Meta] extends NamesResolver { /** This version of the EnumField method accepts e: E as a param to avoid ugly * type parameters like [MyEnum.type] So instead of writing val myEnum = - * EnumField[MyEnum.type, MyMeta] we can simply write val myEnum = - * EnumField(MyEnum) + * OptEnumIdField[MyEnum.type, MyMeta] we can simply write val myEnum = + * OptEnumIdField("name", MyEnum) * @param e * @tparam E * @return */ - protected def OptEnumIdField[E <: Enumeration]( - e: E - ): OptEnumIdField[E, Meta] = named( - new OptEnumIdField[E, Meta](_, this, e) - ) protected def OptEnumIdField[E <: Enumeration]( name: String, e: E ): OptEnumIdField[E, Meta] = named(name)(new OptEnumIdField[E, Meta](_, this, e)) - protected def ListField[V]: ListField[V, Meta] = named( - new ListField[V, Meta](_, this) - ) protected def ListField[V](name: String): ListField[V, Meta] = named(name)(new ListField[V, Meta](_, this)) - protected def OptListField[V]: OptListField[V, Meta] = named( - new OptListField[V, Meta](_, this) - ) protected def OptListField[V](name: String): OptListField[V, Meta] = named(name)(new OptListField[V, Meta](_, this)) - protected def ArrayField[V: ClassTag]: ArrayField[V, Meta] = named( - new ArrayField[V, Meta](_, this) - ) protected def ArrayField[V: ClassTag]( name: String ): ArrayField[V, Meta] = named(name)(new ArrayField[V, Meta](_, this)) - protected def OptArrayField[V: ClassTag]: OptArrayField[V, Meta] = - named(new OptArrayField[V, Meta](_, this)) protected def OptArrayField[V: ClassTag]( name: String ): OptArrayField[V, Meta] = named(name)(new OptArrayField[V, Meta](_, this)) - protected def VectorField[V]: VectorField[V, Meta] = named( - new VectorField[V, Meta](_, this) - ) protected def VectorField[V](name: String): VectorField[V, Meta] = named(name)(new VectorField[V, Meta](_, this)) - protected def OptVectorField[V]: OptVectorField[V, Meta] = named( - new OptVectorField[V, Meta](_, this) - ) protected def OptVectorField[V]( name: String ): OptVectorField[V, Meta] = named(name)(new OptVectorField[V, Meta](_, this)) - protected def SeqField[V]: SeqField[V, Meta] = named( - new SeqField[V, Meta](_, this) - ) protected def SeqField[V](name: String): SeqField[V, Meta] = named(name)(new SeqField[V, Meta](_, this)) - protected def OptSeqField[V]: OptSeqField[V, Meta] = named( - new OptSeqField[V, Meta](_, this) - ) protected def OptSeqField[V](name: String): OptSeqField[V, Meta] = named(name)(new OptSeqField[V, Meta](_, this)) - protected def ClassField[C, MC <: CcMeta[C]]( - mc: MC - ): CClassField[C, MC, Meta] = named( - new CClassField[C, MC, Meta](_, mc, this) - ) protected def ClassField[C, MC <: CcMeta[C]]( name: String, mc: MC ): CClassField[C, MC, Meta] = named(name)(new CClassField[C, MC, Meta](_, mc, this)) - protected def OptClassField[C, MC <: CcMeta[C]]( - mc: MC - ): OptCClassField[C, MC, Meta] = named( - new OptCClassField[C, MC, Meta](_, mc, this) - ) protected def OptClassField[C, MC <: CcMeta[C]]( name: String, mc: MC ): OptCClassField[C, MC, Meta] = named(name)(new OptCClassField[C, MC, Meta](_, mc, this)) - protected def ClassRequiredField[C, MC <: CcMeta[C]]( - mc: MC, - default: C - ): CClassRequiredField[C, MC, Meta] = named( - new CClassRequiredField(_, mc, default, this) - ) protected def ClassRequiredField[C, MC <: CcMeta[C]]( name: String, mc: MC, @@ -412,89 +252,47 @@ trait QueryFieldHelpers[Meta] extends NamesResolver { ): CClassRequiredField[C, MC, Meta] = named(name)(new CClassRequiredField(_, mc, default, this)) - protected def ClassListField[C: ClassTag, MC <: CcMeta[C]]( - mc: MC - ): CClassListField[C, MC, Meta] = named( - new CClassListField[C, MC, Meta](_, mc, this) - ) protected def ClassListField[C: ClassTag, MC <: CcMeta[C]]( name: String, mc: MC ): CClassListField[C, MC, Meta] = named(name)(new CClassListField[C, MC, Meta](_, mc, this)) - protected def OptClassListField[C: ClassTag, MC <: CcMeta[C]]( - mc: MC - ): OptCClassListField[C, MC, Meta] = named( - new OptCClassListField[C, MC, Meta](_, mc, this) - ) protected def OptClassListField[C: ClassTag, MC <: CcMeta[C]]( name: String, mc: MC ): OptCClassListField[C, MC, Meta] = named(name)(new OptCClassListField[C, MC, Meta](_, mc, this)) - protected def ClassArrayField[C: ClassTag, MC <: CcMeta[C]]( - mc: MC - ): CClassArrayField[C, MC, Meta] = named( - new CClassArrayField[C, MC, Meta](_, mc, this) - ) protected def ClassArrayField[C: ClassTag, MC <: CcMeta[C]]( name: String, mc: MC ): CClassArrayField[C, MC, Meta] = named(name)(new CClassArrayField[C, MC, Meta](_, mc, this)) - protected def OptClassArrayField[C: ClassTag, MC <: CcMeta[C]]( - mc: MC - ): OptCClassArrayField[C, MC, Meta] = named( - new OptCClassArrayField[C, MC, Meta](_, mc, this) - ) protected def OptClassArrayField[C: ClassTag, MC <: CcMeta[C]]( name: String, mc: MC ): OptCClassArrayField[C, MC, Meta] = named(name)(new OptCClassArrayField[C, MC, Meta](_, mc, this)) - protected def MapField[K: MapKeyFormat, V]: MapField[K, V, Meta] = - named(new MapField[K, V, Meta](_, this)) protected def MapField[K: MapKeyFormat, V]( name: String ): MapField[K, V, Meta] = named(name)(new MapField[K, V, Meta](_, this)) - protected def OptMapField[V]: OptMapField[V, Meta] = named( - new OptMapField[V, Meta](_, this) - ) protected def OptMapField[V](name: String): OptMapField[V, Meta] = named(name)(new OptMapField[V, Meta](_, this)) - protected def LocaleField: LocaleField[Meta] = named( - new LocaleField[Meta](_, this) - ) protected def LocaleField(name: String): LocaleField[Meta] = named(name)(new LocaleField[Meta](_, this)) - protected def OptLocaleField: OptLocaleField[Meta] = named( - new OptLocaleField[Meta](_, this) - ) protected def OptLocaleField(name: String): OptLocaleField[Meta] = named(name)(new OptLocaleField[Meta](_, this)) - protected def EnumeratumField[E <: EnumEntry]( - e: Enum[E] - ): EnumeratumField[E, Meta] = - named(new EnumeratumField[E, Meta](e, _, this)) - protected def EnumeratumField[E <: EnumEntry]( name: String, e: Enum[E] ): EnumeratumField[E, Meta] = named(name)(new EnumeratumField[E, Meta](e, _, this)) } - -/*trait NamedQueryFieldHelpers[Meta] - extends QueryFieldHelpers[Meta] - with RuntimeNameResolver[Meta] { - requires: Meta => -}*/ diff --git a/cc/src/main/scala/me/sgrouples/rogue/cc/macros/MacroNamesResolver.scala b/cc/src/main/scala/me/sgrouples/rogue/cc/macros/MacroNamesResolver.scala index 7ab40f9..3c3f465 100644 --- a/cc/src/main/scala/me/sgrouples/rogue/cc/macros/MacroNamesResolver.scala +++ b/cc/src/main/scala/me/sgrouples/rogue/cc/macros/MacroNamesResolver.scala @@ -34,16 +34,4 @@ trait MacroNamesResolver[T] extends NamesResolver { field } - - override def named[T <: io.fsq.field.Field[?, ?]]( - func: String => T - ): T = { - println(s"Caller is ${func} - call ${func("x")}") - val caller = Thread.currentThread().getStackTrace()(1) - new RuntimeException().printStackTrace() - throw new IllegalArgumentException( - s"[${caller.getClassName}:L${caller.getLineNumber}] named without name not supported in macros. use @f [me.sgrouples.rogue.cc.macros.f] or provide name" - ) - } - } diff --git a/cc/src/test/scala/me/sgrouples/rogue/cc/TestModels.scala b/cc/src/test/scala/me/sgrouples/rogue/cc/TestModels.scala index c9985c4..061e5b2 100644 --- a/cc/src/test/scala/me/sgrouples/rogue/cc/TestModels.scala +++ b/cc/src/test/scala/me/sgrouples/rogue/cc/TestModels.scala @@ -14,13 +14,15 @@ object VenueStatus extends Enumeration { type VenueStatus = Value val open = Value("Open") val closed = Value("Closed") - given MacroBsonFormat[VenueStatus.Value] = EnumMacroFormats.enumNameMacroFormat(VenueStatus) + given MacroBsonFormat[VenueStatus.Value] = + EnumMacroFormats.enumNameMacroFormat(VenueStatus) } object ClaimStatus extends Enumeration { type ClaimStatus = Value val pending = Value("Pending approval") val approved = Value("Approved") - given MacroBsonFormat[ClaimStatus.Value] = EnumMacroFormats.enumNameMacroFormat(ClaimStatus) + given MacroBsonFormat[ClaimStatus.Value] = + EnumMacroFormats.enumNameMacroFormat(ClaimStatus) } object RejectReason extends Enumeration { @@ -28,7 +30,8 @@ object RejectReason extends Enumeration { val tooManyClaims = Value("too many claims") val cheater = Value("cheater") val wrongCode = Value("wrong code") - given MacroBsonFormat[RejectReason.Value] = EnumMacroFormats.enumNameMacroFormat(RejectReason) + given MacroBsonFormat[RejectReason.Value] = + EnumMacroFormats.enumNameMacroFormat(RejectReason) } case class V1(legacyid: Long) @@ -118,7 +121,8 @@ case class Comment(comments: List[OneComment]) object ConsumerPrivilege extends Enumeration { type ConsumerPrivilege = Value val awardBadges = Value("Award badges") - given MacroBsonFormat[ConsumerPrivilege.Value] = EnumMacroFormats.enumNameMacroFormat(ConsumerPrivilege) + given MacroBsonFormat[ConsumerPrivilege.Value] = + EnumMacroFormats.enumNameMacroFormat(ConsumerPrivilege) } case class OAuthConsumer(privileges: List[ConsumerPrivilege.Value]) @@ -138,11 +142,11 @@ object Metas { } class VenueClaimBsonRMeta - extends MCcMeta[VenueClaimBson, VenueClaimBsonRMeta]("_") - with QueryFieldHelpers[VenueClaimBsonRMeta] { + extends MCcMeta[VenueClaimBson, VenueClaimBsonRMeta]("_") { val uid = LongField("uid") val status = EnumField("status", ClaimStatus) - val source = OptClassField[SourceBson, SourceBsonR.type]("source", SourceBsonR) + val source = + OptClassField[SourceBson, SourceBsonR.type]("source", SourceBsonR) val date = LocalDateTimeField("date") } @@ -170,14 +174,21 @@ object Metas { val tags = ListField[String]("tags") val claims = - ClassListField[VenueClaimBson, VenueClaimBsonRMeta](VenueClaimBsonR) + ClassListField[VenueClaimBson, VenueClaimBsonRMeta]( + "claims", + VenueClaimBsonR + ) val lastClaim = - OptClassField[VenueClaimBson, VenueClaimBsonRMeta](VenueClaimBsonR) - val firstClaim = ClassRequiredField(VenueClaimBsonR, VenueClaimBson.default) + OptClassField[VenueClaimBson, VenueClaimBsonRMeta]( + "lastClaim", + VenueClaimBsonR + ) + val firstClaim = + ClassRequiredField("firstClaim", VenueClaimBsonR, VenueClaimBson.default) - val last_updated = LocalDateTimeField - val popularity = ListField[Long] - val categories = ListField[ObjectId] + val last_updated = LocalDateTimeField("last_updated") + val popularity = ListField[Long]("popularity") + val categories = ListField[ObjectId]("categories") val idIdx = index(id, Asc) val legIdx = index(legacyid, Desc) @@ -189,7 +200,6 @@ object Metas { class VenueClaimRMeta extends MCcMeta[VenueClaim, VenueClaimRMeta]("venueclaims") - with QueryFieldHelpers[VenueClaimRMeta] /*with RuntimeNameResolver[VenueClaimRMeta]*/ { val venueid = ObjectIdSubtypeField[ObjectId @@ Venue]("vid") val status = EnumField("status", ClaimStatus) @@ -206,7 +216,8 @@ object Metas { val counts = new MapField[String, Long, TipR.type]("counts", this) } - object OAuthConsumerR extends MCcMeta[OAuthConsumer, OAuthConsumerR.type]("oauthconsumers") { + object OAuthConsumerR + extends MCcMeta[OAuthConsumer, OAuthConsumerR.type]("oauthconsumers") { val privileges = new ListField[ConsumerPrivilege.Value, OAuthConsumerR.type]( "privileges", @@ -238,14 +249,14 @@ object Metas { case class Invoice(id: Long, name: String, total: Money) class MoneyMeta extends MCcMeta[Money, MoneyMeta] { - val amount = BigDecimalField - val currency = CurrencyField + val amount = BigDecimalField("amount") + val currency = CurrencyField("currency") } class InvoiceMeta extends MCcMeta[Invoice, InvoiceMeta] { - val id = LongField - val name = StringField - val total = ClassField[Money, MoneyMeta](new MoneyMeta) + val id = LongField("id") + val name = StringField("name") + val total = ClassField[Money, MoneyMeta]("total", new MoneyMeta) } val Invoices = new InvoiceMeta @@ -285,7 +296,7 @@ object Metas { case class LocaleData(locale: Locale) class LocaleDataMeta extends MCcMeta[LocaleData, LocaleDataMeta] { - val locale = LocaleField + val locale = LocaleField("locale") } val Locales = new LocaleDataMeta