From 9a3dd27940233bcc05b5aad1920a7714039e650c Mon Sep 17 00:00:00 2001 From: Panxiaobo Date: Mon, 22 Oct 2012 16:46:29 +0800 Subject: [PATCH] Fix an issue while we are not translate annotation defualt if the value is an enum Fixes issue 142 --HG-- branch : 0.0.9.x --- .../googlecode/dex2jar/v3/V3ClassAdapter.java | 26 +++++++++++---- .../java/res/I142_annotation_default.java | 33 +++++++++++++++++++ 2 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 dex-translator/src/test/java/res/I142_annotation_default.java diff --git a/dex-translator/src/main/java/com/googlecode/dex2jar/v3/V3ClassAdapter.java b/dex-translator/src/main/java/com/googlecode/dex2jar/v3/V3ClassAdapter.java index 77801bc1..a21af213 100644 --- a/dex-translator/src/main/java/com/googlecode/dex2jar/v3/V3ClassAdapter.java +++ b/dex-translator/src/main/java/com/googlecode/dex2jar/v3/V3ClassAdapter.java @@ -264,16 +264,22 @@ public class V3ClassAdapter implements DexClassVisitor { @Override public DexAnnotationVisitor visitAnnotation(String name, String desc) { return new EmptyVisitor() { - @Override - public void visit(String name, Object value) { + private void putDefault(String name, Object value) { if (annotationDefaults == null) { annotationDefaults = new HashMap(); } - if (value instanceof DexType) { - value = Type.getType(((DexType) value).desc); - } annotationDefaults.put(name, value); } + + @Override + public void visit(String name, Object value) { + putDefault(name, value); + } + + @Override + public void visitEnum(String name, String desc, String value) { + putDefault(name, new Field(desc, value, desc)); + } }; } }; @@ -312,7 +318,15 @@ public class V3ClassAdapter implements DexClassVisitor { if (value != null) { AnnotationVisitor av = methodNode.visitAnnotationDefault(); if (av != null) { - av.visit(null, value); + if (value instanceof Field) { + Field field = (Field) value; + av.visitEnum(null, field.getOwner(), field.getName()); + } else { + if (value instanceof DexType) { + value = Type.getType(((DexType) value).desc); + } + av.visit(null, value); + } av.visitEnd(); } } diff --git a/dex-translator/src/test/java/res/I142_annotation_default.java b/dex-translator/src/test/java/res/I142_annotation_default.java new file mode 100644 index 00000000..53a1b1b7 --- /dev/null +++ b/dex-translator/src/test/java/res/I142_annotation_default.java @@ -0,0 +1,33 @@ +package res; + +public @interface I142_annotation_default { + + enum AA { + A, B, C + } + + AA aaa() default AA.A; + + AA bbb(); + + String ccc() default ""; + + String ddd() default "ddd"; + + int eee() default 1; + + byte fff() default 1; + + short ggg() default 1; + + char hhh() default 1; + + boolean iii() default true; + + long jjj() default 1L; + + float kkk() default 1.0F; + + double lll() default 1.0D; + +}