I need to generate:
case class Foo(param: Bar = BarEnum.SomeCaseObject)
But this code:
val term = TermName("BarEnum.SomeCaseObject")
showCode(q"""case class Foo(val param : Bar = ${term})""")
outputs the parameter default surrounded by…
I am having trouble writing a macro that transforms a given partial function and creates a new partial function. For instance, I want to be able to decompose the given partial function into its elements - pattern binder, guard condition, and body;…
I'm trying to generate Tree for function that accepts case class value and returns value of case class parameter at given position. This is useful for extracting values of private parameters.
import reflect.runtime.currentMirror
import…
I wrote a macro that parses JSON into a matching case class.
def parse(jsonTree: JsValue): BaseType = macro parserImpl
def parserImpl(c: blackbox.Context)(jsonTree: c.Tree) = {
import c.universe._
val q"$json" = jsonTree
val cases =…
I have a macro and part of that macro consists of replacing every call to a certain method with something else. To accomplish this I use a Transformer and try to match every Tree that enters the transform method against a quasiquote. When I write it…
I'm trying to generate statement by case class parameters.
case class f(a:String, b:String){
val statement = Macroses.st[f]
}
object MacrosTest {
def start() {
val result = f("1", "2").statement
}
}
Result must be INSERT INTO…
I am trying to insert class comments for quasi quotes like so
q"""
package somePackage {
/**
* This is a comment
*/
public class SomeClass {
}
}
"""
But its throwing an exception
Exception in…
I am trying to use quasi quote to generate the package AST. I have a string variable that lists out the package path such that
val pkg = "database.dao"
When I use quasi quote q"package $pkg, it tells me that I need a RefTree instead. I tried…
Context:
I'm working on a library for working with JMX in Scala. One of the objectives is to have a strong typed interface to Managed Beans. I guess akin to to the Spring framework JMX library.
Objective: Macro to Deserialise TabularData to a case…
q"""
val x = ${evalA.primitiveTerm}
val y = ${evalB.primitiveTerm}
val res = 0
for (i <- 0 until x.length; if i < y.length) {
val res = x(i).compareTo(y(i))
if (res != 0) return res
…
Scala allows pattern matching on varargs for unapplySeq:
case class A(args: String*)
A("a", "b", "c") match {
case A(args @ _*) => args // Seq("a", "b", "c")
}
I want to generate such pattern with macros. How should I do it? A natural thing to…
I was trying to use Toolbox and quasiquote together to do code generation tasks, and faced with StackOverflowError while using AST of object returned from reify(x).tree, my code is as follows:
abstract class A[T] {def i: T}
class B(val i: Int)…
I would like to pattern match for the tree of the x -> y operation in Scala macros. I am cross compiling against Scala 2.10.4 (with Macro Paradise) and Scala 2.11.x. I have tried the following patterns and none worked:
arrowTree match {
case q"$x…
I asked a longer question, but it seems it's too much code for people to sort through so I've created this question to focus on one smaller, specific problem I'm facing regarding use of macros in Scala.
Consider the following code snippet:
val tpe =…
I wan to infer an implicit value of an AppliedType, here's what I've done
val valueType = accessorTree.returnType
val encoderType = tq"DatumEncoder[$valueType]" // returns a Tree
val encoder = c.inferImplicitValue(encoderType) // require a Type
But…