22620
|
1 |
<!DOCTYPE html>
|
|
2 |
<html>
|
|
3 |
<head>
|
|
4 |
<title>Repeating Annotations Demo</title>
|
|
5 |
</head>
|
|
6 |
<body>
|
|
7 |
<h2>Repeating Annotations Demo</h2>
|
|
8 |
|
|
9 |
<p>
|
|
10 |
This demo shows how to use repeating annotations at runtime and at compile time.
|
|
11 |
</p>
|
|
12 |
|
|
13 |
<ul>
|
|
14 |
<li><h3>Dependency checker.</h3>
|
|
15 |
|
|
16 |
<p>
|
|
17 |
Shows how to define repeating annotations and process them at compile time.
|
|
18 |
The problem domain is some code that performs useful operations on hardware devices.
|
|
19 |
The code relies on "modules" to be present on the devices. Applicability of the code to a particular
|
|
20 |
device is checked while compiling the code for a particular device.
|
|
21 |
A set of modules provided by a device is listed in an xml file that turns red during the compilation
|
|
22 |
phase and is compared with the required module set specified by annotations.
|
|
23 |
For instance, there is kettle with hardware modules: thermometer, display, and clock.
|
|
24 |
There is also a boiler plug-in that requires clock, thermometer, heater, and optionally an LED light.
|
|
25 |
|
|
26 |
Build the PluginChecker annotation processor first.
|
|
27 |
Then, run javac with the annotation processor against plug-in sources using the following command: </p>
|
|
28 |
|
|
29 |
<code>javac -cp "PluginChecker.jar" -processor checker.PluginChecker -Adevice=Kettle.xml -proc:only <source
|
|
30 |
files></code>
|
|
31 |
|
|
32 |
<p>
|
|
33 |
where <code>PluginChecker.jar</code> - path to jar file that contains PluginChecker annotation processor
|
|
34 |
class. </br>
|
|
35 |
<code>Kettle.xml</code> - path to device descriptor Kettle.xml </br>
|
|
36 |
<code><source files></code> - source files in Plugins/src
|
|
37 |
</p>
|
|
38 |
For more information, see the source files.
|
|
39 |
</p>
|
|
40 |
<ul>
|
|
41 |
<li>Annotation processor sources: <a href="DependencyChecker/PluginChecker/src/">DependencyChecker/PluginChecker/src</a>
|
|
42 |
<li>Processing of repeating annotations can be found in <a href="DependencyChecker/PluginChecker/src/checker/PluginChecker.java">PluginChecker.java</a>
|
|
43 |
<li>Usage of repeating annotation is shown in modules sources.<a href="DependencyChecker/Plugins/src">DependencyChecker/Plugins/src</a>
|
|
44 |
</ul>
|
|
45 |
|
|
46 |
<li><h3>Validator.</h3>
|
|
47 |
|
|
48 |
<p>
|
|
49 |
Shows how to define repeating annotations and process them at runtime.
|
|
50 |
A problem domain is code that needs to validate provided Suppliers for conformance to some criteria.
|
|
51 |
The criteria are implemented by the Validator class which is applied by using annotations that are placed in
|
|
52 |
the code whenever validation is needed. For more information, see the
|
|
53 |
source files.
|
|
54 |
</p>
|
|
55 |
|
|
56 |
<p>
|
|
57 |
<ul>
|
|
58 |
<li>Usage of repeating annotation is described in <a href="Validator/src/PositiveIntegerSupplier.java">PositiveIntegerSupplier.java</a>
|
|
59 |
<li> Example of how to define a repeating annotation type can be found in
|
|
60 |
<a href="Validator/src/Validate.java">Validate.java</a>
|
|
61 |
<li> Usages of the new reflective methods can be found in <a href="Validator/src/SupplierValidator.java">SupplierValidator.java</a>
|
|
62 |
</ul>
|
|
63 |
</p>
|
|
64 |
Sources: <a href="Validator/src/">Validator/src/</a>
|
|
65 |
</ul>
|
|
66 |
</body>
|
|
67 |
</html> |