How do I use Scala-Meta Parse an object?

399 views Asked by At

I am trying to use Scala Meta to write an annotation so I can generate another case class from an existing object.

But when I try to do this:

MyObject.parse[Source].show[Structure]

I got this error:

Error:(5, 20) not enough arguments for method parse: (implicit convert: scala.meta.common.Convert[domain.MyObject.type,scala.meta.inputs.Input], implicit parse: scala.meta.parsers.Parse[scala.meta.Source], implicit dialect: scala.meta.Dialect)scala.meta.parsers.Parsed[scala.meta.Source]. Unspecified value parameters convert, parse, dialect. MyObject.parse[Source].show[Structure];} ^

I am very confused because based on their tutorial, that's what I need to start with http://scalameta.org/tutorial/#.parse[T]

How can I reflect this object to loop through all properties?

Thanks

1

There are 1 answers

2
Arseniy Zhizhelev On BEST ANSWER

parse[Source] parses text. You may try the following

import scala.meta._
"object MyObject".parse[Source].get.show[Syntax]

If you are creating annotation then it might look like:

@MyAnnotation
object MyObject

And in another module:

import scala.meta._
class MyAnnotation extends StaticAnnotation {
  inline def apply(defn: Any): Any = meta { 
    defn.show[Syntax]
    defn
  }
}