我在Scala2.13/ Mill项目中使用齐奥宏。
这里的例子是:
@accessible
@mockable
trait AccountObserver {
val accountObserver: AccountObserver.Service[Any]
}
object AccountObserver {
trait Service[R] {
def processEvent(event: String): ZIO[R, Nothing, Unit]
}
// autogenerated `object Service { ... }`
// autogenerated `object > extends Service[AccountObserver] { ... }`
// autogenerated `implicit val mockable: Mockable[AccountObserver] = ...`
}
我可以运行测试,它可以找到自动生成的代码。
问题是,在Intellij中,对自动生成的代码的引用做而不是编译。
我是否必须配置某些东西,或者缺少什么?
发布于 2019-10-29 22:07:27
下面的项目编译
build.sc
import mill._, scalalib._
object root extends ScalaModule {
def scalaVersion = "2.13.1"
val zioMacrosV = "0.4.0"
def ivyDeps = Agg(
ivy"dev.zio::zio-macros-core:${zioMacrosV}",
ivy"dev.zio::zio-macros-access:${zioMacrosV}",
ivy"dev.zio::zio-macros-mock:${zioMacrosV}"
)
def scalacOptions = Seq(
"-Ymacro-annotations",
"-Ymacro-debug-lite"
)
}
root/src/App.scala
import zio.ZIO
import zio.macros.access.accessible
import zio.macros.mock.mockable
@accessible
@mockable
trait AccountObserver {
val accountObserver: AccountObserver.Service[Any]
}
object AccountObserver {
trait Service[R] {
def processEvent(event: String): ZIO[R, Nothing, Unit]
}
}
命令mill root.compile
编译项目
//{
// abstract trait AccountObserver extends scala.AnyRef {
// val accountObserver: AccountObserver.Service[Any]
// };
// object AccountObserver extends scala.AnyRef {
// def <init>() = {
// super.<init>();
// ()
// };
// abstract trait Service[R] extends scala.AnyRef {
// def processEvent(event: String): ZIO[R, Nothing, Unit]
// };
// object Service extends scala.AnyRef {
// def <init>() = {
// super.<init>();
// ()
// };
// case object processEvent extends _root_.zio.test.mock.Method[String, Unit] with scala.Product with scala.Serializable {
// def <init>() = {
// super.<init>();
// ()
// }
// }
// };
// implicit val mockable: _root_.zio.test.mock.Mockable[AccountObserver] = ((mock: _root_.zio.test.mock.Mock) => {
// final class $anon extends AccountObserver {
// def <init>() = {
// super.<init>();
// ()
// };
// val accountObserver = {
// final class $anon extends Service[Any] {
// def <init>() = {
// super.<init>();
// ()
// };
// def processEvent(event: String): _root_.zio.IO[Nothing, Unit] = mock(Service.processEvent, event)
// };
// new $anon()
// }
// };
// new $anon()
// });
// object $greater extends Service[AccountObserver] {
// def <init>() = {
// super.<init>();
// ()
// };
// def processEvent(event: String): _root_.zio.IO[Nothing, Unit] = _root_.zio.ZIO.accessM(<empty> match {
// case (env @ (_: AccountObserver)) => env.accountObserver.processEvent(event)
// })
// }
// };
// ()
//}
创建IntelliJ文件
mill mill.scalalib.GenIdea/idea
然后在IntelliJ中打开项目(不要导入 it)。
现在,Ctrl+Shift+F9编译项目(类似于上面)。
例如,可以使用对对象AccountObserver.Service
的引用(这是编译的)。当然,IntelliJ将Service
高亮为红色,但这并不重要。
https://stackoverflow.com/questions/58614222
复制相似问题