Skip to content

Commit 1293500

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Migrate AssignmentVerifier.
Change-Id: I45a3c4df63250c611f011d61023ed74485145b78 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/395780 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent b80fdcb commit 1293500

File tree

9 files changed

+57
-30
lines changed

9 files changed

+57
-30
lines changed

pkg/analysis_server/lib/src/lsp/handlers/custom/handler_editable_arguments.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ class EditableArgumentsHandler
173173

174174
/// Returns the name of an enum constant prefixed with the enum name.
175175
String? _qualifiedEnumConstant(FieldElement2 enumConstant) {
176-
var enumName = enumConstant.enclosingElement2?.name3;
176+
var enumName = enumConstant.enclosingElement2.name3;
177177
var name = enumConstant.name3;
178178
return enumName != null && name != null ? '$enumName.$name' : null;
179179
}

pkg/analyzer/analyzer_use_new_elements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ lib/src/dart/resolver/typed_literal_resolver.dart
9898
lib/src/dart/resolver/variable_declaration_resolver.dart
9999
lib/src/dart/resolver/yield_statement_resolver.dart
100100
lib/src/diagnostic/diagnostic_factory.dart
101-
lib/src/error/assignment_verifier.dart
102101
lib/src/error/best_practices_verifier.dart
103102
lib/src/error/correct_override.dart
104103
lib/src/error/dead_code_verifier.dart

