Questions tagged [scalameta]

For meta programming in Scala using the Scalameta library

This tag is for questions relating to the Scalameta library for Scala.

66 questions
2
votes
1 answer

In scala 2 or 3, is it possible to debug implicit resolution process in runtime?

In scala language, implicit resolution is often done in compile-time and sometimes throws obfuscating error information, one famous example of such error is when shapeless Generic throws error information like: error: could not find implicit value…
tribbloid
  • 4,026
  • 14
  • 64
  • 103
2
votes
1 answer

How to get a method return type with scala meta annotation?

I want do a Log annotation use scala meta.Usage simple as: @Log def f1(a: Int) { Future(a + 1) //result is a Future } // after parsed ====> def f1(a: Int) { Future(a + 1).map{x => println(x) x } } How can I check if…
LoranceChen
  • 2,453
  • 2
  • 22
  • 48
2
votes
2 answers

meta-programming to parse json in scala

I need some hints to write a scala program that could read json file and create a case class at run time. As an example if we have json class like - Employ{ name:{datatype:String, null:false} age:{datatype:Int, null:true} …
tesnik03
  • 1,324
  • 2
  • 13
  • 23
1
vote
0 answers

Including `munit` tests that are excluded by default

I have an munit test: package myawesomeproject import munit.FunSuite class MySillyTest extends FunSuite { val theTag = new munit.Tag("tagname") test("THETEST".tag(theTag)) { assertEquals(2, 3) } } and in my build.sbt, I want to exclude…
Andrey Tyukin
  • 43,673
  • 4
  • 57
  • 93
1
vote
1 answer

Scala SymbolMatcher failing to match import prefix

I'm using the scalafix library to try to convert a project from scalaz to cats, but one particular attempt at removing imports (the first case in the following code) is failing. The relevant bits of code are: scalafix code: package fix import…
Charles_F
  • 186
  • 2
1
vote
1 answer

Why is scala.meta.Term.Param#toString dropping modifiers?

I'm trying to rename the parameter of an anonymous function using a semantic scalafix plugin. The relevant code looks like this: case Term.Apply(func, args) => args.collect { case Term.Block(List(Term.Function(List(arg), _))) => …
Corey Woodfield
  • 350
  • 2
  • 10
1
vote
1 answer

scala.meta parent of parent of Defn.Object

Let it be the following hierarchy: object X extends Y{ ... } trait Y extends Z { ... } trait Z { def run(): Unit } I parse the scala file containing the X and I want to know if its parent or grandparent is Z. I can check for parent as…
Chris
  • 549
  • 1
  • 5
  • 18
1
vote
1 answer

How to merge multiple imports in scala?

Assume I have a library a.com. Everytime and in each file, I need to import a lot of package like import a.com._ import a.com.b._ import a.com.c import a.com.Implicits._ I don't want to write these code every time in each file of another…
worldterminator
  • 2,968
  • 6
  • 33
  • 52
1
vote
1 answer

How to replace all specific Term.Name expressions in an AST recursively with scalameta?

I would like to replace ALL occurences of specific Term.Name instances in the AST. Something like: tree match { case t @ Term.Name(n) if (n == "bla") => Term.Apply(Term.Select(t, Term.Name("read")), List()) } However, to achieve this, I will…
Baradé
  • 1,290
  • 1
  • 15
  • 35
1
vote
1 answer

How to get the type of a variable with scalameta if the decltpe is empty?

If I have the following type Defn.Var(mods, pats, decltpe, rhs) in scalameta it might happen that decltype is set to None for a variable like this: var x = 10 I still want to know the exact type of the variable x which Scala has inferred without…
Baradé
  • 1,290
  • 1
  • 15
  • 35
1
vote
1 answer

Does macroparadise no longer work from the command line?

I am trying to start using the paradise macro plugin, so I have been beginning with the identity macro example from: https://docs.scala-lang.org/overviews/macros/annotations.html However, when I try to use the identity annotation I get error:…
1
vote
1 answer

scala.meta.Lit.type does not take parameters

When I run the following: import scala.meta._ class Test { val x = q"1" } I get scala.meta.Lit.type does not take parameters val x = q"1" scalameta_2.11:1.8.0 paradise_2.11.8:3.0.0-M7 I'm trying to get some basic macro examples working,…
user2682459
  • 999
  • 2
  • 13
  • 24
1
vote
1 answer

Generate a case class with Binding.scala Vars using Scala.meta throws an exception

I have a scala.js project. There I have a strange behavior with Scala.Meta and Binding.scala. I want to create a case class from a case class: case class SimpleCaseClass(i: Int, s: String, list: Seq[String]) should generate…
pme
  • 14,156
  • 3
  • 52
  • 95
1
vote
1 answer

Initializing the factory at compile time

I have a factory that should return an implementation depending on the name. val moduleMap = Map(Modules.moduleName -> new ModuleImpl) def getModule(moduleName: String): Module = moduleMap.get(moduleName) match { case…
1
vote
2 answers

Scala macro to auto generate fluent builders

I am interacting with an external Java API which looks like this: val obj: SomeBigJavaObj = { val _obj = new SomeBigJavaObj(p1, p2) _obj.setFoo(p3) _obj.setBar(p4) val somethingElse = { val _obj2 = new SomethingElse(p5) …
pathikrit
  • 32,469
  • 37
  • 142
  • 221