--- /dev/null
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>com.indexdata.annotations.processor</groupId>
+ <artifactId>jaxb-index-generator</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <name>JAXB Index Generator</name>
+ <build>
+ <sourceDirectory>src/main/java</sourceDirectory>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.1</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ <compilerArgument>-proc:none</compilerArgument>
+ <encoding>UTF-8</encoding>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
--- /dev/null
+package com.indexdata.annotations.processor;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.annotation.processing.AbstractProcessor;
+import javax.annotation.processing.Messager;
+import javax.annotation.processing.RoundEnvironment;
+import javax.annotation.processing.SupportedAnnotationTypes;
+import javax.annotation.processing.SupportedOptions;
+import javax.annotation.processing.SupportedSourceVersion;
+import javax.lang.model.SourceVersion;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.TypeElement;
+import javax.tools.Diagnostic.Kind;
+import javax.tools.FileObject;
+import javax.tools.StandardLocation;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@SupportedAnnotationTypes("javax.xml.bind.annotation.XmlRootElement")
+@SupportedSourceVersion(SourceVersion.RELEASE_6)
+@SupportedOptions({ "test", "test2" })
+public class JAXBIndexGenerator extends AbstractProcessor {
+
+ @Override
+ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
+ Set<String> options = this.getSupportedOptions();
+ Messager messager = processingEnv.getMessager();
+ for (String option : options) {
+ messager.printMessage(Kind.NOTE, "option: " + option);
+ }
+ Map<String, List<String>> packageMap = new HashMap<String, List<String>>();
+ for (Element elem : roundEnv.getElementsAnnotatedWith(XmlRootElement.class)) {
+ // XmlRootElement xmlRootElement =
+ // elem.getAnnotation(XmlRootElement.class);
+ String pkg = elem.getEnclosingElement().toString();
+ String className = elem.getSimpleName().toString();
+ String message = "XmlRootElement annotation found in " + pkg + ": " + className;
+ messager.printMessage(Kind.NOTE, message);
+ List<String> classList = packageMap.get(pkg);
+ if (classList == null) {
+ classList = new LinkedList<String>();
+ packageMap.put(pkg, classList);
+ }
+ classList.add(className);
+ }
+ FileObject fo = null;
+ for (String pkg : packageMap.keySet()) {
+ try {
+ Writer w = null;
+ fo = processingEnv.getFiler().createResource(StandardLocation.SOURCE_OUTPUT, pkg,
+ "jaxb.index");
+ w = fo.openWriter();
+ messager.printMessage(Kind.NOTE, "Writing " + fo.getName() + " for package " + pkg);
+ for (String className : packageMap.get(pkg)) {
+ messager.printMessage(Kind.NOTE, "Class " + className);
+ w.write(className + "\n");
+ }
+ w.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ return true; // no further processing of this annotation type
+ }
+
+}