createParamArg function

Expression createParamArg(
  1. ServerParam param, {
  2. Expression? defaultExpression,
  3. Map<String, Expression> customParams = const {},
})

Implementation

Expression createParamArg(
  ServerParam param, {
  Expression? defaultExpression,
  Map<String, Expression> customParams = const {},
}) {
  if (impliedArguments[param.type] case final expression?) {
    return expression;
  }

  if (customParams[param.type] case final expression?) {
    return expression;
  }

  if (defaultExpression != null) {
    return defaultExpression;
  }

  final annotation = param.annotations;
  if (!annotation.hasAnnotation && !param.hasDefaultValue) {
    throw ArgumentError(
      'No annotation or default value for param ${param.name}',
    );
  }

  if (param.defaultValue case final value? when !annotation.hasAnnotation) {
    return CodeExpression(Code(value));
  }

  if (annotation.dep) {
    return createGetFromDi();
  }

  if (annotation.data) {
    return createArgFromData(param);
  }

  if (annotation.body case final bodyAnnotation?) {
    return createArgFromBody(bodyAnnotation, param);
  }

  if (annotation.param case final paramAnnotation?) {
    return createArgFromParam(paramAnnotation, param);
  }

  if (annotation.query case final queryAnnotation?) {
    return createArgFromQuery(queryAnnotation, param);
  }

  if (annotation.header case final headerAnnotation?) {
    return createArgFromHeader(headerAnnotation, param);
  }

  if (annotation.bind case final bind?) {
    return createArgFromBind(bind, param);
  }

  if (annotation.binds case final binds?) {
    return createArgFromBinds(binds, param);
  }

  throw ArgumentError('Unknown annotation for param ${param.name}');
}