scala-macros

    1熱度

    1回答

    我使用Macro Paradise在Scala 2.10.3上。我在那裏我想一個特徵添加到對象宏註釋,如: @MyAnnotation object Foo extends Bar {} 擴張後,我想是這樣的: object Foo extends Bar with Baz {} 凡Baz是在編譯的性狀訪問範圍。使用微距天堂,我可以清晰地解構我的目標樹: q"object $obj ex

    2熱度

    1回答

    在宏內部有使用當前上下文完全展開類型名稱的方法嗎?比如像: context.resolveShortTypeNameToFullTypeName("Foo") = "com.acme.Foo"

    0熱度

    2回答

    我有這樣的代碼: object M { implicit class Obj(str: List[_]) { def mm(other: String) = macro Test.impl } } //macro //in macro i would get a `str` argument with actual value which pass into

    3熱度

    1回答

    我有下一個代碼,我想從值中提取默認參數。 // def extractor[T] = macro extractorImpl[T] def extractorImpl[T: c.WeakTypeTag](c: Context) = { //first i got a type contructor ??? } 我嘗試用attachments但attachments.

    1熱度

    1回答

    下面的代碼爲我失敗: object Message { def parse[T](bsonDoc: BSONDocument): Try[T] = { implicit val bsonHandler = Macros.handler[T] bsonDoc.seeAsTry[T] } } Message.parse[messages.ClientH

    1熱度

    2回答

    Context有方法literal(Int),literal(String)等。我如何創建給定名稱的文字符號(即'name)?有一個明顯的解決方法:創建Symbol.apply(literal(name)),但我希望應該有一個直接的方法。

    3熱度

    1回答

    我想編寫一個宏,其中返回類型取決於參數。簡單示例: def fun[T](methodName: String) = macro funImpl[T] def funImpl[T: WeakTypeTag](c: Context)(methodName: c.Expr[String]): /* c.Expr[T => return type of T.methodName] */ = {

    10熱度

    2回答

    這個限制將來會被克服嗎?或者有什麼方法可以解決這個我不知道的問題? 現在我有一個項目,我想使用宏,但他們需要依賴於該項目的特定類型。爲宏定義一個單獨的編譯單元需要我引入另一個來保存常見類型,我不會每次寫宏時都會這樣做。

    2熱度

    1回答

    我已經定義了下面的宏從當前位置開始的文件,線和對象/類: http://pastebin.com/UsNLemnK 使用SBT,我已經定義了兩個項目,以先編譯宏,然後實際的項目使用這些宏。 這些宏的目的是要在一個日誌方法中使用: def log(msg: Any, srcFile: String = "", srcLine: String = "", srcClass:String = "")

    2熱度

    1回答

    我想要做這樣的事情: trait Endo { def apply[T](x: T): T } trait SuperType { def endoMap(f: Endo): SuperType = macro SuperTypeMacro.endoMapImpl } case class Foo(x: Int) extends SuperType { /