src/java.base/share/classes/java/lang/annotation/ElementType.java
author darcy
Wed, 25 Apr 2018 22:12:06 -0700
changeset 49895 661ef62a6618
parent 47216 71c04702a3d5
permissions -rw-r--r--
8200478: For boxing conversion javac uses Long.valueOf which does not guarantee caching according to its javadoc Reviewed-by: bpb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
44532
39f580829da1 8177949: @link tag arguments need correction for ElementType documentation
darcy
parents: 42338
diff changeset
     2
 * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3063
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3063
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3063
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3063
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3063
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.lang.annotation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
/**
21828
5c9519eb783c 8027413: Clarify javadoc for j.l.a.Target and j.l.a.ElementType
jfranck
parents: 14419
diff changeset
    29
 * The constants of this enumerated type provide a simple classification of the
5c9519eb783c 8027413: Clarify javadoc for j.l.a.Target and j.l.a.ElementType
jfranck
parents: 14419
diff changeset
    30
 * syntactic locations where annotations may appear in a Java program. These
44532
39f580829da1 8177949: @link tag arguments need correction for ElementType documentation
darcy
parents: 42338
diff changeset
    31
 * constants are used in {@link java.lang.annotation.Target Target}
21828
5c9519eb783c 8027413: Clarify javadoc for j.l.a.Target and j.l.a.ElementType
jfranck
parents: 14419
diff changeset
    32
 * meta-annotations to specify where it is legal to write annotations of a
5c9519eb783c 8027413: Clarify javadoc for j.l.a.Target and j.l.a.ElementType
jfranck
parents: 14419
diff changeset
    33
 * given type.
5c9519eb783c 8027413: Clarify javadoc for j.l.a.Target and j.l.a.ElementType
jfranck
parents: 14419
diff changeset
    34
 *
5c9519eb783c 8027413: Clarify javadoc for j.l.a.Target and j.l.a.ElementType
jfranck
parents: 14419
diff changeset
    35
 * <p>The syntactic locations where annotations may appear are split into
5c9519eb783c 8027413: Clarify javadoc for j.l.a.Target and j.l.a.ElementType
jfranck
parents: 14419
diff changeset
    36
 * <em>declaration contexts</em> , where annotations apply to declarations, and
5c9519eb783c 8027413: Clarify javadoc for j.l.a.Target and j.l.a.ElementType
jfranck
parents: 14419
diff changeset
    37
 * <em>type contexts</em> , where annotations apply to types used in
5c9519eb783c 8027413: Clarify javadoc for j.l.a.Target and j.l.a.ElementType
jfranck
parents: 14419
diff changeset
    38
 * declarations and expressions.
5c9519eb783c 8027413: Clarify javadoc for j.l.a.Target and j.l.a.ElementType
jfranck
parents: 14419
diff changeset
    39
 *
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 38587
diff changeset
    40
 * <p>The constants {@link #ANNOTATION_TYPE}, {@link #CONSTRUCTOR}, {@link
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 38587
diff changeset
    41
 * #FIELD}, {@link #LOCAL_VARIABLE}, {@link #METHOD}, {@link #PACKAGE}, {@link
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 38587
diff changeset
    42
 * #MODULE}, {@link #PARAMETER}, {@link #TYPE}, and {@link #TYPE_PARAMETER}
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 38587
diff changeset
    43
 * correspond to the declaration contexts in JLS 9.6.4.1.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *
21828
5c9519eb783c 8027413: Clarify javadoc for j.l.a.Target and j.l.a.ElementType
jfranck
parents: 14419
diff changeset
    45
 * <p>For example, an annotation whose type is meta-annotated with
5c9519eb783c 8027413: Clarify javadoc for j.l.a.Target and j.l.a.ElementType
jfranck
parents: 14419
diff changeset
    46
 * {@code @Target(ElementType.FIELD)} may only be written as a modifier for a
5c9519eb783c 8027413: Clarify javadoc for j.l.a.Target and j.l.a.ElementType
jfranck
parents: 14419
diff changeset
    47
 * field declaration.
5c9519eb783c 8027413: Clarify javadoc for j.l.a.Target and j.l.a.ElementType
jfranck
parents: 14419
diff changeset
    48
 *
38587
512822cb2cfe 8033812: javadoc for java.lang.annotation.ElementType needs minor correction
sadayapalam
parents: 25859
diff changeset
    49
 * <p>The constant {@link #TYPE_USE} corresponds to the type contexts in JLS
21828
5c9519eb783c 8027413: Clarify javadoc for j.l.a.Target and j.l.a.ElementType
jfranck
parents: 14419
diff changeset
    50
 * 4.11, as well as to two declaration contexts: type declarations (including
5c9519eb783c 8027413: Clarify javadoc for j.l.a.Target and j.l.a.ElementType
jfranck
parents: 14419
diff changeset
    51
 * annotation type declarations) and type parameter declarations.
5c9519eb783c 8027413: Clarify javadoc for j.l.a.Target and j.l.a.ElementType
jfranck
parents: 14419
diff changeset
    52
 *
5c9519eb783c 8027413: Clarify javadoc for j.l.a.Target and j.l.a.ElementType
jfranck
parents: 14419
diff changeset
    53
 * <p>For example, an annotation whose type is meta-annotated with
5c9519eb783c 8027413: Clarify javadoc for j.l.a.Target and j.l.a.ElementType
jfranck
parents: 14419
diff changeset
    54
 * {@code @Target(ElementType.TYPE_USE)} may be written on the type of a field
5c9519eb783c 8027413: Clarify javadoc for j.l.a.Target and j.l.a.ElementType
jfranck
parents: 14419
diff changeset
    55
 * (or within the type of the field, if it is a nested, parameterized, or array
5c9519eb783c 8027413: Clarify javadoc for j.l.a.Target and j.l.a.ElementType
jfranck
parents: 14419
diff changeset
    56
 * type), and may also appear as a modifier for, say, a class declaration.
5c9519eb783c 8027413: Clarify javadoc for j.l.a.Target and j.l.a.ElementType
jfranck
parents: 14419
diff changeset
    57
 *
5c9519eb783c 8027413: Clarify javadoc for j.l.a.Target and j.l.a.ElementType
jfranck
parents: 14419
diff changeset
    58
 * <p>The {@code TYPE_USE} constant includes type declarations and type
5c9519eb783c 8027413: Clarify javadoc for j.l.a.Target and j.l.a.ElementType
jfranck
parents: 14419
diff changeset
    59
 * parameter declarations as a convenience for designers of type checkers which
5c9519eb783c 8027413: Clarify javadoc for j.l.a.Target and j.l.a.ElementType
jfranck
parents: 14419
diff changeset
    60
 * give semantics to annotation types. For example, if the annotation type
5c9519eb783c 8027413: Clarify javadoc for j.l.a.Target and j.l.a.ElementType
jfranck
parents: 14419
diff changeset
    61
 * {@code NonNull} is meta-annotated with
5c9519eb783c 8027413: Clarify javadoc for j.l.a.Target and j.l.a.ElementType
jfranck
parents: 14419
diff changeset
    62
 * {@code @Target(ElementType.TYPE_USE)}, then {@code @NonNull}
5c9519eb783c 8027413: Clarify javadoc for j.l.a.Target and j.l.a.ElementType
jfranck
parents: 14419
diff changeset
    63
 * {@code class C {...}} could be treated by a type checker as indicating that
5c9519eb783c 8027413: Clarify javadoc for j.l.a.Target and j.l.a.ElementType
jfranck
parents: 14419
diff changeset
    64
 * all variables of class {@code C} are non-null, while still allowing
5c9519eb783c 8027413: Clarify javadoc for j.l.a.Target and j.l.a.ElementType
jfranck
parents: 14419
diff changeset
    65
 * variables of other classes to be non-null or not non-null based on whether
5c9519eb783c 8027413: Clarify javadoc for j.l.a.Target and j.l.a.ElementType
jfranck
parents: 14419
diff changeset
    66
 * {@code @NonNull} appears at the variable's declaration.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * @author  Joshua Bloch
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * @since 1.5
21828
5c9519eb783c 8027413: Clarify javadoc for j.l.a.Target and j.l.a.ElementType
jfranck
parents: 14419
diff changeset
    70
 * @jls 9.6.4.1 @Target
5c9519eb783c 8027413: Clarify javadoc for j.l.a.Target and j.l.a.ElementType
jfranck
parents: 14419
diff changeset
    71
 * @jls 4.1 The Kinds of Types and Values
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
public enum ElementType {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    /** Class, interface (including annotation type), or enum declaration */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    TYPE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    /** Field declaration (includes enum constants) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    FIELD,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    /** Method declaration */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    METHOD,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
14419
e5214ad6600a 8001598: Augment ElementType enum for JSR 308
jfranck
parents: 8161
diff changeset
    83
    /** Formal parameter declaration */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    PARAMETER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    /** Constructor declaration */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    CONSTRUCTOR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    /** Local variable declaration */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    LOCAL_VARIABLE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    /** Annotation type declaration */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    ANNOTATION_TYPE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /** Package declaration */