pkg/analyzer/lib/dart/element/element2.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,9 @@ abstract class FieldElement2 implements PropertyInducingElement2 {
747747
@override
748748
FieldElement2 get baseElement;
749749

750+
@override
751+
InstanceElement2 get enclosingElement2;
752+
750753
@override
751754
FieldFragment get firstFragment;
752755

pkg/analyzer/lib/src/dart/element/element.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4189,7 +4189,7 @@ class FieldElementImpl2 extends PropertyInducingElementImpl2
41894189
FieldElement2 get baseElement => this;
41904190

41914191
@override
4192-
Element2? get enclosingElement2 =>
4192+
InstanceElement2 get enclosingElement2 =>
41934193
(firstFragment._enclosingElement3 as InstanceFragment).element;
41944194

41954195
@override

pkg/analyzer/lib/src/dart/element/member.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ class FieldMember extends VariableMember
502502
String get displayName => declaration.displayName;
503503

504504
@override
505-
Element2? get enclosingElement2 => _element2.enclosingElement2;
505+
InstanceElement2 get enclosingElement2 => _element2.enclosingElement2;
506506

507507
@override
508508
Element get enclosingElement3 => declaration.enclosingElement3;

pkg/analyzer/lib/src/dart/resolver/extension_member_resolver.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import 'package:analyzer/dart/analysis/features.dart';
66
import 'package:analyzer/dart/ast/syntactic_entity.dart';
77
import 'package:analyzer/dart/element/element.dart';
8+
import 'package:analyzer/dart/element/element2.dart';
89
import 'package:analyzer/dart/element/type.dart';
910
import 'package:analyzer/dart/element/type_provider.dart';
1011
import 'package:analyzer/error/listener.dart';
@@ -466,8 +467,14 @@ enum ExtensionResolutionError implements ExtensionResolutionResult {
466467
@override
467468
ExecutableElement? get getter => null;
468469

470+
@override
471+
ExecutableElement2? get getter2 => null;
472+
469473
@override
470474
ExecutableElement? get setter => null;
475+
476+
@override
477+
ExecutableElement2? get setter2 => null;
471478
}
472479

473480
/// The result of attempting to resolve an identifier to elements, where the

pkg/analyzer/lib/src/dart/resolver/property_element_resolver.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,8 @@ class PropertyElementResolver with ScopeHelpers {
287287

288288
AssignmentVerifier(errorReporter).verify(
289289
node: node,
290-
requested: writeElementRequested,
291-
recovery: writeElementRecovery,
290+
requested: writeElementRequested.asElement2,
291+
recovery: writeElementRecovery.asElement2,
292292
receiverType: null,
293293
);
294294
}
@@ -528,7 +528,7 @@ class PropertyElementResolver with ScopeHelpers {
528528
AssignmentVerifier(errorReporter).verify(
529529
node: propertyName,
530530
requested: null,
531-
recovery: result.getter,
531+
recovery: result.getter2,
532532
receiverType: targetType,
533533
);
534534
}
@@ -736,7 +736,7 @@ class PropertyElementResolver with ScopeHelpers {
736736
AssignmentVerifier(errorReporter).verify(
737737
node: propertyName,
738738
requested: null,
739-
recovery: writeElementRecovery,
739+
recovery: writeElementRecovery.asElement2,
740740
receiverType: typeReference.thisType,
741741
);
742742
}

pkg/analyzer/lib/src/dart/resolver/resolution_result.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:analyzer/dart/element/element.dart';
6+
import 'package:analyzer/dart/element/element2.dart';
67
import 'package:analyzer/dart/element/type.dart';
8+
import 'package:analyzer/src/utilities/extensions/element.dart';
79

810
/// The result of attempting to resolve an identifier to elements.
911
class ResolutionResult extends SimpleResolutionResult {
@@ -57,4 +59,8 @@ class SimpleResolutionResult {
5759
final ExecutableElement? setter;
5860

5961
const SimpleResolutionResult({this.getter, this.setter});
62+
63+
ExecutableElement2? get getter2 => getter.asElement2;
64+
65+
ExecutableElement2? get setter2 => setter.asElement2;
6066
}

pkg/analyzer/lib/src/error/assignment_verifier.dart

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:analyzer/dart/ast/ast.dart';
6-
import 'package:analyzer/dart/element/element.dart';
6+
import 'package:analyzer/dart/element/element2.dart';
77
import 'package:analyzer/dart/element/type.dart';
88
import 'package:analyzer/error/listener.dart';
99
import 'package:analyzer/src/dart/element/element.dart';
@@ -29,12 +29,12 @@ class AssignmentVerifier {
2929
/// [CompileTimeErrorCode.UNDEFINED_IDENTIFIER].
3030
void verify({
3131
required SimpleIdentifier node,
32-
required Element? requested,
33-
required Element? recovery,
32+
required Element2? requested,
33+
required Element2? recovery,
3434
required DartType? receiverType,
3535
}) {
3636
if (requested != null) {
37-
if (requested is VariableElement) {
37+
if (requested is VariableElement2) {
3838
if (requested.isConst) {
3939
_errorReporter.atNode(
4040
node,
@@ -45,54 +45,66 @@ class AssignmentVerifier {
4545
return;
4646
}
4747

48-
if (recovery is DynamicElementImpl ||
49-
recovery is InterfaceElement ||
50-
recovery is TypeAliasElement ||
51-
recovery is TypeParameterElement) {
48+
if (recovery is DynamicElementImpl2 ||
49+
recovery is InterfaceElement2 ||
50+
recovery is TypeAliasElement2 ||
51+
recovery is TypeParameterElement2) {
5252
_errorReporter.atNode(
5353
node,
5454
CompileTimeErrorCode.ASSIGNMENT_TO_TYPE,
5555
);
56-
} else if (recovery is FunctionElement) {
56+
} else if (recovery is LocalFunctionElement ||
57+
recovery is TopLevelFunctionElement) {
5758
_errorReporter.atNode(
5859
node,
5960
CompileTimeErrorCode.ASSIGNMENT_TO_FUNCTION,
6061
);
61-
} else if (recovery is MethodElement) {
62+
} else if (recovery is MethodElement2) {
6263
_errorReporter.atNode(
6364
node,
6465
CompileTimeErrorCode.ASSIGNMENT_TO_METHOD,
6566
);
66-
} else if (recovery is PrefixElement) {
67-
_errorReporter.atNode(
68-
node,
69-
CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT,
70-
arguments: [recovery.name],
71-
);
72-
} else if (recovery is PropertyAccessorElement && recovery.isGetter) {
73-
var variable = recovery.variable2;
67+
} else if (recovery is PrefixElement2) {
68+
if (recovery.name3 case var prefixName?) {
69+
_errorReporter.atNode(
70+
node,
71+
CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT,
72+
arguments: [prefixName],
73+
);
74+
}
75+
} else if (recovery is GetterElement) {
76+
var variable = recovery.variable3;
7477
if (variable == null) {
7578
return;
7679
}
80+
81+
var variableName = variable.name3;
82+
if (variableName == null) {
83+
return;
84+
}
85+
7786
if (variable.isConst) {
7887
_errorReporter.atNode(
7988
node,
8089
CompileTimeErrorCode.ASSIGNMENT_TO_CONST,
8190
);
82-
} else if (variable is FieldElement && variable.isSynthetic) {
91+
} else if (variable is FieldElement2 && variable.isSynthetic) {
8392
_errorReporter.atNode(
8493
node,
8594
CompileTimeErrorCode.ASSIGNMENT_TO_FINAL_NO_SETTER,
86-
arguments: [variable.name, variable.enclosingElement3.displayName],
95+
arguments: [
96+
variableName,
97+
variable.enclosingElement2.displayName,
98+
],
8799
);
88100
} else {
89101
_errorReporter.atNode(
90102
node,
91103
CompileTimeErrorCode.ASSIGNMENT_TO_FINAL,
92-
arguments: [variable.name],
104+
arguments: [variableName],
93105
);
94106
}
95-
} else if (recovery is MultiplyDefinedElementImpl) {
107+
} else if (recovery is MultiplyDefinedElementImpl2) {
96108
// Will be reported in ErrorVerifier.
97109
} else {
98110
if (node.isSynthetic) {

0 commit comments

Comments
 (0)