Creating Java compiler plugin for Java 7

221 Views Asked by At

I'm writing a Java compiler plugin using the -XPlugin argument of javac. This argument is documented in Java 9. It's not documented in Java 8 (according to https://docs.oracle.com/javase/8/docs/technotes/tools/windows/javac.html ), but curiously -XPlugin still works on Java 8.

Is it possible to adopt a plugin for Java 7? The -XPlugin argument isn't supported but I'm wondering if it is still possible to get the same behavior from the compiler, namely: callbacks from the compiler during parsing. Maybe this can be done using an annotation processor?

My plugin does not change the AST, it just collects information about it for static analysis.

1

There are 1 best solutions below

0
bubbles On

From this article:

An important thing to note is the limitation of the annotation processing API — it can only be used to generate new files, not to change existing ones.

In you question you've mentioned that you're not modifying the AST. So I think that you can change your plugin into an annotation processor in your Java 7 project (since it is supported since Java 5).