1

I have a next macro annotation

 class Foo(obj: String) extends StaticAnnotation {
    def macroTransform(annottees: Any*) = macro MacroImpl.impl
 }

 object MacroImpl {
    def impl(c: Context)(annottees: c.Expr[Any]*): c.Expr[Any] = {
      import c.universe._

      // i want find `obj` and modify body
    } 

 }

 // usage
 @Foo("pkg.myObject") class SomeClass {}

Is it possible with macro find object by name and modify body of object?

1 Answer 1

2

This is currently impossible, because macros in Scala can't modify anything outside their scope. E.g. def macros can only rewrite their applications, not the code around, and macro annotations can only rewrite their annottees, not the code around.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.