I am trying to use scalameta’s parser. However, there is an “import” problem that I cannot resolve.
The collect method is mentioned in this link: Tree Guide · Scalameta
Please see that last line in the following code snippet:
object ApiExtractor {
implicit val parameterWrites: Writes[Parameter] = Json.writes[Parameter]
implicit val apiFunctionWrites: Writes[ApiFunction] = Json.writes[ApiFunction]
implicit val apiSchemaWrites: Writes[ApiSchema] = Json.writes[ApiSchema]
def extractApi(sourceFiles: Seq[File]): ApiSchema = {
val apiFunctions = sourceFiles.flatMap { file =>
try {
val bytes = Files.readAllBytes(file.toPath)
val text = new String(bytes, "UTF-8")
val input =
Input.VirtualFile(file.getAbsolutePath, text)
val tree: scala.meta.Source =
input
.parse[Source]
.get // Or use .parse[Source].toEither.right.get for error handling
tree.collect { case Defn.Def(mods, name, _, paramss, decltpe, _) =>
Thank you for asking. Yes, I am getting compile-time error. It says that
“value collect is not a member of scala.meta.Source”
I have the following import statements where XtenstionSyntax helps me with some compile-time errors. I have delved into the source code of scalameta, but cannot find either a “collect” method or an extension that provides such a "collect method:
Hmm. I don’t have any hands-on experience with Scalameta (so I’m just guessing), but I notice that you’re spelling out all of your dependencies explicitly. The Scalameta docs are pretty specific that you should import the whole kit and kaboodle as import scala.meta._, and stuff like implicit conversions can often lurk in the cracks there – have you tried that yet?