From 5abb1b894a0b20eca4eae9e06960608f38b09e2c Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Tue, 30 Sep 2025 14:47:57 -0700 Subject: [PATCH] Stop using TypeDefiningElement. --- lib/src/element_type.dart | 8 ++++---- lib/src/model/model_element.dart | 2 +- lib/src/type_utils.dart | 6 +++--- tool/mustachio/codegen_aot_compiler.dart | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/src/element_type.dart b/lib/src/element_type.dart index 810ca3d652..2e58f96a13 100644 --- a/lib/src/element_type.dart +++ b/lib/src/element_type.dart @@ -34,7 +34,7 @@ abstract class ElementType with CommentReferable, Nameable { factory ElementType.for_( DartType type, Library library, PackageGraph packageGraph) { runtimeStats.incrementAccumulator('elementTypeInstantiation'); - var fElement = type.documentableElement2; + var fElement = type.documentableElement; if (fElement == null || fElement.kind == ElementKind.DYNAMIC || fElement.kind == ElementKind.NEVER) { @@ -102,9 +102,9 @@ class UndefinedElementType extends ElementType { // We can not simply throw here because not all SDK libraries resolve // all types. if (type is InvalidType) return 'dynamic'; - assert(const {'Never'}.contains(type.documentableElement2?.name), + assert(const {'Never'}.contains(type.documentableElement?.name), 'Unrecognized type for UndefinedElementType: $type'); - return type.documentableElement2!.name!; + return type.documentableElement!.name!; } @override @@ -288,7 +288,7 @@ abstract class DefinedElementType extends ElementType { } @override - String get name => type.documentableElement2!.name!; + String get name => type.documentableElement!.name!; @override String get fullyQualifiedName => modelElement.fullyQualifiedName; diff --git a/lib/src/model/model_element.dart b/lib/src/model/model_element.dart index 4a93904df6..653ad8cd56 100644 --- a/lib/src/model/model_element.dart +++ b/lib/src/model/model_element.dart @@ -295,7 +295,7 @@ abstract class ModelElement TypeAliasElement(aliasedType: FunctionType()) => FunctionTypedef(e, library, packageGraph), TypeAliasElement() - when e.aliasedType.documentableElement2 is InterfaceElement => + when e.aliasedType.documentableElement is InterfaceElement => ClassTypedef(e, library, packageGraph), TypeAliasElement() => GeneralizedTypedef(e, library, packageGraph), MethodElement(isOperator: true) when enclosingContainer == null => diff --git a/lib/src/type_utils.dart b/lib/src/type_utils.dart index 3b3d158cb2..e67adfff8e 100644 --- a/lib/src/type_utils.dart +++ b/lib/src/type_utils.dart @@ -6,16 +6,16 @@ import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; extension DartTypeExtension on DartType { - /// The static element associataed with this type, where documentable, and + /// The static element associated 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. - TypeDefiningElement? get documentableElement2 { + Element? get documentableElement { final self = this; return switch (self) { InterfaceType() => self.element, - NeverType() => self.element as TypeDefiningElement, + NeverType() => self.element, TypeParameterType() => self.element, _ => null }; diff --git a/tool/mustachio/codegen_aot_compiler.dart b/tool/mustachio/codegen_aot_compiler.dart index 4a80d81cf1..65706b1dae 100644 --- a/tool/mustachio/codegen_aot_compiler.dart +++ b/tool/mustachio/codegen_aot_compiler.dart @@ -935,7 +935,7 @@ extension on StringBuffer { if (bound == null) { write(typeParameter.name); } else { - var boundElement = bound.documentableElement2!; + var boundElement = bound.documentableElement!; referencedElements.add(boundElement); write('${typeParameter.name} extends ${boundElement.name!}'); }