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.");
    }
  }
Exemple #2
0
  @Override
  public Type matches(Type[] params) {
    if (!params[0].isSubtypeOf(this.sourceType)) {
      return null;
    }

    for (int i = 1; i < params.length; i++) {
      Type givenType = params[i];
      Type requiredType = parameter.get(i - 1).getType();

      if (!givenType.isSubtypeOf(requiredType)) {
        return null;
      }
    }

    return resultType;
  }