org.basex.query.var
Class Var

java.lang.Object
  extended by org.basex.data.ExprInfo
      extended by org.basex.query.var.Var

public final class Var
extends ExprInfo

Variable expression.

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

Field Summary
 SeqType declType
          Declared type, null if not specified.
 int id
          Variable ID.
 QNm name
          Variable name.
 long size
          Expected result size.
 int slot
          Stack slot number.
 
Method Summary
 boolean adoptCheck(SeqType t, boolean prom)
          Tries to adopt the given type check.
 Expr checked(Expr e, QueryContext ctx, VarScope scp, InputInfo ii)
          Returns an equivalent to the given expression that checks this variable's type.
 boolean checksType()
          Determines if this variable checks the type of the expression bound to it.
 Value checkType(Value val, QueryContext ctx, InputInfo ii)
          Checks the type of this value and casts/promotes it when necessary.
 SeqType declaredType()
          Declared type of this variable.
 boolean equals(java.lang.Object obj)
           
 int hashCode()
           
 boolean is(Var v)
          Checks whether the given variable is identical to this one, i.e.
 void plan(FElem plan)
          Creates an expression tree.
 boolean promotes()
          Checks if this variable performs function conversion on its bound values.
 void refineType(SeqType t, QueryContext ctx, InputInfo ii)
          Tries to refine the compile-time type of this variable through the type of the bound expression.
 java.lang.String toString()
           
 SeqType type()
          Type of values bound to this variable.
 
Methods inherited from class org.basex.data.ExprInfo
addPlan, addPlan, description, info, planAttr, planElem
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

name

public final QNm name
Variable name.


id

public final int id
Variable ID.


declType

public SeqType declType
Declared type, null if not specified.


slot

public int slot
Stack slot number.


size

public long size
Expected result size.

Method Detail

type

public SeqType type()
Type of values bound to this variable.

Returns:
(non-null) type

declaredType

public SeqType declaredType()
Declared type of this variable.

Returns:
declared type, possibly null

refineType

public void refineType(SeqType t,
                       QueryContext ctx,
                       InputInfo ii)
                throws QueryException
Tries to refine the compile-time type of this variable through the type of the bound expression.

Parameters:
t - type of the bound expression
ctx - query context
ii - input info
Throws:
QueryException - query exception

checksType

public boolean checksType()
Determines if this variable checks the type of the expression bound to it.

Returns:
true if the type is checked or promoted, false otherwise

checked

public Expr checked(Expr e,
                    QueryContext ctx,
                    VarScope scp,
                    InputInfo ii)
             throws QueryException
Returns an equivalent to the given expression that checks this variable's type.

Parameters:
e - expression
scp - variable scope
ctx - query context
ii - input info
Returns:
checked expression
Throws:
QueryException - query exception

checkType

public Value checkType(Value val,
                       QueryContext ctx,
                       InputInfo ii)
                throws QueryException
Checks the type of this value and casts/promotes it when necessary.

Parameters:
val - value to be checked
ctx - query context
ii - input info
Returns:
checked and possibly cast value
Throws:
QueryException - if the check failed

is

public boolean is(Var v)
Checks whether the given variable is identical to this one, i.e. has the same ID.

Parameters:
v - variable to check
Returns:
true, if the IDs are equal, false otherwise

promotes

public boolean promotes()
Checks if this variable performs function conversion on its bound values.

Returns:
result of check

plan

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

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

toString

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

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

adoptCheck

public boolean adoptCheck(SeqType t,
                          boolean prom)
Tries to adopt the given type check.

Parameters:
t - type to check
prom - if function conversion should be applied
Returns:
true if the check could be adopted, false otherwise