Class NegateExpression

All Implemented Interfaces:
ExportAgent, Locatable, IdentityComparable, Traceable

public class NegateExpression extends UnaryExpression
Negate Expression: implements the unary minus operator. This expression is initially created as an ArithmeticExpression (or in backwards compatibility mode, an ArithmeticExpression10) to take advantage of the type checking code. So we don't need to worry about type checking or argument conversion.
  • Constructor Details

    • NegateExpression

      public NegateExpression(Expression base)
      Create a NegateExpression
      Parameters:
      base - the expression that computes the value whose sign is to be reversed
  • Method Details

    • setBackwardsCompatible

      public void setBackwardsCompatible(boolean compatible)
      Set whether the expression is to be evaluated in XPath 1.0 compatibility mode
      Parameters:
      compatible - true if XPath 1.0 compatibility mode is enabled
    • isBackwardsCompatible

      public boolean isBackwardsCompatible()
      Ask whether the expression is to be evaluated in XPath 1.0 compatibility mode
      Returns:
      true if XPath 1.0 compatibility mode is enabled
    • getOperandRole

      protected OperandRole getOperandRole()
      Description copied from class: UnaryExpression
      Get the usage (in terms of streamability analysis) of the single operand
      Specified by:
      getOperandRole in class UnaryExpression
      Returns:
      the operand usage
    • typeCheck

      public Expression typeCheck(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException
      Description copied from class: UnaryExpression
      Type-check the expression. Default implementation for unary operators that accept any kind of operand
      Overrides:
      typeCheck in class UnaryExpression
      Parameters:
      visitor - an expression visitor
      contextInfo - Information available statically about the context item: whether it is (possibly) absent; its static type; its streaming posture.
      Returns:
      the original expression, rewritten to perform necessary run-time type checks, and to perform other type-related optimizations
      Throws:
      XPathException - if an error is discovered during this phase (typically a type error)
    • getItemType

      public ItemType getItemType()
      Determine the data type of the expression, if this is known statically
      Overrides:
      getItemType in class UnaryExpression
      Returns:
      the item type of the items in the result sequence, insofar as this is known statically.
    • computeCardinality

      protected int computeCardinality()
      Description copied from class: UnaryExpression
      Determine the static cardinality. Default implementation returns the cardinality of the operand
      Overrides:
      computeCardinality in class UnaryExpression
      Returns:
      the computed cardinality, as one of the values StaticProperty.ALLOWS_ZERO_OR_ONE, StaticProperty.EXACTLY_ONE, StaticProperty.ALLOWS_ONE_OR_MORE, StaticProperty.ALLOWS_ZERO_OR_MORE. May also return StaticProperty.ALLOWS_ZERO if the result is known to be an empty sequence, or StaticProperty.ALLOWS_MANY if if is known to return a sequence of length two or more.
    • getImplementationMethod

      public int getImplementationMethod()
      An implementation of Expression must provide at least one of the methods evaluateItem(), iterate(), or process(). This method indicates which of these methods is provided directly. The other methods will always be available indirectly, using an implementation that relies on one of the other methods.
      Specified by:
      getImplementationMethod in class Expression
      Returns:
      the implementation method, for example Expression.ITERATE_METHOD or Expression.EVALUATE_METHOD or Expression.PROCESS_METHOD
    • evaluateItem

      public NumericValue evaluateItem(XPathContext context) throws XPathException
      Evaluate the expression.
      Overrides:
      evaluateItem in class Expression
      Parameters:
      context - The context in which the expression is to be evaluated
      Returns:
      the node or atomic value that results from evaluating the expression; or null to indicate that the result is an empty sequence
      Throws:
      XPathException - if any dynamic error occurs evaluating the expression
    • copy

      public Expression copy(RebindingMap rebindings)
      Copy an expression. This makes a deep copy.
      Specified by:
      copy in class Expression
      Parameters:
      rebindings - variables that need to be re-bound
      Returns:
      the copy of the original expression
    • displayOperator

      protected String displayOperator(Configuration config)
      Description copied from class: UnaryExpression
      Give a string representation of the operator for use in diagnostics
      Overrides:
      displayOperator in class UnaryExpression
      Parameters:
      config - the Saxon configuration
      Returns:
      the operator, as a string
    • getExpressionName

      public String getExpressionName()
      Get a name identifying the kind of expression, in terms meaningful to a user.
      Overrides:
      getExpressionName in class Expression
      Returns:
      a name identifying the kind of expression, in terms meaningful to a user. The name will always be in the form of a lexical XML QName, and should match the name used in explain() output displaying the expression.
    • export

      public void export(ExpressionPresenter out) throws XPathException
      Description copied from class: UnaryExpression
      Diagnostic print of expression structure. The abstract expression tree is written to the supplied output destination.
      Specified by:
      export in interface ExportAgent
      Overrides:
      export in class UnaryExpression
      Parameters:
      out - the expression presenter used to display the structure
      Throws:
      XPathException - if the export fails, for example if an expression is found that won't work in the target environment.
    • getElaborator

      public Elaborator getElaborator()
      Make an elaborator for this expression
      Overrides:
      getElaborator in class Expression
      Returns:
      a suitable elaborator