All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.google.gwt.emul.java.lang.reflect.AnnotatedElement Maven / Gradle / Ivy

The newest version!
package java.lang.reflect;

import com.google.gwt.core.ext.UnableToCompleteException;

import java.lang.annotation.Annotation;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Collectors;

import sun.reflect.annotation.AnnotationSupport;
import sun.reflect.annotation.AnnotationType;

/**
 * Emulation layer compatibility for AnnotatedElement
 * 
 * @originalauthor Josh Bloch
 * @author "James X. Nelson ([email protected])"
 */
public interface AnnotatedElement {
  /**
   * Returns true if an annotation for the specified type is present on this
   * element, else false.
   */
  default boolean isAnnotationPresent(Class annotationClass) {
    for (Annotation annotation : getAnnotations()) {
      if (annotation.annotationType() == annotationClass) {
        return true;
      }
    }
    return false;
  }

  /**
   * Returns this element's annotation for the specified type if such an
   * annotation is present, else null.
   */
   T getAnnotation(Class annotationClass);

  /**
   * Returns all annotations present on this element. (Returns an array of
   * length zero if this element has no annotations.)
   */
  Annotation[] getAnnotations();

  Annotation[] getDeclaredAnnotations();

  default  T[] getAnnotationsByType(Class annotationClass) {
    throw new UnsupportedOperationException();
  }

  default  T getDeclaredAnnotation(Class annotationClass) {
    Objects.requireNonNull(annotationClass);
    for (Annotation annotation : getDeclaredAnnotations()) {
      if (annotation.annotationType() == annotationClass) {
        return (T)annotation;
      }
    }
    return null;
  }

  default  T[] getDeclaredAnnotationsByType(Class annotationClass) {
    throw new UnsupportedOperationException();
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy