1 /*
   2  * Copyright (c) 2005, 2019, 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 
  26 package javax.lang.model.element;
  27 
  28 /**
  29  * The {@code kind} of an element.
  30  *
  31  * <p>Note that it is possible additional element kinds will be added
  32  * to accommodate new, currently unknown, language structures added to
  33  * future versions of the Java&trade; programming language.
  34  *
  35  * @author Joseph D. Darcy
  36  * @author Scott Seligman
  37  * @author Peter von der Ah&eacute;
  38  * @see Element
  39  * @since 1.6
  40  */
  41 public enum ElementKind {
  42 
  43     /** A package. */
  44     PACKAGE,
  45 
  46     // Declared types
  47     /** An enum type. */
  48     ENUM,
  49     /**
  50      * A class not described by a more specific kind (like {@code
  51      * ENUM} or {@code RECORD}).
  52      */
  53     CLASS,
  54 
  55     /** An annotation type. */
  56     ANNOTATION_TYPE,
  57     /**
  58      * An interface not described by a more specific kind (like
  59      * {@code ANNOTATION_TYPE}).
  60      */
  61     INTERFACE,
  62 
  63     // Variables
  64     /** An enum constant. */
  65     ENUM_CONSTANT,
  66     /**
  67      * A field not described by a more specific kind (like
  68      * {@code ENUM_CONSTANT}).
  69      */
  70     FIELD,
  71     /** A parameter of a method or constructor. */
  72     PARAMETER,
  73     /** A local variable. */
  74     LOCAL_VARIABLE,
  75     /** A parameter of an exception handler. */
  76     EXCEPTION_PARAMETER,
  77 
  78     // Executables
  79     /** A method. */
  80     METHOD,
  81     /** A constructor. */
  82     CONSTRUCTOR,
  83     /** A static initializer. */
  84     STATIC_INIT,
  85     /** An instance initializer. */
  86     INSTANCE_INIT,
  87 
  88     /** A type parameter. */
  89     TYPE_PARAMETER,
  90 
  91     /**
  92      * An implementation-reserved element.  This is not the element
  93      * you are looking for.
  94      */
  95     OTHER,
  96 
  97     // Constants added since initial release
  98 
  99     /**
 100      * A resource variable.
 101      * @since 1.7
 102      */
 103      RESOURCE_VARIABLE,
 104 
 105     /**
 106      * A module.
 107      * @since 9
 108      * @spec JPMS
 109      */
 110      MODULE,
 111 
 112     /**
 113      * {@preview Associated with records, a preview feature of the Java language.
 114      *
 115      *           This enum constant is associated with <i>records</i>, a preview
 116      *           feature of the Java language. Preview features
 117      *           may be removed in a future release, or upgraded to permanent
 118      *           features of the Java language.}
 119      *
 120      * A record type.
 121      * @since 14
 122      */
 123     @jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.RECORDS,
 124                                  essentialAPI=false)
 125     RECORD,
 126 
 127     /**
 128      * {@preview Associated with records, a preview feature of the Java language.
 129      *
 130      *           This enum constant is associated with <i>records</i>, a preview
 131      *           feature of the Java language. Preview features
 132      *           may be removed in a future release, or upgraded to permanent
 133      *           features of the Java language.}
 134      *
 135      * A record component of a {@code record}.
 136      * @since 14
 137      */
 138     @jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.RECORDS,
 139                                  essentialAPI=false)
 140     RECORD_COMPONENT,
 141 
 142     /**
 143      * {@preview Associated with pattern matching for {@code
 144      * instanceof}, a preview feature of the Java language.
 145      *
 146      *           This enum constant is associated with <i>pattern
 147      *           matching for {@code instanceof}</i>, a preview
 148      *           feature of the Java language. Preview features
 149      *           may be removed in a future release, or upgraded to permanent
 150      *           features of the Java language.}
 151      *
 152      * A binding variable in a pattern .
 153      * @since 14
 154      */
 155     @jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.PATTERN_MATCHING_IN_INSTANCEOF,
 156                                  essentialAPI=false)
 157     BINDING_VARIABLE;
 158 
 159     /**
 160      * Returns {@code true} if this is a kind of class:
 161      * either {@code CLASS} or {@code ENUM} or {@code RECORD}.
 162      *
 163      * @return {@code true} if this is a kind of class
 164      */
 165     @SuppressWarnings("preview")
 166     public boolean isClass() {
 167         return this == CLASS || this == ENUM || this == RECORD;
 168     }
 169 
 170     /**
 171      * Returns {@code true} if this is a kind of interface:
 172      * either {@code INTERFACE} or {@code ANNOTATION_TYPE}.
 173      *
 174      * @return {@code true} if this is a kind of interface
 175      */
 176     public boolean isInterface() {
 177         return this == INTERFACE || this == ANNOTATION_TYPE;
 178     }
 179 
 180     /**
 181      * Returns {@code true} if this is a kind of field:
 182      * either {@code FIELD} or {@code ENUM_CONSTANT}.
 183      *
 184      * @return {@code true} if this is a kind of field
 185      */
 186     public boolean isField() {
 187         return this == FIELD || this == ENUM_CONSTANT;
 188     }
 189 }