Skip to content

Commit

Permalink
Elements. Changes for google3.
Browse files Browse the repository at this point in the history
Change-Id: Ia0215da239c3948ccd242e583b79df0085109597
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/402400
Reviewed-by: Samuel Rawlins <[email protected]>
Commit-Queue: Konstantin Shcheglov <[email protected]>
  • Loading branch information
scheglov authored and Commit Queue committed Dec 26, 2024
1 parent 61f1d69 commit c01fe77
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ abstract class RenameRefactoring implements Refactoring {
return RenameTypeParameterRefactoringImpl(
workspace,
sessionHelper,
element.asElement2 as TypeParameterElement2,
element.asElement2,
);
}
if (enclosingElement is InterfaceElement) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/analyzer/lib/dart/element/element2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions pkg/analyzer/lib/dart/element/type_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
7 changes: 7 additions & 0 deletions pkg/analyzer/lib/src/dart/element/element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3868,6 +3868,13 @@ abstract class ExecutableElementImpl2 extends FunctionTypedElementImpl2
@override
ExecutableElement2 get baseElement => this;

@override
List<Element2> get children2 => [
...super.children2,
...typeParameters2,
...formalParameters,
];

bool get invokesSuperSelf {
var firstFragment = this.firstFragment as ExecutableElementImpl;
return firstFragment.hasModifier(Modifier.INVOKES_SUPER_SELF);
Expand Down
9 changes: 7 additions & 2 deletions pkg/analyzer/lib/src/dart/element/type_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
24 changes: 24 additions & 0 deletions pkg/analyzer/lib/src/utilities/extensions/element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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;
}

Expand Down Expand Up @@ -437,6 +449,9 @@ extension ListOfTypeParameterElementExtension on List<TypeParameterElement> {

extension MethodElement2Extension on MethodElement2 {
MethodElement get asElement {
if (this case MethodMember member) {
return member;
}
return baseElement.firstFragment as MethodElement;
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -540,3 +558,9 @@ extension TypeParameterElement2Extension on TypeParameterElement2 {
return firstFragment as TypeParameterElement;
}
}

extension TypeParameterElementExtension on TypeParameterElement {
TypeParameterElement2 get asElement2 {
return (this as TypeParameterElementImpl).element;
}
}

0 comments on commit c01fe77

Please sign in to comment.