@@ -43,19 +43,19 @@ public final void finishPi(final byte[] n, final byte[] v) throws IOException {
}

@Override
public final void finishAtomic(final Item b) throws IOException {
public final void atomic(final Item b) throws IOException {
Util.notexpected();
}

@Override
protected final void finishOpen() throws IOException {
build.startElem(tag, att);
build.startElem(elem, att);
att.reset();
}

@Override
protected void finishEmpty() throws IOException {
build.emptyElem(tag, att);
build.emptyElem(elem, att);
att.reset();
}

@@ -2,11 +2,12 @@

import static org.basex.core.Text.*;

import org.basex.data.*;
import org.basex.query.*;
import org.basex.query.expr.*;
import org.basex.query.flwor.*;
import org.basex.query.ft.*;
import org.basex.query.func.*;
import org.basex.query.item.*;
import org.basex.query.path.*;
import org.basex.query.util.*;
import org.basex.util.*;
@@ -55,131 +56,49 @@ private DOTData() { }
/** Hash map, caching colors for expressions. */
private static final Object[][] COLORS = {
// blue
{ "6666FF", "Item" },
{ "6666FF", "sequence" },
{ "6666FF", Item.class, Seq.class, Str.class, QNm.class, Uri.class, Int.class },
// violet
{ "9933FF", CFrag.class },
{ "9933CC", And.class },
{ "9933CC", Or.class },
{ "9933CC", Union.class },
{ "9933CC", InterSect.class },
{ "9933CC", Except.class },
{ "9933CC", "Then" },
{ "9933CC", "Else" },
{ "9933FF", CAttr.class, CComm.class, CDoc.class, CElem.class,
CNSpace.class, CPI.class, CTxt.class },
{ "9933CC", And.class, Or.class, Union.class, InterSect.class, Except.class },
// pink
{ "CC3399", If.class },
{ "CC3399", Quantifier.class },
{ "CC3399", "Where" },
{ "CC3399", Order.class },
{ "CC3399", If.class, Quantifier.class, Order.class, QueryText.WHR },
{ "CC6699", OrderBy.class },
// red
{ "FF3333", Arith.class },
{ "FF3333", CmpG.class },
{ "FF3333", CmpN.class },
{ "FF3333", CmpV.class },
{ "FF3333", CmpR.class },
{ "FF3333", Pos.class },
{ "FF3333", FTContains.class },
{ "FF6666", FTExpr.class },
{ "FF6666", Try.class },
{ "FF6666", Catch.class },
{ "FF3333", Arith.class, CmpG.class, CmpN.class, CmpV.class, CmpR.class,
Pos.class, FTContains.class },
{ "FF6666", FTExpr.class, Try.class, Catch.class },
// orange
{ "AA9988", UserFunc.class },
{ "776655", UserFuncs.class },
{ "CC6600", Path.class },
{ "FF9900", Preds.class },
// green
{ "009900", GFLWOR.class },
{ "009900", FLWR.class, GFLWOR.class },
{ "339933", VarStack.class },
{ "33CC33", ForLet.class },
{ "33CC33", List.class },
{ "33CC33", Range.class },
{ "33CC33", Context.class },
{ "33CC33", "Return" },
{ "66CC66", Var.class },
{ "66CC66", Cast.class },
{ "33CC33", For.class, Let.class, List.class, Range.class, Context.class,
QueryText.RET },
{ "66CC66", Var.class, Cast.class },
// cyan
{ "009999", UserFuncCall.class },
{ "00BBBB", StandardFunc.class },
{ "00BBBB", Root.class },
{ "00BBBB", VarRef.class },
{ "00BBBB", ValueAccess.class },
{ "00BBBB", RangeAccess.class },
{ "00BBBB", StringRangeAccess.class },
{ "00BBBB", FTIndexAccess.class },
{ "009999", UserFuncCall.class, StandardFunc.class, Root.class, VarRef.class,
ValueAccess.class, RangeAccess.class, StringRangeAccess.class,
FTIndexAccess.class },
};

/** Hash map, caching expression names. */
private static final Object[][] NAMES = {
{ "Calculation", Arith.class },
{ "Comparison", CmpG.class },
{ "Comparison", CmpN.class },
{ "Comparison", CmpV.class },
{ "Comparison", CmpR.class },
{ "FLWOR", FLWR.class },
{ "Declaration", UserFunc.class },
{ "Function", StandardFunc.class },
{ null, Path.class },
{ "Step", AxisStep.class },
{ "Variables", VarStack.class },
{ "OrderBy", OrderByExpr.class },
{ "operator", "op" },
};

/**
* Returns the color for the specified expression, or {@code null}.
* @param e expression
* @return color
*/
static String color(final ExprInfo e) {
for(final Object[] o : COLORS) {
if(o[1] instanceof Class<?> && ((Class<?>) o[1]).isInstance(e))
return o[0].toString();
}
return null;
}

/**
* Returns the color for the specified string, or {@code null}.
* @param s string string
* @return color
*/
static String color(final String s) {
for(final Object[] o : COLORS) {
if(o[1] instanceof String && s.equals(o[1].toString())) {
return o[0].toString();
static String color(final byte[] s) {
for(final Object[] color : COLORS) {
for(int c = 1; c < color.length; c++) {
final Object o = color[c];
final byte[] cl = o instanceof byte[] ? (byte[]) o :
Token.token(o instanceof Class ? Util.name((Class<?>) o) : o.toString());
if(Token.eq(cl, s)) return color[0].toString();
}
}
return null;
}

/**
* Returns the node name for the specified expression.
* @param e expression
* @return name
*/
static String name(final ExprInfo e) {
final String name = e.info();
for(final Object[] o : NAMES) {
if(!(o[1] instanceof Class<?>)) continue;
final Class<?> c = (Class<?>) o[1];
if(!c.isInstance(e)) continue;
return o[0] != null ? o[0].toString() : Util.name(c);
}
return name;
}

/**
* Returns the node name for the specified string.
* @param s string
* @return name
*/
static String name(final String s) {
for(final Object[] o : NAMES) {
if(!(o[1] instanceof String)) continue;
final String c = (String) o[1];
if(c.equals(s)) return o[0].toString();
}
return s;
}
}
@@ -7,7 +7,6 @@
import java.io.*;
import java.util.*;

import org.basex.data.*;
import org.basex.query.*;
import org.basex.query.item.*;
import org.basex.util.*;
@@ -29,9 +28,6 @@ public final class DOTSerializer extends OutputSerializer {
private final TokenBuilder tb = new TokenBuilder();
/** Cached nodes. */
private final IntList nodes = new IntList();

/** Current color. */
private String color;
/** Node counter. */
private int count;

@@ -41,9 +37,7 @@ public final class DOTSerializer extends OutputSerializer {
* @param c compact representation
* @throws IOException I/O exception
*/
public DOTSerializer(final OutputStream os, final boolean c)
throws IOException {

public DOTSerializer(final OutputStream os, final boolean c) throws IOException {
super(os, PROPS);
compact = c;
print(HEADER);
@@ -56,15 +50,15 @@ protected void startOpen(final byte[] t) {

@Override
public void attribute(final byte[] n, final byte[] v) {
tb.addExt(DOTATTR, name(string(n)), v);
tb.addExt(DOTATTR, n, v);
}

@Override
protected void finishOpen() throws IOException {
final byte[] attr = tb.finish();
if(color == null) color = color(string(tag));
String color = color(elem);
if(color == null) color = attr.length == 0 ? ELEM1 : ELEM2;
print(concat(tag, attr), color);
print(concat(elem, attr), color);
}

@Override
@@ -82,7 +76,6 @@ protected void finishClose() throws IOException {
indent();
print(Util.info(DOTLINK, c, il.get(i)));
}
color = null;
il.reset();
}

@@ -93,18 +86,16 @@ public void finishText(final byte[] t) throws IOException {

@Override
public void finishComment(final byte[] t) throws IOException {
print(new TokenBuilder(COMM_O).add(norm(t)).add(COMM_C).finish(),
DOTData.COMM);
print(new TokenBuilder(COMM_O).add(norm(t)).add(COMM_C).finish(), DOTData.COMM);
}

@Override
public void finishPi(final byte[] n, final byte[] v) throws IOException {
print(new TokenBuilder(PI_O).add(n).add(SPACE).add(v).add(PI_C).finish(),
DOTData.PI);
print(new TokenBuilder(PI_O).add(n).add(SPACE).add(v).add(PI_C).finish(), DOTData.PI);
}

@Override
public void finishAtomic(final Item it) throws IOException {
public void atomic(final Item it) throws IOException {
try {
print(norm(it.string(null)), ITEM);
} catch(final QueryException ex) {
@@ -144,9 +135,11 @@ private IntList child(final int i) {
return children.get(i);
}

/**
@Override
protected byte[] info(final ExprInfo expr) {
color = color(expr);
return token(name(expr));
}
*/
}
@@ -39,7 +39,7 @@ public class HTMLSerializer extends OutputSerializer {
@Override
public void attribute(final byte[] n, final byte[] v) throws IOException {
// don't append value for boolean attributes
final byte[] tagatt = concat(lc(tag), COLON, lc(n));
final byte[] tagatt = concat(lc(elem), COLON, lc(n));
if(BOOLEAN.contains(tagatt) && eq(n, v)) return;
// escape URI attributes
final byte[] val = escape && URIS.contains(tagatt) ? escape(v) : v;
@@ -98,7 +98,7 @@ protected void startOpen(final byte[] t) throws IOException {
print(t);
sep = indent;
script = SCRIPTS.contains(lc(t));
if(content && eq(lc(tag), HEAD)) ct++;
if(content && eq(lc(elem), HEAD)) ct++;
}

@Override
@@ -111,15 +111,15 @@ protected void finishOpen() throws IOException {
protected void finishEmpty() throws IOException {
if(ct(true, true)) return;
print(ELEM_C);
if(EMPTIES.contains(lc(tag))) return;
if(EMPTIES.contains(lc(elem))) return;
sep = false;
finishClose();
}

@Override
protected void finishClose() throws IOException {
super.finishClose();
script = script && !SCRIPTS.contains(lc(tag));
script = script && !SCRIPTS.contains(lc(elem));
}

// HTML Serializer: cache elements
@@ -58,9 +58,7 @@ protected void startOpen(final byte[] name) throws IOException {
}

@Override
public void attribute(final byte[] name, final byte[] value)
throws IOException {

public void attribute(final byte[] name, final byte[] value) throws IOException {
if(level == 0) {
final int tl = typeCache.length;
for(int t = 0; t < tl; t++) {
@@ -73,9 +71,9 @@ public void attribute(final byte[] name, final byte[] value)
if(eq(name, T_TYPE)) {
types.set(level, value);
if(!eq(value, TYPES))
error("Element <%> has invalid type \"%\"", tag, value);
error("Element <%> has invalid type \"%\"", elem, value);
} else {
error("Element <%> has invalid attribute \"%\"", tag, name);
error("Element <%> has invalid attribute \"%\"", elem, name);
}
}

@@ -89,7 +87,7 @@ protected void finishOpen() throws IOException {
final byte[] par = types.get(level - 1);
if(eq(par, T_OBJECT)) {
print('"');
print(name(tag));
print(name(elem));
print("\": ");
} else if(!eq(par, T_ARRAY)) {
error("Element <%> is typed as \"%\" and cannot be nested",
@@ -101,7 +99,7 @@ protected void finishOpen() throws IOException {
if(type == null) {
int t = -1;
final int tl = typeCache.length;
while(++t < tl && !typeCache[t].contains(tag));
while(++t < tl && !typeCache[t].contains(elem));
if(t != tl) type = TYPES[t];
else type = T_STRING;
types.set(level, type);
@@ -179,13 +177,12 @@ public void finishComment(final byte[] value) throws IOException {
}

@Override
public void finishPi(final byte[] name, final byte[] value)
throws IOException {
public void finishPi(final byte[] name, final byte[] value) throws IOException {
error("Processing instructions cannot be serialized");
}

@Override
public void finishAtomic(final Item value) throws IOException {
public void atomic(final Item value) throws IOException {
error("Atomic values cannot be serialized");
}

@@ -256,8 +253,7 @@ private static byte[] name(final byte[] name) {
* @param ext error details
* @throws IOException I/O exception
*/
private static void error(final String msg, final Object... ext)
throws IOException {
private static void error(final String msg, final Object... ext) throws IOException {
throw JSONSER.thrwSerial(Util.inf(msg, ext));
}
}
@@ -48,9 +48,7 @@ protected void startOpen(final byte[] name) throws IOException {
}

@Override
public void attribute(final byte[] name, final byte[] value)
throws IOException {

public void attribute(final byte[] name, final byte[] value) throws IOException {
print(", ");
if(!att) {
print("{");
@@ -108,16 +106,13 @@ protected void code(final int ch) throws IOException {
}

@Override
public void finishComment(final byte[] value) throws IOException {
}
public void finishComment(final byte[] value) throws IOException { }

@Override
public void finishPi(final byte[] name, final byte[] value)
throws IOException {
}
public void finishPi(final byte[] name, final byte[] value) throws IOException { }

@Override
public void finishAtomic(final Item value) throws IOException {
public void atomic(final Item value) throws IOException {
error("Atomic values cannot be serialized");
}

@@ -127,8 +122,7 @@ public void finishAtomic(final Item value) throws IOException {
* @param ext error details
* @throws IOException I/O exception
*/
private static void error(final String msg, final Object... ext)
throws IOException {
private static void error(final String msg, final Object... ext) throws IOException {
throw JSONSER.thrwSerial(Util.inf(msg, ext));
}
}
@@ -181,7 +181,7 @@ public abstract class OutputSerializer extends Serializer {

// open results element
if(wrap) {
openElement(concat(wPre, COLON, T_RESULTS));
startElement(concat(wPre, COLON, T_RESULTS));
namespace(wPre, token(p.get(S_WRAP_URI)));
}
}
@@ -200,7 +200,7 @@ public void close() throws IOException {

@Override
public void openResult() throws IOException {
if(wrap) openElement(wPre.length != 0 ? concat(wPre, COLON, T_RESULT) : T_RESULT);
if(wrap) startElement(wPre.length != 0 ? concat(wPre, COLON, T_RESULT) : T_RESULT);
}

@Override
@@ -286,7 +286,7 @@ public void finishPi(final byte[] n, final byte[] v) throws IOException {
}

@Override
public void finishAtomic(final Item it) throws IOException {
public void atomic(final Item it) throws IOException {
if(sep && item) {
final byte[] sp = separator;
final int sl = sp.length;
@@ -349,7 +349,7 @@ protected void finishEmpty() throws IOException {
protected void finishClose() throws IOException {
if(sep) indent();
print(ELEM_OS);
print(tag);
print(elem);
print(ELEM_C);
sep = true;
}
@@ -21,13 +21,12 @@ public final class RawSerializer extends TextSerializer {
* @param sp serialization properties
* @throws IOException I/O exception
*/
RawSerializer(final OutputStream os, final SerializerProp sp)
throws IOException {
RawSerializer(final OutputStream os, final SerializerProp sp) throws IOException {
super(os, sp);
}

@Override
public void finishAtomic(final Item it) throws IOException {
public void atomic(final Item it) throws IOException {
try {
final InputStream is = it.input(null);
try {

Large diffs are not rendered by default.

@@ -18,23 +18,22 @@ public class XHTMLSerializer extends OutputSerializer {
* @param p serialization properties
* @throws IOException I/O exception
*/
XHTMLSerializer(final OutputStream os, final SerializerProp p)
throws IOException {
XHTMLSerializer(final OutputStream os, final SerializerProp p) throws IOException {
super(os, p, V10, V11);
}

@Override
public void attribute(final byte[] n, final byte[] v) throws IOException {
// escape URI attributes
final byte[] tagatt = concat(lc(tag), COLON, lc(n));
final byte[] tagatt = concat(lc(elem), COLON, lc(n));
final byte[] val = escape && HTMLSerializer.URIS.contains(tagatt) ? escape(v) : v;
super.attribute(n, val);
}

@Override
protected void startOpen(final byte[] t) throws IOException {
super.startOpen(t);
if(content && eq(lc(tag), HEAD)) ct++;
if(content && eq(lc(elem), HEAD)) ct++;
}

@Override
@@ -46,7 +45,7 @@ protected void finishOpen() throws IOException {
@Override
protected void finishEmpty() throws IOException {
if(ct(true, false)) return;
if(HTMLSerializer.EMPTIES.contains(lc(tag))) {
if(HTMLSerializer.EMPTIES.contains(lc(elem))) {
print(' ');
print(ELEM_SC);
} else {
@@ -510,18 +510,16 @@ void bind(final String name, final Object val, final String type)
}

/**
* Recursively serializes the query plan.
* @param ser serializer
* @throws IOException I/O exception
* Recursively builds a query plan.
* @param doc root node
*/
void plan(final Serializer ser) throws IOException {
void plan(final FDoc doc) {
// only show root node if functions or variables exist
final boolean r = funcs.funcs().length != 0 || vars.globals().size != 0;
if(r) ser.openElement(PLAN);
funcs.plan(ser);
vars.plan(ser);
root.plan(ser);
if(r) ser.closeElement();
final FElem e = new FElem(PLAN);
funcs.plan(e);
vars.plan(e);
root.plan(e);
doc.add(e);
}

// PRIVATE METHODS ====================================================================
@@ -3481,8 +3481,7 @@ private void entityError(final int p, final Err c) throws QueryException {
* @return expression
* @throws QueryException query exception
*/
private <E extends Expr> E check(final E expr, final Err err)
throws QueryException {
private <E extends Expr> E check(final E expr, final Err err) throws QueryException {
if(expr == null) error(err);
return expr;
}
@@ -284,12 +284,13 @@ public static String removeComments(final String qu, final int max) {
}

/**
* Returns the query plan in the dot notation.
* @param ser serializer
* @throws IOException I/O exception
* Returns a tree representation of the query plan.
* @return root node
*/
public void plan(final Serializer ser) throws IOException {
ctx.plan(ser);
public FDoc plan() {
final FDoc doc = new FDoc(EMPTY);
ctx.plan(doc);
return doc;
}

@Override
@@ -125,8 +125,7 @@ protected void checkPred(final boolean open) {
}

@Override
public QueryException error(final Err err, final Object... arg)
throws QueryException {
public QueryException error(final Err err, final Object... arg) throws QueryException {
throw new QueryException(info(), err, arg).suggest(this, complete());
}
}
@@ -561,6 +561,7 @@ public interface QueryText {
String FUNC = "Function";
/** Query Plan. */
String VARBL = "Variable";

/** Query Info: Plan. */
byte[] PLAN = token("QueryPlan");
/** Query Plan. */
@@ -580,12 +581,6 @@ public interface QueryText {
/** Query Plan. */
byte[] RET = token("Return");
/** Query Plan. */
byte[] ITM = token("Item");
/** Query Plan. */
byte[] THN = token("Then");
/** Query Plan. */
byte[] ELS = token("Else");
/** Query Plan. */
byte[] DIR = token("dir");
/** Query Plan. */
byte[] PRE = token("pre");
@@ -604,10 +599,6 @@ public interface QueryText {
/** Minimum . */
byte[] INF = token("inf");
/** Query Plan. */
byte[] ENTRY = token("entry");
/** Query Plan. */
byte[] KEY = token("key");
/** Query Plan. */
byte[] COUNT = token("count");

/** Example for a Date format. */
@@ -68,8 +68,7 @@ public Expr comp(final QueryContext ctx) throws QueryException {
}

@Override
public Bln item(final QueryContext ctx, final InputInfo ii)
throws QueryException {
public Bln item(final QueryContext ctx, final InputInfo ii) throws QueryException {
double s = 0;
for(final Expr e : expr) {
final Item it = e.ebv(ctx, info);
@@ -2,9 +2,6 @@

import static org.basex.query.QueryText.*;

import java.io.*;

import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.item.*;
import org.basex.util.*;
@@ -49,9 +46,7 @@ public Expr comp(final QueryContext ctx) throws QueryException {
}

@Override
public Item item(final QueryContext ctx, final InputInfo ii)
throws QueryException {

public Item item(final QueryContext ctx, final InputInfo ii) throws QueryException {
final Item a = expr[0].item(ctx, info);
if(a == null) return null;
final Item b = expr[1].item(ctx, info);
@@ -60,10 +55,8 @@ public Item item(final QueryContext ctx, final InputInfo ii)
}

@Override
public void plan(final Serializer ser) throws IOException {
ser.openElement(this, OP, Token.token(calc.name));
for(final Expr e : expr) e.plan(ser);
ser.closeElement();
public void plan(final FElem plan) {
addPlan(plan, planElem(OP, calc.name), expr);
}

@Override
@@ -1,9 +1,7 @@
package org.basex.query.expr;

import java.io.*;

import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.item.*;
import org.basex.query.util.*;
import org.basex.util.*;

@@ -29,8 +27,7 @@ protected Arr(final InputInfo ii, final Expr... e) {

@Override
public Expr comp(final QueryContext ctx) throws QueryException {
for(int e = 0; e != expr.length; ++e)
expr[e] = checkUp(expr[e].comp(ctx), ctx);
for(int e = 0; e != expr.length; ++e) expr[e] = checkUp(expr[e].comp(ctx), ctx);
return this;
}

@@ -84,10 +81,8 @@ final boolean oneIsEmpty() {
}

@Override
public void plan(final Serializer ser) throws IOException {
ser.openElement(this);
for(final Expr e : expr) e.plan(ser);
ser.closeElement();
public void plan(final FElem plan) {
addPlan(plan, planElem(), expr);
}

/**
@@ -27,16 +27,13 @@ public final class CAttr extends CName {
* @param n name
* @param v attribute values
*/
public CAttr(final InputInfo ii, final boolean c, final Expr n,
final Expr... v) {
public CAttr(final InputInfo ii, final boolean c, final Expr n, final Expr... v) {
super(ATTRIBUTE, ii, n, v);
comp = c;
}

@Override
public FAttr item(final QueryContext ctx, final InputInfo ii)
throws QueryException {

public FAttr item(final QueryContext ctx, final InputInfo ii) throws QueryException {
QNm nm = qname(ctx, ii);
final byte[] cp = nm.prefix();
if(comp) {
@@ -24,8 +24,7 @@ public CComm(final InputInfo ii, final Expr c) {
}

@Override
public FComm item(final QueryContext ctx, final InputInfo ii)
throws QueryException {
public FComm item(final QueryContext ctx, final InputInfo ii) throws QueryException {
final Iter iter = ctx.iter(expr[0]);

final TokenBuilder tb = new TokenBuilder();
@@ -45,9 +45,7 @@ public CElem comp(final QueryContext ctx) throws QueryException {
}

@Override
public FElem item(final QueryContext ctx, final InputInfo ii)
throws QueryException {

public FElem item(final QueryContext ctx, final InputInfo ii) throws QueryException {
final int s = prepare(ctx);
try {
// adds in-scope namespaces
@@ -26,9 +26,7 @@ public CNSpace(final InputInfo ii, final Expr n, final Expr v) {
}

@Override
public FNames item(final QueryContext ctx, final InputInfo ii)
throws QueryException {

public FNames item(final QueryContext ctx, final InputInfo ii) throws QueryException {
final Item it = name.item(ctx, info);
final byte[] cp = checkEStr(it);
if(cp.length != 0 && !XMLToken.isNCName(cp)) INVNAME.thrw(info, expr[0]);
@@ -2,9 +2,6 @@

import static org.basex.query.util.Err.*;

import java.io.*;

import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.item.*;
import org.basex.query.iter.*;
@@ -30,8 +27,7 @@ public abstract class CName extends CFrag {
* @param n name
* @param v attribute values
*/
CName(final String d, final InputInfo ii, final Expr n,
final Expr... v) {
CName(final String d, final InputInfo ii, final Expr n, final Expr... v) {
super(ii, v);
name = n;
desc = d;
@@ -51,9 +47,7 @@ public CName comp(final QueryContext ctx) throws QueryException {
* @return resulting value
* @throws QueryException query exception
*/
final byte[] value(final QueryContext ctx, final InputInfo ii)
throws QueryException {

final byte[] value(final QueryContext ctx, final InputInfo ii) throws QueryException {
final TokenBuilder tb = new TokenBuilder();
for(final Expr e : expr) {
final Iter ir = ctx.iter(e);
@@ -74,9 +68,7 @@ final byte[] value(final QueryContext ctx, final InputInfo ii)
* @return result
* @throws QueryException query exception
*/
final QNm qname(final QueryContext ctx, final InputInfo ii)
throws QueryException {

final QNm qname(final QueryContext ctx, final InputInfo ii) throws QueryException {
final Item it = checkItem(name, ctx);
final Type ip = it.type;
if(ip == AtomType.QNM) return (QNm) it;
@@ -109,11 +101,8 @@ public final int count(final Var v) {
}

@Override
public final void plan(final Serializer ser) throws IOException {
ser.openElement(this);
name.plan(ser);
for(final Expr e : expr) e.plan(ser);
ser.closeElement();
public final void plan(final FElem plan) {
addPlan(plan, planElem(), name, expr);
}

@Override
@@ -26,9 +26,7 @@ public CPI(final InputInfo ii, final Expr n, final Expr v) {
}

@Override
public FPI item(final QueryContext ctx, final InputInfo ii)
throws QueryException {

public FPI item(final QueryContext ctx, final InputInfo ii) throws QueryException {
final Item it = checkItem(name, ctx);
final Type ip = it.type;
if(!ip.isUntyped() && !ip.isString() && ip != AtomType.QNM)
@@ -25,9 +25,7 @@ public CTxt(final InputInfo ii, final Expr t) {
}

@Override
public FTxt item(final QueryContext ctx, final InputInfo ii)
throws QueryException {

public FTxt item(final QueryContext ctx, final InputInfo ii) throws QueryException {
final Iter iter = ctx.iter(expr[0]);
Item it = iter.next();
if(it == null) return null;
@@ -2,9 +2,6 @@

import static org.basex.query.QueryText.*;

import java.io.*;

import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.item.*;
import org.basex.query.item.SeqType.Occ;
@@ -52,16 +49,13 @@ public Expr comp(final QueryContext ctx) throws QueryException {
}

@Override
public Item item(final QueryContext ctx, final InputInfo ii)
throws QueryException {
public Item item(final QueryContext ctx, final InputInfo ii) throws QueryException {
return type.cast(expr.item(ctx, ii), true, ctx, ii, this);
}

@Override
public void plan(final Serializer ser) throws IOException {
ser.openElement(this, TYP, Token.token(type.toString()));
expr.plan(ser);
ser.closeElement();
public void plan(final FElem plan) {
addPlan(plan, planElem(TYP, type), expr);
}

@Override
@@ -2,9 +2,6 @@

import static org.basex.query.QueryText.*;

import java.io.*;

import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.item.*;
import org.basex.util.*;
@@ -48,10 +45,8 @@ public Bln item(final QueryContext ctx, final InputInfo ii) {
}

@Override
public void plan(final Serializer ser) throws IOException {
ser.openElement(this, TYP, Token.token(seq.toString()));
expr.plan(ser);
ser.closeElement();
public void plan(final FElem plan) {
addPlan(plan, planElem(TYP, seq), expr);
}

@Override
@@ -59,9 +59,7 @@ public Catch comp(final QueryContext ctx) throws QueryException {
* @return resulting item
* @throws QueryException query exception
*/
Value value(final QueryContext ctx, final QueryException ex)
throws QueryException {

Value value(final QueryContext ctx, final QueryException ex) throws QueryException {
if(!find(ex.err(), ex.qname())) return null;

final int s = prepare(ctx);
@@ -3,11 +3,8 @@
import static org.basex.query.QueryText.*;
import static org.basex.query.util.Err.*;

import java.io.*;

import org.basex.index.IndexToken.IndexType;
import org.basex.index.*;
import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.expr.CmpV.OpV;
import org.basex.query.func.*;
@@ -182,9 +179,7 @@ public Expr compEbv(final QueryContext ctx) {
}

@Override
public Bln item(final QueryContext ctx, final InputInfo ii)
throws QueryException {

public Bln item(final QueryContext ctx, final InputInfo ii) throws QueryException {
// atomic evaluation of arguments (faster)
if(atomic) {
final Item it1 = expr[0].item(ctx, info);
@@ -355,10 +350,8 @@ public static AxisStep indexStep(final Expr expr) {
}

@Override
public void plan(final Serializer ser) throws IOException {
ser.openElement(this, OP, Token.token(op.name));
for(final Expr e : expr) e.plan(ser);
ser.closeElement();
public void plan(final FElem plan) {
addPlan(plan, planElem(OP, op.name), expr);
}

@Override
@@ -2,9 +2,6 @@

import static org.basex.query.QueryText.*;

import java.io.*;

import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.item.*;
import org.basex.util.*;
@@ -86,14 +83,11 @@ public CmpN(final Expr e1, final Expr e2, final OpN o, final InputInfo ii) {
@Override
public Expr comp(final QueryContext ctx) throws QueryException {
super.comp(ctx);
return optPre(oneIsEmpty() ? null : allAreValues() ?
item(ctx, info) : this, ctx);
return optPre(oneIsEmpty() ? null : allAreValues() ? item(ctx, info) : this, ctx);
}

@Override
public Bln item(final QueryContext ctx, final InputInfo ii)
throws QueryException {

public Bln item(final QueryContext ctx, final InputInfo ii) throws QueryException {
final Item a = expr[0].item(ctx, info);
if(a == null) return null;
final Item b = expr[1].item(ctx, info);
@@ -102,10 +96,8 @@ public Bln item(final QueryContext ctx, final InputInfo ii)
}

@Override
public void plan(final Serializer ser) throws IOException {
ser.openElement(this, OP, Token.token(op.name));
for(final Expr e : expr) e.plan(ser);
ser.closeElement();
public void plan(final FElem plan) {
addPlan(plan, planElem(OP, op.name), expr);
}

@Override
@@ -2,11 +2,8 @@

import static org.basex.query.QueryText.*;

import java.io.*;

import org.basex.index.IndexToken.IndexType;
import org.basex.index.*;
import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.item.*;
import org.basex.query.iter.*;
@@ -182,10 +179,8 @@ private Stats key(final IndexContext ic, final boolean text) {
}

@Override
public void plan(final Serializer ser) throws IOException {
ser.openElement(this, MIN, Token.token(min), MAX, Token.token(max));
expr.plan(ser);
ser.closeElement();
public void plan(final FElem plan) {
addPlan(plan, planElem(MIN, min, MAX, max), expr);
}

@Override
@@ -2,11 +2,8 @@

import static org.basex.query.QueryText.*;

import java.io.*;

import org.basex.index.IndexToken.IndexType;
import org.basex.index.*;
import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.item.*;
import org.basex.query.iter.*;
@@ -151,11 +148,9 @@ public Expr indexEquivalent(final IndexContext ic) {
}

@Override
public void plan(final Serializer ser) throws IOException {
ser.openElement(this, MIN, min != null ? min : Token.EMPTY, MAX,
max != null ? max : Token.EMPTY);
expr.plan(ser);
ser.closeElement();
public void plan(final FElem plan) {
addPlan(plan, planElem(MIN, min != null ? min : "",
MAX, max != null ? max : ""), expr);
}

@Override
@@ -3,9 +3,6 @@
import static org.basex.query.QueryText.*;
import static org.basex.query.util.Err.*;

import java.io.*;

import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.func.*;
import org.basex.query.item.*;
@@ -200,9 +197,7 @@ public Expr compEbv(final QueryContext ctx) {
}

@Override
public Bln item(final QueryContext ctx, final InputInfo ii)
throws QueryException {

public Bln item(final QueryContext ctx, final InputInfo ii) throws QueryException {
final Item a = expr[0].item(ctx, info);
if(a == null) return null;
final Item b = expr[1].item(ctx, info);
@@ -221,10 +216,8 @@ public CmpV invert() {
}

@Override
public void plan(final Serializer ser) throws IOException {
ser.openElement(this, OP, Token.token(op.name));
for(final Expr e : expr) e.plan(ser);
ser.closeElement();
public void plan(final FElem plan) {
addPlan(plan, planElem(OP, op.name), expr);
}

@Override
@@ -44,8 +44,7 @@ public Value value(final QueryContext ctx) throws QueryException {
}

@Override
public Item item(final QueryContext ctx, final InputInfo ii)
throws QueryException {
public Item item(final QueryContext ctx, final InputInfo ii) throws QueryException {
return checkCtx(ctx).item(ctx, info);
}

@@ -2,10 +2,8 @@

import static org.basex.query.QueryText.*;

import java.io.*;

import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.item.*;
import org.basex.query.iter.*;
import org.basex.util.*;

@@ -43,11 +41,8 @@ public Iter iter(final QueryContext ctx) throws QueryException {
}

@Override
public void plan(final Serializer ser) throws IOException {
ser.openElement(this);
for(final Pragma p : pragmas) p.plan(ser);
expr.plan(ser);
ser.closeElement();
public void plan(final FElem plan) {
addPlan(plan, planElem(), pragmas, expr);
}

@Override
@@ -1,8 +1,5 @@
package org.basex.query.expr;

import java.io.*;

import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.item.*;
import org.basex.query.item.SeqType.Occ;
@@ -163,11 +160,10 @@ public final Expr remove(final Var v) {
}

@Override
public final void plan(final Serializer ser) throws IOException {
ser.openElement(this);
root.plan(ser);
super.plan(ser);
ser.closeElement();
public final void plan(final FElem plan) {
final FElem el = planElem();
addPlan(plan, el, root);
super.plan(el);
}

@Override
@@ -2,9 +2,6 @@

import static org.basex.query.QueryText.*;

import java.io.*;

import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.func.*;
import org.basex.query.item.*;
@@ -82,8 +79,7 @@ public Value value(final QueryContext ctx) throws QueryException {
}

@Override
public Item item(final QueryContext ctx, final InputInfo ii)
throws QueryException {
public Item item(final QueryContext ctx, final InputInfo ii) throws QueryException {
return eval(ctx).item(ctx, info);
}

@@ -103,22 +99,13 @@ public boolean isVacuous() {
}

@Override
public void plan(final Serializer ser) throws IOException {
ser.openElement(this);
expr[0].plan(ser);
ser.openElement(THN);
expr[1].plan(ser);
ser.closeElement();
ser.openElement(ELS);
expr[2].plan(ser);
ser.closeElement();
ser.closeElement();
public void plan(final FElem plan) {
addPlan(plan, planElem(), expr);
}

@Override
public String toString() {
return IF + '(' + expr[0] + ") " + THEN + ' ' + expr[1] + ' ' +
ELSE + ' ' + expr[2];
return IF + '(' + expr[0] + ") " + THEN + ' ' + expr[1] + ' ' + ELSE + ' ' + expr[2];
}

@Override
@@ -2,9 +2,6 @@

import static org.basex.query.QueryText.*;

import java.io.*;

import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.item.*;
import org.basex.util.*;
@@ -38,16 +35,13 @@ public Expr comp(final QueryContext ctx) throws QueryException {
}

@Override
public Bln item(final QueryContext ctx, final InputInfo ii)
throws QueryException {
public Bln item(final QueryContext ctx, final InputInfo ii) throws QueryException {
return Bln.get(seq.instance(ctx.value(expr)));
}

@Override
public void plan(final Serializer ser) throws IOException {
ser.openElement(this, TYP, Token.token(seq.toString()));
expr.plan(ser);
ser.closeElement();
public void plan(final FElem plan) {
addPlan(plan, planElem(TYP, seq), expr);
}

@Override
@@ -23,8 +23,7 @@ public LitMap(final InputInfo ii, final Expr[] e) {
}

@Override
public Item item(final QueryContext ctx, final InputInfo ii)
throws QueryException {
public Item item(final QueryContext ctx, final InputInfo ii) throws QueryException {
Map map = Map.EMPTY;
for(int i = 0; i < expr.length; i++) {
map = map.insert(checkItem(expr[i], ctx), ctx.value(expr[++i]), ii);
@@ -53,8 +53,7 @@ public Expr comp(final QueryContext ctx) throws QueryException {
}

@Override
public Item item(final QueryContext ctx, final InputInfo ii)
throws QueryException {
public Item item(final QueryContext ctx, final InputInfo ii) throws QueryException {
double d = 0;
boolean f = false;
for(final Expr e : expr) {
@@ -2,9 +2,6 @@

import static org.basex.query.QueryText.*;

import java.io.*;

import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.expr.CmpV.OpV;
import org.basex.query.item.*;
@@ -118,9 +115,8 @@ public boolean sameAs(final Expr cmp) {
}

@Override
public void plan(final Serializer ser) throws IOException {
ser.emptyElement(this, MIN, Token.token(min), MAX,
max == Long.MAX_VALUE ? INF : Token.token(max));
public void plan(final FElem plan) {
addPlan(plan, planElem(MIN, min, MAX, max == Long.MAX_VALUE ? INF : max));
}

@Override
@@ -2,10 +2,7 @@

import static org.basex.query.QueryText.*;

import java.io.*;

import org.basex.data.*;
import org.basex.io.serial.*;
import org.basex.query.item.*;
import org.basex.util.*;

@@ -32,10 +29,8 @@ public Pragma(final QNm qn, final byte[] content) {
}

@Override
public void plan(final Serializer ser) throws IOException {
ser.openElement(this, VAL, pContent);
qName.plan(ser);
ser.closeElement();
public void plan(final FElem plan) {
addPlan(plan, planElem(VAL, pContent), qName);
}

@Override
@@ -2,10 +2,8 @@

import static org.basex.query.QueryText.*;

import java.io.*;
import java.util.*;

import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.expr.CmpG.OpG;
import org.basex.query.expr.CmpV.OpV;
@@ -117,9 +115,7 @@ protected boolean useIterator() {
* @return result of check
* @throws QueryException query exception
*/
public boolean preds(final Item it, final QueryContext ctx)
throws QueryException {

public boolean preds(final Item it, final QueryContext ctx) throws QueryException {
if(preds.length == 0) return true;

// set context item and position
@@ -162,8 +158,8 @@ public Expr remove(final Var v) {
}

@Override
public void plan(final Serializer ser) throws IOException {
for(final Expr p : preds) p.plan(ser);
public void plan(final FElem plan) {
for(final Expr p : preds) p.plan(plan);
}

@Override
@@ -2,9 +2,6 @@

import static org.basex.query.QueryText.*;

import java.io.*;

import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.flwor.*;
import org.basex.query.item.*;
@@ -33,8 +30,7 @@ public final class Quantifier extends ParseExpr {
* @param s satisfier
* @param e every flag
*/
public Quantifier(final InputInfo ii, final For[] f, final Expr s,
final boolean e) {
public Quantifier(final InputInfo ii, final For[] f, final Expr s, final boolean e) {
super(ii);
sat = s;
fl = f;
@@ -51,17 +47,15 @@ public Expr comp(final QueryContext ctx) throws QueryException {
ctx.vars.size(vs);

// find empty sequences
boolean empty = sat.isEmpty();
boolean empty = false;
for(final For f : fl) empty |= f.isEmpty();

// return pre-evaluated result
return empty ? optPre(Bln.get(every), ctx) : this;
}

@Override
public Bln item(final QueryContext ctx, final InputInfo ii)
throws QueryException {

public Bln item(final QueryContext ctx, final InputInfo ii) throws QueryException {
final Iter[] iter = new Iter[fl.length];
for(int f = 0; f < fl.length; ++f) iter[f] = ctx.iter(fl[f]);
return Bln.get(iter(ctx, iter, 0));
@@ -75,8 +69,8 @@ public Bln item(final QueryContext ctx, final InputInfo ii)
* @return satisfied flag
* @throws QueryException query exception
*/
private boolean iter(final QueryContext ctx, final Iter[] it,
final int p) throws QueryException {
private boolean iter(final QueryContext ctx, final Iter[] it, final int p)
throws QueryException {

final boolean last = p + 1 == fl.length;
while(it[p].next() != null) {
@@ -115,11 +109,8 @@ public Expr remove(final Var v) {
}

@Override
public void plan(final Serializer ser) throws IOException {
ser.openElement(this, TYP, Token.token(every ? EVERY : SOME));
for(final Expr f : fl) f.plan(ser);
sat.plan(ser);
ser.closeElement();
public void plan(final FElem plan) {
addPlan(plan, planElem(TYP, every ? EVERY : SOME), fl, sat);
}

@Override
@@ -1,15 +1,12 @@
package org.basex.query.expr;

import static org.basex.query.QueryText.*;
import static org.basex.util.Token.*;

import java.io.*;
import java.util.*;

import org.basex.data.*;
import org.basex.index.*;
import org.basex.index.IndexToken.IndexType;
import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.item.*;
import org.basex.query.iter.*;
@@ -52,10 +49,9 @@ public ANode next() {
}

@Override
public void plan(final Serializer ser) throws IOException {
ser.emptyElement(this, DATA, token(ictx.data.meta.name),
MIN, token(ind.min), MAX, token(ind.max),
TYP, token(ind.type.toString()));
public void plan(final FElem plan) {
addPlan(plan, planElem(DATA, ictx.data.meta.name,
MIN, ind.min, MAX, ind.max, TYP, ind.type));
}

@Override
@@ -1,9 +1,7 @@
package org.basex.query.expr;

import java.io.*;

import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.item.*;
import org.basex.query.util.*;
import org.basex.util.*;

@@ -48,7 +46,7 @@ public Expr remove(final Var v) {
}

@Override
public void plan(final Serializer ser) throws IOException {
ser.emptyElement(this);
public void plan(final FElem plan) {
addPlan(plan, planElem());
}
}
@@ -1,9 +1,7 @@
package org.basex.query.expr;

import java.io.*;

import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.item.*;
import org.basex.query.util.*;
import org.basex.util.*;

@@ -55,9 +53,7 @@ public Expr remove(final Var v) {
}

@Override
public void plan(final Serializer ser) throws IOException {
ser.openElement(this);
expr.plan(ser);
ser.closeElement();
public void plan(final FElem plan) {
addPlan(plan, planElem(), expr);
}
}
@@ -1,14 +1,10 @@
package org.basex.query.expr;

import static org.basex.query.QueryText.*;
import static org.basex.util.Token.*;

import java.io.*;

import org.basex.data.*;
import org.basex.index.*;
import org.basex.index.IndexToken.IndexType;
import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.func.*;
import org.basex.query.item.*;
@@ -89,9 +85,9 @@ public boolean more() {
}

@Override
public void plan(final Serializer ser) throws IOException {
ser.emptyElement(this, DATA, token(ictx.data.meta.name),
MIN, sr.min, MAX, sr.max, TYP, token(sr.type.toString()));
public void plan(final FElem plan) {
addPlan(plan, planElem(DATA, ictx.data.meta.name,
MIN, sr.min, MAX, sr.max, TYP, sr.type));
}

@Override
@@ -2,9 +2,6 @@

import static org.basex.query.QueryText.*;

import java.io.*;

import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.item.*;
import org.basex.query.iter.*;
@@ -87,8 +84,7 @@ public Value value(final QueryContext ctx) throws QueryException {
}

@Override
public Item item(final QueryContext ctx, final InputInfo ii)
throws QueryException {
public Item item(final QueryContext ctx, final InputInfo ii) throws QueryException {
return getCase(ctx).item(ctx, ii);
}

@@ -141,11 +137,8 @@ private Expr getCase(final QueryContext ctx) throws QueryException {
}

@Override
public void plan(final Serializer ser) throws IOException {
ser.openElement(this);
cond.plan(ser);
for(final SwitchCase sc : cases) sc.plan(ser);
ser.closeElement();
public void plan(final FElem plan) {
addPlan(plan, planElem(), cond, cases);
}

@Override
@@ -3,9 +3,6 @@
import static org.basex.query.QueryText.*;
import static org.basex.query.util.Err.*;

import java.io.*;

import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.item.*;
import org.basex.query.iter.*;
@@ -92,10 +89,8 @@ public Value value(final QueryContext ctx) throws QueryException {
}

@Override
public void plan(final Serializer ser) throws IOException {
ser.openElement(this, TYP, Token.token(type.toString()));
expr.plan(ser);
ser.closeElement();
public void plan(final FElem plan) {
addPlan(plan, planElem(TYP, type), expr);
}

@Override
@@ -1,8 +1,5 @@
package org.basex.query.expr;

import java.io.*;

import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.item.*;
import org.basex.query.iter.*;
@@ -124,11 +121,8 @@ public Expr remove(final Var v) {
}

@Override
public void plan(final Serializer ser) throws IOException {
ser.openElement(this);
expr.plan(ser);
for(final Catch c : ctch) c.plan(ser);
ser.closeElement();
public void plan(final FElem plan) {
addPlan(plan, planElem(), expr, ctch);
}

@Override
@@ -2,9 +2,6 @@

import static org.basex.query.QueryText.*;

import java.io.*;

import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.item.*;
import org.basex.query.iter.*;
@@ -69,8 +66,7 @@ public boolean uses(final Use u) {
* @return resulting item
* @throws QueryException query exception
*/
Iter iter(final QueryContext ctx, final Value seq)
throws QueryException {
Iter iter(final QueryContext ctx, final Value seq) throws QueryException {
if(var.type != null && !var.type.instance(seq)) return null;
if(var.name == null) return ctx.iter(expr);

@@ -82,11 +78,8 @@ Iter iter(final QueryContext ctx, final Value seq)
}

@Override
public void plan(final Serializer ser) throws IOException {
ser.openElement(this, VAR, var.name != null ? var.name.string() :
Token.EMPTY);
expr.plan(ser);
ser.closeElement();
public void plan(final FElem plan) {
addPlan(plan, planElem(VAR, var.name != null ? var.name.string() : ""), expr);
}

@Override
@@ -2,9 +2,6 @@

import static org.basex.query.QueryText.*;

import java.io.*;

import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.item.*;
import org.basex.query.iter.*;
@@ -113,11 +110,8 @@ public Expr remove(final Var v) {
}

@Override
public void plan(final Serializer ser) throws IOException {
ser.openElement(this);
for(final TypeCase c : cases) c.plan(ser);
ts.plan(ser);
ser.closeElement();
public void plan(final FElem plan) {
addPlan(plan, planElem(), cases, ts);
}

@Override
@@ -2,9 +2,6 @@

import static org.basex.query.QueryText.*;

import java.io.*;

import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.item.*;
import org.basex.query.util.*;
@@ -43,8 +40,7 @@ public Expr comp(final QueryContext ctx) throws QueryException {
}

@Override
public Item item(final QueryContext ctx, final InputInfo ii)
throws QueryException {
public Item item(final QueryContext ctx, final InputInfo ii) throws QueryException {

final Item it = expr.item(ctx, info);
if(it == null) return null;
@@ -64,10 +60,8 @@ public Item item(final QueryContext ctx, final InputInfo ii)
}

@Override
public void plan(final Serializer ser) throws IOException {
ser.openElement(this, VAL, Token.token(minus));
expr.plan(ser);
ser.closeElement();
public void plan(final FElem plan) {
addPlan(plan, planElem(VAL, minus), expr);
}

@Override
@@ -3,12 +3,9 @@
import static org.basex.query.QueryText.*;
import static org.basex.util.Token.*;

import java.io.*;

import org.basex.data.*;
import org.basex.index.*;
import org.basex.index.IndexToken.IndexType;
import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.func.*;
import org.basex.query.item.*;
@@ -139,10 +136,8 @@ public Expr remove(final Var v) {
}

@Override
public void plan(final Serializer ser) throws IOException {
ser.openElement(this, DATA, token(ictx.data.meta.name), TYP, token(itype.toString()));
expr.plan(ser);
ser.closeElement();
public void plan(final FElem plan) {
addPlan(plan, planElem(DATA, ictx.data.meta.name, TYP, itype), expr);
}

@Override
@@ -2,9 +2,6 @@

import static org.basex.query.QueryText.*;

import java.io.*;

import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.func.*;
import org.basex.query.item.*;
@@ -63,8 +60,7 @@ public Expr comp(final QueryContext ctx) throws QueryException {
}

@Override
public Item item(final QueryContext ctx, final InputInfo ii)
throws QueryException {
public Item item(final QueryContext ctx, final InputInfo ii) throws QueryException {
var = ctx.vars.get(var);
return var.item(ctx, ii);
}
@@ -108,10 +104,8 @@ public boolean sameAs(final Expr cmp) {
}

@Override
public void plan(final Serializer ser) throws IOException {
ser.openElement(this);
var.plan(ser);
ser.closeElement();
public void plan(final FElem plan) {
addPlan(plan, planElem(), var);
}

@Override
@@ -1,11 +1,7 @@
package org.basex.query.flwor;

import static org.basex.query.QueryText.*;
import static org.basex.util.Token.*;

import java.io.*;

import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.expr.*;
import org.basex.query.item.*;
@@ -150,12 +146,8 @@ boolean simple(final boolean one) {
}

@Override
public void plan(final Serializer ser) throws IOException {
ser.openElement(this, VAR, token(var.toString()));
if(pos != null) ser.attribute(POS, token(pos.toString()));
if(score != null) ser.attribute(token(SCORE), token(score.toString()));
expr.plan(ser);
ser.closeElement();
public void plan(final FElem plan) {
addPlan(plan, planElem(VAR, var, POS, pos, SCORE, score), expr);
}

@Override
@@ -2,10 +2,8 @@

import static org.basex.query.QueryText.*;

import java.io.*;
import java.util.*;

import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.expr.*;
import org.basex.query.func.*;
@@ -380,20 +378,13 @@ public final Expr remove(final Var v) {
}

@Override
public final void plan(final Serializer ser) throws IOException {
ser.openElement(this);
for(final ForLet f : fl) f.plan(ser);
if(where != null) {
ser.openElement(WHR);
where.plan(ser);
ser.closeElement();
}
if(group != null) group.plan(ser);
if(order != null) order.plan(ser);
ser.openElement(RET);
ret.plan(ser);
ser.closeElement();
ser.closeElement();
public final void plan(final FElem plan) {
final FElem el = planElem();
addPlan(plan, el, fl);
if(where != null) addPlan(el, new FElem(WHR), where);
if(group != null) group.plan(el);
if(order != null) order.plan(el);
addPlan(el, new FElem(RET), ret);
}

@Override
@@ -2,9 +2,6 @@

import static org.basex.query.QueryText.*;

import java.io.*;

import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.expr.*;
import org.basex.query.func.*;
@@ -93,10 +90,8 @@ public Expr remove(final Var v) {
}

@Override
public void plan(final Serializer ser) throws IOException {
ser.openElement(this);
for(int o = 0; o != groupby.length; ++o) groupby[o].plan(ser);
ser.closeElement();
public void plan(final FElem plan) {
addPlan(plan, planElem(), groupby);
}

@Override
@@ -127,11 +122,8 @@ public Spec(final InputInfo ii, final Var gv, final Expr e) {
}

@Override
public void plan(final Serializer ser) throws IOException {
ser.openElement(this);
grp.plan(ser);
expr.plan(ser);
ser.closeElement();
public void plan(final FElem plan) {
addPlan(plan, planElem(), grp, expr);
}

@Override
@@ -1,11 +1,7 @@
package org.basex.query.flwor;

import static org.basex.query.QueryText.*;
import static org.basex.util.Token.*;

import java.io.*;

import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.expr.*;
import org.basex.query.item.*;
@@ -121,10 +117,8 @@ boolean simple(final boolean one) {
}

@Override
public void plan(final Serializer ser) throws IOException {
ser.openElement(this, score ? token(SCORE) : VAR, token(var.toString()));
expr.plan(ser);
ser.closeElement();
public void plan(final FElem plan) {
addPlan(plan, planElem(score ? SCORE : VAR, var), expr);
}

@Override
@@ -3,10 +3,8 @@
import static org.basex.query.QueryText.*;
import static org.basex.util.Array.*;

import java.io.*;
import java.util.*;

import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.expr.*;
import org.basex.query.item.*;
@@ -104,10 +102,10 @@ public Order remove(final Var v) {
}

@Override
public void plan(final Serializer ser) throws IOException {
ser.openElement(this);
for(int o = 0; o != ob.length - 1; ++o) ob[o].plan(ser);
ser.closeElement();
public void plan(final FElem plan) {
final FElem el = planElem();
for(int o = 0; o != ob.length - 1; ++o) ob[o].plan(el);
addPlan(plan, el);
}

@Override
@@ -251,8 +249,7 @@ private int d(final Item[] sa, final Item[] sb) throws QueryException {
* @return result
* @throws QueryException query exception
*/
private int d(final int[] o, final int a, final int b)
throws QueryException {
private int d(final int[] o, final int a, final int b) throws QueryException {
return d(kl.get(o[a]), kl.get(o[b]));
}

@@ -1,11 +1,7 @@
package org.basex.query.flwor;

import static org.basex.query.QueryText.*;
import static org.basex.util.Token.*;

import java.io.*;

import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.expr.*;
import org.basex.query.item.*;
@@ -76,11 +72,9 @@ public OrderByExpr remove(final Var v) {
}

@Override
public void plan(final Serializer ser) throws IOException {
ser.openElement(this, DIR, token(desc ? DESCENDING : ASCENDING),
token(EMPTYORD), token(lst ? LEAST : GREATEST));
expr.plan(ser);
ser.closeElement();
public void plan(final FElem plan) {
addPlan(plan, planElem(DIR, desc ? DESCENDING : ASCENDING,
EMPTYORD, lst ? LEAST : GREATEST), expr);
}

@Override
@@ -1,10 +1,5 @@
package org.basex.query.flwor;

import static org.basex.query.QueryText.*;

import java.io.*;

import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.expr.*;
import org.basex.query.item.*;
@@ -53,8 +48,8 @@ public boolean removable(final Var v) {
}

@Override
public void plan(final Serializer ser) throws IOException {
ser.emptyElement(this, DIR);
public void plan(final FElem plan) {
addPlan(plan, planElem());
}

@Override
@@ -44,8 +44,7 @@ public FTExpr comp(final QueryContext ctx) throws QueryException {
}

@Override
public FTNode item(final QueryContext ctx, final InputInfo ii)
throws QueryException {
public FTNode item(final QueryContext ctx, final InputInfo ii) throws QueryException {
final FTNode item = expr[0].item(ctx, info);
for(int e = 1; e < expr.length; ++e) {
and(item, expr[e].item(ctx, info));
@@ -2,9 +2,6 @@

import static org.basex.query.QueryText.*;

import java.io.*;

import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.expr.*;
import org.basex.query.item.*;
@@ -50,9 +47,7 @@ public final Expr comp(final QueryContext ctx) throws QueryException {
}

@Override
public Bln item(final QueryContext ctx, final InputInfo ii)
throws QueryException {

public Bln item(final QueryContext ctx, final InputInfo ii) throws QueryException {
final Iter iter = expr.iter(ctx);
final FTLexer tmp = ctx.fttoken;
double s = 0;
@@ -81,9 +76,7 @@ public Bln item(final QueryContext ctx, final InputInfo ii)
}

@Override
public final boolean indexAccessible(final IndexContext ic)
throws QueryException {

public final boolean indexAccessible(final IndexContext ic) throws QueryException {
// return if step is no text node, or if no index is available
final AxisStep s = expr instanceof Context ? ic.step : CmpG.indexStep(expr);
final boolean ok = s != null && ic.data.meta.ftxtindex &&
@@ -93,9 +86,7 @@ public final boolean indexAccessible(final IndexContext ic)
}

@Override
public final Expr indexEquivalent(final IndexContext ic)
throws QueryException {

public final Expr indexEquivalent(final IndexContext ic) throws QueryException {
ic.ctx.compInfo(OPTFTXINDEX);

// sequential evaluation with index access
@@ -131,11 +122,8 @@ public final Expr remove(final Var v) {
}

@Override
public final void plan(final Serializer ser) throws IOException {
ser.openElement(this);
expr.plan(ser);
ftexpr.plan(ser);
ser.closeElement();
public final void plan(final FElem plan) {
addPlan(plan, planElem(), expr, ftexpr);
}

@Override
@@ -38,8 +38,7 @@ final class FTContainsIndex extends FTContains {
}

@Override
public Bln item(final QueryContext ctx, final InputInfo ii)
throws QueryException {
public Bln item(final QueryContext ctx, final InputInfo ii) throws QueryException {
final Iter ir = expr.iter(ctx);
final FTLexer tmp = ctx.fttoken;
ctx.fttoken = lex;
@@ -3,11 +3,9 @@
import static org.basex.query.QueryText.*;
import static org.basex.util.Token.*;

import java.io.*;

import org.basex.data.*;
import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.item.*;
import org.basex.util.*;
import org.basex.util.ft.*;

@@ -64,9 +62,8 @@ protected boolean content() {
}

@Override
public void plan(final Serializer ser) throws IOException {
ser.openElement(this, token(start ? START : end ? END : CONTENT), TRUE);
super.plan(ser);
public void plan(final FElem plan) {
addPlan(plan, planElem(start ? START : end ? END : CONTENT, TRUE), expr);
}

@Override
@@ -1,14 +1,11 @@
package org.basex.query.ft;

import static org.basex.query.QueryText.*;
import static org.basex.util.Token.*;

import java.io.*;

import org.basex.data.*;
import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.expr.*;
import org.basex.query.item.*;
import org.basex.query.util.*;
import org.basex.util.*;
import org.basex.util.ft.*;
@@ -100,10 +97,8 @@ public FTExpr remove(final Var v) {
}

@Override
public void plan(final Serializer ser) throws IOException {
ser.openElement(this, token(DISTANCE),
token(dist[0] + "-" + dist[1] + ' ' + unit));
super.plan(ser);
public void plan(final FElem plan) {
addPlan(plan, planElem(DISTANCE, dist[0] + "-" + dist[1] + ' ' + unit), expr);
}

@Override
@@ -1,8 +1,5 @@
package org.basex.query.ft;

import java.io.*;

import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.expr.*;
import org.basex.query.item.*;
@@ -97,10 +94,8 @@ boolean usesExclude() {
}

@Override
public void plan(final Serializer ser) throws IOException {
ser.openElement(this);
for(final FTExpr e : expr) e.plan(ser);
ser.closeElement();
public void plan(final FElem plan) {
addPlan(plan, planElem(), expr);
}

/**
@@ -2,9 +2,6 @@

import static org.basex.query.QueryText.*;

import java.io.*;

import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.expr.*;
import org.basex.query.item.*;
@@ -27,15 +24,13 @@ public final class FTExtensionSelection extends FTExpr {
* @param prag pragmas
* @param e enclosed FTSelection
*/
public FTExtensionSelection(final InputInfo ii, final Pragma[] prag,
final FTExpr e) {
public FTExtensionSelection(final InputInfo ii, final Pragma[] prag, final FTExpr e) {
super(ii, e);
pragmas = prag;
}

@Override
public FTNode item(final QueryContext ctx, final InputInfo ii)
throws QueryException {
public FTNode item(final QueryContext ctx, final InputInfo ii) throws QueryException {
return expr[0].item(ctx, info);
}

@@ -45,11 +40,8 @@ public FTIter iter(final QueryContext ctx) throws QueryException {
}

@Override
public void plan(final Serializer ser) throws IOException {
ser.openElement(this);
for(final Pragma e : pragmas) e.plan(ser);
expr[0].plan(ser);
ser.closeElement();
public void plan(final FElem plan) {
addPlan(plan, planElem(), pragmas, expr);
}

@Override
@@ -1,9 +1,7 @@
package org.basex.query.ft;

import java.io.*;

import org.basex.data.*;
import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.item.*;
import org.basex.query.iter.*;
@@ -105,17 +103,10 @@ final int pos(final int p, final FTLexer ft) {
}

@Override
public final boolean indexAccessible(final IndexContext ic)
throws QueryException {
public final boolean indexAccessible(final IndexContext ic) throws QueryException {
return expr[0].indexAccessible(ic);
}

@Override
public void plan(final Serializer ser) throws IOException {
expr[0].plan(ser);
ser.closeElement();
}

@Override
public String toString() {
return expr[0] + " ";
@@ -1,11 +1,7 @@
package org.basex.query.ft;

import static org.basex.query.QueryText.*;
import static org.basex.util.Token.*;

import java.io.*;

import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.expr.*;
import org.basex.query.func.*;
@@ -83,10 +79,8 @@ public Expr remove(final Var v) {
}

@Override
public void plan(final Serializer ser) throws IOException {
ser.openElement(this, DATA, token(ictx.data.meta.name));
ftexpr.plan(ser);
ser.closeElement();
public void plan(final FElem plan) {
addPlan(plan, planElem(DATA, ictx.data.meta.name), ftexpr);
}

@Override
@@ -31,8 +31,7 @@ public FTMildNot(final InputInfo ii, final FTExpr e1, final FTExpr e2)
}

@Override
public FTNode item(final QueryContext ctx, final InputInfo ii)
throws QueryException {
public FTNode item(final QueryContext ctx, final InputInfo ii) throws QueryException {
return mildnot(expr[0].item(ctx, info), expr[1].item(ctx, info));
}

@@ -34,8 +34,7 @@ public FTExpr comp(final QueryContext ctx) throws QueryException {
}

@Override
public FTNode item(final QueryContext ctx, final InputInfo ii)
throws QueryException {
public FTNode item(final QueryContext ctx, final InputInfo ii) throws QueryException {
return not(expr[0].item(ctx, info));
}

@@ -1,8 +1,5 @@
package org.basex.query.ft;

import java.io.*;

import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.item.*;
import org.basex.query.iter.*;
@@ -42,11 +39,8 @@ public FTExpr comp(final QueryContext ctx) throws QueryException {
}

@Override
public void plan(final Serializer ser) throws IOException {
ser.openElement(this);
opt.plan(ser);
expr[0].plan(ser);
ser.closeElement();
public void plan(final FElem plan) {
addPlan(plan, planElem(), opt, expr[0]);
}

@Override
@@ -41,8 +41,7 @@ public FTExpr comp(final QueryContext ctx) throws QueryException {
}

@Override
public FTNode item(final QueryContext ctx, final InputInfo ii)
throws QueryException {
public FTNode item(final QueryContext ctx, final InputInfo ii) throws QueryException {
final FTNode item = expr[0].item(ctx, info);
for(int e = 1; e < expr.length; ++e) {
or(item, expr[e].item(ctx, info));
@@ -2,11 +2,9 @@

import static org.basex.util.Token.*;

import java.io.*;

import org.basex.data.*;
import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.item.*;
import org.basex.util.*;
import org.basex.util.ft.*;

@@ -45,9 +43,8 @@ protected boolean filter(final QueryContext ctx, final FTMatch mtc,
}

@Override
public void plan(final Serializer ser) throws IOException {
ser.openElement(this, token(QueryText.ORDERED), TRUE);
super.plan(ser);
public void plan(final FElem plan) {
addPlan(plan, planElem(QueryText.ORDERED, TRUE), expr);
}

@Override
@@ -1,13 +1,10 @@
package org.basex.query.ft;

import static org.basex.query.QueryText.*;
import static org.basex.util.Token.*;

import java.io.*;

import org.basex.data.*;
import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.item.*;
import org.basex.util.*;
import org.basex.util.ft.*;
import org.basex.util.list.*;
@@ -64,10 +61,8 @@ protected boolean filter(final QueryContext ctx, final FTMatch mtc,
}

@Override
public void plan(final Serializer ser) throws IOException {
ser.openElement(this, token(same ? SAME : DIFFERENT),
token(unit.toString()));
super.plan(ser);
public void plan(final FElem plan) {
addPlan(plan, planElem(same ? SAME : DIFFERENT, unit), expr);
}

@Override
@@ -47,9 +47,7 @@ public FTTokenizer(final FTWords w, final FTOpt o, final Prop pr) {

cmp = new TokenComparator() {
@Override
public boolean equal(final byte[] in, final byte[] qu)
throws QueryException {

public boolean equal(final byte[] in, final byte[] qu) throws QueryException {
FTWildcard ftw = null;
if(opt.is(WC)) {
ftw = wcCache.get(qu);
@@ -130,9 +128,7 @@ FTTokens cache(final byte[] query) throws QueryException {
* @return number of occurrences
* @throws QueryException query exception
*/
int contains(final FTTokens query, final FTLexer input)
throws QueryException {

int contains(final FTTokens query, final FTLexer input) throws QueryException {
input.init();
final FTBitapSearch bs = new FTBitapSearch(input, query, cmp);
int c = 0;
@@ -2,9 +2,6 @@

import static org.basex.query.util.Err.*;

import java.io.*;

import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.expr.*;
import org.basex.query.item.*;
@@ -41,8 +38,7 @@ public FTExpr comp(final QueryContext ctx) throws QueryException {

// called by sequential variant
@Override
public FTNode item(final QueryContext ctx, final InputInfo ii)
throws QueryException {
public FTNode item(final QueryContext ctx, final InputInfo ii) throws QueryException {
return weight(expr[0].item(ctx, info), ctx);
}

@@ -64,9 +60,7 @@ public FTNode next() throws QueryException {
* @return item
* @throws QueryException query exception
*/
FTNode weight(final FTNode item, final QueryContext ctx)
throws QueryException {

FTNode weight(final FTNode item, final QueryContext ctx) throws QueryException {
// evaluate weight
if(item == null) return null;
final double d = checkDbl(weight, ctx);
@@ -104,11 +98,8 @@ public FTExpr remove(final Var v) {
}

@Override
public void plan(final Serializer ser) throws IOException {
ser.openElement(this);
weight.plan(ser);
expr[0].plan(ser);
ser.closeElement();
public void plan(final FElem plan) {
addPlan(plan, planElem(), weight, expr[0]);
}

@Override
@@ -33,9 +33,7 @@ public class FTWildcard {
* @throws QueryException {@link Err#FTREG}, if the wild
* card expression is not valid
*/
public FTWildcard(final byte[] query, final InputInfo ii)
throws QueryException {

public FTWildcard(final byte[] query, final InputInfo ii) throws QueryException {
final int[] q = cps(query);
final int[] tmpwc = new int[q.length];
final int[] tmpmin = new int[q.length];
@@ -1,13 +1,9 @@
package org.basex.query.ft;

import static org.basex.util.Token.*;

import java.io.*;

import org.basex.data.*;
import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.expr.*;
import org.basex.query.item.*;
import org.basex.query.util.*;
import org.basex.util.*;
import org.basex.util.ft.*;
@@ -97,10 +93,8 @@ public FTExpr remove(final Var v) {
}

@Override
public void plan(final Serializer ser) throws IOException {
ser.openElement(this, token(QueryText.WINDOW), token(unit.toString()));
win.plan(ser);
super.plan(ser);
public void plan(final FElem plan) {
addPlan(plan, planElem(QueryText.WINDOW, unit), win, expr);
}

@Override
@@ -3,11 +3,8 @@
import static org.basex.query.QueryText.*;
import static org.basex.util.ft.FTFlag.*;

import java.io.*;

import org.basex.data.*;
import org.basex.index.ft.*;
import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.expr.*;
import org.basex.query.item.*;
@@ -106,9 +103,7 @@ public FTExpr comp(final QueryContext ctx) throws QueryException {
}

@Override
public FTNode item(final QueryContext ctx, final InputInfo ii)
throws QueryException {

public FTNode item(final QueryContext ctx, final InputInfo ii) throws QueryException {
if(tokNum == 0) tokNum = ++ctx.ftoknum;
matches.reset(tokNum);

@@ -428,22 +423,15 @@ public boolean removable(final Var v) {
@Override
public FTExpr remove(final Var v) {
if(occ != null) {
for(int o = 0; o < occ.length; ++o)
occ[o] = occ[o].remove(v);
for(int o = 0; o < occ.length; ++o) occ[o] = occ[o].remove(v);
}
query = query.remove(v);
return this;
}

@Override
public void plan(final Serializer ser) throws IOException {
ser.openElement(this);
if(occ != null) {
occ[0].plan(ser);
occ[1].plan(ser);
}
query.plan(ser);
ser.closeElement();
public void plan(final FElem plan) {
addPlan(plan, planElem(), occ, query);
}

@Override
@@ -25,9 +25,7 @@ public BaseFuncCall(final InputInfo ii, final QNm nm, final Expr[] arg) {
}

@Override
public Item item(final QueryContext ctx, final InputInfo ii)
throws QueryException {

public Item item(final QueryContext ctx, final InputInfo ii) throws QueryException {
Expr fun = func;
Var[] args = args(ctx);
do {
@@ -2,9 +2,6 @@

import static org.basex.query.util.Err.*;

import java.io.*;

import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.expr.*;
import org.basex.query.item.*;
@@ -48,8 +45,7 @@ public Expr comp(final QueryContext ctx) throws QueryException {
}

@Override
public Item item(final QueryContext ctx, final InputInfo ii)
throws QueryException {
public Item item(final QueryContext ctx, final InputInfo ii) throws QueryException {
return getFun(ctx).invItem(ctx, ii, argv(ctx));
}

@@ -91,11 +87,10 @@ private FItem getFun(final QueryContext ctx) throws QueryException {
}

@Override
public void plan(final Serializer ser) throws IOException {
ser.openElement(this);
expr[expr.length - 1].plan(ser);
for(int i = 0; i < expr.length - 1; i++) expr[i].plan(ser);
ser.closeElement();
public void plan(final FElem plan) {
final FElem el = planElem();
addPlan(plan, el, expr[expr.length - 1]);
for(int i = 0; i < expr.length - 1; i++) expr[i].plan(el);
}

@Override
@@ -27,9 +27,7 @@ public FNAcc(final InputInfo ii, final Function f, final Expr... e) {
}

@Override
public Item item(final QueryContext ctx, final InputInfo ii)
throws QueryException {

public Item item(final QueryContext ctx, final InputInfo ii) throws QueryException {
final Expr e = expr.length != 0 ? expr[0] : checkCtx(ctx);
switch(sig) {
case POSITION:
@@ -77,9 +75,7 @@ private Item string(final Expr e, final InputInfo ii,
* @return double iterator
* @throws QueryException query exception
*/
private Item number(final Iter ir, final QueryContext ctx)
throws QueryException {

private Item number(final Iter ir, final QueryContext ctx) throws QueryException {
final Item it = ir.next();
if(it == null || ir.next() != null) return Dbl.NAN;
final Type t = it.type;
@@ -28,9 +28,7 @@ public FNAggr(final InputInfo ii, final Function f, final Expr... e) {
}

@Override
public Item item(final QueryContext ctx, final InputInfo ii)
throws QueryException {

public Item item(final QueryContext ctx, final InputInfo ii) throws QueryException {
final Iter iter = ctx.iter(expr[0]);
switch(sig) {
case COUNT:
@@ -30,9 +30,7 @@ public FNContext(final InputInfo ii, final Function f, final Expr... e) {
}

@Override
public Item item(final QueryContext ctx, final InputInfo ii)
throws QueryException {

public Item item(final QueryContext ctx, final InputInfo ii) throws QueryException {
switch(sig) {
case CURRENT_DATE:
return currDate(ctx);
@@ -25,9 +25,7 @@ public FNCrypto(final InputInfo ii, final Function fd, final Expr[] args) {
}

@Override
public Item item(final QueryContext ctx, final InputInfo ii)
throws QueryException {

public Item item(final QueryContext ctx, final InputInfo ii) throws QueryException {
switch(sig) {
case _CRYPTO_HMAC:
return new Encryption(ii).hmac(checkStr(expr[0], ctx), checkStr(expr[1],
@@ -30,8 +30,7 @@ public FNDate(final InputInfo ii, final Function f, final Expr... e) {
}

@Override
public Item item(final QueryContext ctx, final InputInfo ii)
throws QueryException {
public Item item(final QueryContext ctx, final InputInfo ii) throws QueryException {
// functions have 1 or 2 arguments...
final Item it = expr[0].item(ctx, info);
if(it == null) return null;
@@ -655,7 +655,7 @@ private Item event(final QueryContext ctx) throws QueryException {
// run serialization
final Serializer ser = Serializer.get(ao, ctx.serParams(true));
final ValueIter ir = ctx.value(expr[1]).iter();
for(Item it; (it = ir.next()) != null;) it.serialize(ser);
for(Item it; (it = ir.next()) != null;) ser.item(it);
ser.close();
} catch(final SerializerException ex) {
throw ex.getCause(info);
@@ -106,9 +106,7 @@ private Item size(final File path) throws QueryException {
* @return result
* @throws QueryException query exception
*/
private Str baseName(final File path, final QueryContext ctx)
throws QueryException {

private Str baseName(final File path, final QueryContext ctx) throws QueryException {
if(path.getPath().isEmpty()) return Str.get(".");
final String suf = expr.length < 2 ? null : string(checkStr(expr[1], ctx));
String pth = path.getName();
@@ -345,7 +343,7 @@ private Item write(final File path, final QueryContext ctx, final boolean append
new FileOutputStream(path, append));
try {
final Serializer ser = Serializer.get(out, FNGen.serialPar(this, 2, ctx));
for(Item it; (it = ir.next()) != null;) it.serialize(ser);
for(Item it; (it = ir.next()) != null;) ser.item(it);
ser.close();
} catch(final SerializerException ex) {
throw ex.getCause(info);
@@ -27,9 +27,7 @@ public FNFormat(final InputInfo ii, final Function f, final Expr... e) {
}

@Override
public Item item(final QueryContext ctx, final InputInfo ii)
throws QueryException {

public Item item(final QueryContext ctx, final InputInfo ii) throws QueryException {
switch(sig) {
case FORMAT_INTEGER: return formatInteger(ctx);
case FORMAT_NUMBER: return formatNumber(ctx);
@@ -91,9 +89,7 @@ private Str formatNumber(final QueryContext ctx) throws QueryException {
* @return string
* @throws QueryException query exception
*/
private Item formatDate(final Type tp, final QueryContext ctx)
throws QueryException {

private Item formatDate(final Type tp, final QueryContext ctx) throws QueryException {
final Item it = expr[0].item(ctx, info);
final byte[] pic = checkEStr(expr[1], ctx);
final byte[] lng = expr.length == 5 ? checkEStr(expr[2], ctx) : EMPTY;
@@ -36,8 +36,7 @@ public FNFt(final InputInfo ii, final Function f, final Expr... e) {
}

@Override
public Item item(final QueryContext ctx, final InputInfo ii)
throws QueryException {
public Item item(final QueryContext ctx, final InputInfo ii) throws QueryException {
switch(sig) {
case _FT_COUNT: return count(ctx);
default: return super.item(ctx, ii);
@@ -39,8 +39,7 @@ public Iter iter(final QueryContext ctx) throws QueryException {
}

@Override
public Item item(final QueryContext ctx, final InputInfo ii)
throws QueryException {
public Item item(final QueryContext ctx, final InputInfo ii) throws QueryException {
switch(sig) {
case FUNCTION_ARITY:
return Int.get(getFun(0, FuncType.ANY_FUN, ctx).arity());
@@ -62,8 +61,7 @@ public Item item(final QueryContext ctx, final InputInfo ii)
* @return function item
* @throws QueryException query exception
*/
private Item lookup(final QueryContext ctx, final InputInfo ii)
throws QueryException {
private Item lookup(final QueryContext ctx, final InputInfo ii) throws QueryException {
final QNm name = (QNm) checkType(expr[0].item(ctx, ii), AtomType.QNM);
final long arity = checkItr(expr[1], ctx);
try {
@@ -81,13 +79,12 @@ private Item lookup(final QueryContext ctx, final InputInfo ii)
* @return function item
* @throws QueryException query exception
*/
private Item partApp(final QueryContext ctx, final InputInfo ii)
throws QueryException {
private Item partApp(final QueryContext ctx, final InputInfo ii) throws QueryException {
final FItem f = getFun(0, FuncType.ANY_FUN, ctx);
final long pos = expr.length == 2 ? 0 : checkItr(expr[2], ctx) - 1;

final int arity = f.arity();
if(pos < 0 || pos >= arity) INVPOS.thrw(ii, f.info(), pos + 1);
if(pos < 0 || pos >= arity) INVPOS.thrw(ii, f.description(), pos + 1);

final FuncType ft = (FuncType) f.type;
final Var[] vars = new Var[arity - 1];
@@ -293,7 +293,7 @@ private Str serialize(final QueryContext ctx) throws QueryException {
// run serialization
final Serializer ser = Serializer.get(ao, serialPar(this, 1, ctx));
final Iter ir = expr[0].iter(ctx);
for(Item it; (it = ir.next()) != null;) it.serialize(ser);
for(Item it; (it = ir.next()) != null;) ser.item(it);
ser.close();
} catch(final SerializerException ex) {
throw ex.getCause(info);
@@ -55,8 +55,7 @@ public Value value(final QueryContext ctx) throws QueryException {
}

@Override
public Item item(final QueryContext ctx, final InputInfo ii)
throws QueryException {
public Item item(final QueryContext ctx, final InputInfo ii) throws QueryException {
switch(sig) {
case _HOF_ID:
case _HOF_CONST: return expr[0].item(ctx, ii);
@@ -44,8 +44,7 @@ public Iter iter(final QueryContext ctx) throws QueryException {
}

@Override
public Item item(final QueryContext ctx, final InputInfo ii)
throws QueryException {
public Item item(final QueryContext ctx, final InputInfo ii) throws QueryException {
// functions have 1 or 2 arguments...
final Item it = checkNoEmpty((expr.length == 2 ? expr[1] :
checkCtx(ctx)).item(ctx, info));
@@ -54,9 +54,7 @@ public FNIndex(final InputInfo ii, final Function f, final Expr... e) {
}

@Override
public Item item(final QueryContext ctx, final InputInfo ii)
throws QueryException {

public Item item(final QueryContext ctx, final InputInfo ii) throws QueryException {
switch(sig) {
case _INDEX_FACETS: return facets(ctx);
default: return super.item(ctx, ii);
@@ -93,9 +91,7 @@ private Item facets(final QueryContext ctx) throws QueryException {
* @return text entries
* @throws QueryException query exception
*/
private Iter values(final QueryContext ctx, final IndexType it)
throws QueryException {

private Iter values(final QueryContext ctx, final IndexType it) throws QueryException {
final Data data = data(0, ctx);
final byte[] prefix = expr.length < 2 ? EMPTY : checkStr(expr[1], ctx);
return entries(data, prefix, it, this);
@@ -137,9 +133,7 @@ static Iter entries(final Data data, final byte[] prefix, final IndexType it,
* @return text entries
* @throws QueryException query exception
*/
private Iter names(final QueryContext ctx, final IndexType it)
throws QueryException {

private Iter names(final QueryContext ctx, final IndexType it) throws QueryException {
final Data data = data(0, ctx);
return entries(it == IndexType.TAG ? data.tagindex : data.atnindex, EMPTY);
}
@@ -183,9 +177,7 @@ private static FElem flat(final Data data) {
* @param name element name
* @param root root node
*/
private static void index(final Names names, final QNm name,
final FElem root) {

private static void index(final Names names, final QNm name, final FElem root) {
for(int i = 0; i < names.size(); ++i) {
final FElem sub = new FElem(name);
sub.add(new FAttr(Q_NAME, names.key(i + 1)));
@@ -69,8 +69,7 @@ public Item next() throws QueryException {
}

@Override
public Item item(final QueryContext ctx, final InputInfo ii)
throws QueryException {
public Item item(final QueryContext ctx, final InputInfo ii) throws QueryException {
switch(sig) {
case ENVIRONMENT_VARIABLE:
final String e = System.getenv(Token.string(checkEStr(expr[0], ctx)));
@@ -31,8 +31,7 @@ public FNJson(final InputInfo ii, final Function f, final Expr... e) {
}

@Override
public Item item(final QueryContext ctx, final InputInfo ii)
throws QueryException {
public Item item(final QueryContext ctx, final InputInfo ii) throws QueryException {
switch(sig) {
case _JSON_PARSE:
return new JSONConverter(info).parse(checkStr(expr[0], ctx));
@@ -54,17 +53,15 @@ public Item item(final QueryContext ctx, final InputInfo ii)
* @return serialized document
* @throws QueryException query exception
*/
private Str serialize(final boolean ml, final QueryContext ctx)
throws QueryException {

private Str serialize(final boolean ml, final QueryContext ctx) throws QueryException {
final ANode node = checkNode(checkItem(expr[0], ctx));
final ArrayOutput ao = new ArrayOutput();
try {
// run serialization
final SerializerProp props = ctx.serParams(false);
final Serializer json = ml ? new JsonMLSerializer(ao, props) :
new JSONSerializer(ao, props);
node.serialize(json);
json.item(node);
json.close();
} catch(final SerializerException ex) {
throw ex.getCause(info);
@@ -43,8 +43,7 @@ public Value value(final QueryContext ctx) throws QueryException {
}

@Override
public Item item(final QueryContext ctx, final InputInfo ii)
throws QueryException {
public Item item(final QueryContext ctx, final InputInfo ii) throws QueryException {
switch(sig) {
case _MAP_NEW: return newMap(ctx, ii);
case _MAP_ENTRY: return entry(ctx, ii);
@@ -63,8 +62,7 @@ public Item item(final QueryContext ctx, final InputInfo ii)
* @return new map with key removed from it
* @throws QueryException query exception
*/
private Map remove(final QueryContext ctx, final InputInfo ii)
throws QueryException {
private Map remove(final QueryContext ctx, final InputInfo ii) throws QueryException {
return map(ctx).delete(expr[1].item(ctx, ii), ii);
}

@@ -75,8 +73,7 @@ private Map remove(final QueryContext ctx, final InputInfo ii)
* @return the singleton map
* @throws QueryException query exception
*/
private Map entry(final QueryContext ctx, final InputInfo ii)
throws QueryException {
private Map entry(final QueryContext ctx, final InputInfo ii) throws QueryException {
return Map.EMPTY.insert(expr[0].item(ctx, ii), ctx.value(expr[1]), ii);
}

@@ -87,8 +84,7 @@ private Map entry(final QueryContext ctx, final InputInfo ii)
* @return new map
* @throws QueryException query exception
*/
private Map newMap(final QueryContext ctx, final InputInfo ii)
throws QueryException {
private Map newMap(final QueryContext ctx, final InputInfo ii) throws QueryException {
if(expr.length == 0) return Map.EMPTY;
if(expr.length == 2) checkColl(expr[1], ctx);

@@ -116,8 +112,7 @@ private Value get(final QueryContext ctx) throws QueryException {
* @return result of check
* @throws QueryException query exception
*/
private Bln contains(final QueryContext ctx, final InputInfo ii)
throws QueryException {
private Bln contains(final QueryContext ctx, final InputInfo ii) throws QueryException {
return map(ctx).contains(expr[1].item(ctx, ii), ii);
}

@@ -25,9 +25,7 @@ public FNMath(final InputInfo ii, final Function f, final Expr... e) {
}

@Override
public Item item(final QueryContext ctx, final InputInfo ii)
throws QueryException {

public Item item(final QueryContext ctx, final InputInfo ii) throws QueryException {
double d = 0;
if(expr.length > 0) {
if(expr[0].isEmpty()) return null;
@@ -26,8 +26,7 @@ public FNNum(final InputInfo ii, final Function f, final Expr... e) {
}

@Override
public Item item(final QueryContext ctx, final InputInfo ii)
throws QueryException {
public Item item(final QueryContext ctx, final InputInfo ii) throws QueryException {
final Item it = expr[0].item(ctx, info);
if(it == null) return null;

@@ -67,9 +66,7 @@ private Item rnd(final Item it, final double d, final boolean h2e,
* @return absolute item
* @throws QueryException query exception
*/
private static Item abs(final Item it, final InputInfo ii)
throws QueryException {

private static Item abs(final Item it, final InputInfo ii) throws QueryException {
final double d = it.dbl(ii);
final boolean s = d > 0d || 1 / d > 0;

@@ -55,8 +55,7 @@ public Iter iter(final QueryContext ctx) throws QueryException {
}

@Override
public Item item(final QueryContext ctx, final InputInfo ii)
throws QueryException {
public Item item(final QueryContext ctx, final InputInfo ii) throws QueryException {
switch(sig) {
case MATCHES: return matches(checkEStr(expr[0], ctx), ctx);
case REPLACE: return replace(checkEStr(expr[0], ctx), ctx);
@@ -72,9 +71,7 @@ public Item item(final QueryContext ctx, final InputInfo ii)
* @return function result
* @throws org.basex.query.QueryException query exception
*/
private Item matches(final byte[] val, final QueryContext ctx)
throws QueryException {

private Item matches(final byte[] val, final QueryContext ctx) throws QueryException {
final Pattern p = pattern(expr[1], expr.length == 3 ? expr[2] : null, ctx);
return Bln.get(p.matcher(string(val)).find());
}
@@ -154,9 +151,7 @@ private static void nonmatch(final String text, final FElem par) {
* @return function result
* @throws org.basex.query.QueryException query exception
*/
private Item replace(final byte[] val, final QueryContext ctx)
throws QueryException {

private Item replace(final byte[] val, final QueryContext ctx) throws QueryException {
final byte[] rep = checkStr(expr[2], ctx);
for(int i = 0; i < rep.length; ++i) {
if(rep[i] == '\\') {
@@ -189,9 +184,7 @@ private Item replace(final byte[] val, final QueryContext ctx)
* @return function result
* @throws org.basex.query.QueryException query exception
*/
private Iter tokenize(final byte[] val, final QueryContext ctx)
throws QueryException {

private Iter tokenize(final byte[] val, final QueryContext ctx) throws QueryException {
final Pattern p = pattern(expr[1], expr.length == 3 ? expr[2] : null, ctx);
if(p.matcher("").matches()) REGROUP.thrw(info);

@@ -37,9 +37,7 @@ public Iter iter(final QueryContext ctx) throws QueryException {
}

@Override
public Item item(final QueryContext ctx, final InputInfo ii)
throws QueryException {

public Item item(final QueryContext ctx, final InputInfo ii) throws QueryException {
// functions have 1 or 2 arguments...
final Item it = expr[0].item(ctx, info);
final Item it2 = expr.length == 2 ? expr[1].item(ctx, info) : null;
@@ -100,9 +98,7 @@ private Item qName(final Item it, final Item it2) throws QueryException {
* @return prefix sequence
* @throws QueryException query exception
*/
private Item lnFromQName(final QueryContext ctx, final Item it)
throws QueryException {

private Item lnFromQName(final QueryContext ctx, final Item it) throws QueryException {
if(it == null) return null;
final QNm nm = (QNm) checkType(it, AtomType.QNM);
return AtomType.NCN.cast(Str.get(nm.local()), ctx, info);
@@ -156,9 +152,7 @@ private Item resolveQName(final QueryContext ctx, final Item it,
* @return prefix sequence
* @throws QueryException query exception
*/
private Item nsUriForPrefix(final Item it, final Item it2)
throws QueryException {

private Item nsUriForPrefix(final Item it, final Item it2) throws QueryException {
final byte[] pref = checkEStr(it);
final ANode an = (ANode) checkType(it2, NodeType.ELM);
if(eq(pref, XML)) return Uri.uri(XMLURI, false);
@@ -33,8 +33,7 @@ public FNSeq(final InputInfo ii, final Function f, final Expr... e) {
}

@Override
public Item item(final QueryContext ctx, final InputInfo ii)
throws QueryException {
public Item item(final QueryContext ctx, final InputInfo ii) throws QueryException {
switch(sig) {
case HEAD: return head(ctx);
default: return super.item(ctx, ii);
@@ -65,8 +64,7 @@ public Iter iter(final QueryContext ctx) throws QueryException {
* @return outermost/innermost nodes
* @throws QueryException exception
*/
private Iter most(final QueryContext ctx, final boolean outer)
throws QueryException {
private Iter most(final QueryContext ctx, final boolean outer) throws QueryException {
final Iter iter = expr[0].iter(ctx);
final NodeCache nc = new NodeCache().random();
for(Item it; (it = iter.next()) != null;) nc.add(checkNode(it));
@@ -69,9 +69,7 @@ public Value value(final QueryContext ctx) throws QueryException {
}

@Override
public Item item(final QueryContext ctx, final InputInfo ii)
throws QueryException {

public Item item(final QueryContext ctx, final InputInfo ii) throws QueryException {
final Expr e = expr.length == 1 ? expr[0] : null;
switch(sig) {
case FALSE:
@@ -56,8 +56,7 @@ public Value value(final QueryContext ctx) throws QueryException {
}

@Override
public Item item(final QueryContext ctx, final InputInfo ii)
throws QueryException {
public Item item(final QueryContext ctx, final InputInfo ii) throws QueryException {
final Expr e = expr[0];

switch(sig) {
@@ -63,8 +63,7 @@ public Value value(final QueryContext ctx) throws QueryException {
}

@Override
public Item item(final QueryContext ctx, final InputInfo ii)
throws QueryException {
public Item item(final QueryContext ctx, final InputInfo ii) throws QueryException {
switch(sig) {
case _UTIL_SLEEP: return sleep(ctx);
case _UTIL_FORMAT: return format(ctx);
@@ -275,9 +274,7 @@ private static Str toBaseFast(final long num, final int shift) {
* @return string representation of the given number
* @throws QueryException query exception
*/
private Str toBase(final QueryContext ctx, final InputInfo ii)
throws QueryException {

private Str toBase(final QueryContext ctx, final InputInfo ii) throws QueryException {
final long num = checkItr(expr[0], ctx), base = checkItr(expr[1], ctx);
if(base < 2 || base > 36) INVBASE.thrw(ii, base);

@@ -315,9 +312,7 @@ private Str toBase(final QueryContext ctx, final InputInfo ii)
* @return read integer
* @throws QueryException exception
*/
private Int fromBase(final QueryContext ctx, final InputInfo ii)
throws QueryException {

private Int fromBase(final QueryContext ctx, final InputInfo ii) throws QueryException {
final byte[] str = checkStr(expr[0], ctx);
final long base = checkItr(expr[1], ctx);
if(base < 2 || base > 36) INVBASE.thrw(ii, base);
@@ -342,9 +337,7 @@ private Int fromBase(final QueryContext ctx, final InputInfo ii)
* @return xs:hexBinary instance containing the hash
* @throws QueryException exception
*/
private Hex hash(final QueryContext ctx, final String algo)
throws QueryException {

private Hex hash(final QueryContext ctx, final String algo) throws QueryException {
final byte[] str = checkStr(expr[0], ctx);
try {
return new Hex(MessageDigest.getInstance(algo).digest(str));
@@ -13,7 +13,6 @@

import org.basex.io.*;
import org.basex.io.out.*;
import org.basex.io.serial.*;
import org.basex.query.*;
import org.basex.query.expr.*;
import org.basex.query.item.*;
@@ -149,13 +148,7 @@ private TokenObjMap<Object> xsltParams(final int arg, final QNm root,
private IO read(final Expr e, final QueryContext ctx) throws Exception {
final Item it = checkNoEmpty(e.item(ctx, info));
final Type ip = it.type;
if(ip.isNode()) {
final ArrayOutput ao = new ArrayOutput();
final Serializer ser = Serializer.get(ao);
it.serialize(ser);
ser.close();
return new IOContent(ao.toArray());
}
if(ip.isNode()) return new IOContent(it.serialize().toArray());
if(ip.isString()) return IO.get(string(it.string(info)));
throw STRNODTYPE.thrw(info, this, ip);
}
@@ -324,7 +324,7 @@ private void create(final ZipOutputStream zos, final AxisIter ai, final String r
try {
final Serializer ser = Serializer.get(zos, serPar(node, ctx));
do {
DataBuilder.stripNS(n, ZIPURI, ctx.context).serialize(ser);
ser.item(DataBuilder.stripNS(n, ZIPURI, ctx.context));
} while((n = ch.next()) != null);
ser.close();
} catch(final SerializerException ex) {