atOffset method

void atOffset({
  1. required int offset,
  2. required int length,
  3. required ErrorCode errorCode,
  4. List<Object>? arguments,
  5. List<DiagnosticMessage>? contextMessages,
  6. Object? data,
})

Report an error with the given errorCode and arguments. The location of the error is specified by the given offset and length.

Implementation

void atOffset({
  required int offset,
  required int length,
  required ErrorCode errorCode,
  List<Object>? arguments,
  List<DiagnosticMessage>? contextMessages,
  Object? data,
}) {
  if (lockLevel != 0) {
    return;
  }

  if (arguments != null) {
    var invalid = arguments
        .whereNotType<String>()
        .whereNotType<DartType>()
        .whereNotType<Element2>()
        .whereNotType<int>()
        .whereNotType<Uri>();
    if (invalid.isNotEmpty) {
      throw ArgumentError('Tried to format an error using '
          '${invalid.map((e) => e.runtimeType).join(', ')}');
    }
  }

  contextMessages ??= [];
  contextMessages.addAll(_convertTypeNames(arguments));
  _errorListener.onError(
    AnalysisError.tmp(
      source: _source,
      offset: offset,
      length: length,
      errorCode: errorCode,
      arguments: arguments ?? const [],
      contextMessages: contextMessages,
      data: data,
    ),
  );
}