Я пытаюсь работать с ByteBuddy.
Как, с учетом TypeDescription
, я могу получить класс аннотаций?
Пока я нашел getActualName
.
@Override
public boolean matches(final TypeDescription target) {
//System.out.printf("matches(%1$s)\n", target);
//System.out.printf("\tcanonicalName: %1$s\n", target.getCanonicalName());
//System.out.printf("\tcomponentType: %1$s\n", target.getComponentType());
{
final AnnotationList inheritedAnnotations = target.getInheritedAnnotations();
inheritedAnnotations.forEach(v -> {
//System.out.printf("\tinherited annotationDescriptor: %1$s\n", v);
});
}
{
final AnnotationList declaredAnnotations = target.getDeclaredAnnotations();
declaredAnnotations.forEach(v -> {
//System.out.printf("\tdeclared annotationDescriptor: %1$s\n", v);
});
}
{
final FieldList<FieldDescription.InDefinedShape> declaredFields = target.getDeclaredFields();
declaredFields.forEach(declaredFiled -> {
System.out.println("declaredField: " + declaredFiled);
final AnnotationList declaredAnnotations = declaredFiled.getDeclaredAnnotations();
declaredAnnotations.forEach(declaredAnnotation -> {
System.out.println("declaredAnnotation: {}" + declaredAnnotation);
final Set<ElementType> elementTypes = declaredAnnotation.getElementTypes();
System.out.println("\telementTypes: " + elementTypes);
final TypeDescription annotationType = declaredAnnotation.getAnnotationType();
System.out.println("\tannotationType: " + annotationType);
System.out.println("\tannotationType.actualName: " + annotationType.getActualName());
});
});
}
return false;
}
На самом деле я пытаюсь добавить некоторые методы в скомпилированные классы с помощью полей, помеченных конкретной аннотацией.