src/share/classes/javax/lang/model/element/Element.java

Thu, 31 Aug 2017 15:17:03 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:17:03 +0800
changeset 2525
2eb010b6cb22
parent 2091
4dd7ffbf01fb
parent 0
959103a6100f
permissions
-rw-r--r--

merge

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

mercurial