001    /* Annotation.java - Base interface for all annotations
002       Copyright (C) 2004 Free Software Foundation
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    package java.lang.annotation;
039    
040    /**
041     * This is the common interface for all annotations.  Note that classes
042     * that implement this class manually are not classed as annotations, and
043     * that this interface does not define an annotation type in itself.
044     *
045     * @author Tom Tromey (tromey@redhat.com)
046     * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
047     * @since 1.5
048     */
049    public interface Annotation
050    {
051    
052      /**
053       * Returns the type of this annotation.
054       *
055       * @return the class of which this annotation is an instance.
056       */
057      Class<? extends Annotation> annotationType();
058    
059      /**
060       * <p>
061       * Returns true if the supplied object is equivalent to this annotation.
062       * For this property to hold, the following must be true of <code>o</code>:
063       * </p>
064       * <ul>
065       * <li>The object is also an instance of the same annotation type.</li>
066       * <li>The members of the supplied annotation are equal to those of this
067       * annotation, according to the following:
068       * <ul>
069       * <li>If the members are <code>float</code>s, then, for floats
070       * <code>x</code> and <code>y</code>,
071       * <code>Float.valueOf(x).equals(Float.valueOf(y)</code> must return
072       * true.  This differs from the usual (<code>==</code>) comparison
073       * in that <code>NaN</code> is considered equal to itself and positive
074       * and negative zero are seen as different.</li>
075       * <li>Likewise, if the members are <code>double</code>s, then, for doubles
076       * <code>x</code> and <code>y</code>,
077       * <code>Double.valueOf(x).equals(Double.valueOf(y)</code> must return
078       * true.  This differs from the usual (<code>==</code>) comparison
079       * in that <code>NaN</code> is considered equal to itself and positive
080       * and negative zero are seen as different.</li>
081       * <li>Strings, classes, enumerations and annotations are considered
082       * equal according to the <code>equals()</code> implementation for these
083       * types.</li>
084       * <li>Arrays are considered equal according to <code>Arrays.equals()</code>
085       * </li>
086       * <li>Any remaining types are considered equal using <code>==</code>.</li>
087       * </li>
088       * </ul>
089       *
090       * @param o the object to compare with this annotation.
091       * @return true if the supplied object is an annotation with equivalent
092       *         members.
093       */
094      boolean equals(Object o);
095    
096      /**
097       * <p>
098       * Returns the hash code of the annotation.  This is computed as the
099       * sum of the hash codes of the annotation's members.
100       * </p>
101       * <p>
102       * The hash code of a member of the annotation is the result of XORing
103       * the hash code of its value with the result of multiplying the hash code
104       * of its name by 127.  Formally, if the value is <code>v</code> and the
105       * name is <code>n</code>, the hash code of the member is
106       * v.hashCode() XOR (127 * String.hashCode(n)).  <code>v.hashCode()</code>
107       * is defined as follows:
108       * </p>
109       * <ul>
110       * <li>The hash code of a primitive value (i.e. <code>byte</code>,
111       * <code>char</code>, <code>double</code>, <code>float</code>,
112       * <code>int</code>, <code>long</code>, <code>short</code> and
113       * <code>boolean</code>) is the hash code obtained from its corresponding
114       * wrapper class using <code>valueOf(v).hashCode()</code>, where
115       * <code>v</code> is the primitive value.</li>
116       * <li>The hash code of an enumeration, string, class or other annotation
117       * is obtained using <code>v.hashCode()</code>.</li>
118       * <li>The hash code of an array is computed using
119       * <code>Arrays.hashCode(v)</code>.</li>
120       * </ul>
121       *
122       * @return the hash code of the annotation, computed as the sum of its
123       *         member hashcodes.
124       */
125      int hashCode();
126    
127      /**
128       * Returns a textual representation of the annotation.  This is
129       * implementation-dependent, but is expected to include the classname
130       * and the names and values of each member.
131       *
132       * @return a textual representation of the annotation.
133       */
134      String toString();
135    }