Class OpMap

java.lang.Object
org.htmlunit.xpath.compiler.OpMap
Direct Known Subclasses:
Compiler

public class OpMap extends Object
This class represents the data structure basics of the XPath object.
Author:
Apache Xalan, Ronald Brill
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected String
    The current pattern string, for diagnostics purposes
    static final int
    The length is always the opcode position + 1.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    error(String msg, Object[] args)
    Tell the user of an error, and probably throw an exception.
    int
    getArgLengthOfStep(int opPos)
    Given a location step, get the length of that step.
    static int
    getFirstChildPos(int opPos)
    Go to the first child of a given operation.
    static int
    Get the first child position of a given location step.
    int
    Given an FROM_stepType position, return the position of the first predicate, if there is one, or else this will point to the end of the FROM_stepType.
    int
    getNextOpPos(int opPos)
    Given an operation position, return the end position, i.e. the beginning of the next operation.
    int
    getNextStepPos(int opPos)
    Given a location step position, return the end position, i.e. the beginning of the next step.
    int
    getOp(int opPos)
    Given an operation position, return the current op.
    Get the underlying OpMapVector.
    Return the expression as a string for diagnostics.
    getStepLocalName(int opPosOfStep)
    Get the local name of the step.
    getStepNS(int opPosOfStep)
    Get the namespace of the step.
    int
    getStepTestType(int opPosOfStep)
    Get the test type of the step, i.e.
    Get the XPath as a list of tokens.
    int
    Get size of the token queue.
    void
    Resets this OpMap to a clean initial state so it can be reused for a fresh parse without constructing a new instance.
    void
    setOp(int opPos, int value)
    Set the op at index to the given int.
    void
    Set the underlying OpMapVector.
    void
    setPatternString(String currentPattern)
    Set the expression string for diagnostics.

    Methods inherited from class java.lang.Object

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

    • currentPattern

      protected String currentPattern
      The current pattern string, for diagnostics purposes
    • MAPINDEX_LENGTH

      public static final int MAPINDEX_LENGTH
      The length is always the opcode position + 1. Length is always expressed as the opcode+length bytes, so it is always 2 or greater.
      See Also:
  • Constructor Details

    • OpMap

      public OpMap()
  • Method Details

    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getPatternString

      public String getPatternString()
      Return the expression as a string for diagnostics.
      Returns:
      The expression string.
    • setPatternString

      public void setPatternString(String currentPattern)
      Set the expression string for diagnostics.
      Parameters:
      currentPattern - The expression string.
    • getTokenQueue

      public List<Object> getTokenQueue()
      Get the XPath as a list of tokens.
      Returns:
      ObjectVector of tokens.
    • getTokenQueueSize

      public int getTokenQueueSize()
      Get size of the token queue.
      Returns:
      The size of the token queue.
    • getOpMap

      public OpMapVector getOpMap()
      Get the underlying OpMapVector.
      Returns:
      The OpMapVector instance.
    • setOpMap

      public void setOpMap(OpMapVector opMap)
      Set the underlying OpMapVector.
      Parameters:
      opMap - The OpMapVector instance to set.
    • reset

      public void reset()
      Resets this OpMap to a clean initial state so it can be reused for a fresh parse without constructing a new instance.

      This is the symmetric counterpart to shrink(): where shrink() releases surplus capacity after a successful parse, reset() clears all content before a new one begins.

      Callers must invoke this before calling Lexer.tokenize(java.lang.String) a second time on the same instance. tokenize() appends to the existing token queue rather than replacing it, and XPathParser.Literal() mutates queue slots from String to XString. If those mutations survive into a subsequent parse, XPathParser.nextToken() will throw ClassCastException when it casts the slot back to String.

    • getOp

      public int getOp(int opPos)
      Given an operation position, return the current op.
      Parameters:
      opPos - index into op map.
      Returns:
      the op that corresponds to the opPos argument.
    • setOp

      public void setOp(int opPos, int value)
      Set the op at index to the given int.
      Parameters:
      opPos - index into op map.
      value - Value to set
    • getNextOpPos

      public int getNextOpPos(int opPos)
      Given an operation position, return the end position, i.e. the beginning of the next operation.
      Parameters:
      opPos - An op position of an operation for which there is a size entry following.
      Returns:
      position of next operation in opMap.
    • getNextStepPos

      public int getNextStepPos(int opPos)
      Given a location step position, return the end position, i.e. the beginning of the next step.
      Parameters:
      opPos - the position of a location step.
      Returns:
      the position of the next location step.
    • getFirstPredicateOpPos

      public int getFirstPredicateOpPos(int opPos) throws TransformerException
      Given an FROM_stepType position, return the position of the first predicate, if there is one, or else this will point to the end of the FROM_stepType. Example: int posOfPredicate = xpath.getNextOpPos(stepPos); boolean hasPredicates = OpCodes.OP_PREDICATE == xpath.getOp(posOfPredicate);
      Parameters:
      opPos - position of FROM_stepType op.
      Returns:
      position of predicate in FROM_stepType structure.
      Throws:
      TransformerException - if an unknown opcode is encountered.
    • error

      public void error(String msg, Object[] args) throws TransformerException
      Tell the user of an error, and probably throw an exception.
      Parameters:
      msg - An error msgkey that corresponds to one of the constants found in XPATHErrorResources, which is a key for a format string.
      args - An array of arguments represented in the format string, which may be null.
      Throws:
      TransformerException - if the current ErrorListoner determines to throw an exception.
    • getFirstChildPos

      public static int getFirstChildPos(int opPos)
      Go to the first child of a given operation.
      Parameters:
      opPos - position of operation.
      Returns:
      The position of the first child of the operation.
    • getArgLengthOfStep

      public int getArgLengthOfStep(int opPos)
      Given a location step, get the length of that step.
      Parameters:
      opPos - Position of location step in op map.
      Returns:
      The length of the step.
    • getFirstChildPosOfStep

      public static int getFirstChildPosOfStep(int opPos)
      Get the first child position of a given location step.
      Parameters:
      opPos - Position of location step in the location map.
      Returns:
      The first child position of the step.
    • getStepTestType

      public int getStepTestType(int opPosOfStep)
      Get the test type of the step, i.e. NODETYPE_XXX value.
      Parameters:
      opPosOfStep - The position of the FROM_XXX step.
      Returns:
      NODETYPE_XXX value.
    • getStepNS

      public String getStepNS(int opPosOfStep)
      Get the namespace of the step.
      Parameters:
      opPosOfStep - The position of the FROM_XXX step.
      Returns:
      The step's namespace, NodeTest.WILD, or null for null namespace.
    • getStepLocalName

      public String getStepLocalName(int opPosOfStep)
      Get the local name of the step.
      Parameters:
      opPosOfStep - The position of the FROM_XXX step.
      Returns:
      OpCodes.EMPTY, OpCodes.ELEMWILDCARD, or the local name.