com.bluemarsh.jswat.util
Class VariableUtils

java.lang.Object
  |
  +--com.bluemarsh.jswat.util.VariableUtils

public class VariableUtils
extends java.lang.Object

Class VariableUtils provides utility methods for getting Field objects and Value objects from an object or class in the debuggee VM.

Author:
Nathan Fiedler

Inner Class Summary
protected static class VariableUtils.ClassAndField
          Holds a ReferenceType/Field pair.
 
Constructor Summary
VariableUtils()
           
 
Method Summary
protected static com.sun.jdi.Field getField(com.sun.jdi.ObjectReference obj, java.lang.String field)
          Retrieves an object's field, given the reference to the object and the name of the field to fetch.
protected static com.sun.jdi.Field getField(com.sun.jdi.ReferenceType clazz, java.lang.String field)
          Retrieves a class's field, given the reference to the class and the name of the field to fetch.
static FieldAndValue getField(java.lang.String expr, com.sun.jdi.ThreadReference thread, int frameNum)
          Retrieves the named variable, using the top stack frame of the given thread.
static com.sun.jdi.Value getValue(java.lang.String expr, com.sun.jdi.ThreadReference thread, int index)
          Retrieves the named variable, using the stack frame of the given thread.
protected static VariableUtils.ClassAndField tryClassName(java.util.StringTokenizer tokenizer, com.sun.jdi.ReferenceType clazz, java.lang.String token, java.lang.NoSuchFieldException nsfe)
          Use the location's class, the token (assumed to be a class name), and the given exception (which is rethrown if this method fails), to see if the named class exists.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VariableUtils

public VariableUtils()
Method Detail

getField

protected static com.sun.jdi.Field getField(com.sun.jdi.ObjectReference obj,
                                            java.lang.String field)
                                     throws com.sun.jdi.ClassNotPreparedException,
                                            java.lang.NoSuchFieldException,
                                            com.sun.jdi.ObjectCollectedException
Retrieves an object's field, given the reference to the object and the name of the field to fetch.
Parameters:
obj - Current value (must be an ObjectReference).
field - Name of the field to look up.
Returns:
New Field as grabbed from the object.
Throws:
com.sun.jdi.ClassNotPreparedException - Thrown if the object's class is not loaded.
java.lang.NoSuchFieldException - Thrown if the field was not found in the object.
com.sun.jdi.ObjectCollectedException - Thrown if the referenced object has been collected.

getField

protected static com.sun.jdi.Field getField(com.sun.jdi.ReferenceType clazz,
                                            java.lang.String field)
                                     throws com.sun.jdi.ClassNotPreparedException,
                                            java.lang.NoSuchFieldException
Retrieves a class's field, given the reference to the class and the name of the field to fetch.
Parameters:
clazz - Class in which to find named field.
field - Name of the field to look up.
Returns:
New Field as grabbed from the class.
Throws:
com.sun.jdi.ClassNotPreparedException - Thrown if the class is not loaded.
java.lang.NoSuchFieldException - Thrown if the field was not found in the class.

getField

public static FieldAndValue getField(java.lang.String expr,
                                     com.sun.jdi.ThreadReference thread,
                                     int frameNum)
                              throws com.sun.jdi.AbsentInformationException,
                                     java.lang.ArrayIndexOutOfBoundsException,
                                     com.sun.jdi.ClassNotPreparedException,
                                     FieldNotObjectException,
                                     java.lang.IllegalThreadStateException,
                                     com.sun.jdi.IncompatibleThreadStateException,
                                     com.sun.jdi.InvalidStackFrameException,
                                     com.sun.jdi.NativeMethodException,
                                     java.lang.NoSuchFieldException,
                                     com.sun.jdi.ObjectCollectedException
Retrieves the named variable, using the top stack frame of the given thread.
Parameters:
expr - Expression referring to variable or object.
thread - ThreadReference from which to find variable.
frameNum - Frame number in which to look for field.
Returns:
instance of FieldAndValue holding the field, its value, and the object containing the field. May also be a local variable and its value, if return value's 'field' field is null.
Throws:
com.sun.jdi.AbsentInformationException - Thrown if class doesn't have local variable info.
java.lang.ArrayIndexOutOfBoundsException - Thrown if expression contained an out-of-range array index.
com.sun.jdi.ClassNotPreparedException - Thrown if the object's class is not loaded.
FieldNotObjectException - Thrown if a non-object is encountered.
java.lang.IllegalThreadStateException - Thrown if thread is not currently running.
com.sun.jdi.IncompatibleThreadStateException - Thrown if thread is not suspended.
com.sun.jdi.InvalidStackFrameException - Thrown if index is out of bounds.
com.sun.jdi.NativeMethodException - Thrown if the method is native and has no variables.
java.lang.NoSuchFieldException - Thrown if the field was not found in the object.
com.sun.jdi.ObjectCollectedException - Thrown if the referenced object has been collected.

getValue

public static com.sun.jdi.Value getValue(java.lang.String expr,
                                         com.sun.jdi.ThreadReference thread,
                                         int index)
                                  throws com.sun.jdi.AbsentInformationException,
                                         com.sun.jdi.ClassNotPreparedException,
                                         FieldNotObjectException,
                                         com.sun.jdi.IncompatibleThreadStateException,
                                         java.lang.IllegalThreadStateException,
                                         com.sun.jdi.InvalidStackFrameException,
                                         com.sun.jdi.NativeMethodException,
                                         java.lang.NoSuchFieldException,
                                         com.sun.jdi.ObjectCollectedException
Retrieves the named variable, using the stack frame of the given thread.
Parameters:
expr - Expression referring to variable or object.
thread - ThreadReference from which to find variable.
index - Index into stack frames to find variable.
Returns:
The Value referred to by 'expr'. Could possibly be null.
Throws:
com.sun.jdi.AbsentInformationException - Thrown if class doesn't have local variable info.
com.sun.jdi.ClassNotPreparedException - Thrown if the object's class is not loaded.
FieldNotObjectException - Thrown if a non-object is encountered.
java.lang.IllegalThreadStateException - Thrown if thread is not currently running.
com.sun.jdi.IncompatibleThreadStateException - Thrown if thread is not suspended.
com.sun.jdi.InvalidStackFrameException - Thrown if index is out of bounds.
com.sun.jdi.NativeMethodException - Thrown if current stack frame is a native method.
java.lang.NoSuchFieldException - Thrown if the field was not found in the object.
com.sun.jdi.ObjectCollectedException - Thrown if the referenced object has been collected.

tryClassName

protected static VariableUtils.ClassAndField tryClassName(java.util.StringTokenizer tokenizer,
                                                          com.sun.jdi.ReferenceType clazz,
                                                          java.lang.String token,
                                                          java.lang.NoSuchFieldException nsfe)
                                                   throws java.lang.NoSuchFieldException
Use the location's class, the token (assumed to be a class name), and the given exception (which is rethrown if this method fails), to see if the named class exists.
Parameters:
tokenizer - string tokenizer of user input.
clazz - class for this location.
token - the token assumed to be a class name.
nsfe - the exception thrown which leads us to guess that cname is a class name.
Returns:
the Field, if found. May not be static, so caller must check for that.
Throws:
java.lang.NoSuchFieldException - Thrown if cname is not a loaded class, or if the next token is not a field of that class.