From c01fe77e57ca8becab4df67349151e3c9206b06c Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Wed, 25 Dec 2024 20:10:49 -0800 Subject: [PATCH] Elements. Changes for google3. Change-Id: Ia0215da239c3948ccd242e583b79df0085109597 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/402400 Reviewed-by: Samuel Rawlins Commit-Queue: Konstantin Shcheglov --- .../refactoring/legacy/refactoring.dart | 2 +- pkg/analyzer/lib/dart/element/element2.dart | 4 ++-- .../lib/dart/element/type_provider.dart | 3 +++ .../lib/src/dart/element/element.dart | 7 ++++++ .../lib/src/dart/element/type_provider.dart | 9 +++++-- .../lib/src/utilities/extensions/element.dart | 24 +++++++++++++++++++ 6 files changed, 44 insertions(+), 5 deletions(-) diff --git a/pkg/analysis_server/lib/src/services/refactoring/legacy/refactoring.dart b/pkg/analysis_server/lib/src/services/refactoring/legacy/refactoring.dart index 0ee171b888f0..87878058ff9b 100644 --- a/pkg/analysis_server/lib/src/services/refactoring/legacy/refactoring.dart +++ b/pkg/analysis_server/lib/src/services/refactoring/legacy/refactoring.dart @@ -513,7 +513,7 @@ abstract class RenameRefactoring implements Refactoring { return RenameTypeParameterRefactoringImpl( workspace, sessionHelper, - element.asElement2 as TypeParameterElement2, + element.asElement2, ); } if (enclosingElement is InterfaceElement) { diff --git a/pkg/analyzer/lib/dart/element/element2.dart b/pkg/analyzer/lib/dart/element/element2.dart index d56914ad6ad6..93c0fc86840a 100644 --- a/pkg/analyzer/lib/dart/element/element2.dart +++ b/pkg/analyzer/lib/dart/element/element2.dart @@ -1619,7 +1619,7 @@ abstract class LibraryElement2 implements Element2, Annotatable { /// An `export` directive within a library fragment. /// /// Clients may not extend, implement or mix-in this class. -abstract class LibraryExport { +abstract class LibraryExport implements Annotatable { /// The combinators that were specified as part of the `export` directive. /// /// The combinators are in the order in which they were specified. @@ -1718,7 +1718,7 @@ abstract class LibraryFragment implements Fragment, Annotatable { /// An `import` directive within a library fragment. /// /// Clients may not extend, implement or mix-in this class. -abstract class LibraryImport { +abstract class LibraryImport implements Annotatable { /// The combinators that were specified as part of the `import` directive. /// /// The combinators are in the order in which they were specified. diff --git a/pkg/analyzer/lib/dart/element/type_provider.dart b/pkg/analyzer/lib/dart/element/type_provider.dart index f3f7d95cad96..9020343a7adc 100644 --- a/pkg/analyzer/lib/dart/element/type_provider.dart +++ b/pkg/analyzer/lib/dart/element/type_provider.dart @@ -223,6 +223,9 @@ abstract class TypeProvider { /// Return `true` if [element] cannot be extended, implemented, or mixed in. bool isNonSubtypableClass(InterfaceElement element); + /// Return `true` if [element] cannot be extended, implemented, or mixed in. + bool isNonSubtypableClass2(InterfaceElement2 element); + /// Return 'true' if [id] is the name of a getter on the `Object` type. bool isObjectGetter(String id); diff --git a/pkg/analyzer/lib/src/dart/element/element.dart b/pkg/analyzer/lib/src/dart/element/element.dart index 5848c930fd34..509ada9aa377 100644 --- a/pkg/analyzer/lib/src/dart/element/element.dart +++ b/pkg/analyzer/lib/src/dart/element/element.dart @@ -3868,6 +3868,13 @@ abstract class ExecutableElementImpl2 extends FunctionTypedElementImpl2 @override ExecutableElement2 get baseElement => this; + @override + List get children2 => [ + ...super.children2, + ...typeParameters2, + ...formalParameters, + ]; + bool get invokesSuperSelf { var firstFragment = this.firstFragment as ExecutableElementImpl; return firstFragment.hasModifier(Modifier.INVOKES_SUPER_SELF); diff --git a/pkg/analyzer/lib/src/dart/element/type_provider.dart b/pkg/analyzer/lib/src/dart/element/type_provider.dart index e8b8af2988b1..d454664c971b 100644 --- a/pkg/analyzer/lib/src/dart/element/type_provider.dart +++ b/pkg/analyzer/lib/src/dart/element/type_provider.dart @@ -533,9 +533,14 @@ class TypeProviderImpl extends TypeProviderBase { @override bool isNonSubtypableClass(InterfaceElement element) { - var name = element.name; + return isNonSubtypableClass2(element.asElement2); + } + + @override + bool isNonSubtypableClass2(InterfaceElement2 element) { + var name = element.name3; if (_nonSubtypableClassNames.contains(name)) { - var libraryUriStr = element.library.source.uri.toString(); + var libraryUriStr = element.library2.uri.toString(); var ofLibrary = _nonSubtypableClassMap[libraryUriStr]; return ofLibrary != null && ofLibrary.contains(name); } diff --git a/pkg/analyzer/lib/src/utilities/extensions/element.dart b/pkg/analyzer/lib/src/utilities/extensions/element.dart index ac1c3ecd5140..c166a83a9779 100644 --- a/pkg/analyzer/lib/src/utilities/extensions/element.dart +++ b/pkg/analyzer/lib/src/utilities/extensions/element.dart @@ -46,6 +46,9 @@ extension CompilationUnitElementExtension on CompilationUnitElement { extension ConstructorElement2Extension on ConstructorElement2 { ConstructorElement get asElement { + if (this case ConstructorMember member) { + return member; + } return baseElement.firstFragment as ConstructorElement; } } @@ -278,6 +281,9 @@ extension EnumElementExtension on EnumElement { extension ExecutableElement2Extension on ExecutableElement2 { ExecutableElement get asElement { + if (this case ExecutableMember member) { + return member; + } return firstFragment as ExecutableElement; } } @@ -324,6 +330,9 @@ extension ExtensionTypeElement2Extension on ExtensionTypeElement2 { extension FieldElement2Extension on FieldElement2 { FieldElement get asElement { + if (this case FieldMember member) { + return member; + } return firstFragment as FieldElement; } } @@ -340,6 +349,9 @@ extension FieldElementExtension on FieldElement { extension FormalParameterExtension on FormalParameterElement { ParameterElement get asElement { + if (this case ParameterMember member) { + return member; + } return firstFragment as ParameterElement; } @@ -437,6 +449,9 @@ extension ListOfTypeParameterElementExtension on List { extension MethodElement2Extension on MethodElement2 { MethodElement get asElement { + if (this case MethodMember member) { + return member; + } return baseElement.firstFragment as MethodElement; } } @@ -491,6 +506,9 @@ extension PrefixElementExtension on PrefixElement { extension PropertyAccessorElement2Extension on PropertyAccessorElement2 { PropertyAccessorElement get asElement { + if (this case PropertyAccessorMember member) { + return member; + } return firstFragment as PropertyAccessorElement; } } @@ -540,3 +558,9 @@ extension TypeParameterElement2Extension on TypeParameterElement2 { return firstFragment as TypeParameterElement; } } + +extension TypeParameterElementExtension on TypeParameterElement { + TypeParameterElement2 get asElement2 { + return (this as TypeParameterElementImpl).element; + } +}