1/*
2 * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
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
26package javax.lang.model.element;
27
28/**
29 * The <i>nesting kind</i> of a type element.
30 * Type elements come in four varieties:
31 * top-level, member, local, and anonymous.
32 * <i>Nesting kind</i> is a non-standard term used here to denote this
33 * 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     * @jls 8.5 Member Type Declarations
93     */
94    MEMBER,
95
96    /**
97     * A named type declared within a construct other than a type.
98     * @jls 14.3 Local Class Declarations
99     */
100    LOCAL,
101
102    /**
103     * A type without a name.
104     * @jls 15.9.5 Anonymous Class Declarations
105     */
106    ANONYMOUS;
107
108    /**
109     * Does this constant correspond to a nested type element?
110     * A <i>nested</i> type element is any that is not top-level.
111     * More specifically, an <i>inner</i> type element is any nested type element that
112     * is not {@linkplain Modifier#STATIC static}.
113     * @return whether or not the constant is nested
114     * @jls 14.3 Inner Classes and Enclosing Instances
115     */
116    public boolean isNested() {
117        return this != TOP_LEVEL;
118    }
119}
120