isInsertMethod function

bool isInsertMethod(
  1. MethodElement method
)

Implementation

bool isInsertMethod(MethodElement method) {
  var requiredParameters =
      method.parameters.where((element) => element.isRequiredPositional);
  var annotation = getAnnotation(method, Insert);

  if (annotation != null && requiredParameters.length == 0) {
    throw InvalidGenerationSourceError(
      'Generator cannot create the target method `${method.name}` because it doesn\'t have required parameter.',
      todo:
          'Remove the [Insert] annotation from method `${method.name}` or define your parameter.',
    );
  } else if (annotation != null && requiredParameters.length > 1) {
    throw InvalidGenerationSourceError(
      'Generator cannot create the target method `${method.name}` because it have multiple required parameters.',
      todo:
          'Remove the [Insert] annotation from the method `${method.name}` or remove other parameters.',
    );
  }
  return annotation != null;
}