Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/src/share/classes/javax/lang/model/element/Element.java
38899 views
/*1* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.lang.model.element;262728import java.lang.annotation.Annotation;29import java.lang.annotation.AnnotationTypeMismatchException;30import java.lang.annotation.IncompleteAnnotationException;31import java.util.List;32import java.util.Set;3334import javax.lang.model.type.*;35import javax.lang.model.util.*;363738/**39* Represents a program element such as a package, class, or method.40* Each element represents a static, language-level construct41* (and not, for example, a runtime construct of the virtual machine).42*43* <p> Elements should be compared using the {@link #equals(Object)}44* method. There is no guarantee that any particular element will45* always be represented by the same object.46*47* <p> To implement operations based on the class of an {@code48* Element} object, either use a {@linkplain ElementVisitor visitor} or49* use the result of the {@link #getKind} method. Using {@code50* instanceof} is <em>not</em> necessarily a reliable idiom for51* determining the effective class of an object in this modeling52* hierarchy since an implementation may choose to have a single object53* implement multiple {@code Element} subinterfaces.54*55* @author Joseph D. Darcy56* @author Scott Seligman57* @author Peter von der Ahé58* @see Elements59* @see TypeMirror60* @since 1.661*/62public interface Element extends javax.lang.model.AnnotatedConstruct {63/**64* Returns the type defined by this element.65*66* <p> A generic element defines a family of types, not just one.67* If this is a generic element, a <i>prototypical</i> type is68* returned. This is the element's invocation on the69* type variables corresponding to its own formal type parameters.70* For example,71* for the generic class element {@code C<N extends Number>},72* the parameterized type {@code C<N>} is returned.73* The {@link Types} utility interface has more general methods74* for obtaining the full range of types defined by an element.75*76* @see Types77*78* @return the type defined by this element79*/80TypeMirror asType();8182/**83* Returns the {@code kind} of this element.84*85* @return the kind of this element86*/87ElementKind getKind();8889/**90* Returns the modifiers of this element, excluding annotations.91* Implicit modifiers, such as the {@code public} and {@code static}92* modifiers of interface members, are included.93*94* @return the modifiers of this element, or an empty set if there are none95*/96Set<Modifier> getModifiers();9798/**99* Returns the simple (unqualified) name of this element. The100* name of a generic type does not include any reference to its101* formal type parameters.102*103* For example, the simple name of the type element {@code104* java.util.Set<E>} is {@code "Set"}.105*106* If this element represents an unnamed {@linkplain107* PackageElement#getSimpleName package}, an empty name is108* returned.109*110* If it represents a {@linkplain ExecutableElement#getSimpleName111* constructor}, the name "{@code <init>}" is returned. If it112* represents a {@linkplain ExecutableElement#getSimpleName static113* initializer}, the name "{@code <clinit>}" is returned.114*115* If it represents an {@linkplain TypeElement#getSimpleName116* anonymous class} or {@linkplain ExecutableElement#getSimpleName117* instance initializer}, an empty name is returned.118*119* @return the simple name of this element120* @see PackageElement#getSimpleName121* @see ExecutableElement#getSimpleName122* @see TypeElement#getSimpleName123* @see VariableElement#getSimpleName124*/125Name getSimpleName();126127/**128* Returns the innermost element129* within which this element is, loosely speaking, enclosed.130* <ul>131* <li> If this element is one whose declaration is lexically enclosed132* immediately within the declaration of another element, that other133* element is returned.134*135* <li> If this is a {@linkplain TypeElement#getEnclosingElement136* top-level type}, its package is returned.137*138* <li> If this is a {@linkplain139* PackageElement#getEnclosingElement package}, {@code null} is140* returned.141*142* <li> If this is a {@linkplain143* TypeParameterElement#getEnclosingElement type parameter},144* {@linkplain TypeParameterElement#getGenericElement the145* generic element} of the type parameter is returned.146*147* <li> If this is a {@linkplain148* VariableElement#getEnclosingElement method or constructor149* parameter}, {@linkplain ExecutableElement the executable150* element} which declares the parameter is returned.151*152* </ul>153*154* @return the enclosing element, or {@code null} if there is none155* @see Elements#getPackageOf156*/157Element getEnclosingElement();158159/**160* Returns the elements that are, loosely speaking, directly161* enclosed by this element.162*163* A {@linkplain TypeElement#getEnclosedElements class or164* interface} is considered to enclose the fields, methods,165* constructors, and member types that it directly declares.166*167* A {@linkplain PackageElement#getEnclosedElements package}168* encloses the top-level classes and interfaces within it, but is169* not considered to enclose subpackages.170*171* Other kinds of elements are not currently considered to enclose172* any elements; however, that may change as this API or the173* programming language evolves.174*175* <p>Note that elements of certain kinds can be isolated using176* methods in {@link ElementFilter}.177*178* @return the enclosed elements, or an empty list if none179* @see PackageElement#getEnclosedElements180* @see TypeElement#getEnclosedElements181* @see Elements#getAllMembers182* @jls 8.8.9 Default Constructor183* @jls 8.9 Enums184*/185List<? extends Element> getEnclosedElements();186187/**188* Returns {@code true} if the argument represents the same189* element as {@code this}, or {@code false} otherwise.190*191* <p>Note that the identity of an element involves implicit state192* not directly accessible from the element's methods, including193* state about the presence of unrelated types. Element objects194* created by different implementations of these interfaces should195* <i>not</i> be expected to be equal even if "the same"196* element is being modeled; this is analogous to the inequality197* of {@code Class} objects for the same class file loaded through198* different class loaders.199*200* @param obj the object to be compared with this element201* @return {@code true} if the specified object represents the same202* element as this203*/204@Override205boolean equals(Object obj);206207/**208* Obeys the general contract of {@link Object#hashCode Object.hashCode}.209*210* @see #equals211*/212@Override213int hashCode();214215216/**217* {@inheritDoc}218*219* <p> To get inherited annotations as well, use {@link220* Elements#getAllAnnotationMirrors(Element)221* getAllAnnotationMirrors}.222*223* @since 1.6224*/225@Override226List<? extends AnnotationMirror> getAnnotationMirrors();227228/**229* {@inheritDoc}230* @since 1.6231*/232@Override233<A extends Annotation> A getAnnotation(Class<A> annotationType);234235/**236* Applies a visitor to this element.237*238* @param <R> the return type of the visitor's methods239* @param <P> the type of the additional parameter to the visitor's methods240* @param v the visitor operating on this element241* @param p additional parameter to the visitor242* @return a visitor-specified result243*/244<R, P> R accept(ElementVisitor<R, P> v, P p);245}246247248