本文整理匯總了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);
}
}