src/java.compiler/share/classes/javax/lang/model/element/NestingKind.java
author darcy
Wed, 27 Sep 2017 14:23:41 -0700
changeset 47283 ce5fd3ba3fea
parent 47216 71c04702a3d5
child 54952 a978d86ac389
permissions -rw-r--r--
8187982: Update SourceVersion to mention restricted keywords Reviewed-by: mcimadamore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
43567
d0d89c3da7be 8173676: Improvements to javax.annotation.processing and javax.lang.model doc
darcy
parents: 25874
diff changeset
     2
 * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package javax.lang.model.element;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
 * The <i>nesting kind</i> of a type element.
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
 * Type elements come in four varieties:
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
 * top-level, member, local, and anonymous.
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
 * <i>Nesting kind</i> is a non-standard term used here to denote this
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
 * classification.
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
 * <p>Note that it is possible additional nesting kinds will be added
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
 * in future versions of the platform.
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
 * <p><b>Example:</b> The classes below are annotated with their nesting kind.
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
 * <blockquote><pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 * import java.lang.annotation.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
 * import static java.lang.annotation.RetentionPolicy.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 * import javax.lang.model.element.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
 * import static javax.lang.model.element.NestingKind.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
 * &#64;Nesting(TOP_LEVEL)
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
 * public class NestingExamples {
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
 *     &#64;Nesting(MEMBER)
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
 *     static class MemberClass1{}
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
 *     &#64;Nesting(MEMBER)
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
 *     class MemberClass2{}
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
 *     public static void main(String... argv) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
 *         &#64;Nesting(LOCAL)
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
 *         class LocalClass{};
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
 *         Class&lt;?&gt;[] classes = {
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
 *             NestingExamples.class,
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
 *             MemberClass1.class,
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
 *             MemberClass2.class,
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
 *             LocalClass.class
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
 *         };
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
 *         for(Class&lt;?&gt; clazz : classes) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
 *             System.out.format("%s is %s%n",
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
 *                               clazz.getName(),
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
 *                               clazz.getAnnotation(Nesting.class).value());
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
 *         }
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
 *     }
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
 * }
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
 * &#64;Retention(RUNTIME)
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
 * &#64;interface Nesting {
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
 *     NestingKind value();
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
 * }
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
 * </pre></blockquote>
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
 * @author Joseph D. Darcy
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
 * @author Scott Seligman
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
 * @author Peter von der Ah&eacute;
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
 * @since 1.6
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
public enum NestingKind {
17548
b0a4fd89079c 8013909: Fix doclint issues in javax.lang.model
darcy
parents: 5520
diff changeset
    85
    /**
b0a4fd89079c 8013909: Fix doclint issues in javax.lang.model
darcy
parents: 5520
diff changeset
    86
     * A top-level type, not contained within another type.
b0a4fd89079c 8013909: Fix doclint issues in javax.lang.model
darcy
parents: 5520
diff changeset
    87
     */
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
    TOP_LEVEL,
17548
b0a4fd89079c 8013909: Fix doclint issues in javax.lang.model
darcy
parents: 5520
diff changeset
    89
b0a4fd89079c 8013909: Fix doclint issues in javax.lang.model
darcy
parents: 5520
diff changeset
    90
    /**
b0a4fd89079c 8013909: Fix doclint issues in javax.lang.model
darcy
parents: 5520
diff changeset
    91
     * A type that is a named member of another type.
43567
d0d89c3da7be 8173676: Improvements to javax.annotation.processing and javax.lang.model doc
darcy
parents: 25874
diff changeset
    92
     * @jls 8.5 Member Type Declarations
17548
b0a4fd89079c 8013909: Fix doclint issues in javax.lang.model
darcy
parents: 5520
diff changeset
    93
     */
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
    MEMBER,
17548
b0a4fd89079c 8013909: Fix doclint issues in javax.lang.model
darcy
parents: 5520
diff changeset
    95
b0a4fd89079c 8013909: Fix doclint issues in javax.lang.model
darcy
parents: 5520
diff changeset
    96
    /**
b0a4fd89079c 8013909: Fix doclint issues in javax.lang.model
darcy
parents: 5520
diff changeset
    97
     * A named type declared within a construct other than a type.
43567
d0d89c3da7be 8173676: Improvements to javax.annotation.processing and javax.lang.model doc
darcy
parents: 25874
diff changeset
    98
     * @jls 14.3 Local Class Declarations
17548
b0a4fd89079c 8013909: Fix doclint issues in javax.lang.model
darcy
parents: 5520
diff changeset
    99
     */
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
    LOCAL,
17548
b0a4fd89079c 8013909: Fix doclint issues in javax.lang.model
darcy
parents: 5520
diff changeset
   101
b0a4fd89079c 8013909: Fix doclint issues in javax.lang.model
darcy
parents: 5520
diff changeset
   102
    /**
b0a4fd89079c 8013909: Fix doclint issues in javax.lang.model
darcy
parents: 5520
diff changeset
   103
     * A type without a name.
43567
d0d89c3da7be 8173676: Improvements to javax.annotation.processing and javax.lang.model doc
darcy
parents: 25874
diff changeset
   104
     * @jls 15.9.5 Anonymous Class Declarations
17548
b0a4fd89079c 8013909: Fix doclint issues in javax.lang.model
darcy
parents: 5520
diff changeset
   105
     */
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
    ANONYMOUS;
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
     * Does this constant correspond to a nested type element?
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
     * A <i>nested</i> type element is any that is not top-level.
43567
d0d89c3da7be 8173676: Improvements to javax.annotation.processing and javax.lang.model doc
darcy
parents: 25874
diff changeset
   111
     * More specifically, an <i>inner</i> type element is any nested type element that
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
     * is not {@linkplain Modifier#STATIC static}.
17548
b0a4fd89079c 8013909: Fix doclint issues in javax.lang.model
darcy
parents: 5520
diff changeset
   113
     * @return whether or not the constant is nested
43567
d0d89c3da7be 8173676: Improvements to javax.annotation.processing and javax.lang.model doc
darcy
parents: 25874
diff changeset
   114
     * @jls 14.3 Inner Classes and Enclosing Instances
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
    public boolean isNested() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
        return this != TOP_LEVEL;
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
}