mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 06:36:33 +00:00
Deprecate some of the lookUp* methods
Change-Id: Ib26cc923321f8cef3912f5cc4cc01d9d8927666c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/353583 Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
3c460923f9
commit
1dba9e917c
|
@ -197,21 +197,24 @@ class _OverriddenElementsFinder {
|
|||
Element? member;
|
||||
// method
|
||||
if (_kinds.contains(ElementKind.METHOD)) {
|
||||
member = classElement.lookUpMethod(_name, _library);
|
||||
var augmented = classElement.augmented;
|
||||
member = augmented?.lookUpMethod(name: _name, library: _library);
|
||||
if (member != null) {
|
||||
return member;
|
||||
}
|
||||
}
|
||||
// getter
|
||||
if (_kinds.contains(ElementKind.GETTER)) {
|
||||
member = classElement.lookUpGetter(_name, _library);
|
||||
var augmented = classElement.augmented;
|
||||
member = augmented?.lookUpGetter(name: _name, library: _library);
|
||||
if (member != null) {
|
||||
return member;
|
||||
}
|
||||
}
|
||||
// setter
|
||||
if (_kinds.contains(ElementKind.SETTER)) {
|
||||
member = classElement.lookUpSetter('$_name=', _library);
|
||||
var augmented = classElement.augmented;
|
||||
member = augmented?.lookUpSetter(name: '$_name=', library: _library);
|
||||
if (member != null) {
|
||||
return member;
|
||||
}
|
||||
|
|
|
@ -205,15 +205,20 @@ class TypeHierarchyComputerHelper {
|
|||
for (var mixin in clazz.mixins.reversed) {
|
||||
var mixinElement = mixin.element;
|
||||
if (pivotKind == ElementKind.METHOD) {
|
||||
result = mixinElement.lookUpMethod(pivotName, pivotLibrary);
|
||||
result = mixinElement.augmented
|
||||
?.lookUpMethod(name: pivotName, library: pivotLibrary);
|
||||
} else if (pivotKind == ElementKind.GETTER) {
|
||||
result = mixinElement.lookUpGetter(pivotName, pivotLibrary);
|
||||
result = mixinElement.augmented
|
||||
?.lookUpGetter(name: pivotName, library: pivotLibrary);
|
||||
} else if (pivotKind == ElementKind.SETTER) {
|
||||
result = mixinElement.lookUpSetter(pivotName, pivotLibrary);
|
||||
result = mixinElement.augmented
|
||||
?.lookUpSetter(name: pivotName, library: pivotLibrary);
|
||||
} else if (pivotKind == ElementKind.FIELD) {
|
||||
result = mixinElement.lookUpGetter(pivotName, pivotLibrary);
|
||||
result = mixinElement.augmented
|
||||
?.lookUpGetter(name: pivotName, library: pivotLibrary);
|
||||
if (result == null && !pivotFieldFinal) {
|
||||
result = mixinElement.lookUpSetter(pivotName, pivotLibrary);
|
||||
result = mixinElement.augmented
|
||||
?.lookUpSetter(name: pivotName, library: pivotLibrary);
|
||||
}
|
||||
}
|
||||
if (result == pivotElement) {
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
* Deprecated `LibraryElement.toLegacyTypeIfOptOut`.
|
||||
* Deprecated `LibraryElement.toLegacyElementIfOptOut`.
|
||||
* Deprecated `LibraryElement.isNonNullableByDefault`.
|
||||
* Deprecated `InterfaceElement.lookUpGetter`, `InterfaceElement.lookUpMethod`,
|
||||
and `InterfaceElement.lookUpSetter`.
|
||||
|
||||
## 6.4.1
|
||||
* Patch for crash in ffi_verifier.
|
||||
|
@ -194,7 +196,7 @@
|
|||
* Update SDK constraints to `>=2.17.0 <3.0.0`.
|
||||
* Deprecated `ImportDirective.COMPARATOR`, use appropriate custom logic, if necessary.
|
||||
* Deprecated `Element.isAccessibleIn()`, use `isAccessibleIn2()` instead.
|
||||
* Bug fixes: 49225.
|
||||
* Bug fixes: 49225.
|
||||
|
||||
## 4.1.0
|
||||
* Deprecated `ParameterElement.isNotOptional`, use `isRequired` instead.
|
||||
|
|
|
@ -1684,7 +1684,7 @@ abstract class InterfaceElement implements InstanceElement {
|
|||
/// <i>m</i> in <i>S</i> with respect to <i>L</i>. Otherwise, we say that the
|
||||
/// lookup has failed.
|
||||
/// </blockquote>
|
||||
// TODO(scheglov): Deprecate and remove it.
|
||||
@Deprecated('Use `element.augmented.lookUpGetter`.')
|
||||
PropertyAccessorElement? lookUpGetter(
|
||||
String getterName, LibraryElement library);
|
||||
|
||||
|
@ -1784,7 +1784,7 @@ abstract class InterfaceElement implements InstanceElement {
|
|||
/// <i>S</i> with respect to <i>L</i>. Otherwise, we say that the lookup has
|
||||
/// failed.
|
||||
/// </blockquote>
|
||||
// TODO(scheglov): Deprecate and remove it.
|
||||
@Deprecated('Use `element.augmented.lookUpMethod`.')
|
||||
MethodElement? lookUpMethod(String methodName, LibraryElement library);
|
||||
|
||||
/// Returns the element representing the setter that results from looking up
|
||||
|
@ -1803,7 +1803,7 @@ abstract class InterfaceElement implements InstanceElement {
|
|||
/// <i>m</i> in <i>S</i> with respect to <i>L</i>. Otherwise, we say that the
|
||||
/// lookup has failed.
|
||||
/// </blockquote>
|
||||
// TODO(scheglov): Deprecate and remove it.
|
||||
@Deprecated('Use `element.augmented.lookUpSetter`.')
|
||||
PropertyAccessorElement? lookUpSetter(
|
||||
String setterName, LibraryElement library);
|
||||
}
|
||||
|
|
|
@ -3683,6 +3683,7 @@ abstract class InterfaceElementImpl extends InstanceElementImpl
|
|||
(method) => !method.isAbstract && method.isAccessibleIn(library));
|
||||
}
|
||||
|
||||
@Deprecated('Use `element.augmented.lookUpGetter`.')
|
||||
@override
|
||||
PropertyAccessorElement? lookUpGetter(
|
||||
String getterName, LibraryElement library) {
|
||||
|
@ -3739,12 +3740,14 @@ abstract class InterfaceElementImpl extends InstanceElementImpl
|
|||
method.enclosingElement != this);
|
||||
}
|
||||
|
||||
@Deprecated('Use `element.augmented.lookUpMethod`.')
|
||||
@override
|
||||
MethodElement? lookUpMethod(String methodName, LibraryElement library) {
|
||||
return _implementationsOfMethod(methodName).firstWhereOrNull(
|
||||
(MethodElement method) => method.isAccessibleIn(library));
|
||||
}
|
||||
|
||||
@Deprecated('Use `element.augmented.lookUpSetter`.')
|
||||
@override
|
||||
PropertyAccessorElement? lookUpSetter(
|
||||
String setterName, LibraryElement library) {
|
||||
|
@ -3878,8 +3881,6 @@ abstract class InterfaceElementImpl extends InstanceElementImpl
|
|||
|
||||
static PropertyAccessorElement? getSetterFromAccessors(
|
||||
String setterName, List<PropertyAccessorElement> accessors) {
|
||||
// TODO(jwren): revisit- should we append '=' here or require clients to
|
||||
// include it?
|
||||
// Do we need the check for isSetter below?
|
||||
if (!setterName.endsWith('=')) {
|
||||
setterName += '=';
|
||||
|
@ -4988,20 +4989,11 @@ mixin MaybeAugmentedInstanceElementMixin implements AugmentedInstanceElement {
|
|||
|
||||
@override
|
||||
PropertyAccessorElement? getSetter(String name) {
|
||||
final nameLength = name.length;
|
||||
final length = accessors.length;
|
||||
for (var i = 0; i < length; i++) {
|
||||
final accessor = accessors[i];
|
||||
if (accessor.isSetter) {
|
||||
final accessorName = accessor.name;
|
||||
if (accessorName.length == nameLength + 1) {
|
||||
if (accessorName.startsWith(name)) {
|
||||
return accessor;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!name.endsWith('=')) {
|
||||
name += '=';
|
||||
}
|
||||
return null;
|
||||
return accessors.firstWhereOrNull(
|
||||
(accessor) => accessor.isSetter && accessor.name == name);
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -192,7 +192,8 @@ class _AstToIRVisitor extends ThrowingAstVisitor<_LValueTemplates> {
|
|||
MethodElement lookupToString(DartType? type) {
|
||||
var class_ =
|
||||
type is InterfaceType ? type.element : typeProvider.objectElement;
|
||||
return class_.lookUpMethod('toString', coreLibrary)!;
|
||||
return (class_.augmented
|
||||
?.lookUpMethod(name: 'toString', library: coreLibrary))!;
|
||||
}
|
||||
|
||||
/// Performs a null check that is part of a null shorting expression.
|
||||
|
|
|
@ -607,6 +607,7 @@ class ClassElementImplTest extends AbstractTypeSystemTest {
|
|||
var getter = ElementFactory.getterElement(getterName, false, intNone);
|
||||
classA.accessors = [getter];
|
||||
library.definingCompilationUnit.classes = [classA];
|
||||
// ignore: deprecated_member_use_from_same_package
|
||||
expect(classA.lookUpGetter(getterName, library), same(getter));
|
||||
}
|
||||
|
||||
|
@ -624,6 +625,7 @@ class ClassElementImplTest extends AbstractTypeSystemTest {
|
|||
ClassElementImpl classB =
|
||||
ElementFactory.classElement("B", interfaceTypeStar(classA));
|
||||
library.definingCompilationUnit.classes = [classA, classB];
|
||||
// ignore: deprecated_member_use_from_same_package
|
||||
expect(classB.lookUpGetter(getterName, library), same(getter));
|
||||
}
|
||||
|
||||
|
@ -633,6 +635,7 @@ class ClassElementImplTest extends AbstractTypeSystemTest {
|
|||
LibraryElementImpl library = _newLibrary();
|
||||
var classA = class_(name: 'A');
|
||||
library.definingCompilationUnit.classes = [classA];
|
||||
// ignore: deprecated_member_use_from_same_package
|
||||
expect(classA.lookUpGetter("g", library), isNull);
|
||||
}
|
||||
|
||||
|
@ -647,6 +650,7 @@ class ClassElementImplTest extends AbstractTypeSystemTest {
|
|||
ElementFactory.classElement("B", interfaceTypeStar(classA));
|
||||
classA.supertype = interfaceTypeStar(classB);
|
||||
library.definingCompilationUnit.classes = [classA, classB];
|
||||
// ignore: deprecated_member_use_from_same_package
|
||||
expect(classA.lookUpGetter("g", library), isNull);
|
||||
}
|
||||
|
||||
|
@ -657,6 +661,7 @@ class ClassElementImplTest extends AbstractTypeSystemTest {
|
|||
var method = ElementFactory.methodElement(methodName, intNone);
|
||||
classA.methods = [method];
|
||||
library.definingCompilationUnit.classes = [classA];
|
||||
// ignore: deprecated_member_use_from_same_package
|
||||
expect(classA.lookUpMethod(methodName, library), same(method));
|
||||
}
|
||||
|
||||
|
@ -669,6 +674,7 @@ class ClassElementImplTest extends AbstractTypeSystemTest {
|
|||
ClassElementImpl classB =
|
||||
ElementFactory.classElement("B", interfaceTypeStar(classA));
|
||||
library.definingCompilationUnit.classes = [classA, classB];
|
||||
// ignore: deprecated_member_use_from_same_package
|
||||
expect(classB.lookUpMethod(methodName, library), same(method));
|
||||
}
|
||||
|
||||
|
@ -676,6 +682,7 @@ class ClassElementImplTest extends AbstractTypeSystemTest {
|
|||
LibraryElementImpl library = _newLibrary();
|
||||
var classA = class_(name: 'A');
|
||||
library.definingCompilationUnit.classes = [classA];
|
||||
// ignore: deprecated_member_use_from_same_package
|
||||
expect(classA.lookUpMethod("m", library), isNull);
|
||||
}
|
||||
|
||||
|
@ -686,6 +693,7 @@ class ClassElementImplTest extends AbstractTypeSystemTest {
|
|||
ElementFactory.classElement("B", interfaceTypeStar(classA));
|
||||
classA.supertype = interfaceTypeStar(classB);
|
||||
library.definingCompilationUnit.classes = [classA, classB];
|
||||
// ignore: deprecated_member_use_from_same_package
|
||||
expect(classA.lookUpMethod("m", library), isNull);
|
||||
}
|
||||
|
||||
|
@ -699,6 +707,7 @@ class ClassElementImplTest extends AbstractTypeSystemTest {
|
|||
var setter = ElementFactory.setterElement(setterName, false, intNone);
|
||||
classA.accessors = [setter];
|
||||
library.definingCompilationUnit.classes = [classA];
|
||||
// ignore: deprecated_member_use_from_same_package
|
||||
expect(classA.lookUpSetter(setterName, library), same(setter));
|
||||
}
|
||||
|
||||
|
@ -716,6 +725,7 @@ class ClassElementImplTest extends AbstractTypeSystemTest {
|
|||
ClassElementImpl classB =
|
||||
ElementFactory.classElement("B", interfaceTypeStar(classA));
|
||||
library.definingCompilationUnit.classes = [classA, classB];
|
||||
// ignore: deprecated_member_use_from_same_package
|
||||
expect(classB.lookUpSetter(setterName, library), same(setter));
|
||||
}
|
||||
|
||||
|
@ -725,6 +735,7 @@ class ClassElementImplTest extends AbstractTypeSystemTest {
|
|||
LibraryElementImpl library = _newLibrary();
|
||||
var classA = class_(name: 'A');
|
||||
library.definingCompilationUnit.classes = [classA];
|
||||
// ignore: deprecated_member_use_from_same_package
|
||||
expect(classA.lookUpSetter("s", library), isNull);
|
||||
}
|
||||
|
||||
|
@ -739,6 +750,7 @@ class ClassElementImplTest extends AbstractTypeSystemTest {
|
|||
ElementFactory.classElement("B", interfaceTypeStar(classA));
|
||||
classA.supertype = interfaceTypeStar(classB);
|
||||
library.definingCompilationUnit.classes = [classA, classB];
|
||||
// ignore: deprecated_member_use_from_same_package
|
||||
expect(classA.lookUpSetter("s", library), isNull);
|
||||
}
|
||||
|
||||
|
|
|
@ -433,7 +433,8 @@ extension MethodDeclarationExtension on MethodDeclaration {
|
|||
}
|
||||
var parent = declaredElement.enclosingElement;
|
||||
if (parent is InterfaceElement) {
|
||||
return parent.lookUpGetter(name.lexeme, declaredElement.library);
|
||||
return parent.augmented
|
||||
?.lookUpGetter(name: name.lexeme, library: declaredElement.library);
|
||||
}
|
||||
if (parent is ExtensionElement) {
|
||||
return parent.getGetter(name.lexeme);
|
||||
|
|
|
@ -1111,8 +1111,8 @@ extension ElementExtension on Element {
|
|||
// The BuildContext object is the field on Flutter's State class.
|
||||
// This object can only be guarded by async gaps with a mounted
|
||||
// check on the State.
|
||||
return enclosingElement.lookUpGetter(
|
||||
'mounted', enclosingElement.library);
|
||||
return enclosingElement.augmented
|
||||
?.lookUpGetter(name: 'mounted', library: enclosingElement.library);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1123,8 +1123,8 @@ extension ElementExtension on Element {
|
|||
}
|
||||
?.element;
|
||||
if (buildContextElement is InterfaceElement) {
|
||||
return buildContextElement.lookUpGetter(
|
||||
'mounted', buildContextElement.library);
|
||||
return buildContextElement.augmented
|
||||
?.lookUpGetter(name: 'mounted', library: buildContextElement.library);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
Loading…
Reference in a new issue