001    /* AnnotatedElement.java
002       Copyright (C) 2004, 2005 Free Software Foundation, Inc.
003    
004    This file is part of GNU Classpath.
005    
006    GNU Classpath is free software; you can redistribute it and/or modify
007    it under the terms of the GNU General Public License as published by
008    the Free Software Foundation; either version 2, or (at your option)
009    any later version.
010    
011    GNU Classpath is distributed in the hope that it will be useful, but
012    WITHOUT ANY WARRANTY; without even the implied warranty of
013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014    General Public License for more details.
015    
016    You should have received a copy of the GNU General Public License
017    along with GNU Classpath; see the file COPYING.  If not, write to the
018    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
019    02110-1301 USA.
020    
021    Linking this library statically or dynamically with other modules is
022    making a combined work based on this library.  Thus, the terms and
023    conditions of the GNU General Public License cover the whole
024    combination.
025    
026    As a special exception, the copyright holders of this library give you
027    permission to link this library with independent modules to produce an
028    executable, regardless of the license terms of these independent
029    modules, and to copy and distribute the resulting executable under
030    terms of your choice, provided that you also meet, for each linked
031    independent module, the terms and conditions of the license of that
032    module.  An independent module is a module which is not derived from
033    or based on this library.  If you modify this library, you may extend
034    this exception to your version of the library, but you are not
035    obligated to do so.  If you do not wish to do so, delete this
036    exception statement from your version. */
037    
038    
039    package java.lang.reflect;
040    
041    import java.lang.annotation.Annotation;
042    
043    /**
044     * <p>
045     * Represents an element that can be annotated.  The methods of this interface
046     * provide reflection-based access to the annotations associated with a
047     * particular element, such as a class, field, method or package.  Each
048     * annotation returned by these methods is both immutable and serializable.
049     * The returned arrays may be freely modified, without any effect on the
050     * arrays returned to future callers.
051     * </p>
052     * <p>
053     * If an annotation refers to a type or enumeration constant that is
054     * inaccessible, then a <code>TypeNotPresentException</code> or
055     * <code>EnumConstantNotPresentException</code> will be thrown.  Likewise,
056     * invalid annotations will produce either a
057     * <code>AnnotationTypeMismatchException</code> or
058     * <code>IncompleteAnnotationException</code>.
059     * </p>
060     *
061     * @author Tom Tromey (tromey@redhat.com)
062     * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
063     * @since 1.5
064     */
065    public interface AnnotatedElement
066    {
067    
068      /**
069       * Returns the element's annotation for the specified annotation type,
070       * or <code>null</code> if no such annotation exists.
071       *
072       * @param annotationClass the type of annotation to look for.
073       * @return this element's annotation for the specified type, or
074       *         <code>null</code> if no such annotation exists.
075       * @throws NullPointerException if the annotation class is <code>null</code>.
076       */
077      <T extends Annotation> T getAnnotation(Class<T> annotationClass);
078    
079      /**
080       * Returns all annotations associated with the element.  If there are
081       * no annotations associated with the element, then a zero-length array
082       * will be returned.  The returned array may be modified by the client
083       * code, but this will have no effect on the annotation content of the
084       * element, and hence no effect on the return value of this method for
085       * future callers.
086       *
087       * @return this element's annotations.
088       */
089      Annotation[] getAnnotations();
090    
091      /**
092       * Returns all annotations directly defined by the element.  If there are
093       * no annotations directly associated with the element, then a zero-length
094       * array will be returned.  The returned array may be modified by the client
095       * code, but this will have no effect on the annotation content of this
096       * class, and hence no effect on the return value of this method for
097       * future callers.
098       *
099       * @return the annotations directly defined by the element.
100       * @since 1.5
101       */
102      Annotation[] getDeclaredAnnotations();
103    
104      /**
105       * Returns true if an annotation for the specified type is associated
106       * with the element.  This is primarily a short-hand for using marker
107       * annotations.
108       *
109       * @param annotationClass the type of annotation to look for.
110       * @return true if an annotation exists for the specified type.
111       * @since 1.5
112       */
113      boolean isAnnotationPresent(Class<? extends Annotation> annotationClass);
114    
115    }