Thu, 27 Jun 2013 11:46:23 -0700
8019308: Add descriptions of Java SE 7 and 8 language changes to SourceVersion
Reviewed-by: jjg
jjg@1645 | 1 | /* |
jjg@1645 | 2 | * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
jjg@1645 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jjg@1645 | 4 | * |
jjg@1645 | 5 | * This code is free software; you can redistribute it and/or modify it |
jjg@1645 | 6 | * under the terms of the GNU General Public License version 2 only, as |
jjg@1645 | 7 | * published by the Free Software Foundation. Oracle designates this |
jjg@1645 | 8 | * particular file as subject to the "Classpath" exception as provided |
jjg@1645 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
jjg@1645 | 10 | * |
jjg@1645 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jjg@1645 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jjg@1645 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jjg@1645 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
jjg@1645 | 15 | * accompanied this code). |
jjg@1645 | 16 | * |
jjg@1645 | 17 | * You should have received a copy of the GNU General Public License version |
jjg@1645 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
jjg@1645 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jjg@1645 | 20 | * |
jjg@1645 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
jjg@1645 | 22 | * or visit www.oracle.com if you need additional information or have any |
jjg@1645 | 23 | * questions. |
jjg@1645 | 24 | */ |
jjg@1645 | 25 | |
jjg@1645 | 26 | package javax.lang.model; |
jjg@1645 | 27 | |
jjg@1647 | 28 | import java.lang.annotation.*; |
jjg@1645 | 29 | import java.util.List; |
jjg@1645 | 30 | import javax.lang.model.element.*; |
jjg@1647 | 31 | import javax.lang.model.type.*; |
jjg@1645 | 32 | |
jjg@1645 | 33 | /** |
darcy@1651 | 34 | * Represents a construct that can be annotated. |
jjg@1645 | 35 | * |
darcy@1651 | 36 | * A construct is either an {@linkplain |
darcy@1651 | 37 | * javax.lang.model.element.Element element} or a {@linkplain |
darcy@1651 | 38 | * javax.lang.model.type.TypeMirror type}. Annotations on an element |
darcy@1651 | 39 | * are on a <em>declaration</em>, whereas annotations on a type are on |
darcy@1651 | 40 | * a specific <em>use</em> of a type name. |
darcy@1651 | 41 | * |
darcy@1777 | 42 | * The terms <em>directly present</em>, <em>present</em>, |
darcy@1777 | 43 | * <em>indirectly present</em>, and <em>associated </em> are used |
darcy@1651 | 44 | * throughout this interface to describe precisely which annotations |
darcy@1777 | 45 | * are returned by the methods defined herein. |
darcy@1651 | 46 | * |
darcy@1777 | 47 | * <p>In the definitions below, an annotation <i>A</i> has an |
darcy@1777 | 48 | * annotation type <i>AT</i>. If <i>AT</i> is a repeatable annotation |
darcy@1777 | 49 | * type, the type of the containing annotation is <i>ATC</i>. |
darcy@1777 | 50 | * |
darcy@1777 | 51 | * <p>Annotation <i>A</i> is <em>directly present</em> on a construct |
darcy@1777 | 52 | * <i>C</i> if either: |
darcy@1651 | 53 | * |
darcy@1651 | 54 | * <ul> |
darcy@1651 | 55 | * |
darcy@1777 | 56 | * <li><i>A</i> is explicitly or implicitly declared as applying to |
darcy@1777 | 57 | * the source code representation of <i>C</i>. |
darcy@1651 | 58 | * |
darcy@1777 | 59 | * <p>Typically, if exactly one annotation of type <i>AT</i> appears in |
darcy@1777 | 60 | * the source code of representation of <i>C</i>, then <i>A</i> is |
darcy@1777 | 61 | * explicitly declared as applying to <i>C</i>. |
darcy@1777 | 62 | * |
darcy@1777 | 63 | * If there are multiple annotations of type <i>AT</i> present on |
darcy@1777 | 64 | * <i>C</i>, then if <i>AT</i> is repeatable annotation type, an |
darcy@1777 | 65 | * annotation of type <i>ATC</i> is implicitly declared on <i>C</i>. |
darcy@1777 | 66 | * |
darcy@1777 | 67 | * <li> A representation of <i>A</i> appears in the executable output |
darcy@1777 | 68 | * for <i>C</i>, such as the {@code RuntimeVisibleAnnotations} or |
darcy@1777 | 69 | * {@code RuntimeVisibleParameterAnnotations} attributes of a class |
darcy@1777 | 70 | * file. |
darcy@1651 | 71 | * |
darcy@1651 | 72 | * </ul> |
darcy@1651 | 73 | * |
darcy@1777 | 74 | * <p>An annotation <i>A</i> is <em>present</em> on a |
darcy@1777 | 75 | * construct <i>C</i> if either: |
darcy@1777 | 76 | * <ul> |
darcy@1777 | 77 | * |
darcy@1777 | 78 | * <li><i>A</i> is directly present on <i>C</i>. |
darcy@1777 | 79 | * |
darcy@1777 | 80 | * <li>No annotation of type <i>AT</i> is directly present on |
darcy@1777 | 81 | * <i>C</i>, and <i>C</i> is a class and <i>AT</i> is inheritable |
darcy@1777 | 82 | * and <i>A</i> is present on the superclass of <i>C</i>. |
darcy@1777 | 83 | * |
darcy@1777 | 84 | * </ul> |
darcy@1777 | 85 | * |
darcy@1777 | 86 | * An annotation <i>A</i> is <em>indirectly present</em> on a construct |
darcy@1777 | 87 | * <i>C</i> if both: |
darcy@1651 | 88 | * |
darcy@1651 | 89 | * <ul> |
darcy@1651 | 90 | * |
darcy@1777 | 91 | * <li><i>AT</i> is a repeatable annotation type with a containing |
darcy@1777 | 92 | * annotation type <i>ATC</i>. |
darcy@1777 | 93 | * |
darcy@1777 | 94 | * <li>An annotation of type <i>ATC</i> is directly present on |
darcy@1777 | 95 | * <i>C</i> and <i>A</i> is an annotation included in the result of |
darcy@1777 | 96 | * calling the {@code value} method of the directly present annotation |
darcy@1777 | 97 | * of type <i>ATC</i>. |
darcy@1777 | 98 | * |
darcy@1777 | 99 | * </ul> |
darcy@1777 | 100 | * |
darcy@1777 | 101 | * An annotation <i>A</i> is <em>associated</em> with a construct |
darcy@1777 | 102 | * <i>C</i> if either: |
darcy@1777 | 103 | * |
darcy@1777 | 104 | * <ul> |
darcy@1777 | 105 | * |
darcy@1777 | 106 | * <li> <i>A</i> is directly or indirectly present on <i>C</i>. |
darcy@1777 | 107 | * |
darcy@1777 | 108 | * <li> No annotation of type <i>AT</i> is directly or indirectly |
darcy@1777 | 109 | * present on <i>C</i>, and <i>C</i> is a class, and <i>AT</i> is |
darcy@1777 | 110 | * inheritable, and <i>A</i> is associated with the superclass of |
darcy@1777 | 111 | * <i>C</i>. |
darcy@1651 | 112 | * |
darcy@1651 | 113 | * </ul> |
jjg@1645 | 114 | * |
jjg@1645 | 115 | * @since 1.8 |
darcy@1651 | 116 | * @jls 9.6 Annotation Types |
darcy@1651 | 117 | * @jls 9.6.3.3 @Inherited |
jjg@1645 | 118 | */ |
jjg@1645 | 119 | public interface AnnotatedConstruct { |
jjg@1645 | 120 | /** |
darcy@1651 | 121 | * Returns the annotations that are <em>directly present</em> on |
darcy@1651 | 122 | * this construct. |
jjg@1645 | 123 | * |
darcy@1651 | 124 | * @return the annotations <em>directly present</em> on this |
darcy@1651 | 125 | * construct; an empty list if there are none |
jjg@1645 | 126 | */ |
jjg@1645 | 127 | List<? extends AnnotationMirror> getAnnotationMirrors(); |
jjg@1645 | 128 | |
jjg@1645 | 129 | /** |
darcy@1777 | 130 | * Returns this construct's annotation of the specified type if |
darcy@1777 | 131 | * such an annotation is <em>present</em>, else {@code null}. |
jjg@1645 | 132 | * |
jjg@1645 | 133 | * <p> The annotation returned by this method could contain an element |
jjg@1645 | 134 | * whose value is of type {@code Class}. |
jjg@1645 | 135 | * This value cannot be returned directly: information necessary to |
jjg@1645 | 136 | * locate and load a class (such as the class loader to use) is |
jjg@1645 | 137 | * not available, and the class might not be loadable at all. |
jjg@1645 | 138 | * Attempting to read a {@code Class} object by invoking the relevant |
jjg@1645 | 139 | * method on the returned annotation |
jjg@1645 | 140 | * will result in a {@link MirroredTypeException}, |
jjg@1645 | 141 | * from which the corresponding {@link TypeMirror} may be extracted. |
jjg@1645 | 142 | * Similarly, attempting to read a {@code Class[]}-valued element |
jjg@1645 | 143 | * will result in a {@link MirroredTypesException}. |
jjg@1645 | 144 | * |
jjg@1645 | 145 | * <blockquote> |
jjg@1645 | 146 | * <i>Note:</i> This method is unlike others in this and related |
jjg@1645 | 147 | * interfaces. It operates on runtime reflective information — |
jjg@1645 | 148 | * representations of annotation types currently loaded into the |
jjg@1645 | 149 | * VM — rather than on the representations defined by and used |
jjg@1645 | 150 | * throughout these interfaces. Consequently, calling methods on |
jjg@1645 | 151 | * the returned annotation object can throw many of the exceptions |
jjg@1645 | 152 | * that can be thrown when calling methods on an annotation object |
jjg@1645 | 153 | * returned by core reflection. This method is intended for |
jjg@1645 | 154 | * callers that are written to operate on a known, fixed set of |
jjg@1645 | 155 | * annotation types. |
jjg@1645 | 156 | * </blockquote> |
jjg@1645 | 157 | * |
jjg@1645 | 158 | * @param <A> the annotation type |
jjg@1645 | 159 | * @param annotationType the {@code Class} object corresponding to |
jjg@1645 | 160 | * the annotation type |
darcy@1777 | 161 | * @return this construct's annotation for the specified |
darcy@1777 | 162 | * annotation type if present, else {@code null} |
jjg@1645 | 163 | * |
jjg@1645 | 164 | * @see #getAnnotationMirrors() |
jjg@1645 | 165 | * @see java.lang.reflect.AnnotatedElement#getAnnotation |
jjg@1645 | 166 | * @see EnumConstantNotPresentException |
jjg@1645 | 167 | * @see AnnotationTypeMismatchException |
jjg@1645 | 168 | * @see IncompleteAnnotationException |
jjg@1645 | 169 | * @see MirroredTypeException |
jjg@1645 | 170 | * @see MirroredTypesException |
darcy@1651 | 171 | * @jls 9.6.1 Annotation Type Elements |
jjg@1645 | 172 | */ |
jjg@1645 | 173 | <A extends Annotation> A getAnnotation(Class<A> annotationType); |
jjg@1645 | 174 | |
jjg@1645 | 175 | /** |
darcy@1777 | 176 | * Returns annotations that are <em>associated</em> with this construct. |
jjg@1645 | 177 | * |
darcy@1777 | 178 | * If there are no annotations associated with this construct, the |
darcy@1777 | 179 | * return value is an array of length 0. |
darcy@1777 | 180 | * |
darcy@1777 | 181 | * The order of annotations which are directly or indirectly |
darcy@1777 | 182 | * present on a construct <i>C</i> is computed as if indirectly present |
darcy@1777 | 183 | * annotations on <i>C</i> are directly present on <i>C</i> in place of their |
darcy@1777 | 184 | * container annotation, in the order in which they appear in the |
darcy@1777 | 185 | * value element of the container annotation. |
jjg@1645 | 186 | * |
jjg@1645 | 187 | * The difference between this method and {@link #getAnnotation(Class)} |
jjg@1645 | 188 | * is that this method detects if its argument is a <em>repeatable |
darcy@1651 | 189 | * annotation type</em>, and if so, attempts to find one or more |
jjg@1645 | 190 | * annotations of that type by "looking through" a container annotation. |
jjg@1645 | 191 | * |
jjg@1645 | 192 | * <p> The annotations returned by this method could contain an element |
jjg@1645 | 193 | * whose value is of type {@code Class}. |
jjg@1645 | 194 | * This value cannot be returned directly: information necessary to |
jjg@1645 | 195 | * locate and load a class (such as the class loader to use) is |
jjg@1645 | 196 | * not available, and the class might not be loadable at all. |
jjg@1645 | 197 | * Attempting to read a {@code Class} object by invoking the relevant |
jjg@1645 | 198 | * method on the returned annotation |
jjg@1645 | 199 | * will result in a {@link MirroredTypeException}, |
jjg@1645 | 200 | * from which the corresponding {@link TypeMirror} may be extracted. |
jjg@1645 | 201 | * Similarly, attempting to read a {@code Class[]}-valued element |
jjg@1645 | 202 | * will result in a {@link MirroredTypesException}. |
jjg@1645 | 203 | * |
jjg@1645 | 204 | * <blockquote> |
jjg@1645 | 205 | * <i>Note:</i> This method is unlike others in this and related |
jjg@1645 | 206 | * interfaces. It operates on runtime reflective information — |
jjg@1645 | 207 | * representations of annotation types currently loaded into the |
jjg@1645 | 208 | * VM — rather than on the representations defined by and used |
jjg@1645 | 209 | * throughout these interfaces. Consequently, calling methods on |
jjg@1645 | 210 | * the returned annotation object can throw many of the exceptions |
jjg@1645 | 211 | * that can be thrown when calling methods on an annotation object |
jjg@1645 | 212 | * returned by core reflection. This method is intended for |
jjg@1645 | 213 | * callers that are written to operate on a known, fixed set of |
jjg@1645 | 214 | * annotation types. |
jjg@1645 | 215 | * </blockquote> |
jjg@1645 | 216 | * |
jjg@1645 | 217 | * @param <A> the annotation type |
jjg@1645 | 218 | * @param annotationType the {@code Class} object corresponding to |
jjg@1645 | 219 | * the annotation type |
darcy@1777 | 220 | * @return this construct's annotations for the specified annotation |
darcy@1777 | 221 | * type if present on this construct, else an empty array |
jjg@1645 | 222 | * |
jjg@1645 | 223 | * @see #getAnnotationMirrors() |
jjg@1645 | 224 | * @see #getAnnotation(java.lang.Class) |
jjg@1645 | 225 | * @see java.lang.reflect.AnnotatedElement#getAnnotationsByType |
jjg@1645 | 226 | * @see EnumConstantNotPresentException |
jjg@1645 | 227 | * @see AnnotationTypeMismatchException |
jjg@1645 | 228 | * @see IncompleteAnnotationException |
jjg@1645 | 229 | * @see MirroredTypeException |
jjg@1645 | 230 | * @see MirroredTypesException |
darcy@1651 | 231 | * @jls 9.6 Annotation Types |
darcy@1651 | 232 | * @jls 9.6.1 Annotation Type Elements |
jjg@1645 | 233 | */ |
jjg@1645 | 234 | <A extends Annotation> A[] getAnnotationsByType(Class<A> annotationType); |
jjg@1645 | 235 | } |