Path: blob/master/src/java.compiler/share/classes/javax/lang/model/element/VariableElement.java
41161 views
/*1* Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.lang.model.element;2627import javax.lang.model.util.Elements;28import javax.lang.model.type.TypeMirror;29import javax.lang.model.type.TypeKind;3031/**32* Represents a field, {@code enum} constant, method or constructor33* parameter, local variable, resource variable, or exception34* parameter.35*36* @author Joseph D. Darcy37* @author Scott Seligman38* @author Peter von der Ahé39* @since 1.640*/41public interface VariableElement extends Element {42/**43* {@return the type of this variable}44*45* Note that the types of variables range over {@linkplain46* TypeKind many kinds} of types, including primitive types,47* declared types, and array types, among others.48*49* @see TypeKind50*/51@Override52TypeMirror asType();5354/**55* Returns the value of this variable if this is a {@code final}56* field initialized to a compile-time constant. Returns {@code57* null} otherwise. The value will be of a primitive type or a58* {@code String}. If the value is of a primitive type, it is59* wrapped in the appropriate wrapper class (such as {@link60* Integer}).61*62* <p>Note that not all {@code final} fields will have63* constant values. In particular, {@code enum} constants are64* <em>not</em> considered to be compile-time constants. To have a65* constant value, a field's type must be either a primitive type66* or {@code String}.67*68* @return the value of this variable if this is a {@code final}69* field initialized to a compile-time constant, or {@code null}70* otherwise71*72* @see Elements#getConstantExpression(Object)73* @jls 15.29 Constant Expressions74* @jls 4.12.4 final Variables75*/76Object getConstantValue();7778/**79* {@return the simple name of this variable element}80*81* <p>For method and constructor parameters, the name of each82* parameter must be distinct from the names of all other83* parameters of the same executable. If the original source84* names are not available, an implementation may synthesize names85* subject to the distinctness requirement above.86*/87@Override88Name getSimpleName();8990/**91* {@return the enclosing element of this variable}92*93* The enclosing element of a method or constructor parameter is94* the executable declaring the parameter.95*/96@Override97Element getEnclosingElement();98}99100101