1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/classes/javax/lang/model/element/Element.java Wed Apr 27 01:34:52 2016 +0800 1.3 @@ -0,0 +1,246 @@ 1.4 +/* 1.5 + * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + */ 1.28 + 1.29 +package javax.lang.model.element; 1.30 + 1.31 + 1.32 +import java.lang.annotation.Annotation; 1.33 +import java.lang.annotation.AnnotationTypeMismatchException; 1.34 +import java.lang.annotation.IncompleteAnnotationException; 1.35 +import java.util.List; 1.36 +import java.util.Set; 1.37 + 1.38 +import javax.lang.model.type.*; 1.39 +import javax.lang.model.util.*; 1.40 + 1.41 + 1.42 +/** 1.43 + * Represents a program element such as a package, class, or method. 1.44 + * Each element represents a static, language-level construct 1.45 + * (and not, for example, a runtime construct of the virtual machine). 1.46 + * 1.47 + * <p> Elements should be compared using the {@link #equals(Object)} 1.48 + * method. There is no guarantee that any particular element will 1.49 + * always be represented by the same object. 1.50 + * 1.51 + * <p> To implement operations based on the class of an {@code 1.52 + * Element} object, either use a {@linkplain ElementVisitor visitor} or 1.53 + * use the result of the {@link #getKind} method. Using {@code 1.54 + * instanceof} is <em>not</em> necessarily a reliable idiom for 1.55 + * determining the effective class of an object in this modeling 1.56 + * hierarchy since an implementation may choose to have a single object 1.57 + * implement multiple {@code Element} subinterfaces. 1.58 + * 1.59 + * @author Joseph D. Darcy 1.60 + * @author Scott Seligman 1.61 + * @author Peter von der Ahé 1.62 + * @see Elements 1.63 + * @see TypeMirror 1.64 + * @since 1.6 1.65 + */ 1.66 +public interface Element extends javax.lang.model.AnnotatedConstruct { 1.67 + /** 1.68 + * Returns the type defined by this element. 1.69 + * 1.70 + * <p> A generic element defines a family of types, not just one. 1.71 + * If this is a generic element, a <i>prototypical</i> type is 1.72 + * returned. This is the element's invocation on the 1.73 + * type variables corresponding to its own formal type parameters. 1.74 + * For example, 1.75 + * for the generic class element {@code C<N extends Number>}, 1.76 + * the parameterized type {@code C<N>} is returned. 1.77 + * The {@link Types} utility interface has more general methods 1.78 + * for obtaining the full range of types defined by an element. 1.79 + * 1.80 + * @see Types 1.81 + * 1.82 + * @return the type defined by this element 1.83 + */ 1.84 + TypeMirror asType(); 1.85 + 1.86 + /** 1.87 + * Returns the {@code kind} of this element. 1.88 + * 1.89 + * @return the kind of this element 1.90 + */ 1.91 + ElementKind getKind(); 1.92 + 1.93 + /** 1.94 + * Returns the modifiers of this element, excluding annotations. 1.95 + * Implicit modifiers, such as the {@code public} and {@code static} 1.96 + * modifiers of interface members, are included. 1.97 + * 1.98 + * @return the modifiers of this element, or an empty set if there are none 1.99 + */ 1.100 + Set<Modifier> getModifiers(); 1.101 + 1.102 + /** 1.103 + * Returns the simple (unqualified) name of this element. The 1.104 + * name of a generic type does not include any reference to its 1.105 + * formal type parameters. 1.106 + * 1.107 + * For example, the simple name of the type element {@code 1.108 + * java.util.Set<E>} is {@code "Set"}. 1.109 + * 1.110 + * If this element represents an unnamed {@linkplain 1.111 + * PackageElement#getSimpleName package}, an empty name is 1.112 + * returned. 1.113 + * 1.114 + * If it represents a {@linkplain ExecutableElement#getSimpleName 1.115 + * constructor}, the name "{@code <init>}" is returned. If it 1.116 + * represents a {@linkplain ExecutableElement#getSimpleName static 1.117 + * initializer}, the name "{@code <clinit>}" is returned. 1.118 + * 1.119 + * If it represents an {@linkplain TypeElement#getSimpleName 1.120 + * anonymous class} or {@linkplain ExecutableElement#getSimpleName 1.121 + * instance initializer}, an empty name is returned. 1.122 + * 1.123 + * @return the simple name of this element 1.124 + * @see PackageElement#getSimpleName 1.125 + * @see ExecutableElement#getSimpleName 1.126 + * @see TypeElement#getSimpleName 1.127 + * @see VariableElement#getSimpleName 1.128 + */ 1.129 + Name getSimpleName(); 1.130 + 1.131 + /** 1.132 + * Returns the innermost element 1.133 + * within which this element is, loosely speaking, enclosed. 1.134 + * <ul> 1.135 + * <li> If this element is one whose declaration is lexically enclosed 1.136 + * immediately within the declaration of another element, that other 1.137 + * element is returned. 1.138 + * 1.139 + * <li> If this is a {@linkplain TypeElement#getEnclosingElement 1.140 + * top-level type}, its package is returned. 1.141 + * 1.142 + * <li> If this is a {@linkplain 1.143 + * PackageElement#getEnclosingElement package}, {@code null} is 1.144 + * returned. 1.145 + * 1.146 + * <li> If this is a {@linkplain 1.147 + * TypeParameterElement#getEnclosingElement type parameter}, 1.148 + * {@linkplain TypeParameterElement#getGenericElement the 1.149 + * generic element} of the type parameter is returned. 1.150 + * 1.151 + * <li> If this is a {@linkplain 1.152 + * VariableElement#getEnclosingElement method or constructor 1.153 + * parameter}, {@linkplain ExecutableElement the executable 1.154 + * element} which declares the parameter is returned. 1.155 + * 1.156 + * </ul> 1.157 + * 1.158 + * @return the enclosing element, or {@code null} if there is none 1.159 + * @see Elements#getPackageOf 1.160 + */ 1.161 + Element getEnclosingElement(); 1.162 + 1.163 + /** 1.164 + * Returns the elements that are, loosely speaking, directly 1.165 + * enclosed by this element. 1.166 + * 1.167 + * A {@linkplain TypeElement#getEnclosedElements class or 1.168 + * interface} is considered to enclose the fields, methods, 1.169 + * constructors, and member types that it directly declares. 1.170 + * 1.171 + * A {@linkplain PackageElement#getEnclosedElements package} 1.172 + * encloses the top-level classes and interfaces within it, but is 1.173 + * not considered to enclose subpackages. 1.174 + * 1.175 + * Other kinds of elements are not currently considered to enclose 1.176 + * any elements; however, that may change as this API or the 1.177 + * programming language evolves. 1.178 + * 1.179 + * <p>Note that elements of certain kinds can be isolated using 1.180 + * methods in {@link ElementFilter}. 1.181 + * 1.182 + * @return the enclosed elements, or an empty list if none 1.183 + * @see PackageElement#getEnclosedElements 1.184 + * @see TypeElement#getEnclosedElements 1.185 + * @see Elements#getAllMembers 1.186 + * @jls 8.8.9 Default Constructor 1.187 + * @jls 8.9 Enums 1.188 + */ 1.189 + List<? extends Element> getEnclosedElements(); 1.190 + 1.191 + /** 1.192 + * Returns {@code true} if the argument represents the same 1.193 + * element as {@code this}, or {@code false} otherwise. 1.194 + * 1.195 + * <p>Note that the identity of an element involves implicit state 1.196 + * not directly accessible from the element's methods, including 1.197 + * state about the presence of unrelated types. Element objects 1.198 + * created by different implementations of these interfaces should 1.199 + * <i>not</i> be expected to be equal even if "the same" 1.200 + * element is being modeled; this is analogous to the inequality 1.201 + * of {@code Class} objects for the same class file loaded through 1.202 + * different class loaders. 1.203 + * 1.204 + * @param obj the object to be compared with this element 1.205 + * @return {@code true} if the specified object represents the same 1.206 + * element as this 1.207 + */ 1.208 + @Override 1.209 + boolean equals(Object obj); 1.210 + 1.211 + /** 1.212 + * Obeys the general contract of {@link Object#hashCode Object.hashCode}. 1.213 + * 1.214 + * @see #equals 1.215 + */ 1.216 + @Override 1.217 + int hashCode(); 1.218 + 1.219 + 1.220 + /** 1.221 + * {@inheritDoc} 1.222 + * 1.223 + * <p> To get inherited annotations as well, use {@link 1.224 + * Elements#getAllAnnotationMirrors(Element) 1.225 + * getAllAnnotationMirrors}. 1.226 + * 1.227 + * @since 1.6 1.228 + */ 1.229 + @Override 1.230 + List<? extends AnnotationMirror> getAnnotationMirrors(); 1.231 + 1.232 + /** 1.233 + * {@inheritDoc} 1.234 + * @since 1.6 1.235 + */ 1.236 + @Override 1.237 + <A extends Annotation> A getAnnotation(Class<A> annotationType); 1.238 + 1.239 + /** 1.240 + * Applies a visitor to this element. 1.241 + * 1.242 + * @param <R> the return type of the visitor's methods 1.243 + * @param <P> the type of the additional parameter to the visitor's methods 1.244 + * @param v the visitor operating on this element 1.245 + * @param p additional parameter to the visitor 1.246 + * @return a visitor-specified result 1.247 + */ 1.248 + <R, P> R accept(ElementVisitor<R, P> v, P p); 1.249 +}