New issue

Summary: support @dalvik.annotation.AnnotationDefault
Labels: Type-Defect Priority-High
Status: Accepted
translate @dalvik.annotation.AnnotationDefault to mv.visitAnnotationDefault

--HG--
branch : 0.0.9.x
This commit is contained in:
Panxiaobo 2011-11-02 20:49:57 +08:00
parent 9373e5f58c
commit 43918638ab
3 changed files with 35 additions and 3 deletions

View File

@ -154,6 +154,7 @@ public class ASMifierClassV implements DexClassVisitor {
@Override
public void visitEnd() {
m.s("mv.visitEnd();");
m.pop();
m.s("}");
m.pop();

View File

@ -16,6 +16,7 @@
package com.googlecode.dex2jar.v3;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@ -35,6 +36,7 @@ import com.googlecode.dex2jar.visitors.DexAnnotationVisitor;
import com.googlecode.dex2jar.visitors.DexClassVisitor;
import com.googlecode.dex2jar.visitors.DexFieldVisitor;
import com.googlecode.dex2jar.visitors.DexMethodVisitor;
import com.googlecode.dex2jar.visitors.EmptyVisitor;
/**
* @author Panxiaobo [pxb1988@gmail.com]
@ -205,15 +207,33 @@ public class V3ClassAdapter implements DexClassVisitor {
}
}
Map<String, Object> annotationDefaults;
boolean isInnerClass = false;
public DexAnnotationVisitor visitAnnotation(String name, boolean visible) {
if (!isInnerClass) {
isInnerClass = "Ldalvik/annotation/InnerClass;".equals(name);
}
Annotation ann = new Annotation(name, visible);
anns.add(ann);
return new V3AnnAdapter(ann);
if (name.equals("Ldalvik/annotation/AnnotationDefault;")) {
return new EmptyVisitor() {
@Override
public DexAnnotationVisitor visitAnnotation(String name, String desc) {
return new EmptyVisitor() {
@Override
public void visit(String name, Object value) {
if (annotationDefaults == null) {
annotationDefaults = new HashMap<String, Object>();
}
annotationDefaults.put(name, value);
}
};
}
};
} else {
Annotation ann = new Annotation(name, visible);
anns.add(ann);
return new V3AnnAdapter(ann);
}
}
public void visitEnd() {
@ -236,6 +256,16 @@ public class V3ClassAdapter implements DexClassVisitor {
@Override
public void visitEnd() {
super.visitEnd();
if (annotationDefaults != null) {
Object value = annotationDefaults.get(method.getName());
if (value != null) {
AnnotationVisitor av = methodNode.visitAnnotationDefault();
if (av != null) {
av.visit(null, value);
av.visitEnd();
}
}
}
methodNode.accept(cv);
}
};

View File

@ -25,5 +25,6 @@ public class I88 {
@Target({ ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.LOCAL_VARIABLE,
ElementType.METHOD, ElementType.PACKAGE, ElementType.PARAMETER, ElementType.TYPE })
public @interface A {
String a() default "234";
}
}