001package org.gbif.utils;
002
003import java.lang.reflect.Field;
004
005/**
006 * Utility method to work with annotations.
007 */
008public class AnnotationUtils {
009
010  /**
011   * Check if a field is annotated with @Deprecated in the provided class.
012   * Mostly used on elements of an Enum but will also work on class {@link Field} (private and public).
013   *
014   * @param _class
015   * @param fieldName
016   * @return true if the specified field is annotated with @Deprecated on the provided class. False is all
017   * other cases (including if the field doesn't exist)
018   */
019  public static boolean isFieldDeprecated(Class<?> _class, String fieldName) {
020    try {
021      Field field = _class.getDeclaredField(fieldName);
022      field.setAccessible(true);
023      return field.isAnnotationPresent(Deprecated.class);
024    } catch (NoSuchFieldException ignore) {}
025    return false;
026  }
027}