示例#1
0
  protected ExpQuery(
      Type resultType, VarDeclList elemVarDecls, Expression rangeExp, Expression queryExp)
      throws ExpInvalidException {
    super(resultType, rangeExp, queryExp);
    fElemVarDecls = elemVarDecls;
    fRangeExp = rangeExp;
    fQueryExp = queryExp;

    // type of rangeExp must be a subtype of Collection, i.e. Set,
    // Sequence or Bag
    if (!fRangeExp.type().isCollection(false))
      throw new ExpInvalidException(
          "Range expression must be of type " + "`Collection', found `" + fRangeExp.type() + "'.");

    // assert that declard element variables are equal or
    // supertypes of range element type
    Type rangeElemType = ((CollectionType) fRangeExp.type()).elemType();

    for (int i = 0; i < fElemVarDecls.size(); i++) {
      VarDecl vd = fElemVarDecls.varDecl(i);
      if (!rangeElemType.isSubtypeOf(vd.type()))
        throw new ExpInvalidException(
            "Type `"
                + vd.type()
                + "' of range variable `"
                + vd.name()
                + "' does not match type `"
                + rangeElemType
                + "' of collection elements.");
    }
  }