From 34137b599dbea13c94224dff2955376b1394dbc9 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sat, 3 Aug 2013 12:33:39 +0200 Subject: wip --- .../io/trygvis/container/compiler/MyProcessor.java | 53 +++++++++++----------- 1 file changed, 27 insertions(+), 26 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 6843659..735d688 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 @@ -1,6 +1,7 @@ package io.trygvis.container.compiler; import io.trygvis.container.log.Log; +import io.trygvis.persistence.SqlEntity; import org.springframework.transaction.annotation.Transactional; import javax.annotation.processing.Completion; @@ -31,19 +32,16 @@ public class MyProcessor implements Processor { @Override public Set getSupportedOptions() { - System.out.println("io.trygvis.container.compiler.MyProcessor.getSupportedOptions"); return emptySet(); } @Override public SourceVersion getSupportedSourceVersion() { - 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(); @@ -51,13 +49,11 @@ 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() { - System.out.println("io.trygvis.container.compiler.MyProcessor.getSupportedAnnotationTypes"); return new HashSet<>(asList( Transactional.class.getName(), Log.class.getName(), @@ -66,34 +62,39 @@ public class MyProcessor implements Processor { @Override public boolean process(Set annotations, RoundEnvironment roundEnv) { - System.out.println("io.trygvis.container.compiler.MyProcessor.process"); - System.out.println("annotations = " + annotations); -// Set transactional = roundEnv.getElementsAnnotatedWith(Transactional.class); + try { + return work(annotations, roundEnv); + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new RuntimeException(e); + } + } + public boolean work(Set annotations, RoundEnvironment roundEnv) throws Exception { TypeElement tx = elements.getTypeElement(Transactional.class.getCanonicalName()); TypeElement log = elements.getTypeElement(Log.class.getCanonicalName()); TypeElement entity = elements.getTypeElement(Entity.class.getCanonicalName()); + EntityHandler entityHandler = new EntityHandler(processingEnv); + + Set sqlEntities = roundEnv.getElementsAnnotatedWith(SqlEntity.class); + entityHandler.phase1(sqlEntities); + 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(), annotationType)) { - new TransactionalHandler(processingEnv).processTransactional((TypeElement) element); - } - if (types.isSameType(log.asType(), annotationType)) { - new LogHandler(processingEnv).processLog((TypeElement) element); - } - if (types.isSameType(entity.asType(), annotationType)) { - new EntityHandler(processingEnv).processEntity((TypeElement) element); - } + System.out.println("Processing: " + element); + for (AnnotationMirror annotationMirror : element.getAnnotationMirrors()) { + DeclaredType annotationType = annotationMirror.getAnnotationType(); + + if (types.isSameType(tx.asType(), annotationType)) { + new TransactionalHandler(processingEnv).processTransactional((TypeElement) element); + } + if (types.isSameType(log.asType(), annotationType)) { + new LogHandler(processingEnv).processLog((TypeElement) element); + } + if (types.isSameType(entity.asType(), annotationType)) { + entityHandler.processEntity((TypeElement) element); } - } catch (RuntimeException e) { - throw e; - } catch (Exception e) { - throw new RuntimeException(e); } } return true; -- cgit v1.2.3