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
This commit is contained in:
Panxiaobo 2012-10-22 16:46:29 +08:00
parent 754bf61820
commit 9a3dd27940
2 changed files with 53 additions and 6 deletions

View File

@ -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<String, Object>();
}
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();
}
}

View File

@ -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;
}