TypeElement.java revision 3958:a32aa9e380e5
1195333Simp/*
2195333Simp * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
3195333Simp * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4195333Simp *
5195333Simp * This code is free software; you can redistribute it and/or modify it
6195333Simp * under the terms of the GNU General Public License version 2 only, as
7195333Simp * published by the Free Software Foundation.  Oracle designates this
8195333Simp * particular file as subject to the "Classpath" exception as provided
9195333Simp * by Oracle in the LICENSE file that accompanied this code.
10195333Simp *
11195333Simp * This code is distributed in the hope that it will be useful, but WITHOUT
12195333Simp * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13195333Simp * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14195333Simp * version 2 for more details (a copy is included in the LICENSE file that
15195333Simp * accompanied this code).
16195333Simp *
17195333Simp * You should have received a copy of the GNU General Public License version
18195333Simp * 2 along with this work; if not, write to the Free Software Foundation,
19195333Simp * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20195333Simp *
21195333Simp * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22195333Simp * or visit www.oracle.com if you need additional information or have any
23195333Simp * questions.
24195333Simp */
25195333Simp
26195333Simppackage javax.lang.model.element;
27195333Simp
28195333Simpimport java.util.List;
29195333Simpimport javax.lang.model.type.*;
30195333Simpimport javax.lang.model.util.*;
31195333Simp
32195333Simp/**
33195333Simp * Represents a class or interface program element.  Provides access
34195333Simp * to information about the type and its members.  Note that an enum
35195333Simp * type is a kind of class and an annotation type is a kind of
36195333Simp * interface.
37195333Simp *
38195333Simp * <p> While a {@code TypeElement} represents a class or interface
39195333Simp * <i>element</i>, a {@link DeclaredType} represents a class
40195333Simp * or interface <i>type</i>, the latter being a use
41195333Simp * (or <i>invocation</i>) of the former.
42195333Simp * The distinction is most apparent with generic types,
43195333Simp * for which a single element can define a whole
44195333Simp * family of types.  For example, the element
45195333Simp * {@code java.util.Set} corresponds to the parameterized types
46195333Simp * {@code java.util.Set<String>} and {@code java.util.Set<Number>}
47195333Simp * (and many others), and to the raw type {@code java.util.Set}.
48195333Simp *
49195333Simp * <p> Each method of this interface that returns a list of elements
50195333Simp * will return them in the order that is natural for the underlying
51195333Simp * source of program information.  For example, if the underlying
52195333Simp * source of information is Java source code, then the elements will be
53205364Sneel * returned in source code order.
54195333Simp *
55195333Simp * @author Joseph D. Darcy
56195333Simp * @author Scott Seligman
57195333Simp * @author Peter von der Ah&eacute;
58195333Simp * @see DeclaredType
59195333Simp * @since 1.6
60195333Simp */
61195333Simppublic interface TypeElement extends Element, Parameterizable, QualifiedNameable {
62195333Simp    /**
63195333Simp     * Returns the fields, methods, constructors, and member types
64195333Simp     * that are directly declared in this class or interface.
65195333Simp     *
66195333Simp     * This includes any {@linkplain Elements.Origin#MANDATED
67195333Simp     * mandated} elements such as the (implicit) default constructor
68195333Simp     * and the implicit {@code values} and {@code valueOf} methods of
69195333Simp     * an enum type.
70195333Simp     *
71195333Simp     * @apiNote As a particular instance of the {@linkplain
72195333Simp     * javax.lang.model.element general accuracy requirements} and the
73195333Simp     * ordering behavior required of this interface, the list of
74203697Sneel     * enclosed elements will be returned in the natural order for the
75208253Sneel     * originating source of information about the type.  For example,
76203697Sneel     * if the information about the type is originating from a source
77203697Sneel     * file, the elements will be returned in source code order.
78203697Sneel     * (However, in that case the the ordering of elements, such as a
79195333Simp     * default constructor, is not specified.)
80195333Simp     *
81195333Simp     * @return the enclosed elements in proper order, or an empty list if none
82195333Simp     *
83195333Simp     * @jls 8.8.9 Default Constructor
84195333Simp     * @jls 8.9.3 Enum Members
85195333Simp     */
86195333Simp    @Override
87195333Simp    List<? extends Element> getEnclosedElements();
88195333Simp
89195333Simp    /**
90195333Simp     * Returns the <i>nesting kind</i> of this type element.
91195333Simp     *
92195333Simp     * @return the nesting kind of this type element
93195333Simp     */
94195333Simp    NestingKind getNestingKind();
95195333Simp
96195333Simp    /**
97195333Simp     * Returns the fully qualified name of this type element.
98203000Sneel     * More precisely, it returns the <i>canonical</i> name.
99203000Sneel     * For local and anonymous classes, which do not have canonical names,
100198669Srrs     * an empty name is returned.
101198669Srrs     *
102198669Srrs     * <p>The name of a generic type does not include any reference
103198669Srrs     * to its formal type parameters.
104198669Srrs     * For example, the fully qualified name of the interface
105198669Srrs     * {@code java.util.Set<E>} is "{@code java.util.Set}".
106195333Simp     * Nested types use "{@code .}" as a separator, as in
107203510Sneel     * "{@code java.util.Map.Entry}".
108203510Sneel     *
109203510Sneel     * @return the fully qualified name of this class or interface, or
110203510Sneel     * an empty name if none
111203510Sneel     *
112203510Sneel     * @see Elements#getBinaryName
113203510Sneel     * @jls 6.7 Fully Qualified Names and Canonical Names
114203510Sneel     */
115203510Sneel    Name getQualifiedName();
116203510Sneel
117203510Sneel    /**
118203510Sneel     * Returns the simple name of this type element.
119203697Sneel     *
120203697Sneel     * For an anonymous class, an empty name is returned.
121203697Sneel     *
122203697Sneel     * @return the simple name of this class or interface,
123203697Sneel     * an empty name for an anonymous class
124203697Sneel     *
125203697Sneel     */
126203697Sneel    @Override
127203697Sneel    Name getSimpleName();
128203697Sneel
129203697Sneel    /**
130203697Sneel     * Returns the direct superclass of this type element.
131203697Sneel     * If this type element represents an interface or the class
132203510Sneel     * {@code java.lang.Object}, then a {@link NoType}
133203510Sneel     * with kind {@link TypeKind#NONE NONE} is returned.
134203510Sneel     *
135203510Sneel     * @return the direct superclass, or a {@code NoType} if there is none
136195333Simp     */
137195333Simp    TypeMirror getSuperclass();
138216318Sgonzo
139195333Simp    /**
140195333Simp     * Returns the interface types directly implemented by this class
141195333Simp     * or extended by this interface.
142195333Simp     *
143195333Simp     * @return the interface types directly implemented by this class
144195333Simp     * or extended by this interface, or an empty list if there are none
145195333Simp     */
146195333Simp    List<? extends TypeMirror> getInterfaces();
147195333Simp
148195333Simp    /**
149195333Simp     * Returns the formal type parameters of this type element
150195333Simp     * in declaration order.
151195333Simp     *
152195333Simp     * @return the formal type parameters, or an empty list
153195333Simp     * if there are none
154195333Simp     */
155195333Simp    List<? extends TypeParameterElement> getTypeParameters();
156195333Simp
157195333Simp    /**
158207131Sjmallett     * Returns the package of a top-level type and returns the
159207131Sjmallett     * immediately lexically enclosing element for a {@linkplain
160207131Sjmallett     * NestingKind#isNested nested} type.
161207131Sjmallett     *
162207131Sjmallett     * @return the package of a top-level type, the immediately
163207131Sjmallett     * lexically enclosing element for a nested type
164207131Sjmallett     */
165207131Sjmallett    @Override
166207131Sjmallett    Element getEnclosingElement();
167207131Sjmallett}
168207131Sjmallett