KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > lang > reflect > AnnotatedElement


1 /*
2  * @(#)AnnotatedElement.java 1.3 04/02/03
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package java.lang.reflect;
9
10 import java.lang.annotation.Annotation JavaDoc;
11
12 /**
13  * Represents an annotated element of the program currently running in this
14  * VM. This interface allows annotations to be read reflectively. All
15  * annotations returned by methods in this interface are immutable and
16  * serializable. It is permissible for the caller to modify the
17  * arrays returned by accessors for array-valued enum members; it will
18  * have no affect on the arrays returned to other callers.
19  *
20  * <p>If an annotation returned by a method in this interface contains
21  * (directly or indirectly) a {@link Class}-valued member referring to
22  * a class that is not accessible in this VM, attempting to read the class
23  * by calling the relevant Class-returning method on the returned annotation
24  * will result in a {@link TypeNotPresentException}.
25  *
26  * <p>Similarly, attempting to read an enum-valued member will result in
27  * a {@link EnumConstantNotPresentException} if the enum constant in the
28  * annotation is no longer present in the enum type.
29  *
30  * <p>Finally, Attempting to read a member whose definition has evolved
31  * incompatibly will result in a {@link
32  * java.lang.annotation.AnnotationTypeMismatchException} or an
33  * {@link java.lang.annotation.IncompleteAnnotationException}.
34  *
35  * @since 1.5
36  * @author Josh Bloch
37  */

38 public interface AnnotatedElement {
39     /**
40      * Returns true if an annotation for the specified type
41      * is present on this element, else false. This method
42      * is designed primarily for convenient access to marker annotations.
43      *
44      * @param annotationType the Class object corresponding to the
45      * annotation type
46      * @return true if an annotation for the specified annotation
47      * type is present on this element, else false
48      * @throws NullPointerException if annotationType is null
49      * @since 1.5
50      */

51      boolean isAnnotationPresent(Class JavaDoc<? extends Annotation JavaDoc> annotationType);
52
53    /**
54      * Returns this element's annotation for the specified type if
55      * such an annotation is present, else null.
56      *
57      * @param annotationType the Class object corresponding to the
58      * annotation type
59      * @return this element's annotation for the specified annotation type if
60      * present on this element, else null
61      * @throws NullPointerException if annotationType is null
62      * @since 1.5
63      */

64     <T extends Annotation JavaDoc> T getAnnotation(Class JavaDoc<T> annotationType);
65
66     /**
67      * Returns all annotations present on this element. (Returns an array
68      * of length zero if this element has no annotations.) The caller of
69      * this method is free to modify the returned array; it will have no
70      * effect on the arrays returned to other callers.
71      *
72      * @return all annotations present on this element
73      * @since 1.5
74      */

75     Annotation JavaDoc[] getAnnotations();
76
77     /**
78      * Returns all annotations that are directly present on this
79      * element. Unlike the other methods in this interface, this method
80      * ignores inherited annotations. (Returns an array of length zero if
81      * no annotations are directly present on this element.) The caller of
82      * this method is free to modify the returned array; it will have no
83      * effect on the arrays returned to other callers.
84      *
85      * @return All annotations directly present on this element
86      * @since 1.5
87      */

88     Annotation JavaDoc[] getDeclaredAnnotations();
89 }
90
Popular Tags