TypeElement.java revision 3915:6a9dd3d893b0
155714Skris/*
255714Skris * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
355714Skris * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
455714Skris *
555714Skris * This code is free software; you can redistribute it and/or modify it
655714Skris * under the terms of the GNU General Public License version 2 only, as
755714Skris * published by the Free Software Foundation.  Oracle designates this
8296465Sdelphij * particular file as subject to the "Classpath" exception as provided
955714Skris * by Oracle in the LICENSE file that accompanied this code.
1055714Skris *
1155714Skris * This code is distributed in the hope that it will be useful, but WITHOUT
1255714Skris * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1355714Skris * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1455714Skris * version 2 for more details (a copy is included in the LICENSE file that
15296465Sdelphij * accompanied this code).
1655714Skris *
1755714Skris * You should have received a copy of the GNU General Public License version
1855714Skris * 2 along with this work; if not, write to the Free Software Foundation,
1955714Skris * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2055714Skris *
2155714Skris * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22296465Sdelphij * or visit www.oracle.com if you need additional information or have any
2355714Skris * questions.
2455714Skris */
2555714Skris
2655714Skrispackage javax.lang.model.element;
2755714Skris
2855714Skrisimport java.util.List;
2955714Skrisimport javax.lang.model.type.*;
3055714Skrisimport javax.lang.model.util.*;
3155714Skris
3255714Skris/**
3355714Skris * Represents a class or interface program element.  Provides access
3455714Skris * to information about the type and its members.  Note that an enum
3555714Skris * type is a kind of class and an annotation type is a kind of
3655714Skris * interface.
37296465Sdelphij *
3855714Skris * <p> While a {@code TypeElement} represents a class or interface
3955714Skris * <i>element</i>, a {@link DeclaredType} represents a class
40296465Sdelphij * or interface <i>type</i>, the latter being a use
4155714Skris * (or <i>invocation</i>) of the former.
4255714Skris * The distinction is most apparent with generic types,
4355714Skris * for which a single element can define a whole
4455714Skris * family of types.  For example, the element
4555714Skris * {@code java.util.Set} corresponds to the parameterized types
4655714Skris * {@code java.util.Set<String>} and {@code java.util.Set<Number>}
4755714Skris * (and many others), and to the raw type {@code java.util.Set}.
4855714Skris *
4955714Skris * <p> Each method of this interface that returns a list of elements
5055714Skris * will return them in the order that is natural for the underlying
5155714Skris * source of program information.  For example, if the underlying
52296465Sdelphij * source of information is Java source code, then the elements will be
5355714Skris * returned in source code order.
5455714Skris *
5555714Skris * @author Joseph D. Darcy
5655714Skris * @author Scott Seligman
5755714Skris * @author Peter von der Ah&eacute;
58100928Snectar * @see DeclaredType
59160814Ssimon * @since 1.6
60100928Snectar */
61100928Snectarpublic interface TypeElement extends Element, Parameterizable, QualifiedNameable {
62100928Snectar    /**
63100928Snectar     * Returns the fields, methods, constructors, and member types
64100928Snectar     * that are directly declared in this class or interface.
65100928Snectar     *
66296465Sdelphij     * This includes any (implicit) default constructor and
67100928Snectar     * the implicit {@code values} and {@code valueOf} methods of an
68100928Snectar     * enum type.
69100928Snectar     *
70100928Snectar     * <p> Note that as a particular instance of the {@linkplain
71100928Snectar     * javax.lang.model.element general accuracy requirements} and the
72100928Snectar     * ordering behavior required of this interface, the list of
73100928Snectar     * enclosed elements will be returned in the natural order for the
74100928Snectar     * originating source of information about the type.  For example,
75100928Snectar     * if the information about the type is originating from a source
76100928Snectar     * file, the elements will be returned in source code order.
77100928Snectar     * (However, in that case the the ordering of synthesized
78100928Snectar     * elements, such as a default constructor, is not specified.)
79100928Snectar     *
80100928Snectar     * @return the enclosed elements in proper order, or an empty list if none
81100928Snectar     */
82100928Snectar    @Override
83100928Snectar    List<? extends Element> getEnclosedElements();
84100928Snectar
85100928Snectar    /**
86100928Snectar     * Returns the <i>nesting kind</i> of this type element.
87100928Snectar     *
88100928Snectar     * @return the nesting kind of this type element
89100928Snectar     */
90100928Snectar    NestingKind getNestingKind();
91100928Snectar
92100928Snectar    /**
93100928Snectar     * Returns the fully qualified name of this type element.
94100928Snectar     * More precisely, it returns the <i>canonical</i> name.
95100928Snectar     * For local and anonymous classes, which do not have canonical names,
96100928Snectar     * an empty name is returned.
97100928Snectar     *
98100928Snectar     * <p>The name of a generic type does not include any reference
99100928Snectar     * to its formal type parameters.
100100928Snectar     * For example, the fully qualified name of the interface
101100928Snectar     * {@code java.util.Set<E>} is "{@code java.util.Set}".
102100928Snectar     * Nested types use "{@code .}" as a separator, as in
103100928Snectar     * "{@code java.util.Map.Entry}".
104100928Snectar     *
105100928Snectar     * @return the fully qualified name of this class or interface, or
106100928Snectar     * an empty name if none
107100928Snectar     *
108100928Snectar     * @see Elements#getBinaryName
109100928Snectar     * @jls 6.7 Fully Qualified Names and Canonical Names
110100928Snectar     */
11155714Skris    Name getQualifiedName();
11255714Skris
11355714Skris    /**
11455714Skris     * Returns the simple name of this type element.
11555714Skris     *
11659191Skris     * For an anonymous class, an empty name is returned.
11759191Skris     *
11859191Skris     * @return the simple name of this class or interface,
11959191Skris     * an empty name for an anonymous class
12059191Skris     *
12155714Skris     */
12255714Skris    @Override
12355714Skris    Name getSimpleName();
12455714Skris
12555714Skris    /**
12655714Skris     * Returns the direct superclass of this type element.
127109998Smarkm     * If this type element represents an interface or the class
128109998Smarkm     * {@code java.lang.Object}, then a {@link NoType}
129160814Ssimon     * with kind {@link TypeKind#NONE NONE} is returned.
130296465Sdelphij     *
131296465Sdelphij     * @return the direct superclass, or a {@code NoType} if there is none
132296465Sdelphij     */
133296465Sdelphij    TypeMirror getSuperclass();
134296465Sdelphij
135296465Sdelphij    /**
136296465Sdelphij     * Returns the interface types directly implemented by this class
13755714Skris     * or extended by this interface.
138296465Sdelphij     *
139296465Sdelphij     * @return the interface types directly implemented by this class
140296465Sdelphij     * or extended by this interface, or an empty list if there are none
141296465Sdelphij     */
142296465Sdelphij    List<? extends TypeMirror> getInterfaces();
143296465Sdelphij
144296465Sdelphij    /**
145296465Sdelphij     * Returns the formal type parameters of this type element
146296465Sdelphij     * in declaration order.
147296465Sdelphij     *
148296465Sdelphij     * @return the formal type parameters, or an empty list
149296465Sdelphij     * if there are none
150296465Sdelphij     */
151296465Sdelphij    List<? extends TypeParameterElement> getTypeParameters();
152296465Sdelphij
153296465Sdelphij    /**
154296465Sdelphij     * Returns the package of a top-level type and returns the
155296465Sdelphij     * immediately lexically enclosing element for a {@linkplain
156296465Sdelphij     * NestingKind#isNested nested} type.
157296465Sdelphij     *
158296465Sdelphij     * @return the package of a top-level type, the immediately
159296465Sdelphij     * lexically enclosing element for a nested type
160296465Sdelphij     */
161296465Sdelphij    @Override
162296465Sdelphij    Element getEnclosingElement();
163296465Sdelphij}
164296465Sdelphij