private ExpressionBase convertCheck(Check chk, OldExpressionConverter exprConv) {
    final SourcePos sourcePos = exprConv.getSourcePos(chk);

    final ExpressionBase preCondExpression =
        (chk.getGuard() == null)
            ? exprConv.convert(chk.getConstraint())
            : new OrExpression(
                new InvocationOnObjectExpression(
                    new QualifiedName(SysLibNames.OPERATOR_NOT),
                    Arrays.asList(exprConv.convert(chk.getGuard())),
                    true,
                    sourcePos),
                new AndExpression(
                    exprConv.convert(chk.getGuard()),
                    exprConv.convert(chk.getConstraint()),
                    sourcePos),
                sourcePos);

    final String addIssueMethodName = chk.isErrorCheck() ? "addError" : "addWarning";

    final List<ExpressionBase> failureParams = new ArrayList<ExpressionBase>();
    failureParams.add(new LocalVarEvalExpression(ISSUES_PARAM_NAME, sourcePos));
    failureParams.add(exprConv.convert(chk.getMsg()));
    failureParams.add(new LocalVarEvalExpression(SyntaxConstants.THIS, sourcePos));

    final ExpressionBase failureExpression =
        new InvocationOnObjectExpression(
            new QualifiedName(addIssueMethodName), failureParams, true, sourcePos);

    final ExpressionBase onEachExpression =
        new IfExpression(
            preCondExpression,
            new LiteralExpression(null, sourcePos),
            failureExpression,
            sourcePos);

    final List<ExpressionBase> typeSelectParams = new ArrayList<ExpressionBase>();
    typeSelectParams.add(new LocalVarEvalExpression(ALL_OBJECTS_PARAM_NAME, sourcePos));
    typeSelectParams.add(
        new LiteralExpression(_typeConverter.convertToBackendType(chk.getType()), sourcePos));
    final ExpressionBase typeSelectExpression =
        new InvocationOnObjectExpression(
            new QualifiedName(SysLibNames.TYPE_SELECT), typeSelectParams, true, sourcePos);

    final List<ExpressionBase> collectParams = new ArrayList<ExpressionBase>();
    collectParams.add(typeSelectExpression);
    collectParams.add(
        new InitClosureExpression(
            Arrays.asList(SyntaxConstants.THIS),
            Arrays.asList(ObjectType.INSTANCE),
            onEachExpression,
            sourcePos));
    return new InvocationOnObjectExpression(
        new QualifiedName(SysLibNames.COLLECT), collectParams, true, sourcePos);
  }
  public NamedFunction createCheckFunction(BackendTypesystem ts, ExtensionFile extensionFile) {
    final OldExpressionConverter exprConv =
        new OldExpressionConverter(
            _emptyExecutionContext.cloneWithResource(extensionFile),
            _typeConverter,
            OldHelper.normalizeXtendResourceName(extensionFile.getFullyQualifiedName()));
    final List<String> paramNames = Arrays.asList(ISSUES_PARAM_NAME, ALL_OBJECTS_PARAM_NAME);
    final List<BackendType> paramTypes =
        Arrays.asList(ts.findType(Issues.class), CollectionType.INSTANCE);

    final List<ExpressionBase> allChecks = new ArrayList<ExpressionBase>();
    for (Check chk : extensionFile.getChecks()) {
      if (!exprConv.hasThis()) {
        ExecutionContext oldCtx = exprConv.getExecutionContext();
        exprConv.setExecutionContext(
            oldCtx.cloneWithVariable(
                new Variable(
                    ExecutionContext.IMPLICIT_VARIABLE,
                    oldCtx.getTypeForName(chk.getType().getValue()))));
        allChecks.add(convertCheck(chk, exprConv));
        exprConv.setExecutionContext(oldCtx);
      }
    }

    final ExpressionBase body =
        new SequenceExpression(allChecks, exprConv.getSourcePos(extensionFile));

    return new NamedFunction(
        ALL_CHECKS_FUNCTION_NAME,
        new SourceDefinedFunction(
            ALL_CHECKS_FUNCTION_NAME,
            paramNames,
            paramTypes,
            BooleanType.INSTANCE,
            body,
            false,
            null));
  }