Diagnostic.tmp constructor

Diagnostic.tmp({
  1. required Source source,
  2. required int offset,
  3. required int length,
  4. required DiagnosticCode diagnosticCode,
  5. List<Object?> arguments = const [],
  6. List<DiagnosticMessage> contextMessages = const [],
})

Initialize a newly created diagnostic.

The diagnostic is associated with the given source and is located at the given offset with the given length. The diagnostic will have the given diagnosticCode and the list of arguments will be used to complete the message and correction. If any contextMessages are provided, they will be recorded with the diagnostic.

Implementation

factory Diagnostic.tmp({
  required Source source,
  required int offset,
  required int length,
  required DiagnosticCode diagnosticCode,
  List<Object?> arguments = const [],
  List<DiagnosticMessage> contextMessages = const [],
}) {
  assert(
    arguments.length == diagnosticCode.numParameters,
    'Message $diagnosticCode requires ${diagnosticCode.numParameters} '
    'argument${diagnosticCode.numParameters == 1 ? '' : 's'}, but '
    '${arguments.length} '
    'argument${arguments.length == 1 ? ' was' : 's were'} '
    'provided',
  );
  String message = formatList(diagnosticCode.problemMessage, arguments);
  String? correctionTemplate = diagnosticCode.correctionMessage;
  String? correctionMessage;
  if (correctionTemplate != null) {
    correctionMessage = formatList(correctionTemplate, arguments);
  }

  return new Diagnostic.forValues(
    source: source,
    offset: offset,
    length: length,
    diagnosticCode: diagnosticCode,
    message: message,
    correctionMessage: correctionMessage,
    contextMessages: contextMessages,
  );
}