Constraint right = replaceReferences(context, and.right(), mapping, node);
if (left == and.left() && right == and.right()) return and;
return new And(left, right);
}
if (constraint instanceof Or) {
Or or = (Or)constraint;
Constraint left = replaceReferences(context, or.left(), mapping, node);
Constraint right = replaceReferences(context, or.right(), mapping, node);
if (left == or.left() && right == or.right()) return or;
return new Or(left, right);
}
if (constraint instanceof Not) {
Not not = (Not)constraint;
Constraint wrapped = replaceReferences(context, not.getConstraint(), mapping, node);
return wrapped == not.getConstraint() ? not : new Not(wrapped);