summaryrefslogtreecommitdiff
path: root/container-compiler-plugin
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2013-08-02 03:04:53 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2013-08-02 03:04:53 +0200
commit7c3bf7a43911375589fd5c16f9a3e85e7fda0c80 (patch)
tree602b9228288d946a73e68ea4ba5f7b3312b5cd5b /container-compiler-plugin
parent35330309221b7c39adf71f508190628459ad7138 (diff)
downloadcontainer-playground-7c3bf7a43911375589fd5c16f9a3e85e7fda0c80.tar.gz
container-playground-7c3bf7a43911375589fd5c16f9a3e85e7fda0c80.tar.bz2
container-playground-7c3bf7a43911375589fd5c16f9a3e85e7fda0c80.tar.xz
container-playground-7c3bf7a43911375589fd5c16f9a3e85e7fda0c80.zip
wip
Diffstat (limited to 'container-compiler-plugin')
-rw-r--r--container-compiler-plugin/src/main/java/io/trygvis/container/compiler/LogHandler.java21
-rw-r--r--container-compiler-plugin/src/main/java/io/trygvis/container/compiler/MyProcessor.java8
-rw-r--r--container-compiler-plugin/src/main/java/io/trygvis/container/compiler/TransactionalHandler.java36
3 files changed, 24 insertions, 41 deletions
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<ParameterRef> parameters = new ArrayList<>();
List<String> arguments = new ArrayList<>();
@@ -121,10 +100,6 @@ public class TransactionalHandler {
}
List<String> 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<String> 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(" }");
}
}