【问题标题】:Macros annotation not working in IntelliJ14宏注释在 IntelliJ14 中不起作用
【发布时间】:2015-08-14 05:10:58
【问题描述】:

我在使用 Scala 宏时遇到问题。它一直告诉我要

启用宏天堂扩展宏注释

来自我写的@compileTimeOnly 消息。我遵循了Macro annotation documentationSBT example 的所有说明。

IDE:IntelliJ 14.1

Scala 版本:2.11.7

Project文件夹下的Build.scala:

import sbt._
import sbt.Keys._

object Build extends Build {
  val paradiseVersion = "2.1.0-M5"
  lazy val sm = Project(id = "server-modules", base = file(".")).settings(
    version := "1.0",
    logLevel := Level.Warn,
    scalacOptions ++= Seq(),
    scalaVersion := "2.11.7",
    crossScalaVersions := Seq("2.10.2", "2.10.3", "2.10.4", "2.10.5", "2.11.0", "2.11.1", "2.11.2", "2.11.3", "2.11.4", "2.11.5", "2.11.6", "2.11.7"),
    resolvers += Resolver.sonatypeRepo("snapshots"),
    resolvers += Resolver.sonatypeRepo("releases"),
    addCompilerPlugin("org.scalamacros" % "paradise" % paradiseVersion cross CrossVersion.full),
    libraryDependencies <+= (scalaVersion)("org.scala-lang" % "scala-reflect" % _),
  )
}

代码:

@compileTimeOnly("enable macro paradise to expand macro annotations")
class dmCompile extends StaticAnnotation{
  def macroTransform(annottees: Any*): Any = macro DMCompile.impl
}

object DMCompile {
  def impl(c: whitebox.Context)(annottees: c.Expr[Any]*): c.Expr[Any] = {
    import c.universe._

    Log.info("Work work work!")

    c.Expr(q"""var x = y""")
  }
}

@dmCompile class Test{}

我到底错过了什么?

【问题讨论】:

    标签: scala intellij-idea scala-macros intellij-14 scala-macro-paradise


    【解决方案1】:

    这花了我一整天的时间,但我得到了它的工作。

    只需忽略 SBT 设置宏天堂并手动将其添加到 Preference -> Scala Compiler

    就是这样!

    【讨论】:

      【解决方案2】:

      对我来说,一个解决方案是在设置中将增量类型从 IDEA 更改为 SBT。这允许使用原生 SBT 的构建引擎而不是 IDEA 的构建引擎。

      【讨论】:

        猜你喜欢
        • 2014-08-14
        • 1970-01-01
        • 2018-05-12
        • 1970-01-01
        • 1970-01-01
        • 2011-01-29
        • 2013-09-20
        • 2020-10-09
        • 2012-09-19
        相关资源
        最近更新 更多