Elements. Deprecate ClassElement.

Change-Id: I0bf4a73bacc4917d4f61c91bcdceba41a9c18ec9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/418903
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Konstantin Shcheglov
2025-03-31 11:09:38 -07:00
committed by Commit Queue
parent a0d4786adc
commit 0fda5de36a
5 changed files with 43 additions and 24 deletions
+5 -5
View File
@@ -3015,7 +3015,7 @@ package:analyzer/dart/element/element.dart:
elementModelDeprecationMsg (static getter: String)
BindPatternVariableElement (class extends Object implements PatternVariableElement, deprecated):
new (constructor: BindPatternVariableElement Function())
ClassElement (class extends Object implements InterfaceElement):
ClassElement (class extends Object implements InterfaceElement, deprecated):
new (constructor: ClassElement Function())
hasNonFinalField (getter: bool)
isAbstract (getter: bool)
@@ -3033,7 +3033,7 @@ package:analyzer/dart/element/element.dart:
isExtendableIn (method: bool Function(LibraryElement))
isImplementableIn (method: bool Function(LibraryElement))
isMixableIn (method: bool Function(LibraryElement))
ClassMemberElement (class extends Object implements Element):
ClassMemberElement (class extends Object implements Element, deprecated):
new (constructor: ClassMemberElement Function())
enclosingElement3 (getter: Element)
isStatic (getter: bool)
@@ -3342,9 +3342,9 @@ package:analyzer/dart/element/element.dart:
allSupertypes (getter: List<InterfaceType>)
constructors (getter: List<ConstructorElement>, deprecated)
interfaces (getter: List<InterfaceType>)
mixins (getter: List<InterfaceType>)
mixins (getter: List<InterfaceType>, deprecated)
name (getter: String)
supertype (getter: InterfaceType?)
supertype (getter: InterfaceType?, deprecated)
thisType (getter: InterfaceType)
unnamedConstructor (getter: ConstructorElement?, deprecated)
getField (method: FieldElement? Function(String))
@@ -3392,7 +3392,7 @@ package:analyzer/dart/element/element.dart:
typeProvider (getter: TypeProvider)
typeSystem (getter: TypeSystem)
units (getter: List<CompilationUnitElement>, deprecated)
getClass (method: ClassElement? Function(String))
getClass (method: ClassElement? Function(String), deprecated)
LibraryExportElement (class extends Object implements _ExistingElement):
new (constructor: LibraryExportElement Function())
combinators (getter: List<NamespaceCombinator>)
+20 -2
View File
@@ -78,6 +78,7 @@ abstract class BindPatternVariableElement implements PatternVariableElement {}
/// a class body), a mixin declaration, or an enum declaration.
///
/// Clients may not extend, implement or mix-in this class.
@Deprecated('Use ClassElement2 instead')
abstract class ClassElement implements InterfaceElement {
/// Whether the class or its superclass declares a non-final instance field.
bool get hasNonFinalField;
@@ -170,6 +171,13 @@ abstract class ClassElement implements InterfaceElement {
/// An element that is contained within a [ClassElement].
///
/// Clients may not extend, implement or mix-in this class.
@Deprecated('''
There is no common interface for class members in the new analyzer element
model. If you are using this class in an `is` test or a pattern match, replace
it with checks for the specific element types you are interested in (e.g.,
`ConstructorElement2`, `MethodElement2`, etc.). If you are using this class as
a type annotation for a variable that could hold any kind of class member, use
`Element2` instead.''')
abstract class ClassMemberElement implements Element {
// TODO(brianwilkerson): Either remove this class or rename it to something
// more correct.
@@ -1196,7 +1204,10 @@ abstract class ExtensionTypeElement implements InterfaceElement {
///
/// Clients may not extend, implement or mix-in this class.
abstract class FieldElement
implements ClassMemberElement, PropertyInducingElement {
implements
// ignore:deprecated_member_use_from_same_package
ClassMemberElement,
PropertyInducingElement {
@override
FieldElement get declaration;
@@ -1369,6 +1380,7 @@ abstract class InterfaceElement implements InstanceElement {
/// 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
@@ -1389,6 +1401,7 @@ abstract class InterfaceElement implements InstanceElement {
/// 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
@@ -1713,6 +1726,7 @@ abstract class LibraryElement implements _ExistingElement {
/// The class defined in this library that has the given [name], or
/// `null` if this library does not define a class with the given name.
@Deprecated(elementModelDeprecationMsg)
ClassElement? getClass(String name);
}
@@ -1806,7 +1820,11 @@ abstract class LocalVariableElement implements PromotableElement {
/// An element that represents a method defined within a class.
///
/// Clients may not extend, implement or mix-in this class.
abstract class MethodElement implements ClassMemberElement, ExecutableElement {
abstract class MethodElement
implements
// ignore:deprecated_member_use_from_same_package
ClassMemberElement,
ExecutableElement {
@override
MethodElement get declaration;
}
@@ -140,7 +140,10 @@ class BindPatternVariableElementImpl2 extends PatternVariableElementImpl2
/// An [InterfaceElementImpl] which is a class.
class ClassElementImpl extends ClassOrMixinElementImpl
implements ClassElement, ClassFragment {
implements
// ignore:deprecated_member_use_from_same_package
ClassElement,
ClassFragment {
late ClassElementImpl2 augmentedInternal;
/// Initialize a newly created class element to have the given [name] at the
@@ -221,7 +224,7 @@ class ClassElementImpl extends ClassOrMixinElementImpl
bool get hasNoSuchMethod {
MethodElement? method = lookUpConcreteMethod(
FunctionElement.NO_SUCH_METHOD_METHOD_NAME, library);
var definingClass = method?.enclosingElement3 as ClassElement?;
var definingClass = method?.enclosingElement3 as ClassElementImpl?;
return definingClass != null && !definingClass.isDartCoreObject;
}
@@ -6161,6 +6164,7 @@ abstract class InterfaceElementImpl extends InstanceElementImpl
getter.enclosingElement3 != this);
}
@Deprecated(elementModelDeprecationMsg)
ExecutableElement? lookUpInheritedConcreteMember(
String name, LibraryElement library) {
if (name.endsWith('=')) {
@@ -6181,6 +6185,7 @@ abstract class InterfaceElementImpl extends InstanceElementImpl
method.enclosingElement3 != this);
}
@Deprecated(elementModelDeprecationMsg)
@override
PropertyAccessorElement? lookUpInheritedConcreteSetter(
String setterName, LibraryElement library) {
@@ -6242,6 +6247,7 @@ abstract class InterfaceElementImpl extends InstanceElementImpl
/// This method should be used only for error recovery during analysis,
/// when instance access to a static class member, defined in this class,
/// or a superclass.
@Deprecated(elementModelDeprecationMsg)
PropertyAccessorElement? lookupStaticSetter(
String name, LibraryElement library) {
return _implementationsOfSetter(name).firstWhereOrNull(
@@ -6326,6 +6332,7 @@ abstract class InterfaceElementImpl extends InstanceElementImpl
/// The setters are returned based on the depth of their defining class; if
/// this class contains a definition of the setter it will occur first, if
/// Object contains a definition of the setter it will occur last.
@Deprecated(elementModelDeprecationMsg)
Iterable<PropertyAccessorElement> _implementationsOfSetter(
String setterName) sync* {
var visitedClasses = <InterfaceElement>{};
@@ -53,18 +53,6 @@ extension BindPatternVariableElementImplExtension
}
}
extension ClassElement2Extension on ClassElement2 {
ClassElement get asElement {
return firstFragment as ClassElement;
}
}
extension ClassElementExtension on ClassElement {
ClassElement2 get asElement2 {
return (this as ClassElementImpl).element;
}
}
extension ClassElementImpl2Extension on ClassElementImpl2 {
ClassElementImpl get asElement {
return firstFragment;
@@ -42,14 +42,17 @@ class AnalyzerUseNewElementsTest extends LintRuleTest {
}
test_enablement_optedOut() async {
await assertDiagnostics(r'''
await assertDiagnostics(
r'''
// ignore_for_file: analyzer_use_new_elements
import 'package:analyzer/dart/element/element.dart';
ClassElement f() {
throw 42;
}
''', []);
''',
[error(HintCode.DEPRECATED_MEMBER_USE_WITH_MESSAGE, 100, 12)],
);
}
test_interfaceTypeImpl_element() async {
@@ -138,7 +141,10 @@ ClassElement f() {
throw 42;
}
''',
[lint(54, 12)],
[
error(HintCode.DEPRECATED_MEMBER_USE_WITH_MESSAGE, 54, 12),
lint(54, 12),
],
);
}