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 import javax.lang.model.util.Elements;
  29 import javax.lang.model.type.TypeMirror;
  30 import javax.lang.model.type.TypeKind;
  31 
  32 /**
  33  * Represents a field, {@code enum} constant, method or constructor
  34  * parameter, local variable, resource variable, or exception
  35  * parameter.
  36  *
  37  * @author Joseph D. Darcy
  38  * @author Scott Seligman
  39  * @author Peter von der Ahé
  40  * @since 1.6
  41  */
  42 public interface VariableElement extends Element {
  43     /**
  44      * Returns the type of this variable.
  45      *
  46      * Note that the types of variables range over {@linkplain
  47      * TypeKind many kinds} of types, including primitive types,
  48      * declared types, and array types, among others.
  49      *
  50      * @return the type of this variable
  51      *
  52      * @see TypeKind
  53      */
  54     @Override
  55     TypeMirror asType();
  56 
  57     /**
  58      * Returns the value of this variable if this is a {@code final}
  59      * field initialized to a compile-time constant.  Returns {@code
  60      * null} otherwise.  The value will be of a primitive type or a
  61      * {@code String}.  If the value is of a primitive type, it is
  62      * wrapped in the appropriate wrapper class (such as {@link
  63      * Integer}).
  64      *
  65      * <p>Note that not all {@code final} fields will have
  66      * constant values.  In particular, {@code enum} constants are
  67      * <em>not</em> considered to be compile-time constants.  To have a
  68      * constant value, a field's type must be either a primitive type
  69      * or {@code String}.
  70      *
  71      * @return the value of this variable if this is a {@code final}
  72      * field initialized to a compile-time constant, or {@code null}
  73      * otherwise
  74      *
  75      * @see Elements#getConstantExpression(Object)
  76      * @jls 15.28 Constant Expression
  77      * @jls 4.12.4 final Variables
  78      */
  79     Object getConstantValue();
  80 
  81     /**
  82      * Returns the simple name of this variable element.
  83      *
  84      * <p>For method and constructor parameters, the name of each
  85      * parameter must be distinct from the names of all other
  86      * parameters of the same executable.  If the original source
  87      * names are not available, an implementation may synthesize names
  88      * subject to the distinctness requirement above.
  89      *
  90      * @return the simple name of this variable element
  91      */
  92     @Override
  93     Name getSimpleName();
  94 
  95     /**
  96      * Returns the enclosing element of this variable.
  97      *
  98      * The enclosing element of a method or constructor parameter is
  99      * the executable declaring the parameter.
 100      *
 101      * @return the enclosing element of this variable
 102      */
 103     @Override
 104     Element getEnclosingElement();
 105 }