Mon, 07 Oct 2013 16:51:56 -0700
8026017: Make history of AnnotatedConstruct methods in jx.l.m.e.Element clearer
Reviewed-by: jjg
duke@1 | 1 | /* |
jfranck@1491 | 2 | * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. |
duke@1 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@1 | 4 | * |
duke@1 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@1 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ohair@554 | 7 | * published by the Free Software Foundation. Oracle designates this |
duke@1 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair@554 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
duke@1 | 10 | * |
duke@1 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@1 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@1 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@1 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@1 | 15 | * accompanied this code). |
duke@1 | 16 | * |
duke@1 | 17 | * You should have received a copy of the GNU General Public License version |
duke@1 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@1 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@1 | 20 | * |
ohair@554 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@554 | 22 | * or visit www.oracle.com if you need additional information or have any |
ohair@554 | 23 | * questions. |
duke@1 | 24 | */ |
duke@1 | 25 | |
duke@1 | 26 | package javax.lang.model.element; |
duke@1 | 27 | |
duke@1 | 28 | |
duke@1 | 29 | import java.lang.annotation.Annotation; |
duke@1 | 30 | import java.lang.annotation.AnnotationTypeMismatchException; |
duke@1 | 31 | import java.lang.annotation.IncompleteAnnotationException; |
duke@1 | 32 | import java.util.List; |
duke@1 | 33 | import java.util.Set; |
duke@1 | 34 | |
duke@1 | 35 | import javax.lang.model.type.*; |
duke@1 | 36 | import javax.lang.model.util.*; |
duke@1 | 37 | |
duke@1 | 38 | |
duke@1 | 39 | /** |
duke@1 | 40 | * Represents a program element such as a package, class, or method. |
duke@1 | 41 | * Each element represents a static, language-level construct |
duke@1 | 42 | * (and not, for example, a runtime construct of the virtual machine). |
duke@1 | 43 | * |
duke@1 | 44 | * <p> Elements should be compared using the {@link #equals(Object)} |
duke@1 | 45 | * method. There is no guarantee that any particular element will |
duke@1 | 46 | * always be represented by the same object. |
duke@1 | 47 | * |
duke@1 | 48 | * <p> To implement operations based on the class of an {@code |
duke@1 | 49 | * Element} object, either use a {@linkplain ElementVisitor visitor} or |
duke@1 | 50 | * use the result of the {@link #getKind} method. Using {@code |
duke@1 | 51 | * instanceof} is <em>not</em> necessarily a reliable idiom for |
duke@1 | 52 | * determining the effective class of an object in this modeling |
duke@1 | 53 | * hierarchy since an implementation may choose to have a single object |
duke@1 | 54 | * implement multiple {@code Element} subinterfaces. |
duke@1 | 55 | * |
duke@1 | 56 | * @author Joseph D. Darcy |
duke@1 | 57 | * @author Scott Seligman |
duke@1 | 58 | * @author Peter von der Ahé |
duke@1 | 59 | * @see Elements |
duke@1 | 60 | * @see TypeMirror |
duke@1 | 61 | * @since 1.6 |
duke@1 | 62 | */ |
jjg@1645 | 63 | public interface Element extends javax.lang.model.AnnotatedConstruct { |
duke@1 | 64 | /** |
duke@1 | 65 | * Returns the type defined by this element. |
duke@1 | 66 | * |
duke@1 | 67 | * <p> A generic element defines a family of types, not just one. |
duke@1 | 68 | * If this is a generic element, a <i>prototypical</i> type is |
duke@1 | 69 | * returned. This is the element's invocation on the |
duke@1 | 70 | * type variables corresponding to its own formal type parameters. |
duke@1 | 71 | * For example, |
duke@1 | 72 | * for the generic class element {@code C<N extends Number>}, |
duke@1 | 73 | * the parameterized type {@code C<N>} is returned. |
duke@1 | 74 | * The {@link Types} utility interface has more general methods |
duke@1 | 75 | * for obtaining the full range of types defined by an element. |
duke@1 | 76 | * |
duke@1 | 77 | * @see Types |
duke@1 | 78 | * |
duke@1 | 79 | * @return the type defined by this element |
duke@1 | 80 | */ |
duke@1 | 81 | TypeMirror asType(); |
duke@1 | 82 | |
duke@1 | 83 | /** |
duke@1 | 84 | * Returns the {@code kind} of this element. |
duke@1 | 85 | * |
duke@1 | 86 | * @return the kind of this element |
duke@1 | 87 | */ |
duke@1 | 88 | ElementKind getKind(); |
duke@1 | 89 | |
duke@1 | 90 | /** |
duke@1 | 91 | * Returns the modifiers of this element, excluding annotations. |
duke@1 | 92 | * Implicit modifiers, such as the {@code public} and {@code static} |
duke@1 | 93 | * modifiers of interface members, are included. |
duke@1 | 94 | * |
duke@1 | 95 | * @return the modifiers of this element, or an empty set if there are none |
duke@1 | 96 | */ |
duke@1 | 97 | Set<Modifier> getModifiers(); |
duke@1 | 98 | |
duke@1 | 99 | /** |
darcy@849 | 100 | * Returns the simple (unqualified) name of this element. The |
darcy@849 | 101 | * name of a generic type does not include any reference to its |
darcy@849 | 102 | * formal type parameters. |
darcy@849 | 103 | * |
darcy@849 | 104 | * For example, the simple name of the type element {@code |
darcy@849 | 105 | * java.util.Set<E>} is {@code "Set"}. |
darcy@849 | 106 | * |
darcy@849 | 107 | * If this element represents an unnamed {@linkplain |
darcy@849 | 108 | * PackageElement#getSimpleName package}, an empty name is |
duke@1 | 109 | * returned. |
duke@1 | 110 | * |
darcy@849 | 111 | * If it represents a {@linkplain ExecutableElement#getSimpleName |
darcy@849 | 112 | * constructor}, the name "{@code <init>}" is returned. If it |
darcy@849 | 113 | * represents a {@linkplain ExecutableElement#getSimpleName static |
darcy@849 | 114 | * initializer}, the name "{@code <clinit>}" is returned. |
darcy@849 | 115 | * |
darcy@849 | 116 | * If it represents an {@linkplain TypeElement#getSimpleName |
darcy@849 | 117 | * anonymous class} or {@linkplain ExecutableElement#getSimpleName |
darcy@849 | 118 | * instance initializer}, an empty name is returned. |
darcy@849 | 119 | * |
duke@1 | 120 | * @return the simple name of this element |
darcy@1484 | 121 | * @see PackageElement#getSimpleName |
darcy@1484 | 122 | * @see ExecutableElement#getSimpleName |
darcy@1484 | 123 | * @see TypeElement#getSimpleName |
darcy@1484 | 124 | * @see VariableElement#getSimpleName |
duke@1 | 125 | */ |
duke@1 | 126 | Name getSimpleName(); |
duke@1 | 127 | |
duke@1 | 128 | /** |
duke@1 | 129 | * Returns the innermost element |
duke@1 | 130 | * within which this element is, loosely speaking, enclosed. |
duke@1 | 131 | * <ul> |
duke@1 | 132 | * <li> If this element is one whose declaration is lexically enclosed |
duke@1 | 133 | * immediately within the declaration of another element, that other |
duke@1 | 134 | * element is returned. |
darcy@849 | 135 | * |
darcy@849 | 136 | * <li> If this is a {@linkplain TypeElement#getEnclosingElement |
darcy@849 | 137 | * top-level type}, its package is returned. |
darcy@849 | 138 | * |
darcy@849 | 139 | * <li> If this is a {@linkplain |
darcy@849 | 140 | * PackageElement#getEnclosingElement package}, {@code null} is |
darcy@849 | 141 | * returned. |
darcy@926 | 142 | * |
darcy@849 | 143 | * <li> If this is a {@linkplain |
darcy@849 | 144 | * TypeParameterElement#getEnclosingElement type parameter}, |
darcy@926 | 145 | * {@linkplain TypeParameterElement#getGenericElement the |
darcy@926 | 146 | * generic element} of the type parameter is returned. |
darcy@926 | 147 | * |
darcy@1484 | 148 | * <li> If this is a {@linkplain |
darcy@1484 | 149 | * VariableElement#getEnclosingElement method or constructor |
darcy@1484 | 150 | * parameter}, {@linkplain ExecutableElement the executable |
darcy@1484 | 151 | * element} which declares the parameter is returned. |
darcy@1484 | 152 | * |
duke@1 | 153 | * </ul> |
duke@1 | 154 | * |
duke@1 | 155 | * @return the enclosing element, or {@code null} if there is none |
duke@1 | 156 | * @see Elements#getPackageOf |
duke@1 | 157 | */ |
duke@1 | 158 | Element getEnclosingElement(); |
duke@1 | 159 | |
duke@1 | 160 | /** |
duke@1 | 161 | * Returns the elements that are, loosely speaking, directly |
duke@1 | 162 | * enclosed by this element. |
duke@1 | 163 | * |
darcy@1181 | 164 | * A {@linkplain TypeElement#getEnclosedElements class or |
darcy@1181 | 165 | * interface} is considered to enclose the fields, methods, |
darcy@1181 | 166 | * constructors, and member types that it directly declares. |
duke@1 | 167 | * |
darcy@1181 | 168 | * A {@linkplain PackageElement#getEnclosedElements package} |
darcy@1181 | 169 | * encloses the top-level classes and interfaces within it, but is |
darcy@1181 | 170 | * not considered to enclose subpackages. |
duke@1 | 171 | * |
duke@1 | 172 | * Other kinds of elements are not currently considered to enclose |
duke@1 | 173 | * any elements; however, that may change as this API or the |
duke@1 | 174 | * programming language evolves. |
duke@1 | 175 | * |
duke@1 | 176 | * <p>Note that elements of certain kinds can be isolated using |
duke@1 | 177 | * methods in {@link ElementFilter}. |
duke@1 | 178 | * |
duke@1 | 179 | * @return the enclosed elements, or an empty list if none |
darcy@1181 | 180 | * @see PackageElement#getEnclosedElements |
darcy@1181 | 181 | * @see TypeElement#getEnclosedElements |
duke@1 | 182 | * @see Elements#getAllMembers |
jjh@972 | 183 | * @jls 8.8.9 Default Constructor |
jjh@972 | 184 | * @jls 8.9 Enums |
duke@1 | 185 | */ |
duke@1 | 186 | List<? extends Element> getEnclosedElements(); |
duke@1 | 187 | |
duke@1 | 188 | /** |
duke@1 | 189 | * Returns {@code true} if the argument represents the same |
duke@1 | 190 | * element as {@code this}, or {@code false} otherwise. |
duke@1 | 191 | * |
duke@1 | 192 | * <p>Note that the identity of an element involves implicit state |
duke@1 | 193 | * not directly accessible from the element's methods, including |
duke@1 | 194 | * state about the presence of unrelated types. Element objects |
duke@1 | 195 | * created by different implementations of these interfaces should |
duke@1 | 196 | * <i>not</i> be expected to be equal even if "the same" |
duke@1 | 197 | * element is being modeled; this is analogous to the inequality |
duke@1 | 198 | * of {@code Class} objects for the same class file loaded through |
duke@1 | 199 | * different class loaders. |
duke@1 | 200 | * |
duke@1 | 201 | * @param obj the object to be compared with this element |
duke@1 | 202 | * @return {@code true} if the specified object represents the same |
duke@1 | 203 | * element as this |
duke@1 | 204 | */ |
darcy@2091 | 205 | @Override |
duke@1 | 206 | boolean equals(Object obj); |
duke@1 | 207 | |
duke@1 | 208 | /** |
duke@1 | 209 | * Obeys the general contract of {@link Object#hashCode Object.hashCode}. |
duke@1 | 210 | * |
duke@1 | 211 | * @see #equals |
duke@1 | 212 | */ |
darcy@2091 | 213 | @Override |
duke@1 | 214 | int hashCode(); |
duke@1 | 215 | |
jjg@1645 | 216 | |
jjg@1645 | 217 | /** |
jjg@1645 | 218 | * {@inheritDoc} |
jjg@1645 | 219 | * |
jjg@1645 | 220 | * <p> To get inherited annotations as well, use {@link |
jjg@1645 | 221 | * Elements#getAllAnnotationMirrors(Element) |
jjg@1645 | 222 | * getAllAnnotationMirrors}. |
jjg@1645 | 223 | * |
jjg@1645 | 224 | * @since 1.6 |
jjg@1645 | 225 | */ |
jjg@1645 | 226 | @Override |
jjg@1645 | 227 | List<? extends AnnotationMirror> getAnnotationMirrors(); |
darcy@2091 | 228 | |
darcy@2091 | 229 | /** |
darcy@2091 | 230 | * {@inheritDoc} |
darcy@2091 | 231 | * @since 1.6 |
darcy@2091 | 232 | */ |
darcy@2091 | 233 | @Override |
darcy@2091 | 234 | <A extends Annotation> A getAnnotation(Class<A> annotationType); |
darcy@2091 | 235 | |
duke@1 | 236 | /** |
duke@1 | 237 | * Applies a visitor to this element. |
duke@1 | 238 | * |
duke@1 | 239 | * @param <R> the return type of the visitor's methods |
duke@1 | 240 | * @param <P> the type of the additional parameter to the visitor's methods |
duke@1 | 241 | * @param v the visitor operating on this element |
duke@1 | 242 | * @param p additional parameter to the visitor |
duke@1 | 243 | * @return a visitor-specified result |
duke@1 | 244 | */ |
duke@1 | 245 | <R, P> R accept(ElementVisitor<R, P> v, P p); |
duke@1 | 246 | } |