gpt4 book ai didi

scala - 宏注释在 IntelliJ14 中不起作用

转载 作者:行者123 更新时间:2023-12-01 11:30:56 24 4
gpt4 key购买 nike

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

enable macro paradise to expand macro annotations

来 self 写的@compileTimeOnly 消息。我按照 Macro annotation documentation 中的所有说明进行操作和 SBT example .

集成环境: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{}

我到底错过了什么?

最佳答案

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

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

enter image description here

就是这样!

关于scala - 宏注释在 IntelliJ14 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32002680/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com