Elements. Remove V1 InterfaceElement.
Change-Id: I1316f25a9f290fbc2d3a13507b675ea876a159fd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/423202
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analyzer/api.txt b/pkg/analyzer/api.txt
index 70fe020..2f84335 100644
--- a/pkg/analyzer/api.txt
+++ b/pkg/analyzer/api.txt
@@ -3206,19 +3206,6 @@
isAugmentation (getter: bool)
methods (getter: List<MethodElement>)
thisType (getter: DartType)
- InterfaceElement (class extends Object implements InstanceElement, deprecated):
- new (constructor: InterfaceElement Function())
- allSupertypes (getter: List<InterfaceType>)
- interfaces (getter: List<InterfaceType>)
- mixins (getter: List<InterfaceType>, deprecated)
- name (getter: String)
- supertype (getter: InterfaceType?, deprecated)
- thisType (getter: InterfaceType)
- getField (method: FieldElement? Function(String))
- getGetter (method: PropertyAccessorElement? Function(String))
- getMethod (method: MethodElement? Function(String))
- getSetter (method: PropertyAccessorElement? Function(String))
- instantiate (method: InterfaceType Function({required NullabilitySuffix nullabilitySuffix, required List<DartType> typeArguments}))
JoinPatternVariableElement (class extends Object implements PatternVariableElement, deprecated):
new (constructor: JoinPatternVariableElement Function())
isConsistent (getter: bool)
@@ -4192,7 +4179,6 @@
nullabilitySuffix (getter: NullabilitySuffix)
accept (method: R Function<R>(TypeVisitor<R>))
acceptWithArgument (method: R Function<R, A>(TypeVisitorWithArgument<R, A>, A))
- asInstanceOf (method: InterfaceType? Function(InterfaceElement), deprecated)
asInstanceOf2 (method: InterfaceType? Function(InterfaceElement2), experimental)
getDisplayString (method: String Function({bool withNullability}))
isStructurallyEqualTo (method: bool Function(DartType), deprecated)
@@ -4336,7 +4322,6 @@
new (constructor: TypeSystem Function())
flatten (method: DartType Function(DartType))
greatestLowerBound (method: DartType Function(DartType, DartType))
- instantiateInterfaceToBounds (method: InterfaceType Function({required InterfaceElement element, required NullabilitySuffix nullabilitySuffix}), deprecated)
instantiateInterfaceToBounds2 (method: InterfaceType Function({required InterfaceElement2 element, required NullabilitySuffix nullabilitySuffix}), experimental)
instantiateTypeAliasToBounds (method: DartType Function({required TypeAliasElement element, required NullabilitySuffix nullabilitySuffix}), deprecated)
instantiateTypeAliasToBounds2 (method: DartType Function({required TypeAliasElement2 element, required NullabilitySuffix nullabilitySuffix}), experimental)
diff --git a/pkg/analyzer/lib/dart/element/element.dart b/pkg/analyzer/lib/dart/element/element.dart
index 60dfb48..5123957 100644
--- a/pkg/analyzer/lib/dart/element/element.dart
+++ b/pkg/analyzer/lib/dart/element/element.dart
@@ -1030,92 +1030,6 @@
DartType get thisType;
}
-/// An element that defines an [InterfaceType].
-///
-/// Clients may not extend, implement or mix-in this class.
-@Deprecated('Use InterfaceElement2 instead')
-abstract class InterfaceElement implements InstanceElement {
- /// All the supertypes defined for this element and its supertypes.
- ///
- /// This includes superclasses, mixins, interfaces, and superclass constraints.
- List<InterfaceType> get allSupertypes;
-
- /// The interfaces that are implemented by this class.
- ///
- /// <b>Note:</b> Because the element model represents the state of the code,
- /// it is possible for it to be semantically invalid. In particular, it is not
- /// safe to assume that the inheritance structure of a class does not contain
- /// a cycle. Clients that traverse the inheritance structure must explicitly
- /// guard against infinite loops.
- List<InterfaceType> get interfaces;
-
- /// The mixins that are applied to the class being extended in order to
- /// derive the superclass of this class.
- ///
- /// [ClassElement] and [EnumElement] can have mixins.
- ///
- /// [MixinElement] cannot have mixins, so the empty list is returned.
- ///
- /// <b>Note:</b> Because the element model represents the state of the code,
- /// it is possible for it to be semantically invalid. In particular, it is not
- /// safe to assume that the inheritance structure of a class does not contain
- /// a cycle. Clients that traverse the inheritance structure must explicitly
- /// guard against infinite loops.
- @Deprecated(elementModelDeprecationMsg)
- List<InterfaceType> get mixins;
-
- @override
- String get name;
-
- /// The superclass of this element.
- ///
- /// For [ClassElement] returns `null` only if this class is `Object`. If the
- /// superclass is not explicitly specified, or the superclass cannot be
- /// resolved, then the implicit superclass `Object` is returned.
- ///
- /// For [EnumElement] returns `Enum` from `dart:core`.
- ///
- /// For [MixinElement] always returns `null`.
- ///
- /// <b>Note:</b> Because the element model represents the state of the code,
- /// it is possible for it to be semantically invalid. In particular, it is not
- /// safe to assume that the inheritance structure of a class does not contain
- /// a cycle. Clients that traverse the inheritance structure must explicitly
- /// guard against infinite loops.
- @Deprecated(elementModelDeprecationMsg)
- InterfaceType? get supertype;
-
- @override
- InterfaceType get thisType;
-
- /// The field (synthetic or explicit) defined directly in this class or
- /// augmentation that has the given [name].
- // TODO(scheglov): Deprecate and remove it.
- FieldElement? getField(String name);
-
- /// The getter (synthetic or explicit) defined directly in this class or
- /// augmentation that has the given [name].
- // TODO(scheglov): Deprecate and remove it.
- PropertyAccessorElement? getGetter(String name);
-
- /// The method defined directly in this class or augmentation that has the
- /// given [name].
- // TODO(scheglov): Deprecate and remove it.
- MethodElement? getMethod(String name);
-
- /// The setter (synthetic or explicit) defined directly in this class or
- /// augmentation that has the given [name].
- // TODO(scheglov): Deprecate and remove it.
- PropertyAccessorElement? getSetter(String name);
-
- /// Create the [InterfaceType] for this element with the given
- /// [typeArguments] and [nullabilitySuffix].
- InterfaceType instantiate({
- required List<DartType> typeArguments,
- required NullabilitySuffix nullabilitySuffix,
- });
-}
-
/// A pattern variable that is a join of other pattern variables, created
/// for a logical-or patterns, or shared `case` bodies in `switch` statements.
///
diff --git a/pkg/analyzer/lib/dart/element/type.dart b/pkg/analyzer/lib/dart/element/type.dart
index 5810338..b3fe3d9 100644
--- a/pkg/analyzer/lib/dart/element/type.dart
+++ b/pkg/analyzer/lib/dart/element/type.dart
@@ -165,24 +165,6 @@
///
/// For a [TypeParameterType] with a bound (declared or promoted), returns
/// the interface implemented by the bound.
- @Deprecated('Use asInstanceOf2() instead')
- InterfaceType? asInstanceOf(InterfaceElement element);
-
- /// Return the canonical interface that this type implements for [element],
- /// or `null` if such an interface does not exist.
- ///
- /// For example, given the following definitions
- /// ```
- /// class A<E> {}
- /// class B<E> implements A<E> {}
- /// class C implements A<String> {}
- /// ```
- /// Asking the type `B<int>` for the type associated with `A` will return the
- /// type `A<int>`. Asking the type `C` for the type associated with `A` will
- /// return the type `A<String>`.
- ///
- /// For a [TypeParameterType] with a bound (declared or promoted), returns
- /// the interface implemented by the bound.
@experimental
InterfaceType? asInstanceOf2(InterfaceElement2 element);
diff --git a/pkg/analyzer/lib/dart/element/type_system.dart b/pkg/analyzer/lib/dart/element/type_system.dart
index f911657..9133b10 100644
--- a/pkg/analyzer/lib/dart/element/type_system.dart
+++ b/pkg/analyzer/lib/dart/element/type_system.dart
@@ -43,13 +43,6 @@
DartType greatestLowerBound(DartType T1, DartType T2);
/// Instantiate the given [element] with default type arguments.
- @Deprecated('Use instantiateInterfaceToBounds2() instead')
- InterfaceType instantiateInterfaceToBounds({
- required InterfaceElement element,
- required NullabilitySuffix nullabilitySuffix,
- });
-
- /// Instantiate the given [element] with default type arguments.
@experimental
InterfaceType instantiateInterfaceToBounds2({
required InterfaceElement2 element,
diff --git a/pkg/analyzer/lib/src/dart/element/element.dart b/pkg/analyzer/lib/src/dart/element/element.dart
index 8c313e4..10d9ca5 100644
--- a/pkg/analyzer/lib/src/dart/element/element.dart
+++ b/pkg/analyzer/lib/src/dart/element/element.dart
@@ -5835,10 +5835,7 @@
}
abstract class InterfaceElementImpl extends InstanceElementImpl
- implements
- // ignore:deprecated_member_use_from_same_package,analyzer_use_new_elements
- InterfaceElement,
- InterfaceFragment {
+ implements InterfaceFragment {
/// A list containing all of the mixins that are applied to the class being
/// extended in order to derive the superclass of this class.
List<InterfaceTypeImpl> _mixins = const [];
@@ -5852,9 +5849,6 @@
InterfaceTypeImpl? _supertype;
- /// The cached result of [allSupertypes].
- List<InterfaceType>? _allSupertypes;
-
/// A flag indicating whether the types associated with the instance members
/// of this class have been inferred.
bool hasBeenInferred = false;
@@ -5865,12 +5859,6 @@
/// given [offset] in the file that contains the declaration of this element.
InterfaceElementImpl(super.name, super.offset);
- @override
- List<InterfaceType> get allSupertypes {
- return _allSupertypes ??=
- library.session.classHierarchy.implementedInterfaces(element);
- }
-
@Deprecated('Use Element2 instead')
@override
List<Element> get children => [
@@ -6004,39 +5992,6 @@
return element.thisType;
}
- @Deprecated(elementModelDeprecationMsg)
- @override
- FieldElement? getField(String name) {
- return fields.firstWhereOrNull((fieldElement) => name == fieldElement.name);
- }
-
- @override
- PropertyAccessorElementOrMember? getGetter(String getterName) {
- return accessors.firstWhereOrNull(
- (accessor) => accessor.isGetter && accessor.name == getterName);
- }
-
- @override
- MethodElementOrMember? getMethod(String methodName) {
- return methods.firstWhereOrNull((method) => method.name == methodName);
- }
-
- @override
- PropertyAccessorElementOrMember? getSetter(String setterName) {
- return getSetterFromAccessors(setterName, accessors);
- }
-
- @override
- InterfaceTypeImpl instantiate({
- required List<DartType> typeArguments,
- required NullabilitySuffix nullabilitySuffix,
- }) {
- return element.instantiate(
- typeArguments: typeArguments,
- nullabilitySuffix: nullabilitySuffix,
- );
- }
-
InterfaceTypeImpl instantiateImpl({
required List<TypeImpl> typeArguments,
required NullabilitySuffix nullabilitySuffix,
@@ -6047,10 +6002,6 @@
);
}
- void resetCachedAllSupertypes() {
- _allSupertypes = null;
- }
-
/// Builds constructors for this mixin application.
void _buildMixinAppConstructors() {}
@@ -6078,8 +6029,14 @@
InterfaceTypeImpl? _thisType;
+ /// The cached result of [allSupertypes].
+ List<InterfaceType>? _allSupertypes;
+
@override
- List<InterfaceType> get allSupertypes => firstFragment.allSupertypes;
+ List<InterfaceType> get allSupertypes {
+ return _allSupertypes ??=
+ library2.session.classHierarchy.implementedInterfaces(this);
+ }
@override
List<Element2> get children2 {
@@ -6351,7 +6308,7 @@
}
void resetCachedAllSupertypes() {
- firstFragment._allSupertypes = null;
+ _allSupertypes = null;
}
}
diff --git a/pkg/analyzer/lib/src/dart/element/type.dart b/pkg/analyzer/lib/src/dart/element/type.dart
index e75ae6b..00fe976 100644
--- a/pkg/analyzer/lib/src/dart/element/type.dart
+++ b/pkg/analyzer/lib/src/dart/element/type.dart
@@ -1558,10 +1558,6 @@
/// Append a textual representation of this type to the given [builder].
void appendTo(ElementDisplayStringBuilder builder);
- @Deprecated('Use asInstanceOf2() instead')
- @override
- InterfaceTypeImpl? asInstanceOf(InterfaceElement targetElement) => null;
-
@override
InterfaceTypeImpl? asInstanceOf2(InterfaceElement2 targetElement) => null;
@@ -1728,12 +1724,6 @@
builder.writeTypeParameterType(this);
}
- @Deprecated('Use asInstanceOf2() instead')
- @override
- InterfaceTypeImpl? asInstanceOf(InterfaceElement targetElement) {
- return bound.asInstanceOf(targetElement);
- }
-
@override
InterfaceTypeImpl? asInstanceOf2(InterfaceElement2 targetElement) {
return bound.asInstanceOf2(targetElement);
diff --git a/pkg/analyzer/lib/src/dart/element/type_system.dart b/pkg/analyzer/lib/src/dart/element/type_system.dart
index ac782a6..6e3456c 100644
--- a/pkg/analyzer/lib/src/dart/element/type_system.dart
+++ b/pkg/analyzer/lib/src/dart/element/type_system.dart
@@ -669,18 +669,6 @@
return inferrer.chooseFinalTypes();
}
- @Deprecated('Use instantiateInterfaceToBounds2() instead')
- @override
- InterfaceTypeImpl instantiateInterfaceToBounds({
- required covariant InterfaceElementImpl element,
- required NullabilitySuffix nullabilitySuffix,
- }) {
- return instantiateInterfaceToBounds2(
- element: element.asElement2,
- nullabilitySuffix: nullabilitySuffix,
- );
- }
-
@override
InterfaceTypeImpl instantiateInterfaceToBounds2({
required covariant InterfaceElementImpl2 element,
diff --git a/pkg/analyzer/lib/src/error/inheritance_override.dart b/pkg/analyzer/lib/src/error/inheritance_override.dart
index f0acc70..48a9bd5 100644
--- a/pkg/analyzer/lib/src/error/inheritance_override.dart
+++ b/pkg/analyzer/lib/src/error/inheritance_override.dart
@@ -166,7 +166,7 @@
final List<InterfaceType> directSuperInterfaces = [];
late final bool implementsDartCoreEnum =
- classElement.allSupertypes.any((e) => e.isDartCoreEnum);
+ classElement.element.allSupertypes.any((e) => e.isDartCoreEnum);
_ClassVerifier({
required this.typeSystem,
diff --git a/pkg/analyzer/lib/src/generated/error_verifier.dart b/pkg/analyzer/lib/src/generated/error_verifier.dart
index 12170ea..f483e68 100644
--- a/pkg/analyzer/lib/src/generated/error_verifier.dart
+++ b/pkg/analyzer/lib/src/generated/error_verifier.dart
@@ -2252,12 +2252,12 @@
}
void _checkForConflictingEnumTypeVariableErrorCodes(
- EnumElementImpl element,
+ EnumElementImpl fragment,
) {
- for (var typeParameter in element.typeParameters) {
+ for (var typeParameter in fragment.typeParameters) {
var name = typeParameter.name;
// name is same as the name of the enclosing enum
- if (element.name == name) {
+ if (fragment.name == name) {
errorReporter.atElement2(
typeParameter.asElement2,
CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_ENUM,
@@ -2265,9 +2265,10 @@
);
}
// check members
- if (element.getMethod(name) != null ||
- element.getGetter(name) != null ||
- element.getSetter(name) != null) {
+ var element = fragment.element;
+ if (element.getMethod2(name) != null ||
+ element.getGetter2(name) != null ||
+ element.getSetter2(name) != null) {
errorReporter.atElement2(
typeParameter.asElement2,
CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER_ENUM,