This demo shows how to use repeating annotations at runtime and at compile time.
Shows how to define repeating annotations and process them at compile time. The problem domain is some code that performs useful operations on hardware devices. The code relies on "modules" to be present on the devices. Applicability of the code to a particular device is checked while compiling the code for a particular device. A set of modules provided by a device is listed in an xml file that turns red during the compilation phase and is compared with the required module set specified by annotations. For instance, there is kettle with hardware modules: thermometer, display, and clock. There is also a boiler plug-in that requires clock, thermometer, heater, and optionally an LED light. Build the PluginChecker annotation processor first. Then, run javac with the annotation processor against plug-in sources using the following command:
javac -cp "PluginChecker.jar" -processor checker.PluginChecker -Adevice=Kettle.xml -proc:only <source
files>
where PluginChecker.jar
- path to jar file that contains PluginChecker annotation processor
class.
Kettle.xml
- path to device descriptor Kettle.xml
<source files>
- source files in Plugins/src
Shows how to define repeating annotations and process them at runtime. A problem domain is code that needs to validate provided Suppliers for conformance to some criteria. The criteria are implemented by the Validator class which is applied by using annotations that are placed in the code whenever validation is needed. For more information, see the source files.