blob: ae706b3e2bc947751a8efc2c6e023ed4243e8dc1 [file] [log] [blame]
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/dart/element/element2.dart';
import 'package:analyzer/dart/element/type.dart';
extension DartTypeExtension on DartType {
/// The static element associataed with this type, where documentable, and
/// `null` otherwise.
///
/// For example, the documentable element of [DynamicType] is `null`, as there
/// is no documentation for `dynamic` which we can link to.
TypeDefiningElement2? get documentableElement2 {
final self = this;
return switch (self) {
InterfaceType() => self.element3,
NeverType() => self.element3 as TypeDefiningElement2,
TypeParameterType() => self.element3,
_ => null
};
}
}