Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. for (AnnotationMirror annotation : field.getAnnotationMirrors()) {
  2. Map<? extends ExecutableElement, ? extends AnnotationValue> annotationValueMap = annotation.getElementValues();
  3.  
  4. messager.printMessage(Diagnostic.Kind.WARNING, annotation.toString() + ":" + annotationValueMap.toString());
  5. }
  6.  
  7. @MyAnnotation:{}
  8.  
  9. @MyAnnotation(max = 387, min = 66876, ...)
  10. private Integer myField;
  11.  
  12. @Retention(RetentionPolicy.SOURCE)
  13. @Target(ElementType.FIELD)
  14. public @interface MyAnnotation {
  15. int max();
  16.  
  17. boolean allowAuto();
  18.  
  19. int min();
  20. }
  21.  
  22. MyAnnotation myAnnotation= field.getAnnotation(MyAnnotation.class);
  23. int max = myAnnotation.max();
  24. int min = myAnnotation.min();
  25.  
  26. for (AnnotationMirror annotation : field.getAnnotationMirrors()) {
  27. Map<? extends ExecutableElement, ? extends AnnotationValue> annotationValueMap = annotation.getElementValues();
  28. annotationValueMap.forEach((element, annotationValue) -> {
  29. messager.printMessage(Diagnostic.Kind.WARNING, element.getSimpleName().toString() + ":" + annotationValue.getValue());
  30. });
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement