Sorry if this question has already been discussed here.
Is there an officially recommended way migrate libraries with macro annotations to Scala 3?
In Scala 2 I use annotations to analyze case class field and generate helper methods in companion object. Library example.
In Scala 3 I know great way to replace annotations in case of typeclass derivation but what about just code generation?
Use case to make it clear:
@Validation // <- my macro annotation
case class Test(a: Int, b: Int Refined Positive, c: Int Refined Negative)
// MACRO GENERATED CODE START
object Test {
// helper method with arguments constructed after case class fields analysis
def create(a: Int, b: Int, c: Int): Either[List[String] Refined NonEmpty, Test] = {
// some code generated with my macros, beside the point
}
}
// MACRO GENERATED CODE END
This approach works if code generation at pre-compile time is enough and if limitations are not critical for a use case. Code generation at compile time is not possible yet (although using semanticdb can sometimes transfer things from compile time to pre-compile time).
One more use case besides Simulacrum-scalafix: Breeze uses sbt plugin and Scalameta for source code generation as a Scala 3 replacement for macro annotation @expand