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
1
vote
1 answer

Get a fully qualified name for references using scalameta

I'm trying to write a simple program to traverse all the referenced code starting from a given method using scalameta. I was able to follow the calls but could not resolve method references. analyzeme/src/main/scala/codelab/FindMe.scala package…
Gabor Juhasz
  • 317
  • 2
  • 9
1
vote
1 answer

Scalameta's Semantic API

In Scalameta's tutorial, it notes that the Semantic API can be used for name resolution (println => _root_.scala.Predef.println). The FAQ "How do I use the Semantic API?" links to scalafix, but I was unable to find a tutorial or concrete examples. …
Sledge
  • 178
  • 13
1
vote
0 answers

using scala-meta, how to infer types

I would like to be able to detect the full type name of a type T when it is referred within some other compilation unit A. So say A is package p import com.p1.A import com.p2._ class X { def method1:A // detect it as com.p1.A, which I can do…
kostas.kougios
  • 945
  • 10
  • 21
1
vote
1 answer

Scala macros: generate code based on file contents

I would like to generate scala classes based on some files. Placement of the files doesn't matter (it can be resources folder or files can be placed just near my scala source files). How can I read them when scala macro is executed? (I use…
Eugene Nacu
  • 1,613
  • 2
  • 14
  • 22
1
vote
1 answer

How to match methods which return a Future and have multiple arguments or multiple arguments list (curried)?

I am playing with scalameta and I want to have a generic measurement annotation which sends measurements about how long the method execution took. I used Qing Wei's cache annotation…
Jeno Laszlo
  • 2,023
  • 18
  • 36
1
vote
1 answer

Compile Time Parameter for Macro Expansion

I would like to write an annotation macro that adds an extends to traits where can be specified at compile time. How can a compile time parameter be passed to a macro expansion? Ideally I would like to specify a command line…
Stefan
  • 207
  • 2
  • 8
1
vote
1 answer

scala-meta: type mismatch when unquoting; found: Option[scala.meta.Type.Arg] required: scala.meta.Type

I am playing a bit with the new-style macro annotations of scala-meta. So I extended the example of the @Main annotation: SConsumer.scala: import scala.meta._ class SConsumer extends scala.annotation.StaticAnnotation { inline def apply(defn:…
1
vote
1 answer

How to preserve sugar, formatting, and whitespace in macro annotations (inline-meta)?

I'm exporting Scala functions to an external format. For this purpose I use scala.meta and a StaticAnnotation. Something like: @ExportFunctions object MyFunctions { def max(x: Int, y: Int): Int = x max y } class ExportFunctions extends…
1
vote
1 answer

With scala.meta replacing scala.reflect, what will happen to ClassTags and TypeTags?

Or is this even relevant? What I have in mind is using the ClassTag or TypeTag annotations, like so: scala> import scala.reflect.runtime.universe.TypeTag def f[T : TypeTag](ls : List[T]) : String = { ??? } results in : f: [T](ls:…
Luciano
  • 2,388
  • 1
  • 22
  • 33
1
vote
3 answers

Using scala-meta to annotate a case class

I have a real beginners question using scala-meta I want to add annotations to a subset of a case class’s fields based on the name of the the field. The classes and fields to annotate are defined as follows: val classMapping = Map[String,String]( …
iandebeer
  • 227
  • 2
  • 8
0
votes
1 answer

issue with resolving sbt dependencies scalameta

I have created an sbt project. I am trying to add the org.scalameta dependency for scala code formatting. I added following dependency in project/plugins.sbt addSbtPlugin("org.scalameta" %% "scalameta_2.11" % "4.5.3") But I am getting following…
bu0603
  • 37
  • 2
  • 3
0
votes
1 answer

ScalaMeta: What's difference between `stats` and `children`

stats is short for statements while children is what it's. I ran both methods and it seems results are same. Can someone please point to me a more detailed differentiation between both. Attaching a sample code, feel free to run it on…
Ravinder Payal
  • 2,884
  • 31
  • 40
0
votes
1 answer

Is it possible to using macro to modify the generated code of structural-typing instance invocation?

For example as the following code: object Test extends App { trait Class { val f1: Int } val c = new Class { val f1: Int = 1 val f2: String = "Class" } println(c.f1) println(c.f2) } I look into…
xiagao1982
  • 1,077
  • 1
  • 13
  • 25
0
votes
1 answer

How to use one or multiple SemanticRules with scalafix similar to scalameta's Transformer?

In the tutorial https://scalacenter.github.io/scalafix/docs/developers/tutorial.html I see how a SemanticRule is implemented for scalafix. I would like to call it directly in the source code on a Scala file which I have read from the disk and…
Baradé
  • 1,290
  • 1
  • 15
  • 35
0
votes
1 answer

How to parse and transform all source code files from an sbt project with scalameta?

I would like to use scalameta to parse ALL source code files from an SBT based Scala project and transform them. As the documentation states (https://scalameta.org/docs/trees/guide.html#from-programs-with-multiple-top-level-statements) I can parse…
Baradé
  • 1,290
  • 1
  • 15
  • 35