use of org.eclipse.wst.xml.xpath2.processor.internal.ast.XPathExpr in project webtools.sourceediting by eclipse.
the class StaticNameResolver method visit.
/**
* Validate an xpath expression.
*
* @param e
* is the expression.
* @return null.
*/
public Object visit(XPathExpr e) {
XPathExpr xp = e;
boolean firstStep = true;
while (xp != null) {
if (firstStep && xp.slashes() != 0)
_rootUsed = true;
firstStep = false;
StepExpr se = xp.expr();
if (se != null)
se.accept(this);
xp = xp.next();
}
return null;
}
use of org.eclipse.wst.xml.xpath2.processor.internal.ast.XPathExpr in project webtools.sourceediting by eclipse.
the class DefaultEvaluator method visit.
/**
* visit XPath expression
*
* @param e
* is the XPath expression.
* @return a new function
*/
public Object visit(XPathExpr e) {
XPathExpr xp = e;
ResultSequence rs = null;
Focus original_focus = focus();
// do all the steps
while (xp != null) {
StepExpr se = xp.expr();
if (se != null) {
// this is not the first step
if (rs != null) {
// results...
if (rs.size() == 0)
break;
// nodes!
for (Iterator i = rs.iterator(); i.hasNext(); ) {
AnyType item = (AnyType) i.next();
if (!(item instanceof NodeType)) {
report_error(TypeError.step_conatins_atoms(null));
// unreach
return null;
}
}
// check if we got a //
if (xp.slashes() == 2) {
rs = descendant_or_self_node(rs);
if (rs.size() == 0)
break;
}
// make result of previous step the new
// focus
set_focus(new Focus(rs));
// do the step for all item in context
rs = do_step(se);
} else // this is first step...
// note... we may be called from upstream...
// like in the expression sorbo/*[2] ... we may
// be called to evaluate the 2... the caller
// will iterate through the whole outer focus
// for us
{
// XXX ???
if (xp.slashes() == 1) {
rs = root_self_node();
set_focus(new Focus(rs));
rs = do_step(se);
} else if (xp.slashes() == 2) {
rs = root_self_node();
rs = descendant_or_self_node(rs);
set_focus(new Focus(rs));
rs = do_step(se);
} else
rs = (ResultSequence) se.accept(this);
}
} else // the expression is "/"
{
assert xp.slashes() == 1;
rs = root_self_node();
}
xp = xp.next();
}
// restore focus
set_focus(original_focus);
return rs;
}
use of org.eclipse.wst.xml.xpath2.processor.internal.ast.XPathExpr in project webtools.sourceediting by eclipse.
the class DefaultEvaluator method do_predicate.
// do the predicate for all items in focus
private ResultSequence do_predicate(Collection exprs) {
ResultBuffer rs = new ResultBuffer();
Focus focus = focus();
int original_cp = focus.position();
// check if predicate is single numeric constant
if (exprs.size() == 1) {
Expr expr = (Expr) exprs.iterator().next();
if (expr instanceof XPathExpr) {
XPathExpr xpe = (XPathExpr) expr;
if (xpe.next() == null && xpe.slashes() == 0 && xpe.expr() instanceof FilterExpr) {
FilterExpr fex = (FilterExpr) xpe.expr();
if (fex.primary() instanceof IntegerLiteral) {
int pos = (((IntegerLiteral) fex.primary()).value().int_value()).intValue();
if (pos <= focus.last() && pos > 0) {
focus.set_position(pos);
rs.add(focus.context_item());
}
focus.set_position(original_cp);
return rs.getSequence();
}
}
}
}
// go through all elements
while (true) {
// do the predicate
// XXX saxon doesn't allow for predicates to have
// commas... but XPath 2.0 spec seems to do
ResultSequence res = do_expr(exprs.iterator());
// in the sequence
if (predicate_truth(res))
rs.add(focus().context_item());
if (!focus.advance_cp())
break;
}
// restore
focus.set_position(original_cp);
return rs.getSequence();
}
use of org.eclipse.wst.xml.xpath2.processor.internal.ast.XPathExpr in project webtools.sourceediting by eclipse.
the class Normalizer method make_convert_operand.
private XPathExpr make_convert_operand(XPathExpr arg1, XPathExpr arg2) {
Collection args = new ArrayList();
args.add(arg1);
args.add(arg2);
return make_function(new QName("fs", "convert-operand", OpFunctionLibrary.XPATH_OP_NS), args);
}
use of org.eclipse.wst.xml.xpath2.processor.internal.ast.XPathExpr in project webtools.sourceediting by eclipse.
the class Normalizer method make_convert_binop.
// fs:fname( fs:convert-operand( fn:data(ARG1), 1.0E0 ),
// fs:convert-operand( fn:data(ARG2), 1.0E0 )
// )
private XPathExpr make_convert_binop(BinExpr e, XPathExpr convarg, QName name) {
Collection args = normalize_bin_args(e);
XPathExpr[] args_arr = new XPathExpr[2];
int j = 0;
for (Iterator i = args.iterator(); i.hasNext(); ) {
args_arr[j] = (XPathExpr) i.next();
j++;
}
Collection argsfname = new ArrayList();
for (j = 0; j < 2; j++) {
XPathExpr arg = make_convert_operand(args_arr[j], convarg);
argsfname.add(arg);
}
return make_function(name, argsfname);
}
Aggregations