14419
e5214ad6600a 8001598: Augment ElementType enum for JSR 308
jfranck
parents: 8161
diff changeset
    96
    PACKAGE,
e5214ad6600a 8001598: Augment ElementType enum for JSR 308
jfranck
parents: 8161
diff changeset
    97
e5214ad6600a 8001598: Augment ElementType enum for JSR 308
jfranck
parents: 8161
diff changeset
    98
    /**
e5214ad6600a 8001598: Augment ElementType enum for JSR 308
jfranck
parents: 8161
diff changeset
    99
     * Type parameter declaration
e5214ad6600a 8001598: Augment ElementType enum for JSR 308
jfranck
parents: 8161
diff changeset
   100
     *
e5214ad6600a 8001598: Augment ElementType enum for JSR 308
jfranck
parents: 8161
diff changeset
   101
     * @since 1.8
e5214ad6600a 8001598: Augment ElementType enum for JSR 308
jfranck
parents: 8161
diff changeset
   102
     */
e5214ad6600a 8001598: Augment ElementType enum for JSR 308
jfranck
parents: 8161
diff changeset
   103
    TYPE_PARAMETER,
e5214ad6600a 8001598: Augment ElementType enum for JSR 308
jfranck
parents: 8161
diff changeset
   104
e5214ad6600a 8001598: Augment ElementType enum for JSR 308
jfranck
parents: 8161
diff changeset
   105
    /**
e5214ad6600a 8001598: Augment ElementType enum for JSR 308
jfranck
parents: 8161
diff changeset
   106
     * Use of a type
e5214ad6600a 8001598: Augment ElementType enum for JSR 308
jfranck
parents: 8161
diff changeset
   107
     *
e5214ad6600a 8001598: Augment ElementType enum for JSR 308
jfranck
parents: 8161
diff changeset
   108
     * @since 1.8
e5214ad6600a 8001598: Augment ElementType enum for JSR 308
jfranck
parents: 8161
diff changeset
   109
     */
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 38587
diff changeset
   110
    TYPE_USE,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 38587
diff changeset
   111
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 38587
diff changeset
   112
    /**
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 38587
diff changeset
   113
     * Module declaration.
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 38587
diff changeset
   114
     *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 38587
diff changeset
   115
     * @since 9
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 38587
diff changeset
   116
     */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 38587
diff changeset
   117
    MODULE
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
}