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
0
votes
2 answers

How to get the (static) type of an expression in Scala?

Does Scala have any equivalent to GCC's typeofextension? (Or C++ decltype?) I'm generating code that references some external code (which may not be available yet), and I need a way to reference the type of that code in a method definition For…
aij
  • 5,903
  • 3
  • 37
  • 41
0
votes
2 answers

How does one obtain the type of the value that an AST represents?

I’m trying to write the following: import scala.reflect.runtime.universe._ val value: Tree = /* some AST */ val tpe = typeOf(value) // This should be the result type of the AST. // This is pseudocode. What should …
Dan Li
  • 866
  • 1
  • 7
  • 19
0
votes
1 answer

How does one use quasiquotes to obtain the type of a value?

I’m trying to write the following: val value: Int = 3 val tpe = typeOf(value) // This is pseudocode. What should // actually go on this line? q""" type U = $tpe val v: U = $value """ Essentially, I need to capture the…
Dan Li
  • 866
  • 1
  • 7
  • 19
0
votes
1 answer

Obtaining a SemanticDocument from a Scala source file using ScalaFix

What are the steps of parsing a Scala source file into a SemanticDocument using ScalaFix?
Gakuo
  • 845
  • 6
  • 26
0
votes
1 answer

object contrib is not a member of package meta

I am trying to use the isEqual method in ScalaMeta. import scala.meta.contrib._ q"true".isEqual(q"true") The import does not work: object contrib is not a member of package meta I am using sbt and I have the following in my…
Gakuo
  • 845
  • 6
  • 26
0
votes
1 answer

Scala Meta: Confused about the versions

In the tutorial you find 2 versions for Scala-Meta. lazy val MetaVersion = "3.7.2" lazy val MetaVersion1 = "1.8.0" I am a bit confused as they seem to refer the same project: lazy val scalameta1 = "org.scalameta" %% "scalameta" % MetaVersion1 lazy…
pme
  • 14,156
  • 3
  • 52
  • 95
0
votes
1 answer

make creating non-native JS trait instances easier in scala.js with scala.meta

I create alot of non-native JS trait instances as parameters to javascript functions trait ElementOpts extends js.Object { val prop1: js.UndefOr[String] = js.undefined // another 10-15 vals } To create an instance: createElement(new ElementOpts…
user1763729
  • 167
  • 1
  • 11
0
votes
1 answer

Lifting string with Scalameta

I would like injecting a method 'toCSV' to parse a class into CSV String. My function take two paramters : Seq[String] : header Seq[Seq[Any]] : fields My macro : class model extends scala.annotation.StaticAnnotation { inline def apply(defn:…
user2931656
  • 253
  • 2
  • 3
  • 13
0
votes
1 answer

Passing parameters to scalameta paradise macro

I am trying to create a macro annotation but I need to pass it parameters. class ToPojo(param1: String, param2: String) extends StaticAnnotation { inline def apply(defn: Any): Any = meta { ... } } which is used as @ToPojo("p1",…
Vojtech Letal
  • 2,168
  • 3
  • 13
  • 17
0
votes
1 answer

scala-meta: parse vararg in class constructor

How can I parse a Term as shown below and extract the arguments parsed to the class apply method. The class apply method takes a variable argument and hence it is not known how many arguments are present in the class constructor.…
rogue-one
  • 11,259
  • 7
  • 53
  • 75
0
votes
1 answer

Scala-meta for instrumentation

I noticed that scala-meta provides transformation functions, but not functions to insert additional code (e.g., import statements, or a method call at every start of a function). Since all structures (scala.meta.Tree and its children) are immutable,…
Captain Obvious
  • 745
  • 3
  • 17
  • 39
0
votes
1 answer

Parsing a method definition string, don't know how to parse into scala.meta.Decl.Def

I want to be able to parse a string to Decl.Def but the code doesn't compile: import scala.meta._ val s:String = ... known only at runtime s.parse[Decl.Def].get Error:(39, 52) don't know how to parse into scala.meta.Decl.Def What do I need to do to…
kostas.kougios
  • 945
  • 10
  • 21
0
votes
1 answer

Defining implicit encoder using scala meta and quasiquotes

I am trying to create an implicit encoder using Circe. However this encoder will be created using an annotation hence I am using Scalameta. Here is my code. However, the compiler complains about having an override statement within quasiquotes. class…
igalbenardete
  • 207
  • 2
  • 12
0
votes
1 answer

Find method in scala reflect by it's bytecode name

Is there a way to find a method by it's bytecode name? For example, I would like to find a reference to println(Object) by string "_root_.scala.Predef.println(Ljava/lang/Object;)V."
0
votes
1 answer

How do I pass an argument to the macro annotation?

I want get StaticAnnotation's parameters defined as: class Log(logTag: List[LogTag] = Info() :: Nil ) (implicit logger: String => Unit = a => {println(a)}) extends scala.annotation.StaticAnnotation { inline def apply(defn: Any): Any =…
LoranceChen
  • 2,453
  • 2
  • 22
  • 48