convertDiagnosticMessage method

DiagnosticMessage convertDiagnosticMessage(
  1. DiagnosticMessage message, {
  2. LineInfo? lineInfo,
})

Convert the diagnostic message from the 'analyzer' package to an analysis error defined by the plugin API. If a lineInfo is provided then the error's location will have a start line and start column.

Implementation

plugin.DiagnosticMessage convertDiagnosticMessage(
    analyzer.DiagnosticMessage message,
    {analyzer.LineInfo? lineInfo}) {
  var file = message.filePath;
  var offset = message.offset;
  var length = message.length;
  var startLine = -1;
  var startColumn = -1;
  var endLine = -1;
  var endColumn = -1;
  if (lineInfo != null) {
    var lineLocation = lineInfo.getLocation(offset);
    startLine = lineLocation.lineNumber;
    startColumn = lineLocation.columnNumber;
    var endLocation = lineInfo.getLocation(offset + length);
    endLine = endLocation.lineNumber;
    endColumn = endLocation.columnNumber;
  }
  return plugin.DiagnosticMessage(
      message.messageText(includeUrl: true),
      plugin.Location(file, offset, length, startLine, startColumn,
          endLine: endLine, endColumn: endColumn));
}