I am creating some macros for a class that extends scala.Dynamic
. These macros looks like:
class MyProxy extends scala.Dynamic {
final def selectDynamic(field: String): MyProxy = macro ...
final def updateDynamic(field: String)(value: Any): Unit = macro ...
}
These macros works fine. But a MyProxy
only allows a set of limited members accessing, and I want these members are listed from Scala IDE's content assist and REPL console's Tab key.
Because MyProxy
instances themselves are created by macros, I wonder if there is any attribute like setCodeCompletionType
that can be set from the macros that create MyProxy
, helping REPL and Scala IDE's code completion (and does not affect the generated Java byte code). Then I would have a macro like this:
def newMyProxyInstanceImpl(c: Context)(...): c.Expr[MyProxy] = {
import c.universe._
val tree: Tree = ...
val codeCompletionHint: Type = RefinedType(...)
tree.setCodeCompletionType(codeCompletionHint)
c.Expr(tree)
}
How can I hack the Scala compiler to make this approach work?