Class JSUtilities.Locator

java.lang.Object
org.bzdev.util.JSUtilities.Locator
Enclosing class:
JSUtilities

public static class JSUtilities.Locator extends Object
Determines a location in nested instances of JSObject and JSArray. To capture a location, set the locator and then use the constructor Location(Locator).

When parsing or traversing a tree of nested instances of JSObject and JSArray, one will call pushLevel() when starting to process an object and popLevel() when done. The method setKey(String) for each property name (or key) in a JSObject, and incrList() is called whenever moving to the next element in a JSArray. For a parser, each time the location changes one should use the constructor Location(Locator) to capture the current location and add a map entry mapping that location to an instance of JSUtilities.LocationPair that contains the corresponding line number and column number.

See Also:
  • Constructor Details

    • Locator

      public Locator()
      Constructor.
  • Method Details

    • size

      public int size()
      Get current nesting depth. The value is the sum of the number of keys and indexes at the current point in nested instances of JSObject and JSArray.
      Returns:
      the nesting depth
    • pushLevel

      public void pushLevel()
      Add the nest nesting level.
    • popLevel

      public void popLevel()
      Add remove the deepest nesting level.
    • incrList

      public void incrList()
      Increment the index at the current nesting level and remove any key that was set at this level.
    • setKey

      public void setKey(String value)
      Set the key for the current nesting level.
      Parameters:
      value - the key
    • toString

      public String toString()
      Overrides:
      toString in class Object