IDEA can't expand the longevity macro annotations, and consequently shows error messages for primaryKey
and props
in an example like this:
@persistent[DomainModel]
case class User(username: Username, email: Email, fullName: FullName)
object User {
implicit val usernameKey = primaryKey(props.username)
}
For references to User in other source files, while implicit resolution of the generated PEv
s and the keys seems to work fine, we still get compiler errors on things like User.props
and User.queryDsl
(inherited from PType
).
It looks like the right way to handle this is to use the "IntelliJ API to build scala macros support": https://blog.jetbrains.com/scala/2015/10/14/intellij-api-to-build-scala-macros-support/
Another potential alternative is to make modifications/enhancements to longevity API to allow users to specify things a little differently so that IDEA can follow along. I'm thinking along the lines of:
- Allow users to say something like this:
@persistent[DomainModel]
case class User(username: Username, email: Email, fullName: FullName)
object User extends PType[Domain, User] {
implicit val usernameKey = primaryKey(props.username)
}
So the @persistent
annotation already extends the User
companion object with PType
, but we could allow this redundancy easily enough.
- Add a
PType
method something like:
def dprop[A](propName: String): Prop[User, A]
This method finds the right property in the User.props
object generated by the @persistent
macro. In this case, we could say dprop[Username]("username")
instead of props.username
. Of course we would lose a lot of type safety guarantees here: this method could throw runtime exception on misnamed or mistyped properties.
It looks like these two changes would allow IDEA users to have workarounds for the build errors. The non-workaround, IDEA API for scala macros approach would be much more desirable, but probably a good deal more work.