本文整理汇总了Java中org.objectweb.asm.AnnotationVisitor.visitAnnotation方法的典型用法代码示例。如果您正苦于以下问题:Java AnnotationVisitor.visitAnnotation方法的具体用法?Java AnnotationVisitor.visitAnnotation怎么用?Java AnnotationVisitor.visitAnnotation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.objectweb.asm.AnnotationVisitor
的用法示例。
在下文中一共展示了AnnotationVisitor.visitAnnotation方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitAnnotationValue
import org.objectweb.asm.AnnotationVisitor; //导入方法依赖的package包/类
private void visitAnnotationValue(AnnotationVisitor annotationVisitor, AnnotationValue<?> value) {
String name = value.getName();
if (value instanceof EnumAnnotationValue) {
annotationVisitor.visitEnum(name, ((EnumAnnotationValue) value).getTypeDesc(), (String) value.getValue());
} else if (value instanceof SimpleAnnotationValue) {
annotationVisitor.visit(name, value.getValue());
} else if (value instanceof ArrayAnnotationValue) {
AnnotationVisitor arrayVisitor = annotationVisitor.visitArray(name);
AnnotationValue<?>[] values = ((ArrayAnnotationValue) value).getValue();
for (AnnotationValue<?> annotationValue : values) {
visitAnnotationValue(arrayVisitor, annotationValue);
}
arrayVisitor.visitEnd();
} else if (value instanceof AnnotationAnnotationValue) {
AnnotationMember annotation = ((AnnotationAnnotationValue) value).getValue();
AnnotationVisitor annVisitor = annotationVisitor.visitAnnotation(name, annotation.getName());
visitAnnotationValues(annotation, annVisitor);
}
}
示例2: visitAnnotationValues
import org.objectweb.asm.AnnotationVisitor; //导入方法依赖的package包/类
private void visitAnnotationValues(Annotation annotation, AnnotationVisitor annotationVisitor) {
for (Method method : annotation.annotationType().getDeclaredMethods()) {
String name = method.getName();
Class<?> returnType = method.getReturnType();
if (returnType.isEnum()) {
annotationVisitor.visitEnum(name, Type.getType(returnType).getDescriptor(), getAnnotationParameterValue(annotation, method).toString());
} else if (returnType.isArray() && !PRIMITIVE_TYPES.contains(returnType.getComponentType())) {
AnnotationVisitor arrayVisitor = annotationVisitor.visitArray(name);
Object[] elements = (Object[]) getAnnotationParameterValue(annotation, method);
visitArrayElements(arrayVisitor, returnType.getComponentType(), elements);
arrayVisitor.visitEnd();
} else if (returnType.equals(Class.class)) {
Class<?> clazz = (Class<?>) getAnnotationParameterValue(annotation, method);
annotationVisitor.visit(name, Type.getType(clazz));
} else if (returnType.isAnnotation()) {
Annotation nestedAnnotation = (Annotation) getAnnotationParameterValue(annotation, method);
AnnotationVisitor nestedAnnotationVisitor = annotationVisitor.visitAnnotation(name, Type.getType(returnType).getDescriptor());
visitAnnotationValues(nestedAnnotation, nestedAnnotationVisitor);
nestedAnnotationVisitor.visitEnd();
} else {
annotationVisitor.visit(name, getAnnotationParameterValue(annotation, method));
}
}
}
示例3: addAnnotation
import org.objectweb.asm.AnnotationVisitor; //导入方法依赖的package包/类
private static void addAnnotation(String name, Class<?> annotationMethodType, String typeDesc, AnnotationVisitor av,
Object value)
throws IllegalAccessException, InvocationTargetException {
if (Enum.class.isAssignableFrom(annotationMethodType)) {
av.visitEnum(name, typeDesc, value.toString());
} else if (annotationMethodType.isAnnotation()) {
@SuppressWarnings("unchecked")
Class<? extends Annotation> annType = (Class<? extends Annotation>) annotationMethodType;
AnnotationVisitor annotationVisitor = av.visitAnnotation(name, typeDesc);
addAnnotationTree(annotationVisitor, (Annotation) value, annType);
annotationVisitor.visitEnd();
} else {
av.visit(name, value);
}
}