From 4e794b5ed03e5020770becb068d11e6838feec64 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Fri, 2 Aug 2013 21:57:54 +0200 Subject: wip --- .../io/trygvis/container/compiler/MyProcessor.java | 31 +++++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'container-compiler-plugin/src/main/java/io/trygvis/container/compiler/MyProcessor.java') diff --git a/container-compiler-plugin/src/main/java/io/trygvis/container/compiler/MyProcessor.java b/container-compiler-plugin/src/main/java/io/trygvis/container/compiler/MyProcessor.java index 729a0ee..6843659 100644 --- a/container-compiler-plugin/src/main/java/io/trygvis/container/compiler/MyProcessor.java +++ b/container-compiler-plugin/src/main/java/io/trygvis/container/compiler/MyProcessor.java @@ -12,8 +12,10 @@ import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.Element; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.TypeElement; +import javax.lang.model.type.DeclaredType; import javax.lang.model.util.Elements; import javax.lang.model.util.Types; +import javax.persistence.Entity; import java.util.HashSet; import java.util.Set; @@ -29,16 +31,19 @@ public class MyProcessor implements Processor { @Override public Set getSupportedOptions() { + System.out.println("io.trygvis.container.compiler.MyProcessor.getSupportedOptions"); return emptySet(); } @Override public SourceVersion getSupportedSourceVersion() { - return SourceVersion.RELEASE_5; + System.out.println("io.trygvis.container.compiler.MyProcessor.getSupportedSourceVersion"); + return SourceVersion.RELEASE_7; } @Override public void init(ProcessingEnvironment processingEnv) { + System.out.println("io.trygvis.container.compiler.MyProcessor.init"); this.processingEnv = processingEnv; elements = processingEnv.getElementUtils(); types = processingEnv.getTypeUtils(); @@ -46,32 +51,44 @@ public class MyProcessor implements Processor { @Override public Iterable getCompletions(Element element, AnnotationMirror annotation, ExecutableElement member, String userText) { + System.out.println("io.trygvis.container.compiler.MyProcessor.getCompletions"); return emptyList(); } @Override public Set getSupportedAnnotationTypes() { - return new HashSet<>(asList(Transactional.class.getName(), Log.class.getName())); + System.out.println("io.trygvis.container.compiler.MyProcessor.getSupportedAnnotationTypes"); + return new HashSet<>(asList( + Transactional.class.getName(), + Log.class.getName(), + Entity.class.getName())); } @Override public boolean process(Set annotations, RoundEnvironment roundEnv) { - Set transactional = roundEnv.getElementsAnnotatedWith(Transactional.class); + System.out.println("io.trygvis.container.compiler.MyProcessor.process"); + System.out.println("annotations = " + annotations); +// Set transactional = roundEnv.getElementsAnnotatedWith(Transactional.class); TypeElement tx = elements.getTypeElement(Transactional.class.getCanonicalName()); - TypeElement log = elements.getTypeElement(Transactional.class.getCanonicalName()); + TypeElement log = elements.getTypeElement(Log.class.getCanonicalName()); + TypeElement entity = elements.getTypeElement(Entity.class.getCanonicalName()); - for (Element element : transactional) { + for (Element element : roundEnv.getRootElements()) { try { System.out.println("Processing: " + element); for (AnnotationMirror annotationMirror : element.getAnnotationMirrors()) { + DeclaredType annotationType = annotationMirror.getAnnotationType(); - if (types.isSameType(tx.asType(), annotationMirror.getAnnotationType())) { + if (types.isSameType(tx.asType(), annotationType)) { new TransactionalHandler(processingEnv).processTransactional((TypeElement) element); } - if (types.isSameType(log.asType(), annotationMirror.getAnnotationType())) { + if (types.isSameType(log.asType(), annotationType)) { new LogHandler(processingEnv).processLog((TypeElement) element); } + if (types.isSameType(entity.asType(), annotationType)) { + new EntityHandler(processingEnv).processEntity((TypeElement) element); + } } } catch (RuntimeException e) { throw e; -- cgit v1.2.3