Use static strings from FunctionElement where possible

This improves discovery, refactoring, etc.

I did not change any locations which would have required interpolation,
or tests which refer to a String immediately nearby (in tests).

Change-Id: I8479fd7822713e878e56fdf5ec35969492049333
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/213580
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
This commit is contained in:
Sam Rawlins 2021-09-16 19:05:55 +00:00 committed by commit-bot@chromium.org
parent e7201752dc
commit 1f66977de1
9 changed files with 25 additions and 16 deletions

View file

@ -21,10 +21,11 @@ import 'package:analyzer/dart/element/element.dart'
Element,
ElementKind,
FieldElement,
FunctionElement,
LibraryElement,
LocalVariableElement,
PropertyAccessorElement,
TopLevelVariableElement,
LocalVariableElement;
TopLevelVariableElement;
import 'package:analyzer/dart/element/type.dart';
import 'package:analyzer/dart/element/type_provider.dart';
import 'package:analyzer/dart/element/type_system.dart';
@ -322,7 +323,9 @@ class FeatureComputer {
// override of `noSuchMethod`.
return 0.0;
}
return proposedMemberName == 'noSuchMethod' ? -1.0 : 0.0;
return proposedMemberName == FunctionElement.NO_SUCH_METHOD_METHOD_NAME
? -1.0
: 0.0;
}
/// Return the value of the _keyword_ feature for the [keyword] when

View file

@ -457,9 +457,8 @@ class SuggestionBuilder {
/// Add a suggestion for the `call` method defined on functions.
void suggestFunctionCall() {
const callString = 'call';
final element = protocol.Element(
protocol.ElementKind.METHOD, callString, protocol.Element.makeFlags(),
final element = protocol.Element(protocol.ElementKind.METHOD,
FunctionElement.CALL_METHOD_NAME, protocol.Element.makeFlags(),
location: null,
typeParameters: null,
parameters: '()',
@ -467,8 +466,8 @@ class SuggestionBuilder {
_add(CompletionSuggestion(
CompletionSuggestionKind.INVOCATION,
Relevance.callFunction,
callString,
callString.length,
FunctionElement.CALL_METHOD_NAME,
FunctionElement.CALL_METHOD_NAME.length,
0,
false,
false,

View file

@ -140,7 +140,8 @@ class IndexElementInfo {
if (elementKind == ElementKind.CONSTRUCTOR) {
kind = IndexSyntheticElementKind.constructor;
element = element.enclosingElement!;
} else if (element is FunctionElement && element.name == 'loadLibrary') {
} else if (element is FunctionElement &&
element.name == FunctionElement.LOAD_LIBRARY_NAME) {
kind = IndexSyntheticElementKind.loadLibrary;
element = element.library;
} else if (elementKind == ElementKind.FIELD) {

View file

@ -43,7 +43,8 @@ class GetterMethodConflict extends Conflict {
/// Manages knowledge about interface types and their members.
class InheritanceManager3 {
static final _noSuchMethodName = Name(null, 'noSuchMethod');
static final _noSuchMethodName =
Name(null, FunctionElement.NO_SUCH_METHOD_METHOD_NAME);
/// Cached instance interfaces for [ClassElement].
final Map<ClassElement, Interface> _interfaces = {};

View file

@ -316,7 +316,9 @@ class TypeSystemImpl implements TypeSystem {
/// return the function type for the call method, otherwise return null.
FunctionType? getCallMethodType(DartType t) {
if (t is InterfaceType) {
return t.lookUpMethod2('call', t.element.library)?.type;
return t
.lookUpMethod2(FunctionElement.CALL_METHOD_NAME, t.element.library)
?.type;
}
return null;
}

View file

@ -350,7 +350,8 @@ class PropertyElementResolver {
var targetType = target.typeOrThrow;
if (targetType is FunctionType && propertyName.name == 'call') {
if (targetType is FunctionType &&
propertyName.name == FunctionElement.CALL_METHOD_NAME) {
return PropertyElementResolverResult(
functionTypeCallType: targetType,
);

View file

@ -170,14 +170,16 @@ class TypePropertyResolver {
if (_hasGetterOrSetter) {
return _toResult();
}
if (receiverTypeResolved.isDartCoreFunction && _name == 'call') {
if (receiverTypeResolved.isDartCoreFunction &&
_name == FunctionElement.CALL_METHOD_NAME) {
_needsGetterError = false;
_needsSetterError = false;
return _toResult();
}
}
if (receiverTypeResolved is FunctionType && _name == 'call') {
if (receiverTypeResolved is FunctionType &&
_name == FunctionElement.CALL_METHOD_NAME) {
return _toResult();
}

View file

@ -14,7 +14,7 @@ class DuplicateDefinitionVerifier {
static final Set<String> _enumInstanceMembers = {
'hashCode',
'index',
'noSuchMethod',
FunctionElement.NO_SUCH_METHOD_METHOD_NAME,
'runtimeType',
'toString',
};

View file

@ -2396,7 +2396,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
name == 'hashCode' ||
name == 'toString' ||
name == 'runtimeType' ||
name == 'noSuchMethod') {
name == FunctionElement.NO_SUCH_METHOD_METHOD_NAME) {
errorReporter.reportErrorForNode(
CompileTimeErrorCode.EXTENSION_DECLARES_MEMBER_OF_OBJECT,
node.name,