From 7c3bf7a43911375589fd5c16f9a3e85e7fda0c80 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Fri, 2 Aug 2013 03:04:53 +0200 Subject: wip --- .../io/trygvis/container/compiler/LogHandler.java | 21 +++++++++++++ .../io/trygvis/container/compiler/MyProcessor.java | 8 ++--- .../container/compiler/TransactionalHandler.java | 36 ---------------------- 3 files changed, 24 insertions(+), 41 deletions(-) create mode 100644 container-compiler-plugin/src/main/java/io/trygvis/container/compiler/LogHandler.java diff --git a/container-compiler-plugin/src/main/java/io/trygvis/container/compiler/LogHandler.java b/container-compiler-plugin/src/main/java/io/trygvis/container/compiler/LogHandler.java new file mode 100644 index 0000000..064193d --- /dev/null +++ b/container-compiler-plugin/src/main/java/io/trygvis/container/compiler/LogHandler.java @@ -0,0 +1,21 @@ +package io.trygvis.container.compiler; + +import javax.annotation.processing.ProcessingEnvironment; +import javax.lang.model.element.TypeElement; +import javax.lang.model.util.Elements; +import javax.lang.model.util.Types; + +public class LogHandler { + private final ProcessingEnvironment processingEnv; + private final Elements elements; + private final Types types; + + public LogHandler(ProcessingEnvironment processingEnv) { + this.processingEnv = processingEnv; + this.elements = processingEnv.getElementUtils(); + this.types = processingEnv.getTypeUtils(); + } + + public void processLog(TypeElement element) { + } +} 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 4873e9b..729a0ee 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 @@ -66,14 +66,12 @@ public class MyProcessor implements Processor { System.out.println("Processing: " + element); for (AnnotationMirror annotationMirror : element.getAnnotationMirrors()) { - System.out.println("annotationMirror.getAnnotationType().asElement().getSimpleName() = " + annotationMirror.getAnnotationType().asElement().getSimpleName()); - if (types.isSameType(tx.asType(), annotationMirror.getAnnotationType())) { new TransactionalHandler(processingEnv).processTransactional((TypeElement) element); } -// if (types.isSameType(log.asType(), annotationMirror.getAnnotationType())) { -// processLog((TypeElement) element); -// } + if (types.isSameType(log.asType(), annotationMirror.getAnnotationType())) { + new LogHandler(processingEnv).processLog((TypeElement) element); + } } } catch (RuntimeException e) { throw e; diff --git a/container-compiler-plugin/src/main/java/io/trygvis/container/compiler/TransactionalHandler.java b/container-compiler-plugin/src/main/java/io/trygvis/container/compiler/TransactionalHandler.java index f1f3bc5..2877e15 100644 --- a/container-compiler-plugin/src/main/java/io/trygvis/container/compiler/TransactionalHandler.java +++ b/container-compiler-plugin/src/main/java/io/trygvis/container/compiler/TransactionalHandler.java @@ -54,15 +54,6 @@ public class TransactionalHandler { try (PrintWriter w = new PrintWriter(sourceFile.openWriter())) { ClassG g = new ClassG(p, className, targetClassName.toString()); -// writer.println("package " + p + ";"); -// writer.println(); -// writer.println("import io.trygvis.container.tx.PlatformTransactionManager;"); -// writer.println(); -// writer.println("public class " + className + " extends " + targetClassName + " {"); -// writer.println(" private final PlatformTransactionManager transactionManager;"); -// writer.println(); - -// TypeRef platformTransactionManager = g.addImport(PlatformTransactionManager.class); FieldRef transactionManager = g.addField(PlatformTransactionManager.class, "transactionManager"); for (ExecutableElement constructor : constructorsIn(elements.getAllMembers(element))) { @@ -73,7 +64,6 @@ public class TransactionalHandler { constructor(g, constructor, transactionManager); } -// System.out.println("elements.getTypeElement(\"Object\") = " + elements.getTypeElement("java.lang.Object")); Name javaLangObjectName = elements.getTypeElement("java.lang.Object").getQualifiedName(); for (Element e : elements.getAllMembers(element)) { @@ -93,23 +83,12 @@ public class TransactionalHandler { continue; } -// System.out.println("ee.getSimpleName() = " + ee.getSimpleName()); -// System.out.println("ee.getEnclosingElement() = " + enclosingElement); -// System.out.println("ee.getEnclosingElement().getQualifiedName() = " + enclosingElement.getQualifiedName()); -// System.out.println("ee.getEnclosingElement().asType().getKind().getDeclaringClass() = " + enclosingElement.asType().getKind().getDeclaringClass()); - TypeMirror returnTypeMirror = ee.getReturnType(); TypeKind kind = returnTypeMirror.getKind(); boolean isVoid = kind == TypeKind.VOID; TypeRef returnType = isVoid ? TypeRef.VOID : g.addImport(returnTypeMirror); -// String returnString; -// if (isVoid) { -// returnString = "void"; -// } else { -// returnString = returnTypeMirror.toString(); -// } List parameters = new ArrayList<>(); List arguments = new ArrayList<>(); @@ -121,10 +100,6 @@ public class TransactionalHandler { } List body = new ArrayList<>(); - -// writer.println(); -// writer.println(" public " + returnString + " " + ee.getSimpleName() + "(" + collectionToDelimitedString(parameters, ", ") + ") {"); - body.add((isVoid ? "" : "return ") + "transactionManager.doInTransaction("); body.add(" PlatformTransactionManager.TransactionIsolation.ISOLATION_" + transactional.isolation() + ","); body.add(" PlatformTransactionManager.TransactionPropagation.PROPAGATION_" + transactional.propagation() + ","); @@ -144,9 +119,7 @@ public class TransactionalHandler { body.add(" });"); g.addMethod(body, returnType, ee.getSimpleName().toString(), parameters.toArray(new ParameterRef[arguments.size()])); -// elements.printElements(new PrintWriter(System.out), ee); } -// writer.println("}"); g.write(w); } } @@ -159,24 +132,15 @@ public class TransactionalHandler { ParameterRef transactionManager = parameters.addParameter(k, "transactionManager"); for (VariableElement p : constructor.getParameters()) { -// parameters.add(p.asType().toString() + " " + p.getSimpleName().toString()); -// arguments.add(p.getSimpleName().toString()); k = g.addImport(p.asType()); String name = p.getSimpleName().toString(); parameters.addParameter(k, name); goesToSuper.add(name); } -// String params = parameters.size() == 0 ? "" : ", " + collectionToDelimitedString(parameters, ", "); - List body = new ArrayList<>(); body.add("super(" + collectionToDelimitedString(goesToSuper, ", ") + ");"); body.add("this." + platformTransactionManager.name + " = " + transactionManager.name + ";"); g.addConstructor(parameters, body); - -// writer.println(" public " + className + "(PlatformTransactionManager _transactionManager_" + params + ") {"); -// writer.println(" super(" + collectionToDelimitedString(arguments, ", ") + ");"); -// writer.println(" this.transactionManager = _transactionManager_;"); -// writer.println(" }"); } } -- cgit v1.2.3