private final ContextProvider context;
private final TemplateEntry template;
private Match transform(Match m, int searchExpressionPosition) throws ParseError {
if (m instanceof Parent) {
Match child = transform(((Parent) m).getOperand(), searchExpressionPosition);
return new ParentSet(child);
} else if (m instanceof Child) {
Match parent = transform(((Child) m).getOperand(), searchExpressionPosition);
return new ChildSet(parent);
} else if (m instanceof And) {
Match lhs = transform(((And) m).getLhs(), searchExpressionPosition);
Match rhs = transform(((And) m).getRhs(), searchExpressionPosition);
if (lhs instanceof ContextProvider && rhs instanceof ContextProvider)
return new AndSet((ContextProvider)lhs, (ContextProvider)rhs);
else if (lhs instanceof ContextProvider) {
ContextProvider cp = (ContextProvider) lhs;
if (cp.condition == null) {
cp.condition = rhs;
} else {
cp.condition = new And(cp.condition, rhs);
}
return cp;
} else if (rhs instanceof ContextProvider) {
ContextProvider cp = (ContextProvider) rhs;
if (cp.condition == null) {
cp.condition = lhs;
} else {
cp.condition = new And(lhs, cp.condition);
}
return cp;
} else
return m;
} else if (m instanceof Or) {
Match lhs = transform(((Or) m).getLhs(), searchExpressionPosition);
Match rhs = transform(((Or) m).getRhs(), searchExpressionPosition);
if (lhs instanceof ContextProvider && rhs instanceof ContextProvider)
return new OrSet((ContextProvider)lhs, (ContextProvider)rhs);
else if (lhs instanceof ContextProvider)
throw new ParseError(tr("Error in search expression on position {0} - right side of or(|) expression must return set of primitives", searchExpressionPosition));
else if (rhs instanceof ContextProvider)
throw new ParseError(tr("Error in search expression on position {0} - left side of or(|) expression must return set of primitives", searchExpressionPosition));
else
return m;
} else if (m instanceof Not) {
Match match = transform(((Not) m).getMatch(), searchExpressionPosition);
if (match instanceof ContextProvider)
throw new ParseError(tr("Error in search expression on position {0} - not(-) cannot be used in this context", searchExpressionPosition));
else
return m;
} else