org.basex.query.value.item
Class FuncItem

java.lang.Object
  extended by org.basex.data.ExprInfo
      extended by org.basex.query.expr.Expr
          extended by org.basex.query.value.Value
              extended by org.basex.query.value.item.Item
                  extended by org.basex.query.value.item.FItem
                      extended by org.basex.query.value.item.FuncItem
All Implemented Interfaces:
java.lang.Iterable<Item>, XQFunction, Scope

public final class FuncItem
extends FItem
implements Scope

Function item.

Author:
BaseX Team 2005-12, BSD License, Leo Woerteler

Nested Class Summary
 
Nested classes/interfaces inherited from class org.basex.query.expr.Expr
Expr.Flag
 
Field Summary
 StaticFunc func
          Original function.
 
Fields inherited from class org.basex.query.value.item.Item
score, UNDEF
 
Fields inherited from class org.basex.query.value.Value
type
 
Constructor Summary
FuncItem(QNm n, Var[] arg, Expr body, FuncType t, boolean cst, java.util.Map<Var,Value> cls, VarScope scp, StaticContext sctx, StaticFunc sf)
          Constructor.
FuncItem(QNm n, Var[] arg, Expr body, FuncType t, boolean cst, Value vl, long ps, long sz, java.util.Map<Var,Value> cls, VarScope scp, StaticContext sctx, StaticFunc sf)
          Constructor.
FuncItem(QNm n, Var[] arg, Expr body, FuncType t, VarScope scp, StaticContext sctx, StaticFunc sf)
          Constructor.
FuncItem(Var[] arg, Expr body, FuncType t, java.util.Map<Var,Value> cl, boolean cst, VarScope scp, StaticContext sctx)
          Constructor for anonymous functions.
 
Method Summary
 boolean accept(ASTVisitor visitor)
          Traverses this expression, notifying the visitor of declared and used variables, and checking the tree for other recursive properties.
 int arity()
          Number of arguments this function takes.
 FItem coerceTo(FuncType ft, QueryContext ctx, InputInfo ii)
          Coerces this function item to the given function type.
 void compile(QueryContext ctx)
          Compiles the expression contained in this scope.
 boolean compiled()
          Checks if this scope has already been compiled.
 QNm fName()
          Name of this function, null means anonymous function.
 FuncType funcType()
          Type of this function.
 Item invItem(QueryContext ctx, InputInfo ii, Value... args)
          Invokes this function with the given arguments.
 Value invValue(QueryContext ctx, InputInfo ii, Value... args)
          Invokes this function with the given arguments.
 void plan(FElem plan)
          Creates an expression tree.
 java.lang.String toString()
           
 boolean visit(ASTVisitor visitor)
          Traverses this scope with the given ASTVisitor.
 
Methods inherited from class org.basex.query.value.item.FItem
eq, string, toJava
 
Methods inherited from class org.basex.query.value.item.Item
bool, castErr, comparable, dbl, dec, description, diff, ebv, equiv, flt, hash, homogeneous, input, isItem, item, itemAt, iter, iterable, itr, materialize, score, score, size, test, type, typeId, writeTo, xdmInfo
 
Methods inherited from class org.basex.query.value.Value
cache, checkUp, compile, copy, count, data, exprSize, has, inline, isValue, iter, iterator, removable, serialize, value
 
Methods inherited from class org.basex.query.expr.Expr
addText, compEbv, copy, hasFreeVars, indexAccessible, indexEquivalent, inlineAll, isEmpty, isFunction, isVacuous, markTailCalls, optimize, sameAs, uses, visitAll
 
Methods inherited from class org.basex.data.ExprInfo
addPlan, addPlan, info, planAttr, planElem
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

func

public final StaticFunc func
Original function.

Constructor Detail

FuncItem

public FuncItem(QNm n,
                Var[] arg,
                Expr body,
                FuncType t,
                VarScope scp,
                StaticContext sctx,
                StaticFunc sf)
Constructor.

Parameters:
n - function name
arg - function arguments
body - function body
t - function type
scp - variable scope
sctx - static context
sf - original function

FuncItem

public FuncItem(QNm n,
                Var[] arg,
                Expr body,
                FuncType t,
                boolean cst,
                java.util.Map<Var,Value> cls,
                VarScope scp,
                StaticContext sctx,
                StaticFunc sf)
Constructor.

Parameters:
n - function name
arg - function arguments
body - function body
t - function type
cst - cast flag
cls - closure
scp - variable scope
sctx - static context
sf - original function

FuncItem

public FuncItem(Var[] arg,
                Expr body,
                FuncType t,
                java.util.Map<Var,Value> cl,
                boolean cst,
                VarScope scp,
                StaticContext sctx)
Constructor for anonymous functions.

Parameters:
arg - function arguments
body - function body
t - function type
cl - variables in the closure
cst - cast flag
scp - variable scope
sctx - static context

FuncItem

public FuncItem(QNm n,
                Var[] arg,
                Expr body,
                FuncType t,
                boolean cst,
                Value vl,
                long ps,
                long sz,
                java.util.Map<Var,Value> cls,
                VarScope scp,
                StaticContext sctx,
                StaticFunc sf)
Constructor.

Parameters:
n - function name
arg - function arguments
body - function body
t - function type
cst - cast flag
vl - context value
ps - context position
sz - context size
cls - closure
scp - variable scope
sctx - static context
sf - original function
Method Detail

arity

public int arity()
Description copied from interface: XQFunction
Number of arguments this function takes.

Specified by:
arity in interface XQFunction
Returns:
function arity

fName

public QNm fName()
Description copied from interface: XQFunction
Name of this function, null means anonymous function.

Specified by:
fName in interface XQFunction
Returns:
name or null

funcType

public FuncType funcType()
Description copied from interface: XQFunction
Type of this function.

Specified by:
funcType in interface XQFunction
Returns:
this function's type

invValue

public Value invValue(QueryContext ctx,
                      InputInfo ii,
                      Value... args)
               throws QueryException
Description copied from interface: XQFunction
Invokes this function with the given arguments.

Specified by:
invValue in interface XQFunction
Parameters:
ctx - query context
ii - input info
args - arguments
Returns:
resulting iterator
Throws:
QueryException - query exception

invItem

public Item invItem(QueryContext ctx,
                    InputInfo ii,
                    Value... args)
             throws QueryException
Description copied from interface: XQFunction
Invokes this function with the given arguments.

Specified by:
invItem in interface XQFunction
Overrides:
invItem in class FItem
Parameters:
ctx - query context
ii - input info
args - arguments
Returns:
resulting item
Throws:
QueryException - query exception

coerceTo

public FItem coerceTo(FuncType ft,
                      QueryContext ctx,
                      InputInfo ii)
               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
ctx - query context
ii - input info
Returns:
coerced item
Throws:
QueryException - query exception

plan

public void plan(FElem plan)
Description copied from class: ExprInfo
Creates an expression tree.

Specified by:
plan in class FItem
Parameters:
plan - root element

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

compile

public void compile(QueryContext ctx)
             throws QueryException
Description copied from interface: Scope
Compiles the expression contained in this scope.

Specified by:
compile in interface Scope
Parameters:
ctx - query context
Throws:
QueryException - compilation errors

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

toString

public java.lang.String toString()
Specified by:
toString in class ExprInfo