Altering AST with javac Plugin

Jonathan Gibbons jonathan.gibbons at oracle.com
Wed Jun 12 15:12:04 UTC 2019


On 6/11/19 11:30 PM, Gunnar Morling wrote:
> Hi,
>
> I recently came across a javac plug-in (i.e. implementation 
> of com.sun.source.util.Plugin) which alters/amends the AST of the 
> classes under compilation.
>
> Is this an "officially" foreseen usage of that plug-in API? Or i this 
> rather a hack akin to annotation processor implementations that cast 
> the model types to the javac-internal ones in order to modify them? 
> I'm curious, because those AST-modifying annotation processors are 
> troublesome to deal with for other processors which won't "see" those 
> amendments, so I'm wondering whether one would or would not have 
> similar issues when altering the AST with such c.s.s.u.Plugin 
> implementation.
>
> Thanks,
>
> --Gunnar
>

Gunnar,

There is no publicly supported API in the jdk.compiler module (or any 
other module) for modifying an AST during a compilation.  Does that 
answer your question?

-- Jon



More information about the compiler-dev mailing list