locationFromElement method

Location? locationFromElement(
  1. Element? element, {
  2. int? offset,
  3. int? length,
})

Create a location based on an the given element.

Implementation

plugin.Location? locationFromElement(analyzer.Element? element,
    {int? offset, int? length}) {
  if (element == null || element.source == null) {
    return null;
  }
  offset ??= element.nameOffset;
  length ??= element.nameLength;
  if (element is analyzer.CompilationUnitElement ||
      (element is analyzer.LibraryElement && offset < 0)) {
    offset = 0;
    length = 0;
  }
  var unitElement = _getUnitElement(element);
  var range = analyzer.SourceRange(offset, length);
  return _locationForArgs(unitElement, range);
}