I am trying to do what is mentioned below but am struggling with the object side of things for my particular case. This all relates back to trying to auto-generate some classes that I posted back a while ago on. I would love to generate 1 file that has the trait and the object in it that I then inherit from in my sub-class and object sub-class in another file.
Autogenerated.scala trait FC[MapperType <: FC[MapperType]] extends Mapper[MapperType] { self: MapperType => object today extends MappedLong(this) } trait FCObj extends FC[MapperType] with LongKeyedMetaMapper[FC [MapperType]] { override def fieldOrder = List(today) } In UserClass.scala class FC_Wrapper extends LongKeyedMapper[FC_Wrapper] with IdPK with FC [Wrapper] { def getSingleton = FCObj_Wrapper // define methods } object FCObj_Wrapper extends FCObj { // define auxiliary functionality } I know that the FCObj and FCObj_Wrapper is not correct syntax wise. But the basic idea is that I want to have my autogeneration generate the boilerplate code for me in a separate file. This boilerplate would ideally include the class and object related stuff. Then in a file that won't be stomped upon the next time I run the generator I inherit from these objects. I hope this makes sense. I admit to not totally understanding the templated/generic programming that is happening. On Sep 3, 1:33 pm, glenn <gl...@exmbly.com> wrote: > Isn't this really a matter of type casting, and asInstanceOf is just > Scala's > way of doing this. It's always best if you don't have to downcast your > objects, but sometimes its unavoidable. > > Glenn... > > On Sep 3, 10:29 am, glenn <gl...@exmbly.com> wrote: > > > I'm not sure of what the exact problem is. I created an Address trait > > that > > I couple with a number of mapper classes. > > > trait Address[OwnerType <: KeyedMapper[Long, OwnerType]]{ > > > def owner = this.asInstanceOf[OwnerType] > > > .... > > > Where exactly does this construct break down? > > > Glenn... > > > On Sep 3, 7:55 am, Giuseppe Fogliazza <g.foglia...@mcmspa.it> wrote: > > > > jon suggested to me the way to avoid both explicit type parameter and > > > asinstance of: > > > trait Timestamp[MapperType <: TimeStamp[MapperType]] extends Mapper > > > [MapperType] { > > >self:MapperType => > > > object xdatetime extends MappedDateTime(this) > > > > // all sorts of utility functions for dealing with timestamps > > > > } > > > > Thanks jon I have improved model in my application with this approach. > > > > Giuseppe > > > > On 3 Set, 16:16, Giuseppe Fogliazza <g.foglia...@mcmspa.it> wrote: > > > > > As an alternative to asInstanceOf you could use explicit type > > > > parameter in MappedField creation: > > > >self:MapperType => > > > > object xdatetime extends MappedDateTime[MapperType](this) > > > > > On 3 Set, 09:19, Giuseppe Fogliazza <g.foglia...@mcmspa.it> wrote: > > > > > > Unfortunately you cannot escape from asInstanceOf . Forcing > > > > >self:MapperType the type of "this" will be TimeStamp with MapperType > > > > > violating the constraint for the type of the first parameter of > > > > > MappedDateTime :T <: Mapper[T]. > > > > > > Regards > > > > > Giuseppe > > > > > > On 3 Set, 07:08, Naftoli Gugenheim <naftoli...@gmail.com> wrote: > > > > > > > So I guess you can't escape the asInstanceOf. Can you successfully > > > > > > give the trait aself-type of this: MapperType =>, or declare it to > > > > > > extend Mapper[MapperType], without running into problems elsewhere? > > > > > > > ------------------------------------- > > > > > > > harryh<har...@gmail.com> wrote: > > > > > > > I've been handling this with traits, for example I have something > > > > > > like > > > > > > so: > > > > > > > trait Timestamp[MapperType <: Mapper[MapperType]] { > > > > > > object xdatetime extends > > > > > > MappedDateTime[MapperType](this.asInstanceOf > > > > > > [MapperType]) > > > > > > > // all sorts of utility functions for dealing with timestamps > > > > > > > } > > > > > > > Then I can do > > > > > > > class Foo extends LongKeyedMapper[Foo] with IdPK with > > > > > > Timestamp[Foo] { > > > > > > // additional fields that are Foo specific > > > > > > > } > > > > > > > I have quite a few traits similar to Timestamp at this point > > > > > > corresponding to various fields that appear in lots of different > > > > > > tables in my application. > > > > > > > -harryh --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Lift" group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~----------~----~----~----~------~----~------~--~---