1 /*
   2  * Copyright (c) 1998, 2013, 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 com.sun.jdi;
  27 
  28 /**
  29  * A local variable in the target VM. Each variable declared within a
  30  * {@link Method} has its own LocalVariable object. Variables of the same
  31  * name declared in different scopes have different LocalVariable objects.
  32  * LocalVariables can be used alone to retrieve static information
  33  * about their declaration, or can be used in conjunction with a
  34  * {@link StackFrame} to set and get values.
  35  *
  36  * @see StackFrame
  37  * @see Method
  38  *
  39  * @author Robert Field
  40  * @author Gordon Hirsch
  41  * @author James McIlree
  42  * @since  1.3
  43  */
  44 
  45 public interface LocalVariable extends Mirror, Comparable<LocalVariable> {
  46 
  47     /**
  48      * Gets the name of the local variable.
  49      *
  50      * @return a string containing the name.
  51      */
  52     String name();
  53 
  54     /**
  55      * Returns a text representation of the type
  56      * of this variable.
  57      * Where the type is the type specified in the declaration
  58      * of this local variable.
  59      * <P>
  60      * This type name is always available even if
  61      * the type has not yet been created or loaded.
  62      *
  63      * @return a String representing the
  64      * type of this local variable.
  65 
  66      */
  67     String typeName();
  68 
  69     /**
  70      * Returns the type of this variable.
  71      * Where the type is the type specified in the declaration
  72      * of this local variable.
  73      * <P>
  74      * Note: if the type of this variable is a reference type (class,
  75      * interface, or array) and it has not been created or loaded
  76      * by the class loader of the enclosing class,
  77      * then ClassNotLoadedException will be thrown.
  78      * Also, a reference type may have been loaded but not yet prepared,
  79      * in which case the type will be returned
  80      * but attempts to perform some operations on the returned type
  81      * (e.g. {@link ReferenceType#fields() fields()}) will throw
  82      * a {@link ClassNotPreparedException}.
  83      * Use {@link ReferenceType#isPrepared()} to determine if
  84      * a reference type is prepared.
  85      *
  86      * @see Type
  87      * @see Field#type() Field.type() - for usage examples
  88      * @return the {@link Type} of this local variable.
  89      * @throws ClassNotLoadedException if the type has not yet been loaded
  90      * through the appropriate class loader.
  91      */
  92     Type type() throws ClassNotLoadedException;
  93 
  94     /**
  95      * Gets the <a href="{@docRoot}/../specs/jni/types.html#type-signatures">
  96      * type signature</a> of the local variable.
  97      *
  98      * @return a string containing the signature.
  99      */
 100     String signature();
 101 
 102     /**
 103      * Gets the generic signature for this variable if there is one.
 104      * Generic signatures are described in the
 105      * <cite>The Java Virtual Machine Specification</cite>.
 106      *
 107      * @return a string containing the generic signature, or <code>null</code>
 108      * if there is no generic signature.
 109      *
 110      * @since 1.5
 111      */
 112     String genericSignature();
 113 
 114     /**
 115      * Determines whether this variable can be accessed from the given
 116      * {@link StackFrame}.
 117      *
 118      * See {@link StackFrame#visibleVariables} for a complete description
 119      * variable visibility in this interface.
 120      *
 121      * @param frame the StackFrame querying visibility
 122      * @return <code>true</code> if this variable is visible;
 123      * <code>false</code> otherwise.
 124      * @throws IllegalArgumentException if the stack frame's method
 125      * does not match this variable's method.
 126      */
 127     boolean isVisible(StackFrame frame);
 128 
 129     /**
 130      * Determines if this variable is an argument to its method.
 131      *
 132      * @return <code>true</code> if this variable is an argument;
 133      * <code>false</code> otherwise.
 134      */
 135     boolean isArgument();
 136 
 137     /**
 138      * Compares the specified Object with this LocalVariable for equality.
 139      *
 140      * @return  true if the Object is a LocalVariable, if both LocalVariables
 141      * are contained in the same method (as determined by
 142      * {@link Method#equals}), and if both LocalVariables mirror
 143      * the same declaration within that method
 144      */
 145     boolean equals(Object obj);
 146 
 147     /**
 148      * Returns the hash code value for this LocalVariable.
 149      *
 150      * @return the integer hash code
 151      */
 152     int hashCode();
 153 }