Questions tagged [scala-macros]

Scala macros is a facility for Scala—a general-purpose programming language—that permits compile-time metaprogramming against Scala syntax trees, from within the Scala language.

774 questions
0
votes
1 answer

Can I get the package/owner from a ClassDef in an impl of a Scala macro annotation?

Given (Scala 2.10.3), package models @MyAnnotation case class MyClass() How do I get the package name in the impl of the macro? I've tried: 1) A typeCheck like was suggested here, but that results in a stack overflow (although I can see it…
Julian Peeters
  • 853
  • 1
  • 6
  • 19
0
votes
1 answer

Is there a way to deflate & map bit-mapped database columns into scala objects via slick

This is in continuation to the following post: How to combine multiple columns in one case class field when using lifted embedding? I am a great fan of bit fields, wants to use this logic in a project where I am using slick-macros. Unfortunately…
sgireddy
  • 155
  • 10
0
votes
1 answer

Scala macro: rewrite partial function into match

I would like to rewrite partial function into match expression. //macro and impl def pfRewrite(pf: PartialFunction[Int, Int]) = macro ResponderImpl.pfRewriteImpl def pfRewriteImpl(c: Context)(pf: c.Expr[PartialFunction[Int, Int]]) = { import…
mike
  • 749
  • 10
  • 21
0
votes
0 answers

Access all scoped symbols in Macro

I want to find a scoped symbol by name inside a macro. The symbol might be in a method, var or import. Is there a simple way of doing this? Eg access the Symbol Table?
user3293336
  • 121
  • 1
0
votes
1 answer

Scala Macros: How to create setter function for case classes

I would like to use macro to generate a setter for case classes. e.g: case class Person(name: String, age: Int) Macro.mkSetter[Person, String]("name") : Person => String => Person I tried the following implementation but I keep getting the…
Julien Truffaut
  • 477
  • 4
  • 10
0
votes
1 answer

Adding aliases for macro annotations

While doing DSL stuff, I'd like to add several aliases to an existing macro annotation and, if possible, I'd like to avoid typing the macroTransform definition. That is to say that I want to declare an alias for the "macro header", instead of the…
neutropolis
  • 1,884
  • 15
  • 34
0
votes
1 answer

Scala Macros: get vals from object

I use scala macros for extract all object from package, and then i would like get some values from object: package example trait A {} object B extends A { val test = "test" } //macro object Macro def getVals(packageName: String) = macro…
mike
  • 749
  • 10
  • 21
0
votes
1 answer

Scala Macro Annotations - Why doesn't my class appear to be updated when I use it as a type parameter?

I used Eugene Burmako's macro annotation example from Macro Paradise (thanks Eugene!) and modified here it to add a val to an empty class here. As an instance, I can call the new val as expected. But when I try to use the updated class as a type…
Julian Peeters
  • 853
  • 1
  • 6
  • 19
0
votes
1 answer

How to get Type of arbitrary tree and check its strong/weak conformance?

For example, one need to check whether an expression is of whole number type: Byte, Short, Int, Long but not Double or Float. The following code doesn't always work: case Apply(Select(q, n), List(rhs)) => if (q.tpe.weak_<:<(typeOf[Long])) true…
nau
  • 1,145
  • 8
  • 20
0
votes
0 answers

Implementing case by case type level functions in Scala

I would like to implement something, probably a macro, to implement something like Int --> java.lang.Integer Float --> java.lang.Float so that I can implement something like def box[X <: AnyVal : Numeric](x: X) : Boxed[X] = ... that would cause…
Daniel Mahler
  • 7,653
  • 5
  • 51
  • 90
0
votes
1 answer

How to run a java program upon compilation of class

I have a java jar I want to invoke when a class is compiled using the Eclipse IDE : java -jar myjar.jar args1 args2 Is there a java lib I can use for this or perhaps use a Scala macro ?
blue-sky
  • 51,962
  • 152
  • 427
  • 752
0
votes
1 answer

`embeddedFile` warns during compilation while using quasiquotes

After I started using quasiquotes for Scala 2.10 via SBT plugin I have warnings as follows: [warn] embeddedFile--QuasiquoteCompat.scala@e97d744663044acca2f60c8e99547f14:320: Adapting argument list by inserting (): leaky (Object-receiving) target…
Alexander Myltsev
  • 459
  • 1
  • 3
  • 13
0
votes
0 answers

Is it possible to determine the type of a pattern variable in a Scala macro?

As part of a macro I need to inspect the patterns of case definitions. Is there a way to determine the type of a pattern variable, or even the whole pattern? Consider the polymorphic class Data, and a macro which uses a transformer to inspect and…
Martin Zuber
  • 137
  • 6
0
votes
2 answers

Scala 2.10 Pass field as argument

Think of a case class like this: case class User(firstname: String, lastname: String) now think of calling a method check with the firstname check(User.firstname) The Problem is, that the method check must have the name of the field too. It must…
user1563700
0
votes
1 answer

DSL for safe navigation operator in Scala

I want to build a Scala DSL to convert from a existing structure of Java POJOs to a structure equivalent to a Map. However the incoming objects structure is very likely to contain a lot of null references, which will result in no value in the output…
Michel Daviot
  • 206
  • 1
  • 10
1 2 3
51
52