< prev index next >

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

Print this page




  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javax.lang.model.element;
  27 
  28 
  29 import java.lang.annotation.Annotation;
  30 import java.lang.annotation.AnnotationTypeMismatchException;
  31 import java.lang.annotation.IncompleteAnnotationException;
  32 import java.util.List;
  33 import java.util.Set;
  34 
  35 import javax.lang.model.type.*;
  36 import javax.lang.model.util.*;
  37 
  38 
  39 /**
  40  * Represents a program element such as a package, class, or method.
  41  * Each element represents a static, language-level construct
  42  * (and not, for example, a runtime construct of the virtual machine).
  43  *
  44  * <p> Elements should be compared using the {@link #equals(Object)}
  45  * method.  There is no guarantee that any particular element will
  46  * always be represented by the same object.
  47  *
  48  * <p> To implement operations based on the class of an {@code
  49  * Element} object, either use a {@linkplain ElementVisitor visitor} or
  50  * use the result of the {@link #getKind} method.  Using {@code
  51  * instanceof} is <em>not</em> necessarily a reliable idiom for
  52  * determining the effective class of an object in this modeling
  53  * hierarchy since an implementation may choose to have a single object
  54  * implement multiple {@code Element} subinterfaces.
  55  *
  56  * @author Joseph D. Darcy
  57  * @author Scott Seligman
  58  * @author Peter von der Ah&eacute;
  59  * @see Elements
  60  * @see TypeMirror


 163 
 164     /**
 165      * Returns the elements that are, loosely speaking, directly
 166      * enclosed by this element.
 167      *
 168      * A {@linkplain TypeElement#getEnclosedElements class or
 169      * interface} is considered to enclose the fields, methods,
 170      * constructors, and member types that it directly declares.
 171      *
 172      * A {@linkplain PackageElement#getEnclosedElements package}
 173      * encloses the top-level classes and interfaces within it, but is
 174      * not considered to enclose subpackages.
 175      *
 176      * A {@linkplain ModuleElement#getEnclosedElements module}
 177      * encloses packages within it.
 178      *
 179      * Other kinds of elements are not currently considered to enclose
 180      * any elements; however, that may change as this API or the
 181      * programming language evolves.
 182      *
 183      * <p>Note that elements of certain kinds can be isolated using
 184      * methods in {@link ElementFilter}.
 185      *
 186      * @return the enclosed elements, or an empty list if none
 187      * @see TypeElement#getEnclosedElements
 188      * @see PackageElement#getEnclosedElements
 189      * @see ModuleElement#getEnclosedElements
 190      * @see Elements#getAllMembers
 191      * @jls 8.8.9 Default Constructor
 192      * @jls 8.9 Enums
 193      */
 194     List<? extends Element> getEnclosedElements();
 195 
 196     /**
 197      * Returns {@code true} if the argument represents the same
 198      * element as {@code this}, or {@code false} otherwise.
 199      *
 200      * <p>Note that the identity of an element involves implicit state
 201      * not directly accessible from the element's methods, including
 202      * state about the presence of unrelated types.  Element objects
 203      * created by different implementations of these interfaces should
 204      * <i>not</i> be expected to be equal even if &quot;the same&quot;
 205      * element is being modeled; this is analogous to the inequality
 206      * of {@code Class} objects for the same class file loaded through
 207      * different class loaders.
 208      *
 209      * @param obj  the object to be compared with this element
 210      * @return {@code true} if the specified object represents the same
 211      *          element as this
 212      */
 213     @Override
 214     boolean equals(Object obj);
 215 
 216     /**
 217      * Obeys the general contract of {@link Object#hashCode Object.hashCode}.
 218      *
 219      * @see #equals
 220      */




  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javax.lang.model.element;
  27 
  28 
  29 import java.lang.annotation.Annotation;
  30 import java.lang.annotation.AnnotationTypeMismatchException;
  31 import java.lang.annotation.IncompleteAnnotationException;
  32 import java.util.List;
  33 import java.util.Set;
  34 
  35 import javax.lang.model.type.*;
  36 import javax.lang.model.util.*;
  37 
  38 
  39 /**
  40  * Represents a program element such as a module, package, class, or method.
  41  * Each element represents a static, language-level construct
  42  * (and not, for example, a runtime construct of the virtual machine).
  43  *
  44  * <p> Elements should be compared using the {@link #equals(Object)}
  45  * method.  There is no guarantee that any particular element will
  46  * always be represented by the same object.
  47  *
  48  * <p> To implement operations based on the class of an {@code
  49  * Element} object, either use a {@linkplain ElementVisitor visitor} or
  50  * use the result of the {@link #getKind} method.  Using {@code
  51  * instanceof} is <em>not</em> necessarily a reliable idiom for
  52  * determining the effective class of an object in this modeling
  53  * hierarchy since an implementation may choose to have a single object
  54  * implement multiple {@code Element} subinterfaces.
  55  *
  56  * @author Joseph D. Darcy
  57  * @author Scott Seligman
  58  * @author Peter von der Ah&eacute;
  59  * @see Elements
  60  * @see TypeMirror


 163 
 164     /**
 165      * Returns the elements that are, loosely speaking, directly
 166      * enclosed by this element.
 167      *
 168      * A {@linkplain TypeElement#getEnclosedElements class or
 169      * interface} is considered to enclose the fields, methods,
 170      * constructors, and member types that it directly declares.
 171      *
 172      * A {@linkplain PackageElement#getEnclosedElements package}
 173      * encloses the top-level classes and interfaces within it, but is
 174      * not considered to enclose subpackages.
 175      *
 176      * A {@linkplain ModuleElement#getEnclosedElements module}
 177      * encloses packages within it.
 178      *
 179      * Other kinds of elements are not currently considered to enclose
 180      * any elements; however, that may change as this API or the
 181      * programming language evolves.
 182      *
 183      * @apiNote Elements of certain kinds can be isolated using
 184      * methods in {@link ElementFilter}.
 185      *
 186      * @return the enclosed elements, or an empty list if none
 187      * @see TypeElement#getEnclosedElements
 188      * @see PackageElement#getEnclosedElements
 189      * @see ModuleElement#getEnclosedElements
 190      * @see Elements#getAllMembers
 191      * @jls 8.8.9 Default Constructor
 192      * @jls 8.9 Enums
 193      */
 194     List<? extends Element> getEnclosedElements();
 195 
 196     /**
 197      * Returns {@code true} if the argument represents the same
 198      * element as {@code this}, or {@code false} otherwise.
 199      *
 200      * @apiNote The identity of an element involves implicit state
 201      * not directly accessible from the element's methods, including
 202      * state about the presence of unrelated types.  Element objects
 203      * created by different implementations of these interfaces should
 204      * <i>not</i> be expected to be equal even if &quot;the same&quot;
 205      * element is being modeled; this is analogous to the inequality
 206      * of {@code Class} objects for the same class file loaded through
 207      * different class loaders.
 208      *
 209      * @param obj  the object to be compared with this element
 210      * @return {@code true} if the specified object represents the same
 211      *          element as this
 212      */
 213     @Override
 214     boolean equals(Object obj);
 215 
 216     /**
 217      * Obeys the general contract of {@link Object#hashCode Object.hashCode}.
 218      *
 219      * @see #equals
 220      */


< prev index next >