9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package java.lang.reflect;
27
28 import java.lang.annotation.Annotation;
29
30 /**
31 * Represents an annotated element of the program currently running in this
32 * VM. This interface allows annotations to be read reflectively. All
33 * annotations returned by methods in this interface are immutable and
34 * serializable. It is permissible for the caller to modify the
35 * arrays returned by accessors for array-valued enum members; it will
36 * have no affect on the arrays returned to other callers.
37 *
38 * <p>The {@link #getAnnotationsByType(Class)} and {@link
39 * #getDeclaredAnnotationsByType(Class)} methods support multiple
40 * annotations of the same type on an element. If the argument to either method
41 * is a repeatable annotation type (JLS 9.6), then the method will "look
42 * through" a container annotation (JLS 9.7) which was generated at
43 * compile-time to wrap multiple annotations of the argument type.
44 *
45 * <p>The terms <em>directly present</em> and <em>present</em> are used
46 * throughout this interface to describe precisely which annotations are
47 * returned by methods:
48 *
69 *
70 * <li>A is not <em>directly present</em> on E, and E is a class, and A's type
71 * is inheritable (JLS 9.6.3.3), and A is <em>present</em> on the superclass of
72 * E.
73 * </ul>
74 *
75 * </ul>
76 *
77 * <p>If an annotation returned by a method in this interface contains
78 * (directly or indirectly) a {@link Class}-valued member referring to
79 * a class that is not accessible in this VM, attempting to read the class
80 * by calling the relevant Class-returning method on the returned annotation
81 * will result in a {@link TypeNotPresentException}.
82 *
83 * <p>Similarly, attempting to read an enum-valued member will result in
84 * a {@link EnumConstantNotPresentException} if the enum constant in the
85 * annotation is no longer present in the enum type.
86 *
87 * <p>Attempting to read annotations of a repeatable annotation type T
88 * that are contained in an annotation whose type is not, in fact, the
89 * containing annotation type of T will result in an
90 * InvalidContainerAnnotationError.
91 *
92 * <p>Finally, attempting to read a member whose definition has evolved
93 * incompatibly will result in a {@link
94 * java.lang.annotation.AnnotationTypeMismatchException} or an
95 * {@link java.lang.annotation.IncompleteAnnotationException}.
96 *
97 * @see java.lang.EnumConstantNotPresentException
98 * @see java.lang.TypeNotPresentException
99 * @see java.lang.annotation.AnnotationFormatError
100 * @see java.lang.annotation.AnnotationTypeMismatchException
101 * @see java.lang.annotation.IncompleteAnnotationException
102 * @see java.lang.annotation.InvalidContainerAnnotationError
103 * @since 1.5
104 * @author Josh Bloch
105 */
106 public interface AnnotatedElement {
107 /**
108 * Returns true if an annotation for the specified type
109 * is present on this element, else false. This method
110 * is designed primarily for convenient access to marker annotations.
111 *
112 * <p>The truth value returned by this method is equivalent to:
113 * {@code getAnnotation(annotationClass) != null}
114 *
115 * <p>The body of the default method is specified to be the code
116 * above.
117 *
118 * @param annotationClass the Class object corresponding to the
119 * annotation type
120 * @return true if an annotation for the specified annotation
121 * type is present on this element, else false
122 * @throws NullPointerException if the given annotation class is null
|
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package java.lang.reflect;
27
28 import java.lang.annotation.Annotation;
29 import java.lang.annotation.AnnotationFormatError;
30
31 /**
32 * Represents an annotated element of the program currently running in this
33 * VM. This interface allows annotations to be read reflectively. All
34 * annotations returned by methods in this interface are immutable and
35 * serializable. It is permissible for the caller to modify the
36 * arrays returned by accessors for array-valued enum members; it will
37 * have no affect on the arrays returned to other callers.
38 *
39 * <p>The {@link #getAnnotationsByType(Class)} and {@link
40 * #getDeclaredAnnotationsByType(Class)} methods support multiple
41 * annotations of the same type on an element. If the argument to either method
42 * is a repeatable annotation type (JLS 9.6), then the method will "look
43 * through" a container annotation (JLS 9.7) which was generated at
44 * compile-time to wrap multiple annotations of the argument type.
45 *
46 * <p>The terms <em>directly present</em> and <em>present</em> are used
47 * throughout this interface to describe precisely which annotations are
48 * returned by methods:
49 *
70 *
71 * <li>A is not <em>directly present</em> on E, and E is a class, and A's type
72 * is inheritable (JLS 9.6.3.3), and A is <em>present</em> on the superclass of
73 * E.
74 * </ul>
75 *
76 * </ul>
77 *
78 * <p>If an annotation returned by a method in this interface contains
79 * (directly or indirectly) a {@link Class}-valued member referring to
80 * a class that is not accessible in this VM, attempting to read the class
81 * by calling the relevant Class-returning method on the returned annotation
82 * will result in a {@link TypeNotPresentException}.
83 *
84 * <p>Similarly, attempting to read an enum-valued member will result in
85 * a {@link EnumConstantNotPresentException} if the enum constant in the
86 * annotation is no longer present in the enum type.
87 *
88 * <p>Attempting to read annotations of a repeatable annotation type T
89 * that are contained in an annotation whose type is not, in fact, the
90 * containing annotation type of T, will result in an {@link
91 * AnnotationFormatError}.
92 *
93 * <p>Finally, attempting to read a member whose definition has evolved
94 * incompatibly will result in a {@link
95 * java.lang.annotation.AnnotationTypeMismatchException} or an
96 * {@link java.lang.annotation.IncompleteAnnotationException}.
97 *
98 * @see java.lang.EnumConstantNotPresentException
99 * @see java.lang.TypeNotPresentException
100 * @see AnnotationFormatError
101 * @see java.lang.annotation.AnnotationTypeMismatchException
102 * @see java.lang.annotation.IncompleteAnnotationException
103 * @since 1.5
104 * @author Josh Bloch
105 */
106 public interface AnnotatedElement {
107 /**
108 * Returns true if an annotation for the specified type
109 * is present on this element, else false. This method
110 * is designed primarily for convenient access to marker annotations.
111 *
112 * <p>The truth value returned by this method is equivalent to:
113 * {@code getAnnotation(annotationClass) != null}
114 *
115 * <p>The body of the default method is specified to be the code
116 * above.
117 *
118 * @param annotationClass the Class object corresponding to the
119 * annotation type
120 * @return true if an annotation for the specified annotation
121 * type is present on this element, else false
122 * @throws NullPointerException if the given annotation class is null
|