Class FuncItem

All Implemented Interfaces:
Iterable<Item>, XQFunction, XQFunctionExpr, Scope

public final class FuncItem extends FItem implements Scope
Function item.
Author:
BaseX Team 2005-21, BSD License, Leo Woerteler
  • Field Details

  • Constructor Details

    • FuncItem

      public FuncItem(StaticContext sc, AnnList anns, QNm name, Var[] params, FuncType type, Expr expr, int stackSize, InputInfo info)
      Constructor.
      Parameters:
      sc - static context
      anns - function annotations
      name - function name (may be null)
      params - formal parameters
      type - function type
      expr - function body
      stackSize - stack-frame size
      info - input info
    • FuncItem

      public FuncItem(StaticContext sc, AnnList anns, QNm name, Var[] params, FuncType type, Expr expr, QueryFocus focus, int stackSize, InputInfo info)
      Constructor.
      Parameters:
      sc - static context
      anns - function annotations
      name - function name (may be null)
      params - formal parameters
      type - function type
      expr - function body
      focus - query focus (may be null)
      stackSize - stack-frame size
      info - input info
  • Method Details

    • arity

      public int arity()
      Description copied from interface: XQFunctionExpr
      Number of arguments this function takes.
      Specified by:
      arity in interface XQFunctionExpr
      Returns:
      function arity
    • funcName

      public QNm funcName()
      Description copied from interface: XQFunctionExpr
      Name of this function, null means anonymous function.
      Specified by:
      funcName in interface XQFunctionExpr
      Returns:
      name or null
    • paramName

      public QNm paramName(int ps)
      Description copied from interface: XQFunctionExpr
      Name of the parameter at the given position.
      Specified by:
      paramName in interface XQFunctionExpr
      Parameters:
      ps - position of the parameter
      Returns:
      name of the parameter
    • invokeInternal

      public Value invokeInternal(QueryContext qc, InputInfo ii, Value[] args) throws QueryException
      Description copied from interface: XQFunction
      Internally invokes this function with the given arguments.
      Specified by:
      invokeInternal in interface XQFunction
      Parameters:
      qc - query context
      ii - input info
      args - arguments
      Returns:
      resulting value
      Throws:
      QueryException - query exception
    • stackFrameSize

      public int stackFrameSize()
      Description copied from interface: XQFunction
      Size of this function's stack frame.
      Specified by:
      stackFrameSize in interface XQFunction
      Returns:
      stack frame size
    • coerceTo

      public FuncItem coerceTo(FuncType ft, QueryContext qc, InputInfo ii, boolean optimize) throws QueryException
      Description copied from class: FItem
      Coerces this function item to the given function type.
      Specified by:
      coerceTo in class FItem
      Parameters:
      ft - function type
      qc - query context
      ii - input info
      optimize - optimize resulting item
      Returns:
      coerced item
      Throws:
      QueryException - query exception
    • accept

      public boolean accept(ASTVisitor visitor)
      Description copied from class: Expr
      Traverses this expression, notifying the visitor of declared and used variables, and checking the tree for other recursive properties.
      Overrides:
      accept in class Value
      Parameters:
      visitor - visitor
      Returns:
      if the walk should be continued
    • visit

      public boolean visit(ASTVisitor visitor)
      Description copied from interface: Scope
      Traverses this scope with the given ASTVisitor.
      Specified by:
      visit in interface Scope
      Parameters:
      visitor - visitor
      Returns:
      continue flag
    • comp

      public void comp(CompileContext cc)
      Description copied from interface: Scope
      Compiles the expression contained in this scope.
      Specified by:
      comp in interface Scope
      Parameters:
      cc - compilation context
    • compiled

      public boolean compiled()
      Description copied from interface: Scope
      Checks if this scope has already been compiled.
      Specified by:
      compiled in interface Scope
      Returns:
      result of check
    • toJava

      public Object toJava()
      Description copied from class: Value
      Returns a Java representation of the value.
      Specified by:
      toJava in class Value
      Returns:
      Java object
    • inline

      public Expr inline(Expr[] exprs, CompileContext cc) throws QueryException
      Description copied from interface: XQFunctionExpr
      Tries to inline this function with the given arguments.
      Specified by:
      inline in interface XQFunctionExpr
      Parameters:
      exprs - arguments
      cc - compilation context
      Returns:
      the expression to inline if successful, null otherwise
      Throws:
      QueryException - query exception
    • atomValue

      public Value atomValue(QueryContext qc, InputInfo ii) throws QueryException
      Description copied from class: Item
      Evaluates the expression and returns the atomized items. Overwritten by XQArray, FuncItem and ANode.
      Overrides:
      atomValue in class Item
      Parameters:
      qc - query context
      ii - input info (only required by Seq instances, which have no input info)
      Returns:
      atomized item
      Throws:
      QueryException - query exception
    • atomItem

      public Item atomItem(QueryContext qc, InputInfo ii) throws QueryException
      Description copied from class: Item
      Evaluates the expression and returns the resulting, atomized item, or Empty.VALUE if the expression yields an empty sequence. Overwritten by XQArray, FuncItem and ANode.
      Overrides:
      atomItem in class Item
      Parameters:
      qc - query context
      ii - input info (only required by Seq instances, which have no input info)
      Returns:
      item or Empty.VALUE
      Throws:
      QueryException - query exception
    • materialize

      public Item materialize(QueryContext qc, boolean copy)
      Description copied from class: Item
      Returns a materialized, context-independent version of this item.
      Overrides:
      materialize in class Item
      Parameters:
      qc - query context (if null, process cannot be interrupted)
      copy - create full copy
      Returns:
      item copy, or null) if the item cannot be materialized
    • deep

      public boolean deep(Item item, Collation coll, InputInfo ii) throws QueryException
      Description copied from class: FItem
      Performs a deep comparison of two items.
      Specified by:
      deep in class FItem
      Parameters:
      item - item to be compared
      coll - collation (can be null)
      ii - input info
      Returns:
      result of check
      Throws:
      QueryException - query exception
    • vacuousBody

      public boolean vacuousBody()
      Description copied from interface: XQFunctionExpr
      Checks if this function returns vacuous results (see Expr.vacuous()).
      Specified by:
      vacuousBody in interface XQFunctionExpr
      Returns:
      result of check
    • equals

      public boolean equals(Object obj)
      Description copied from class: Expr
      This function is e.g. called by:
      Specified by:
      equals in class Expr
    • description

      public String description()
      Description copied from class: ExprInfo
      Returns a string description of the expression. This method is only called by error messages. Contrary to the ExprInfo.toString() method, arguments are not included in the output.
      Overrides:
      description in class Item
      Returns:
      result of check
    • plan

      public void plan(QueryPlan plan)
      Description copied from class: ExprInfo
      Creates a query plan.
      Overrides:
      plan in class Item
      Parameters:
      plan - expression plan
    • toErrorString

      public String toErrorString()
      Description copied from class: ExprInfo
      Returns a string representation of the expression that can be embedded in error messages. Defaults to ExprInfo.toString().
      Overrides:
      toErrorString in class ExprInfo
      Returns:
      class name
    • plan

      public void plan(QueryString qs)
      Description copied from class: ExprInfo
      Creates a query string.
      Specified by:
      plan in class ExprInfo
      Parameters:
      qs - query string builder