How Do Plug-ins Differ
from Annotation Processors?
Here are some ways that plug-ins differ from annotation processors:
■ Plug-ins are more flexible.They can run at various points in the compilation
pipeline through a TaskListener.
■ Plug-ins do not use the model of processing rounds, which incurs
additional overhead.
■ Plug-ins have a simpler interface.
■Annotation processors are defined by a standard (JSR 269).
Plug-ins are
javac-specific.
■Plug-ins require the use of a ServiceLoader.
Java Compiler Plug-in Architecture
A javac plug-in supports two methods:
■First, a getName() method that returns the
name of the plug-in for identification purposes.
■Second, a call() method that is invoked by
the javac with the current environment it is processing.The call() method gives access to the
compiler functionalities through a JavacTask object, which allows you to
perform parsing, type checking, and compilation. In addition, the JavacTask object
lets you add observers (which are instances of TaskListener) to various events
generated during compilation.
This is done through the method addTaskListener(), which accepts an object
TaskListener.
No comments:
Post a Comment