emul/mini/src/main/java/java/lang/reflect/AnnotatedElement.java
branchemul
changeset 554 05224402145d
parent 258 21b390daf444
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/emul/mini/src/main/java/java/lang/reflect/AnnotatedElement.java	Wed Jan 23 20:39:23 2013 +0100
     1.3 @@ -0,0 +1,112 @@
     1.4 +/*
     1.5 + * Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package java.lang.reflect;
    1.30 +
    1.31 +import java.lang.annotation.Annotation;
    1.32 +
    1.33 +/**
    1.34 + * Represents an annotated element of the program currently running in this
    1.35 + * VM.  This interface allows annotations to be read reflectively.  All
    1.36 + * annotations returned by methods in this interface are immutable and
    1.37 + * serializable.  It is permissible for the caller to modify the
    1.38 + * arrays returned by accessors for array-valued enum members; it will
    1.39 + * have no affect on the arrays returned to other callers.
    1.40 + *
    1.41 + * <p>If an annotation returned by a method in this interface contains
    1.42 + * (directly or indirectly) a {@link Class}-valued member referring to
    1.43 + * a class that is not accessible in this VM, attempting to read the class
    1.44 + * by calling the relevant Class-returning method on the returned annotation
    1.45 + * will result in a {@link TypeNotPresentException}.
    1.46 + *
    1.47 + * <p>Similarly, attempting to read an enum-valued member will result in
    1.48 + * a {@link EnumConstantNotPresentException} if the enum constant in the
    1.49 + * annotation is no longer present in the enum type.
    1.50 + *
    1.51 + * <p>Finally, Attempting to read a member whose definition has evolved
    1.52 + * incompatibly will result in a {@link
    1.53 + * java.lang.annotation.AnnotationTypeMismatchException} or an
    1.54 + * {@link java.lang.annotation.IncompleteAnnotationException}.
    1.55 + *
    1.56 + * @see java.lang.EnumConstantNotPresentException
    1.57 + * @see java.lang.TypeNotPresentException
    1.58 + * @see java.lang.annotation.AnnotationFormatError
    1.59 + * @see java.lang.annotation.AnnotationTypeMismatchException
    1.60 + * @see java.lang.annotation.IncompleteAnnotationException
    1.61 + * @since 1.5
    1.62 + * @author Josh Bloch
    1.63 + */
    1.64 +public interface AnnotatedElement {
    1.65 +    /**
    1.66 +     * Returns true if an annotation for the specified type
    1.67 +     * is present on this element, else false.  This method
    1.68 +     * is designed primarily for convenient access to marker annotations.
    1.69 +     *
    1.70 +     * @param annotationClass the Class object corresponding to the
    1.71 +     *        annotation type
    1.72 +     * @return true if an annotation for the specified annotation
    1.73 +     *     type is present on this element, else false
    1.74 +     * @throws NullPointerException if the given annotation class is null
    1.75 +     * @since 1.5
    1.76 +     */
    1.77 +     boolean isAnnotationPresent(Class<? extends Annotation> annotationClass);
    1.78 +
    1.79 +   /**
    1.80 +     * Returns this element's annotation for the specified type if
    1.81 +     * such an annotation is present, else null.
    1.82 +     *
    1.83 +     * @param annotationClass the Class object corresponding to the
    1.84 +     *        annotation type
    1.85 +     * @return this element's annotation for the specified annotation type if
    1.86 +     *     present on this element, else null
    1.87 +     * @throws NullPointerException if the given annotation class is null
    1.88 +     * @since 1.5
    1.89 +     */
    1.90 +    <T extends Annotation> T getAnnotation(Class<T> annotationClass);
    1.91 +
    1.92 +    /**
    1.93 +     * Returns all annotations present on this element.  (Returns an array
    1.94 +     * of length zero if this element has no annotations.)  The caller of
    1.95 +     * this method is free to modify the returned array; it will have no
    1.96 +     * effect on the arrays returned to other callers.
    1.97 +     *
    1.98 +     * @return all annotations present on this element
    1.99 +     * @since 1.5
   1.100 +     */
   1.101 +    Annotation[] getAnnotations();
   1.102 +
   1.103 +    /**
   1.104 +     * Returns all annotations that are directly present on this
   1.105 +     * element.  Unlike the other methods in this interface, this method
   1.106 +     * ignores inherited annotations.  (Returns an array of length zero if
   1.107 +     * no annotations are directly present on this element.)  The caller of
   1.108 +     * this method is free to modify the returned array; it will have no
   1.109 +     * effect on the arrays returned to other callers.
   1.110 +     *
   1.111 +     * @return All annotations directly present on this element
   1.112 +     * @since 1.5
   1.113 +     */
   1.114 +    Annotation[] getDeclaredAnnotations();
   1.115 +}