Legacy. Remove toLegacyElement()

Change-Id: Ic9bad044fd72b5d43fa67a3a727b91edef708fda
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/350348
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
This commit is contained in:
Konstantin Shcheglov 2024-02-06 17:17:10 +00:00 committed by Commit Queue
parent b7e1eaafc6
commit 6d4204e3f5
10 changed files with 8 additions and 52 deletions

View file

@ -69,7 +69,6 @@ class AnnotationResolver {
ExecutableElement? getter;
if (getterName != null) {
getter = classElement.getGetter(getterName.name);
getter = _resolver.toLegacyElement(getter);
// Recovery, try to find a constructor.
getter ??= classElement.getNamedConstructor(getterName.name);
} else {
@ -102,7 +101,6 @@ class AnnotationResolver {
InterfaceType Function(List<DartType> typeArguments) instantiateElement,
List<WhyNotPromotedGetter> whyNotPromotedList,
) {
constructorElement = _resolver.toLegacyElement(constructorElement);
constructorName?.staticElement = constructorElement;
node.element = constructorElement;
@ -147,7 +145,6 @@ class AnnotationResolver {
ExecutableElement? getter;
if (getterName != null) {
getter = extensionElement.getGetter(getterName.name);
getter = _resolver.toLegacyElement(getter);
}
getterName?.staticElement = getter;
@ -187,7 +184,6 @@ class AnnotationResolver {
PropertyAccessorElement element,
List<WhyNotPromotedGetter> whyNotPromotedList,
) {
element = _resolver.toLegacyElement(element);
name.staticElement = element;
node.element = element;
@ -381,7 +377,6 @@ class AnnotationResolver {
var classElement = aliasedType.element;
if (getterName != null) {
getter = classElement.getGetter(getterName.name);
getter = _resolver.toLegacyElement(getter);
}
}

View file

@ -62,7 +62,6 @@ class CommentReferenceResolver {
var prefixScope = prefixElement.scope;
var lookupResult = prefixScope.lookup(name.name);
var element = lookupResult.getter ?? lookupResult.setter;
element = _resolver.toLegacyElement(element);
name.staticElement = element;
return;
}
@ -121,7 +120,6 @@ class CommentReferenceResolver {
var prefixScope = prefixElement.scope;
var lookupResult = prefixScope.lookup(name.name);
var element = lookupResult.getter ?? lookupResult.setter;
element = _resolver.toLegacyElement(element);
name.staticElement = element;
var propertyName = expression.propertyName;
@ -143,9 +141,7 @@ class CommentReferenceResolver {
/// resolved. This does not record the results of the resolution.
Element? _resolveSimpleIdentifier(SimpleIdentifierImpl identifier) {
var lookupResult = identifier.scopeLookupResult!;
var element = _resolver.toLegacyElement(lookupResult.getter) ??
_resolver.toLegacyElement(lookupResult.setter);
var element = lookupResult.getter ?? lookupResult.setter;
if (element == null) {
InterfaceType enclosingType;

View file

@ -159,9 +159,6 @@ class ExtensionMemberResolver {
var setterMember =
setter != null ? ExecutableMember.from2(setter, substitution) : null;
getterMember = _resolver.toLegacyElement(getterMember);
setterMember = _resolver.toLegacyElement(setterMember);
return ResolutionResult(getter: getterMember, setter: setterMember);
}

View file

@ -347,7 +347,7 @@ class FunctionReferenceResolver {
var propertyName = function.propertyName;
var result =
_extensionResolver.getOverrideMember(override, propertyName.name);
var member = _resolver.toLegacyElement(result.getter);
var member = result.getter;
if (member == null) {
node.staticType = InvalidTypeImpl.instance;
@ -439,7 +439,6 @@ class FunctionReferenceResolver {
node.staticType = InvalidTypeImpl.instance;
return;
} else {
functionElement = _resolver.toLegacyElement(functionElement);
_resolveReceiverPrefix(node, prefixElement, function, functionElement);
return;
}

View file

@ -115,7 +115,6 @@ class InvocationInferenceHelper {
if (rawElement == null) {
return null;
}
rawElement = _resolver.toLegacyElement(rawElement);
return ConstructorElementToInfer(typeParameters, rawElement);
}

View file

@ -361,7 +361,6 @@ class MethodInvocationResolver with ScopeHelpers {
{required DartType? contextType}) {
var getter = extension.getGetter(name);
if (getter != null) {
getter = _resolver.toLegacyElement(getter);
nameNode.staticElement = getter;
_reportStaticAccessToInstanceMember(getter, nameNode);
_rewriteAsFunctionExpressionInvocation(node, getter.returnType,
@ -371,7 +370,6 @@ class MethodInvocationResolver with ScopeHelpers {
var method = extension.getMethod(name);
if (method != null) {
method = _resolver.toLegacyElement(method);
nameNode.staticElement = method;
_reportStaticAccessToInstanceMember(method, nameNode);
_setResolution(node, method.type, whyNotPromotedList,
@ -398,7 +396,7 @@ class MethodInvocationResolver with ScopeHelpers {
List<WhyNotPromotedGetter> whyNotPromotedList,
{required DartType? contextType}) {
var result = _extensionResolver.getOverrideMember(override, name);
var member = _resolver.toLegacyElement(result.getter);
var member = result.getter;
if (member == null) {
_setInvalidTypeResolution(node,
@ -454,7 +452,6 @@ class MethodInvocationResolver with ScopeHelpers {
arguments.length == target.parameters.length &&
!arguments.any((e) => e is NamedExpression);
if (hasMatchingObjectMethod) {
target = _resolver.toLegacyElement(target);
nameNode.staticElement = target;
rawType = target.type;
node.staticType = target.returnType;
@ -491,7 +488,6 @@ class MethodInvocationResolver with ScopeHelpers {
var objectElement = _resolver.typeProvider.objectElement;
var objectMember = objectElement.getMethod(methodName.name);
if (objectMember != null) {
objectMember = _resolver.toLegacyElement(objectMember);
methodName.staticElement = objectMember;
_setResolution(
node,
@ -546,7 +542,6 @@ class MethodInvocationResolver with ScopeHelpers {
var element = scopeLookupResult.getter;
if (element != null) {
element = _resolver.toLegacyElement(element);
nameNode.staticElement = element;
if (element is MultiplyDefinedElement) {
MultiplyDefinedElement multiply = element;
@ -615,7 +610,6 @@ class MethodInvocationResolver with ScopeHelpers {
imports[0].prefix is DeferredImportElementPrefix) {
var importedLibrary = imports[0].importedLibrary;
var element = importedLibrary?.loadLibraryFunction;
element = _resolver.toLegacyElement(element);
if (element is ExecutableElement) {
nameNode.staticElement = element;
return _setResolution(
@ -632,7 +626,6 @@ class MethodInvocationResolver with ScopeHelpers {
);
var element = scopeLookupResult.getter;
element = _resolver.toLegacyElement(element);
nameNode.staticElement = element;
if (element is MultiplyDefinedElement) {
@ -685,7 +678,6 @@ class MethodInvocationResolver with ScopeHelpers {
_currentName!,
forSuper: true,
);
target = _resolver.toLegacyElement(target);
// If there is that concrete dispatch target, then we are done.
if (target != null) {
@ -828,7 +820,6 @@ class MethodInvocationResolver with ScopeHelpers {
}
var element = _resolveElement(receiver, nameNode);
element = _resolver.toLegacyElement(element) as ExecutableElement?;
if (element != null) {
if (element is ExecutableElement) {
nameNode.staticElement = element;

View file

@ -256,7 +256,7 @@ class PropertyElementResolver with ScopeHelpers {
);
}
readElementRequested = _resolver.toLegacyElement(readLookup?.requested);
readElementRequested = readLookup?.requested;
if (readElementRequested is PropertyAccessorElement &&
!readElementRequested.isStatic) {
var unpromotedType = readElementRequested.returnType;
@ -276,8 +276,8 @@ class PropertyElementResolver with ScopeHelpers {
if (hasWrite) {
var writeLookup = LexicalLookup.resolveSetter(scopeLookupResult) ??
_resolver.thisLookupSetter(node);
writeElementRequested = _resolver.toLegacyElement(writeLookup?.requested);
writeElementRecovery = _resolver.toLegacyElement(writeLookup?.recovery);
writeElementRequested = writeLookup?.requested;
writeElementRecovery = writeLookup?.recovery;
AssignmentVerifier(errorReporter).verify(
node: node,
@ -554,7 +554,6 @@ class PropertyElementResolver with ScopeHelpers {
arguments: [memberName, extension.name!],
);
} else {
readElement = _resolver.toLegacyElement(readElement);
getType = readElement.returnType;
if (_checkForStaticAccessToInstanceMember(propertyName, readElement)) {
readElementRecovery = readElement;
@ -575,7 +574,6 @@ class PropertyElementResolver with ScopeHelpers {
arguments: [memberName, extension.name!],
);
} else {
writeElement = _resolver.toLegacyElement(writeElement);
if (_checkForStaticAccessToInstanceMember(propertyName, writeElement)) {
writeElementRecovery = writeElement;
writeElement = null;
@ -683,7 +681,6 @@ class PropertyElementResolver with ScopeHelpers {
}
if (readElement != null) {
readElement = _resolver.toLegacyElement(readElement);
getType = readElement.returnType;
if (_checkForStaticAccessToInstanceMember(propertyName, readElement)) {
readElementRecovery = readElement;
@ -706,7 +703,6 @@ class PropertyElementResolver with ScopeHelpers {
if (hasWrite) {
writeElement = augmented.getSetter(propertyName.name);
if (writeElement != null) {
writeElement = _resolver.toLegacyElement(writeElement);
if (!_isAccessible(writeElement)) {
errorReporter.atNode(
propertyName,
@ -754,8 +750,8 @@ class PropertyElementResolver with ScopeHelpers {
hasWrite: hasWrite,
);
var readElement = _resolver.toLegacyElement(lookupResult.getter);
var writeElement = _resolver.toLegacyElement(lookupResult.setter);
var readElement = lookupResult.getter;
var writeElement = lookupResult.setter;
DartType? getType;
if (hasRead && readElement is PropertyAccessorElement) {
getType = readElement.returnType;
@ -807,7 +803,6 @@ class PropertyElementResolver with ScopeHelpers {
.getMember2(targetType.element, name, forSuper: true);
if (readElement != null) {
readElement = _resolver.toLegacyElement(readElement);
_checkForStaticMember(target, propertyName, readElement);
} else {
// We were not able to find the concrete dispatch target.
@ -849,7 +844,6 @@ class PropertyElementResolver with ScopeHelpers {
);
if (writeElement != null) {
writeElement = _resolver.toLegacyElement(writeElement);
_checkForStaticMember(target, propertyName, writeElement);
} else {
// We were not able to find the concrete dispatch target.

View file

@ -286,12 +286,6 @@ class TypePropertyResolver {
}
ResolutionResult _toResult() {
_getterRequested = _resolver.toLegacyElement(_getterRequested);
_getterRecovery = _resolver.toLegacyElement(_getterRecovery);
_setterRequested = _resolver.toLegacyElement(_setterRequested);
_setterRecovery = _resolver.toLegacyElement(_setterRecovery);
var getter = _getterRequested ?? _getterRecovery;
var setter = _setterRequested ?? _setterRecovery;

View file

@ -156,10 +156,8 @@ class ElementResolver {
var name = node.name;
if (name == null) {
constructor = type.lookUpConstructor(null, _definingLibrary);
constructor = _resolver.toLegacyElement(constructor);
} else {
constructor = type.lookUpConstructor(name.name, _definingLibrary);
constructor = _resolver.toLegacyElement(constructor);
name.staticElement = constructor;
}
node.staticElement = constructor;
@ -355,7 +353,6 @@ class ElementResolver {
var name = node.constructorName;
var superName = name?.name;
var element = superType.lookUpConstructor(superName, _definingLibrary);
element = _resolver.toLegacyElement(element);
if (element == null || !element.isAccessibleIn(_definingLibrary)) {
if (name != null) {
_errorReporter.atNode(

View file

@ -1732,12 +1732,6 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
return ThisLookup.lookupSetter(this, node);
}
/// If in a legacy library, return the legacy view on the [element].
/// Otherwise, return the original element.
T toLegacyElement<T extends Element?>(T element) {
return element;
}
@override
DartType variableTypeFromInitializerType(DartType type) {
if (type.isDartCoreNull) {