All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.arainko.ducktape.internal.CodePrinter.scala Maven / Gradle / Ivy

There is a newer version: 0.2.5
Show newest version
package io.github.arainko.ducktape.internal

import io.github.arainko.ducktape.*

import scala.quoted.*

private[ducktape] object CodePrinter {
  inline def structure[A](inline value: A) = ${ structureMacro('value) }

  private def structureMacro[A: Type](value: Expr[A])(using Quotes): Expr[A] = {
    import quotes.reflect.*

    val struct = Printer.TreeStructure.show(value.asTerm)
    report.info(struct)
    value.asTerm.changeOwner(Symbol.spliceOwner).asExprOf[A]
  }

  inline def code[A](inline value: A): A = ${ codeMacro('value) }

  private def codeMacro[A: Type](value: Expr[A])(using Quotes): Expr[A] = {
    import quotes.reflect.*
    val struct = Printer.TreeShortCode.show(value.asTerm)
    report.info(struct)
    value
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy