1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| package com.jmdoudoux.tests.annotations.outils;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Set;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.Filer;
import javax.annotation.processing.Messager;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.annotation.processing.SupportedSourceVersion;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import javax.lang.model.util.Elements;
import javax.persistence.Entity;
import javax.tools.StandardLocation;
import javax.tools.Diagnostic.Kind;
@SupportedAnnotationTypes(value = { "javax.persistence.*" })
@SupportedSourceVersion(SourceVersion.RELEASE_6)
public class Processor extends AbstractProcessor {
@Override
public boolean process(
Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) {
Filer filer = processingEnv.getFiler();
Messager messager = processingEnv.getMessager();
Elements eltUtils = processingEnv.getElementUtils();
if (!roundEnv.processingOver()) {
Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(Entity.class);
if (!elements.isEmpty())
try {
messager.printMessage(Kind.NOTE, "Creation du fichier Todo");
PrintWriter pw = new PrintWriter(filer.createResource(
StandardLocation.SOURCE_OUTPUT, "", "Todo.txt")
.openOutputStream());
// .createSourceFile("Todo").openOutputStream());
pw.println("Liste des todos\n");
for (Element element : annotations) {
pw.println("\nelement:" + element.getSimpleName());
System.out.println("aa3333333");
}
pw.close();
} catch (IOException ioe) {
messager.printMessage(Kind.ERROR, ioe.getMessage());
}
else
messager.printMessage(Kind.NOTE, "Rien a faire");
} else
messager.printMessage(Kind.NOTE, "Fin des traitements");
return true;
}
} |
Partager