I created the following code snippet for use as an encode generator for scala type to java type.
object Macros {
def encode[A <: Product, B](value:A):B = macro MacrosImpl.encode_impl[A, B]
}
class MacrosImpl(val c:Context) {
import…
I'm experimenting with macro annotations in Scala 2.10.3 using macroparadise 2.0.0-M3. I am trying to understand how to use quasiquotes to generate a companion object to an annotated class. What I have found so far is how to generate a companion…
I have a type resultType of Context.this.type#c#universe#Type. I need to match it against Unit type. I tried
resultType match {
case q"Unit" => ...
}
but I suppose that Unit is just a string literal here that obviously do not match. How to match…
Apologies for the handwavey title. I’m not entirely sure how to phrase the question succinctly, since I’ve never encountered something like this before.
Background info:
I have the following trait, where the type U is meant to hold a Shapeless…
Suppose I want a macro that takes an expression and returns the arity if it's a tuple literal. Something like this works for tuples but returns Some(1) instead of None for everything else:
import scala.reflect.macros.blackbox.Context
class…
Unfortunately, the most intuitive way,
val world = "Earth"
val tree = q"""println("Hello $world")"""
results in
Error:(16, 36) Don't know how to unquote here
val tree = q"""println("Hello $world")"""
^
because $ within…
Update: Modified the code to use macro annotation, but still missing something
The following code works (question below):
object MyTypes {
trait RealType
class Container[RT <: RealType] {
this: RT =>
}
trait SomeRealType extends…
I want to use the power of Scala's pattern matching within a set of `condition-action' rules. These rules are not known in advance, but rather are generated at runtime according to some complex critera. The algorithmic generation mechanism can be…
I need to generate an implementation of a trait at runtime, then execute a known method on an instance of the trait. In this example I'm running A's a method:
import reflect.runtime._, universe._, tools.reflect.ToolBox
package p {
trait A { def…
I have an array of quasi quotes called definitions which I want to inject to the quasi quote tree. How do I go about doing this?
private def generateDaoComponent(files: Array[File]) = {
val file = createNewFile(compDirectory)
val…
I am trying to use scala-pickling in one of my projects. I tried to mimic the build file of macroid which seems to use pickling too but I keep getting this error on sbt test:
[error] Modules were resolved with conflicting cross-version suffixes in…
I have a quoasiquote matcher where q"someMethod[$ts]()" where def someMethod[I <: shapeless.HList]()".
Printing ts gives:
List(shapeless.HNil)
or, e.g.
List(String, Int)
Then I try to assign:
val types: List[scala.reflect.api.Types.Type] =…
I am trying to write a framework to make writing Scala compiler plugins easier, what I am doing is writing a framework on top of the Scala quasiquotes. So my project depends on macros from macro-paradise and both scala-compiler and scala-reflect…
I'm trying to use freshName as a parameter name in the following macro:
I.
def test: Unit = macro implTst
def implTst(c: blackbox.Context): c.Expr[Unit] = {
import c.universe._
def withImplicitsM(exprs: List[c.Tree], expr: c.Tree): c.Tree =
…
I'm trying to avoid repetition of long quasiquotes in matches. So, I'd like to convert this:
def appendTree(clazz: ClassDef, tree: Tree): ClassDef =
clazz match {
case q"$mods class $tpname[..$tparams] $ctorMods(...$paramss) extends {…