use of org.eclipse.wst.xml.xpath2.processor.internal.ast.StepExpr in project webtools.sourceediting by eclipse.
the class Normalizer method make_descendant_or_self.
private XPathExpr make_descendant_or_self() {
Step desc_self_node = new ForwardStep(ForwardStep.DESCENDANT_OR_SELF, new AnyKindTest());
StepExpr se = new AxisStep(desc_self_node, new ArrayList());
return new XPathExpr(0, se);
}
use of org.eclipse.wst.xml.xpath2.processor.internal.ast.StepExpr in project webtools.sourceediting by eclipse.
the class Normalizer method make_root_self_node.
private XPathExpr make_root_self_node() {
// self::node()
Step self_node = new ForwardStep(ForwardStep.SELF, new AnyKindTest());
StepExpr self_node_expr = new AxisStep(self_node, new ArrayList());
XPathExpr self_node_xpath = new XPathExpr(0, self_node_expr);
// fn:root(self::node())
Collection args = new ArrayList();
args.add(self_node_xpath);
XPathExpr xpe = make_function(new QName("fn", "root", FnFunctionLibrary.XPATH_FUNCTIONS_NS), args);
return xpe;
}
use of org.eclipse.wst.xml.xpath2.processor.internal.ast.StepExpr in project webtools.sourceediting by eclipse.
the class Normalizer method visit.
/**
* @param e
* is the xpath expression.
* @return result.
*/
public Object visit(XPathExpr e) {
XPathExpr xp = e;
// indicates how many / we traversed
int depth = 0;
XPathExpr result = e;
while (xp != null) {
int slashes = xp.slashes();
StepExpr se = xp.expr();
if (slashes == 1) {
// this is a single slash and nothing else...
if (se == null)
return make_root_self_node();
// /RelativePathExpr
if (depth == 0) {
XPathExpr xpe = make_root_self_node();
xpe.set_next(e);
result = xpe;
}
}
if (slashes == 2) {
// //RelativePathExpr
if (depth == 0) {
XPathExpr desc = make_descendant_or_self();
desc.set_slashes(1);
e.set_slashes(1);
desc.set_next(e);
XPathExpr root_self = make_root_self_node();
root_self.set_next(desc);
return root_self;
}
}
if (se != null)
se.accept(this);
XPathExpr next = xp.next();
// peek if the next guy will have 2 slashes...
if (next != null) {
// StepExpr//StepExpr
if (next.slashes() == 2) {
// create the node to stick between the
// slashes
XPathExpr desc = make_descendant_or_self();
desc.set_slashes(1);
// current node / desc / next
xp.set_next(desc);
desc.set_next(next);
next.set_slashes(1);
}
}
xp = next;
depth++;
}
return result;
}
use of org.eclipse.wst.xml.xpath2.processor.internal.ast.StepExpr 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.StepExpr 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;
}
Aggregations