Class VariableAccessor

java.lang.Object
org.jruby.runtime.ivars.VariableAccessor
Direct Known Subclasses:
FieldVariableAccessor, NonvolatileVariableAccessor, StampedVariableAccessor, SynchronizedVariableAccessor

public abstract class VariableAccessor extends Object
Abstraction of an accessor for instance or internal variables on Ruby objects. Subclasses specialize this implementation appropriate to the current JVM's capabilities and the mechanism for laying out variables.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final int
    the symbol of the class associated with this variable
    static final VariableAccessor
    a dummy accessor that will always return null
    protected final int
    the index allocated for it in the variable table
    protected final String
    the name of the variable
    protected final RubyClass
    the "real" class associated with this variable
  • Constructor Summary

    Constructors
    Constructor
    Description
    VariableAccessor(RubyClass realClass, String name, int index, int classId)
    Construct a new VariableAccessor for the given "real" class, name, variable index, and class symbol.
  • Method Summary

    Modifier and Type
    Method
    Description
    get(Object object)
    Retrieve the variable's value from the given object.
    int
    Get the symbol of the class associated with this variable.
    int
    Get the index allocated for this variable.
    Get the name of this variable.
    static Object
    getVariable(RubyBasicObject object, int index)
    Retrieve the variable's value from the given object.
    void
    set(Object object, Object value)
    Set the value for this variable in the given object.
    Produce a string representation of this VariableAccessor.
    boolean
    verify(Object object)
    Verify if this is the correct accessor for the given object.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • name

      protected final String name
      the name of the variable
    • index

      protected final int index
      the index allocated for it in the variable table
    • classId

      protected final int classId
      the symbol of the class associated with this variable
    • realClass

      protected final RubyClass realClass
      the "real" class associated with this variable
    • DUMMY_ACCESSOR

      public static final VariableAccessor DUMMY_ACCESSOR
      a dummy accessor that will always return null
  • Constructor Details

    • VariableAccessor

      public VariableAccessor(RubyClass realClass, String name, int index, int classId)
      Construct a new VariableAccessor for the given "real" class, name, variable index, and class symbol.
      Parameters:
      realClass - the "real" class
      name - the variable's name
      index - the variable's index
      classId - the class's symbol
  • Method Details

    • getClassId

      public int getClassId()
      Get the symbol of the class associated with this variable.
      Returns:
      this variable's class's id
    • getIndex

      public int getIndex()
      Get the index allocated for this variable.
      Returns:
      this variable's index
    • getName

      public String getName()
      Get the name of this variable.
      Returns:
      this variable's name
    • get

      public Object get(Object object)
      Retrieve the variable's value from the given object.
      Parameters:
      object - the object from which to retrieve this variable
      Returns:
      the variable's value
    • getVariable

      public static Object getVariable(RubyBasicObject object, int index)
      Retrieve the variable's value from the given object. This version is static, allowing it to be more direct, and accepts nnly with RubyBasicObject and subclasses along with the direct index of the variable.
      Parameters:
      object - the object from which to retrieve the variable
      index - the index of the variable
      Returns:
      the variable's value
    • set

      public void set(Object object, Object value)
      Set the value for this variable in the given object.
      Parameters:
      object - the object into which to set this variable
      value - the value of the variable
    • verify

      public boolean verify(Object object)
      Verify if this is the correct accessor for the given object.
      Parameters:
      object - the object for which to test this accessor
      Returns:
      true if this is the correct accessor for the given object, false otherwise
    • toString

      public String toString()
      Produce a string representation of this VariableAccessor.
      Overrides:
      toString in class Object
      Returns:
      a string representation of this VariableAccessor