< prev index next >

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

Print this page




  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  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 import java.util.List;
  29 import javax.lang.model.type.*;
  30 import javax.lang.model.util.*;
  31 
  32 /**
  33  * Represents a class or interface program element.  Provides access
  34  * to information about the type and its members.  Note that an enum
  35  * type is a kind of class and an annotation type is a kind of
  36  * interface.
  37  *
  38  * <p> While a {@code TypeElement} represents a class or interface
  39  * <i>element</i>, a {@link DeclaredType} represents a class
  40  * or interface <i>type</i>, the latter being a use
  41  * (or <i>invocation</i>) of the former.
  42  * The distinction is most apparent with generic types,
  43  * for which a single element can define a whole
  44  * family of types.  For example, the element
  45  * {@code java.util.Set} corresponds to the parameterized types
  46  * {@code java.util.Set<String>} and {@code java.util.Set<Number>}
  47  * (and many others), and to the raw type {@code java.util.Set}.
  48  *
  49  * <p> Each method of this interface that returns a list of elements
  50  * will return them in the order that is natural for the underlying
  51  * source of program information.  For example, if the underlying
  52  * source of information is Java source code, then the elements will be
  53  * returned in source code order.
  54  *
  55  * @author Joseph D. Darcy


  65      *
  66      * <p>A generic element defines a family of types, not just one.
  67      * If this is a generic element, a prototypical type is
  68      * returned which has the element's invocation on the
  69      * 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 methods
  74      * for obtaining the full range of types defined by an element.
  75      *
  76      * @return the type defined by this type element
  77      *
  78      * @see Types#asMemberOf(DeclaredType, Element)
  79      * @see Types#getDeclaredType(TypeElement, TypeMirror...)
  80      */
  81     @Override
  82     TypeMirror asType();
  83 
  84     /**
  85      * Returns the fields, methods, constructors, and member types
  86      * that are directly declared in this class or interface.
  87      *
  88      * This includes any {@linkplain Elements.Origin#MANDATED
  89      * mandated} elements such as the (implicit) default constructor
  90      * and the implicit {@code values} and {@code valueOf} methods of
  91      * an enum type.
  92      *
  93      * @apiNote As a particular instance of the {@linkplain
  94      * javax.lang.model.element general accuracy requirements} and the
  95      * ordering behavior required of this interface, the list of
  96      * enclosed elements will be returned in the natural order for the
  97      * originating source of information about the type.  For example,
  98      * if the information about the type is originating from a source
  99      * file, the elements will be returned in source code order.
 100      * (However, in that case the the ordering of {@linkplain
 101      * Elements.Origin#MANDATED implicitly declared} elements, such as
 102      * default constructors, is not specified.)
 103      *
 104      * @return the enclosed elements in proper order, or an empty list if none
 105      *


 159      */
 160     TypeMirror getSuperclass();
 161 
 162     /**
 163      * Returns the interface types directly implemented by this class
 164      * or extended by this interface.
 165      *
 166      * @return the interface types directly implemented by this class
 167      * or extended by this interface, or an empty list if there are none
 168      */
 169     List<? extends TypeMirror> getInterfaces();
 170 
 171     /**
 172      * Returns the formal type parameters of this type element
 173      * in declaration order.
 174      *
 175      * @return the formal type parameters, or an empty list
 176      * if there are none
 177      */
 178     List<? extends TypeParameterElement> getTypeParameters();
































 179 
 180     /**
 181      * Returns the package of a top-level type and returns the
 182      * immediately lexically enclosing element for a {@linkplain
 183      * NestingKind#isNested nested} type.
 184      *
 185      * @return the package of a top-level type, the immediately
 186      * lexically enclosing element for a nested type
 187      */
 188     @Override
 189     Element getEnclosingElement();
 190 }


  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  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 import java.util.List;
  29 import javax.lang.model.type.*;
  30 import javax.lang.model.util.*;
  31 
  32 /**
  33  * Represents a class or interface program element.  Provides access
  34  * to information about the type and its members.  Note that an enum
  35  * type and a record type are kinds of class esand an annotation type is a kind of
  36  * interface.
  37  *
  38  * <p> While a {@code TypeElement} represents a class or interface
  39  * <i>element</i>, a {@link DeclaredType} represents a class
  40  * or interface <i>type</i>, the latter being a use
  41  * (or <i>invocation</i>) of the former.
  42  * The distinction is most apparent with generic types,
  43  * for which a single element can define a whole
  44  * family of types.  For example, the element
  45  * {@code java.util.Set} corresponds to the parameterized types
  46  * {@code java.util.Set<String>} and {@code java.util.Set<Number>}
  47  * (and many others), and to the raw type {@code java.util.Set}.
  48  *
  49  * <p> Each method of this interface that returns a list of elements
  50  * will return them in the order that is natural for the underlying
  51  * source of program information.  For example, if the underlying
  52  * source of information is Java source code, then the elements will be
  53  * returned in source code order.
  54  *
  55  * @author Joseph D. Darcy


  65      *
  66      * <p>A generic element defines a family of types, not just one.
  67      * If this is a generic element, a prototypical type is
  68      * returned which has the element's invocation on the
  69      * 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 methods
  74      * for obtaining the full range of types defined by an element.
  75      *
  76      * @return the type defined by this type element
  77      *
  78      * @see Types#asMemberOf(DeclaredType, Element)
  79      * @see Types#getDeclaredType(TypeElement, TypeMirror...)
  80      */
  81     @Override
  82     TypeMirror asType();
  83 
  84     /**
  85      * Returns the fields, methods, constructors, state components, and member types
  86      * that are directly declared in this class or interface.
  87      *
  88      * This includes any {@linkplain Elements.Origin#MANDATED
  89      * mandated} elements such as the (implicit) default constructor
  90      * and the implicit {@code values} and {@code valueOf} methods of
  91      * an enum type.
  92      *
  93      * @apiNote As a particular instance of the {@linkplain
  94      * javax.lang.model.element general accuracy requirements} and the
  95      * ordering behavior required of this interface, the list of
  96      * enclosed elements will be returned in the natural order for the
  97      * originating source of information about the type.  For example,
  98      * if the information about the type is originating from a source
  99      * file, the elements will be returned in source code order.
 100      * (However, in that case the the ordering of {@linkplain
 101      * Elements.Origin#MANDATED implicitly declared} elements, such as
 102      * default constructors, is not specified.)
 103      *
 104      * @return the enclosed elements in proper order, or an empty list if none
 105      *


 159      */
 160     TypeMirror getSuperclass();
 161 
 162     /**
 163      * Returns the interface types directly implemented by this class
 164      * or extended by this interface.
 165      *
 166      * @return the interface types directly implemented by this class
 167      * or extended by this interface, or an empty list if there are none
 168      */
 169     List<? extends TypeMirror> getInterfaces();
 170 
 171     /**
 172      * Returns the formal type parameters of this type element
 173      * in declaration order.
 174      *
 175      * @return the formal type parameters, or an empty list
 176      * if there are none
 177      */
 178     List<? extends TypeParameterElement> getTypeParameters();
 179 
 180     /**
 181      * Returns the state components of this type element in
 182      * declaration order.
 183      *
 184      * @implSpec The default implementations of this method returns an
 185      * empty and unmodifiable list.
 186      *
 187      * @return the state components, or an empty list if there are
 188      * none
 189      *
 190      * @since amber
 191      */
 192     default List<? extends VariableElement> getStateComponents() {
 193         return List.of();
 194     }
 195 
 196     /**
 197      * Returns the permitted subtypes of this type element in
 198      * declaration order.
 199      *
 200      * @implSpec The default implementations of this method returns an
 201      * empty and unmodifiable list.
 202      *
 203      * @return the permitted subtypes, or an empty list
 204      * if there are none
 205      *
 206      * @since amber
 207      */
 208     default List<? extends TypeMirror> getPermittedSubtypes() {
 209         return List.of();
 210     }
 211 
 212     /**
 213      * Returns the package of a top-level type and returns the
 214      * immediately lexically enclosing element for a {@linkplain
 215      * NestingKind#isNested nested} type.
 216      *
 217      * @return the package of a top-level type, the immediately
 218      * lexically enclosing element for a nested type
 219      */
 220     @Override
 221     Element getEnclosingElement();
 222 }
< prev index next >