From 86c174ddf24b3e5ac8c8d45fa4d7dc6c5d5d3a3a Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sat, 10 Aug 2013 10:32:09 +0200 Subject: Nits. --- .../io/trygvis/container/compiler/model/AnnotationG.java | 15 +++++++++++++++ .../java/io/trygvis/container/compiler/model/ClassG.java | 6 ++++-- .../io/trygvis/container/compiler/model/MethodRef.java | 6 ++++++ .../persistence/generators/EntityManagerGenerator.java | 8 ++++---- 4 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 container-compiler-plugin/src/main/java/io/trygvis/container/compiler/model/AnnotationG.java (limited to 'container-compiler-plugin/src') diff --git a/container-compiler-plugin/src/main/java/io/trygvis/container/compiler/model/AnnotationG.java b/container-compiler-plugin/src/main/java/io/trygvis/container/compiler/model/AnnotationG.java new file mode 100644 index 0000000..4b6c05c --- /dev/null +++ b/container-compiler-plugin/src/main/java/io/trygvis/container/compiler/model/AnnotationG.java @@ -0,0 +1,15 @@ +package io.trygvis.container.compiler.model; + +public class AnnotationG { + public final TypeRef type; + public final String body; + + public AnnotationG(TypeRef type, String body) { + this.type = type; + this.body = body; + } + + public String toJava() { + return "@" + type.plainName + "(" + body + ")"; + } +} diff --git a/container-compiler-plugin/src/main/java/io/trygvis/container/compiler/model/ClassG.java b/container-compiler-plugin/src/main/java/io/trygvis/container/compiler/model/ClassG.java index 3aa9c62..fe595a0 100644 --- a/container-compiler-plugin/src/main/java/io/trygvis/container/compiler/model/ClassG.java +++ b/container-compiler-plugin/src/main/java/io/trygvis/container/compiler/model/ClassG.java @@ -9,7 +9,6 @@ import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; -import java.util.TreeSet; import static io.trygvis.container.compiler.Utils.toJavaString; import static java.lang.reflect.Modifier.*; @@ -195,10 +194,13 @@ public class ClassG { parameters.add("final " + p.klass + " " + p.name); } + List body = new ArrayList<>(); + for (AnnotationG annotation : method.annotations) { + body.add(annotation.toJava()); + } String m = Modifier.toString(method.modifiers) + " " + typeArgs + returnString + " " + method.name + "(" + collectionToDelimitedString(parameters, ", ") + ")"; - List body = new ArrayList<>(); if (method.exceptions.isEmpty()) { body.add(m + " {"); } else { diff --git a/container-compiler-plugin/src/main/java/io/trygvis/container/compiler/model/MethodRef.java b/container-compiler-plugin/src/main/java/io/trygvis/container/compiler/model/MethodRef.java index 952a1e5..65a5ff2 100644 --- a/container-compiler-plugin/src/main/java/io/trygvis/container/compiler/model/MethodRef.java +++ b/container-compiler-plugin/src/main/java/io/trygvis/container/compiler/model/MethodRef.java @@ -17,6 +17,7 @@ public class MethodRef { public final Parameters parameters; public final Set exceptions = new TreeSet<>(); public final List typeArgs = new ArrayList<>(); + public final List annotations = new ArrayList<>(); public final List body; public MethodRef(int modifiers, TypeRef returnType, String name, String body) { @@ -48,4 +49,9 @@ public class MethodRef { addAll(typeArgs, args); return this; } + + public MethodRef annotation(AnnotationG annotation) { + this.annotations.add(annotation); + return this; + } } diff --git a/container-compiler-plugin/src/main/java/io/trygvis/persistence/generators/EntityManagerGenerator.java b/container-compiler-plugin/src/main/java/io/trygvis/persistence/generators/EntityManagerGenerator.java index f524b1a..f621343 100644 --- a/container-compiler-plugin/src/main/java/io/trygvis/persistence/generators/EntityManagerGenerator.java +++ b/container-compiler-plugin/src/main/java/io/trygvis/persistence/generators/EntityManagerGenerator.java @@ -1,6 +1,7 @@ package io.trygvis.persistence.generators; import io.trygvis.container.compiler.SqlUnitModel; +import io.trygvis.container.compiler.model.AnnotationG; import io.trygvis.container.compiler.model.ClassG; import io.trygvis.container.compiler.model.Constructor; import io.trygvis.container.compiler.model.FieldRef; @@ -66,13 +67,12 @@ public class EntityManagerGenerator { List body = new ArrayList<>(); for (EntityMirror entity : unit.getEntities().values()) { body.add("if (klass == " + entity.type.plainName + ".class) {"); - body.add(" @SuppressWarnings(\"unchecked\")"); - body.add(" SqlDao dao = (SqlDao) " + daoFields.get(entity).name + ";"); - body.add(" return (SqlDao) dao;"); + body.add(" return (SqlDao) " + daoFields.get(entity).name + ";"); body.add("}"); } body.add("throw new RuntimeException(\"Type is not a part of this persistence unit: \" + klass);"); - return new MethodRef(PUBLIC, sqlDatoType, "getDao", p, body).typeArgs("Id", "T"); + return new MethodRef(PUBLIC, sqlDatoType, "getDao", p, body).typeArgs("Id", "T"). + annotation(new AnnotationG(new TypeRef(SuppressWarnings.class), "\"unchecked\"")); } /* -- cgit v1.2.3