41 import javax.annotation.processing.ProcessingEnvironment;
42 import javax.annotation.processing.RoundEnvironment;
43 import javax.annotation.processing.SupportedAnnotationTypes;
44 import javax.annotation.processing.SupportedSourceVersion;
45 import javax.lang.model.SourceVersion;
46 import javax.lang.model.element.Element;
47 import javax.lang.model.element.TypeElement;
48 import javax.tools.Diagnostic;
49 import javax.xml.bind.JAXBContext;
51 import java.util.Arrays;
52 import java.util.HashSet;
55 import javax.xml.bind.JAXBException;
62 @SupportedAnnotationTypes(
"checker.RequireContainer")
63 @SupportedSourceVersion(SourceVersion.RELEASE_8)
69 public static final String DEVICE_OPTION =
"device";
79 return new HashSet<>(Arrays.asList(DEVICE_OPTION));
88 public synchronized void init(ProcessingEnvironment processingEnv) {
89 super.init(processingEnv);
91 String deviceOption = processingEnv.getOptions().get(DEVICE_OPTION);
93 .createUnmarshaller().unmarshal(
new File(deviceOption));
94 }
catch (JAXBException e) {
95 throw new RuntimeException(
96 "Please specify device by -Adevice=device.xml\n"
107 public boolean process(Set<? extends TypeElement> annotations,
108 RoundEnvironment roundEnv) {
109 for (Element el : roundEnv.getElementsAnnotatedWith(
RequireContainer.class)) {
115 || version < req.minVersion()
116 || version > req.maxVersion()) {
118 if (req.optional()) {
119 processingEnv.getMessager()
120 .printMessage(Diagnostic.Kind.WARNING,
121 "Plugin [" + el +
"] requires " + req
122 +
"\n but device " + (version ==
null
123 ?
"doesn't have such module."
124 +
" This module is optional."
125 +
" So plugin will work but miss"
126 +
" some functionality"
128 +
" version of that module"));
130 processingEnv.getMessager()
131 .printMessage(Diagnostic.Kind.ERROR,
132 "Plugin [" + el +
"] requires " + req
135 ?
"doesn't have such module"
137 +
" version of that module"));