本文整理汇总了Java中org.objectweb.asm.MethodVisitor.visitAnnotation方法的典型用法代码示例。如果您正苦于以下问题:Java MethodVisitor.visitAnnotation方法的具体用法?Java MethodVisitor.visitAnnotation怎么用?Java MethodVisitor.visitAnnotation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.objectweb.asm.MethodVisitor
的用法示例。
在下文中一共展示了MethodVisitor.visitAnnotation方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addMethodAnnotations
import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private static void addMethodAnnotations(Method method, MethodVisitor mv)
throws IllegalAccessException, InvocationTargetException {
for (Annotation ann : method.getAnnotations()) {
Class<? extends Annotation> annotationType = ann.annotationType();
AnnotationVisitor av0 = mv.visitAnnotation(Type.getDescriptor(annotationType), true);
addAnnotationTree(av0, ann, annotationType);
av0.visitEnd();
}
}
示例2: visitAnnotationMembers
import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private void visitAnnotationMembers(MethodVisitor mv, Set<AnnotationMember> annotationMembers) {
for (AnnotationMember annotation : annotationMembers) {
AnnotationVisitor annotationVisitor;
if (annotation instanceof ParameterAnnotationMember) {
annotationVisitor = mv.visitParameterAnnotation(
((ParameterAnnotationMember) annotation).getParameter(), annotation.getName(),
annotation.isVisible());
} else {
annotationVisitor = mv.visitAnnotation(annotation.getName(), annotation.isVisible());
}
visitAnnotationValues(annotation, annotationVisitor);
}
}
示例3: addConstructor
import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
public void addConstructor(Constructor<?> constructor) throws Exception {
List<Type> paramTypes = new ArrayList<Type>();
for (Class<?> paramType : constructor.getParameterTypes()) {
paramTypes.add(Type.getType(paramType));
}
String methodDescriptor = Type.getMethodDescriptor(VOID_TYPE, paramTypes.toArray(EMPTY_TYPES));
MethodVisitor methodVisitor = visitor.visitMethod(Opcodes.ACC_PUBLIC, "<init>", methodDescriptor, signature(constructor), EMPTY_STRINGS);
for (Annotation annotation : constructor.getDeclaredAnnotations()) {
if (annotation.annotationType().getAnnotation(Inherited.class) != null) {
continue;
}
Retention retention = annotation.annotationType().getAnnotation(Retention.class);
AnnotationVisitor annotationVisitor = methodVisitor.visitAnnotation(Type.getType(annotation.annotationType()).getDescriptor(), retention != null && retention.value() == RetentionPolicy.RUNTIME);
annotationVisitor.visitEnd();
}
methodVisitor.visitCode();
// this.super(p0 .. pn)
methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
for (int i = 0; i < constructor.getParameterTypes().length; i++) {
methodVisitor.visitVarInsn(Type.getType(constructor.getParameterTypes()[i]).getOpcode(Opcodes.ILOAD), i + 1);
}
methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, superclassType.getInternalName(), "<init>", methodDescriptor, false);
methodVisitor.visitInsn(Opcodes.RETURN);
methodVisitor.visitMaxs(0, 0);
methodVisitor.visitEnd();
}