NestingKind.java revision 2571:10fc81ac75b4
11854Swollman/*
21854Swollman * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
31573Srgrimes * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
41573Srgrimes *
51573Srgrimes * This code is free software; you can redistribute it and/or modify it
61573Srgrimes * under the terms of the GNU General Public License version 2 only, as
71573Srgrimes * published by the Free Software Foundation.  Oracle designates this
81854Swollman * particular file as subject to the "Classpath" exception as provided
91573Srgrimes * by Oracle in the LICENSE file that accompanied this code.
101573Srgrimes *
111573Srgrimes * This code is distributed in the hope that it will be useful, but WITHOUT
121573Srgrimes * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
131573Srgrimes * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
141573Srgrimes * version 2 for more details (a copy is included in the LICENSE file that
151573Srgrimes * accompanied this code).
161573Srgrimes *
171573Srgrimes * You should have received a copy of the GNU General Public License version
181573Srgrimes * 2 along with this work; if not, write to the Free Software Foundation,
191573Srgrimes * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
201573Srgrimes *
211573Srgrimes * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
221573Srgrimes * or visit www.oracle.com if you need additional information or have any
231573Srgrimes * questions.
241573Srgrimes */
251573Srgrimes
261573Srgrimespackage javax.lang.model.element;
271573Srgrimes
281573Srgrimes/**
291573Srgrimes * The <i>nesting kind</i> of a type element.
301573Srgrimes * Type elements come in four varieties:
311573Srgrimes * top-level, member, local, and anonymous.
321573Srgrimes * <i>Nesting kind</i> is a non-standard term used here to denote this
331573Srgrimes * classification.
34 *
35 * <p>Note that it is possible additional nesting kinds will be added
36 * in future versions of the platform.
37 *
38 * <p><b>Example:</b> The classes below are annotated with their nesting kind.
39 * <blockquote><pre>
40 *
41 * import java.lang.annotation.*;
42 * import static java.lang.annotation.RetentionPolicy.*;
43 * import javax.lang.model.element.*;
44 * import static javax.lang.model.element.NestingKind.*;
45 *
46 * &#64;Nesting(TOP_LEVEL)
47 * public class NestingExamples {
48 *     &#64;Nesting(MEMBER)
49 *     static class MemberClass1{}
50 *
51 *     &#64;Nesting(MEMBER)
52 *     class MemberClass2{}
53 *
54 *     public static void main(String... argv) {
55 *         &#64;Nesting(LOCAL)
56 *         class LocalClass{};
57 *
58 *         Class&lt;?&gt;[] classes = {
59 *             NestingExamples.class,
60 *             MemberClass1.class,
61 *             MemberClass2.class,
62 *             LocalClass.class
63 *         };
64 *
65 *         for(Class&lt;?&gt; clazz : classes) {
66 *             System.out.format("%s is %s%n",
67 *                               clazz.getName(),
68 *                               clazz.getAnnotation(Nesting.class).value());
69 *         }
70 *     }
71 * }
72 *
73 * &#64;Retention(RUNTIME)
74 * &#64;interface Nesting {
75 *     NestingKind value();
76 * }
77 * </pre></blockquote>
78 *
79 * @author Joseph D. Darcy
80 * @author Scott Seligman
81 * @author Peter von der Ah&eacute;
82 * @since 1.6
83 */
84public enum NestingKind {
85    /**
86     * A top-level type, not contained within another type.
87     */
88    TOP_LEVEL,
89
90    /**
91     * A type that is a named member of another type.
92     */
93    MEMBER,
94
95    /**
96     * A named type declared within a construct other than a type.
97     */
98    LOCAL,
99
100    /**
101     * A type without a name.
102     */
103    ANONYMOUS;
104
105    /**
106     * Does this constant correspond to a nested type element?
107     * A <i>nested</i> type element is any that is not top-level.
108     * An <i>inner</i> type element is any nested type element that
109     * is not {@linkplain Modifier#STATIC static}.
110     * @return whether or not the constant is nested
111     */
112    public boolean isNested() {
113        return this != TOP_LEVEL;
114    }
115}
116