Example #1
0
  /**
   * 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;
  }