Is it possible for a compiler plugin to modify the...
# compiler
r
Is it possible for a compiler plugin to modify the AST? I've tried PsiElement#replace and PsiElement#astReplace and both of them throw exceptions. The former throws a MissingResourceException, the latter a NullPointerException because PomModel.getModel returns null for the project I'm acting on
r
it’s not AFAIK. I have been trying at that for a week. I’m at the point where you can modify it if you intercept the
LazyDeclarationResolver
which is a compiler service you can replace accessing the project container internals
Once you get to that point you can provide your own LazyClassDescriptor instance when you see your modified sources but then you have to also intercept the internals of the BindingTrac to avoid Class and Fun being associated to the previous read sources.
Not sure yet if there is a better way to do this
r
Not sure if I'll be able to use that for what I'm trying to do. I'm trying to make a compiler plugin that vaguely resembles scala's macro system (without quoting because that's far too much work), just for fun. I need to substitute the macro call with the resultant expression in the AST
I'll play around with it though, thanks
r
I’m working on the same thing but with quoting, ping me if you make any advancements and I’ll do the same 🙂
r
Is the code for your attempt so far on Github? If I'm going to keep playing around with this I might as well contribute to something that might go somewhere, I was just doing this for the heck of it
it’s not there the part we discussed today as I’m still prototyping this and currently is complaining the functions are redeclared in the binding trace
but a lot of what we’ve done is there in different branches
including a DSL to register extensions easily and prototype
We are also working on documenting how to intercept all compiler services we’ve been encountering https://github.com/47deg/arrow-meta-prototype/issues/10