/** * This uses a deceptively simple algorithm to determine what bound variables are in scope for a * given constraint (including connectives). Does not take into account globals. */ public List<String> getBoundVariablesInScope(final BaseSingleFieldConstraint con) { final List<String> result = new ArrayList<String>(); for (int i = 0; i < this.lhs.length; i++) { IPattern pat = this.lhs[i]; if (pat instanceof FromCompositeFactPattern) { pat = ((FromCompositeFactPattern) pat).getFactPattern(); } if (pat instanceof FactPattern) { final FactPattern fact = (FactPattern) pat; if (fact.getConstraintList() != null) { final FieldConstraint[] cons = fact.getConstraintList().getConstraints(); if (cons != null) { for (int k = 0; k < cons.length; k++) { FieldConstraint fc = cons[k]; if (fc instanceof SingleFieldConstraint) { final SingleFieldConstraint c = (SingleFieldConstraint) fc; if (c == con) { return result; } if (c.getConnectives() != null) { for (int j = 0; j < c.getConnectives().length; j++) { if (con == c.getConnectives()[j]) { return result; } } } if (c.isBound()) { result.add(c.getFieldBinding()); } } } } if (fact.isBound()) { result.add(fact.getBoundName()); } } else { if (fact.isBound()) { result.add(fact.getBoundName()); } } } } return result; }
/** This will get a list of all LHS bound variables, including bound fields.. */ public List<String> getAllLHSVariables() { List<String> result = new ArrayList<String>(); for (int i = 0; i < this.lhs.length; i++) { IPattern pat = this.lhs[i]; if (pat instanceof FromCompositeFactPattern) { pat = ((FromCompositeFactPattern) pat).getFactPattern(); } if (pat instanceof FactPattern) { FactPattern fact = (FactPattern) pat; if (fact.isBound()) { result.add(fact.getBoundName()); } for (int j = 0; j < fact.getFieldConstraints().length; j++) { FieldConstraint fc = fact.getFieldConstraints()[j]; if (fc instanceof SingleFieldConstraintEBLeftSide) { SingleFieldConstraintEBLeftSide exp = (SingleFieldConstraintEBLeftSide) fc; if (exp.getExpressionLeftSide() != null && exp.getExpressionLeftSide().isBound()) { result.add(exp.getExpressionLeftSide().getBinding()); } } else if (fc instanceof SingleFieldConstraint) { SingleFieldConstraint con = (SingleFieldConstraint) fc; if (con.isBound()) { result.add(con.getFieldBinding()); } if (con.getExpressionValue() != null && con.getExpressionValue().isBound()) { result.add(con.getExpressionValue().getBinding()); } } } } } return result; }
/** * Get the data-type associated with the binding * * @param var * @return The data-type, or null if the binding could not be found */ public String getLHSBindingType(final String var) { if (this.lhs == null) { return null; } for (int i = 0; i < this.lhs.length; i++) { IPattern pat = this.lhs[i]; if (pat instanceof FromCompositeFactPattern) { pat = ((FromCompositeFactPattern) pat).getFactPattern(); } if (pat instanceof FactPattern) { final FactPattern p = (FactPattern) pat; if (p.isBound() && var.equals(p.getBoundName())) { return p.getFactType(); } for (FieldConstraint fc : p.getFieldConstraints()) { String type = getFieldBinding(fc, var); if (type != null) { return type; } } } } return null; }