From 156b0cba4f5b6c7274b3dedf88cce5c407f37cc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Westk=C3=A4mper?= Date: Mon, 19 Jul 2010 14:08:42 +0000 Subject: [PATCH] improved annotation serialization updated codegen version to 0.1.7 --- pom.xml | 2 +- .../java/com/mysema/codegen/JavaWriter.java | 38 +++++++++++++------ 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/pom.xml b/pom.xml index 023bee5ee..a51488047 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.mysema.codegen codegen - 0.1.6-SNAPSHOT + 0.1.7 Codegen Code generation and compilation for Java diff --git a/src/main/java/com/mysema/codegen/JavaWriter.java b/src/main/java/com/mysema/codegen/JavaWriter.java index 64a8f7d40..1d59a6dd0 100644 --- a/src/main/java/com/mysema/codegen/JavaWriter.java +++ b/src/main/java/com/mysema/codegen/JavaWriter.java @@ -86,16 +86,10 @@ public final class JavaWriter implements Appendable, CodeWriter{ @Override public JavaWriter annotation(Annotation annotation) throws IOException { append(indent).append("@").appendType(annotation.annotationType()).append("("); - boolean first = true; - for (Method method : annotation.annotationType().getDeclaredMethods()){ + Method[] methods = annotation.annotationType().getDeclaredMethods(); + if (methods.length == 1 && methods[0].getName().equals("value")){ try { - Object value = method.invoke(annotation); - if (value == null){ - continue; - }else if (!first){ - append(COMMA); - } - append(method.getName()+"="); + Object value = methods[0].invoke(annotation); annotationConstant(value); } catch (IllegalArgumentException e) { throw new CodegenException(e); @@ -103,9 +97,29 @@ public final class JavaWriter implements Appendable, CodeWriter{ throw new CodegenException(e); } catch (InvocationTargetException e) { throw new CodegenException(e); - } - first = false; - } + } + }else{ + boolean first = true; + for (Method method : methods){ + try { + Object value = method.invoke(annotation); + if (value == null){ + continue; + }else if (!first){ + append(COMMA); + } + append(method.getName()+"="); + annotationConstant(value); + } catch (IllegalArgumentException e) { + throw new CodegenException(e); + } catch (IllegalAccessException e) { + throw new CodegenException(e); + } catch (InvocationTargetException e) { + throw new CodegenException(e); + } + first = false; + } + } return append(")").nl(); }