Skip to content

Commit 1e1dcf8

Browse files
scheglovCommit Queue
authored and
Commit Queue
committed
Elements. Switch to ElementImpl in MemberDuplicateDefinitionVerifier.
Not really the migration, but maybe this is approach that we have to take for now. Change-Id: I5d7e9b9441f47d966a8552ff68a2497b74a2c59c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/415262 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent a5077aa commit 1e1dcf8

File tree

4 files changed

+69
-41
lines changed

4 files changed

+69
-41
lines changed

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

+16-2
Original file line numberDiff line numberDiff line change
@@ -8364,6 +8364,11 @@ class MethodElementImpl extends ExecutableElementImpl
83648364
return displayName;
83658365
}
83668366

8367+
@override
8368+
InstanceElementImpl get enclosingElement3 {
8369+
return super.enclosingElement3 as InstanceElementImpl;
8370+
}
8371+
83678372
@override
83688373
InstanceFragment? get enclosingFragment =>
83698374
enclosingElement3 as InstanceFragment;
@@ -10020,6 +10025,11 @@ sealed class PropertyAccessorElementImpl extends ExecutableElementImpl
1002010025
@override
1002110026
PropertyAccessorElementImpl2 get element;
1002210027

10028+
@override
10029+
ElementImpl get enclosingElement3 {
10030+
return super.enclosingElement3 as ElementImpl;
10031+
}
10032+
1002310033
@override
1002410034
Fragment get enclosingFragment {
1002510035
var enclosing = enclosingElement3;
@@ -10134,7 +10144,9 @@ class PropertyAccessorElementImpl_ImplicitGetter extends GetterFragmentImpl {
1013410144
}
1013510145

1013610146
@override
10137-
Element get enclosingElement3 => variable2.enclosingElement3;
10147+
ElementImpl get enclosingElement3 {
10148+
return variable2.enclosingElement3 as ElementImpl;
10149+
}
1013810150

1013910151
@override
1014010152
bool get hasImplicitReturnType => variable2.hasImplicitType;
@@ -10200,7 +10212,9 @@ class PropertyAccessorElementImpl_ImplicitSetter extends SetterFragmentImpl {
1020010212
}
1020110213

1020210214
@override
10203-
Element get enclosingElement3 => variable2.enclosingElement3;
10215+
ElementImpl get enclosingElement3 {
10216+
return variable2.enclosingElement3 as ElementImpl;
10217+
}
1020410218

1020510219
@override
1020610220
bool get isSetter => true;

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

+34-37
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// ignore_for_file: analyzer_use_new_elements
6-
75
import 'package:analyzer/dart/analysis/features.dart';
86
import 'package:analyzer/dart/ast/token.dart';
9-
import 'package:analyzer/dart/element/element.dart';
107
import 'package:analyzer/dart/element/element2.dart';
118
import 'package:analyzer/error/error.dart';
129
import 'package:analyzer/error/listener.dart';
@@ -361,13 +358,13 @@ class DuplicateDefinitionVerifier {
361358

362359
/// Information to pass from declarations to augmentations.
363360
class DuplicationDefinitionContext {
364-
final Map<InstanceElement, _InstanceElementContext> _instanceElementContexts =
365-
{};
361+
final Map<InstanceElementImpl, _InstanceElementContext>
362+
_instanceElementContexts = {};
366363
}
367364

368365
class MemberDuplicateDefinitionVerifier {
369366
final InheritanceManager3 _inheritanceManager;
370-
final LibraryElement _currentLibrary;
367+
final LibraryElementImpl _currentLibrary;
371368
final CompilationUnitElementImpl _currentUnit;
372369
final ErrorReporter _errorReporter;
373370
final DuplicationDefinitionContext context;
@@ -436,7 +433,7 @@ class MemberDuplicateDefinitionVerifier {
436433
element: field.declaredFragment!,
437434
setterScope: member.isStatic ? staticSetters : instanceSetters,
438435
);
439-
if (fragment is EnumElement) {
436+
if (fragment is EnumElementImpl) {
440437
_checkValuesDeclarationInEnum(field.name);
441438
}
442439
}
@@ -447,7 +444,7 @@ class MemberDuplicateDefinitionVerifier {
447444
element: member.declaredFragment!,
448445
setterScope: member.isStatic ? staticSetters : instanceSetters,
449446
);
450-
if (fragment is EnumElement) {
447+
if (fragment is EnumElementImpl) {
451448
if (!(member.isStatic && member.isSetter)) {
452449
_checkValuesDeclarationInEnum(member.name);
453450
}
@@ -517,14 +514,14 @@ class MemberDuplicateDefinitionVerifier {
517514
}
518515

519516
void _checkConflictingConstructorAndStatic({
520-
required InterfaceElement interfaceElement,
521-
required Map<String, Element> staticGetters,
522-
required Map<String, Element> staticSetters,
517+
required InterfaceElementImpl interfaceElement,
518+
required Map<String, ElementImpl> staticGetters,
519+
required Map<String, ElementImpl> staticSetters,
523520
}) {
524521
for (var constructor in interfaceElement.constructors) {
525522
var name = constructor.name;
526523
var staticMember = staticGetters[name] ?? staticSetters[name];
527-
if (staticMember is PropertyAccessorElement) {
524+
if (staticMember is PropertyAccessorElementImpl) {
528525
CompileTimeErrorCode errorCode;
529526
if (staticMember.isSynthetic) {
530527
errorCode =
@@ -541,7 +538,7 @@ class MemberDuplicateDefinitionVerifier {
541538
errorCode,
542539
arguments: [name],
543540
);
544-
} else if (staticMember is MethodElement) {
541+
} else if (staticMember is MethodElementImpl) {
545542
_errorReporter.atElement2(
546543
constructor.asElement2,
547544
CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_AND_STATIC_METHOD,
@@ -555,27 +552,27 @@ class MemberDuplicateDefinitionVerifier {
555552
/// in one of the scopes - [getterScope] or [setterScope], and produce an
556553
/// error if it is.
557554
void _checkDuplicateIdentifier(
558-
Map<String, Element> getterScope, Token identifier,
559-
{required Element element, Map<String, Element>? setterScope}) {
555+
Map<String, ElementImpl> getterScope, Token identifier,
556+
{required ElementImpl element, Map<String, ElementImpl>? setterScope}) {
560557
if (identifier.isSynthetic || element.asElement2.isWildcardVariable) {
561558
return;
562559
}
563560

564561
switch (element) {
565-
case ExecutableElement _:
562+
case ExecutableElementImpl _:
566563
if (element.isAugmentation) return;
567-
case FieldElement _:
564+
case FieldElementImpl _:
568565
if (element.isAugmentation) return;
569-
case InstanceElement _:
566+
case InstanceElementImpl _:
570567
if (element.isAugmentation) return;
571-
case TypeAliasElement _:
568+
case TypeAliasElementImpl _:
572569
if (element.isAugmentation) return;
573-
case TopLevelVariableElement _:
570+
case TopLevelVariableElementImpl _:
574571
if (element.isAugmentation) return;
575572
}
576573

577574
// Fields define getters and setters, so check them separately.
578-
if (element is PropertyInducingElement) {
575+
if (element is PropertyInducingElementImpl) {
579576
_checkDuplicateIdentifier(getterScope, identifier,
580577
element: element.getter!, setterScope: setterScope);
581578
var setter = element.setter;
@@ -587,7 +584,7 @@ class MemberDuplicateDefinitionVerifier {
587584
}
588585

589586
var name = switch (element) {
590-
MethodElement() => element.name,
587+
MethodElementImpl() => element.name,
591588
_ => identifier.lexeme,
592589
};
593590

@@ -608,7 +605,7 @@ class MemberDuplicateDefinitionVerifier {
608605
}
609606

610607
if (setterScope != null) {
611-
if (element is PropertyAccessorElement && element.isSetter) {
608+
if (element is PropertyAccessorElementImpl && element.isSetter) {
612609
previous = setterScope[name];
613610
if (previous != null) {
614611
_errorReporter.reportError(
@@ -665,7 +662,7 @@ class MemberDuplicateDefinitionVerifier {
665662
}
666663
var baseName = accessor.displayName;
667664
var inherited = _getInheritedMember(firstFragment, baseName);
668-
if (inherited is MethodElement) {
665+
if (inherited is MethodElementImpl) {
669666
_errorReporter.atElement2(
670667
accessor.asElement2,
671668
CompileTimeErrorCode.CONFLICTING_FIELD_AND_METHOD,
@@ -687,7 +684,7 @@ class MemberDuplicateDefinitionVerifier {
687684
}
688685
var baseName = method.displayName;
689686
var inherited = _getInheritedMember(firstFragment, baseName);
690-
if (inherited is PropertyAccessorElement) {
687+
if (inherited is PropertyAccessorElementImpl) {
691688
_errorReporter.atElement2(
692689
method.asElement2,
693690
CompileTimeErrorCode.CONFLICTING_METHOD_AND_FIELD,
@@ -862,13 +859,13 @@ class MemberDuplicateDefinitionVerifier {
862859
}
863860
}
864861

865-
_InstanceElementContext _getElementContext(InstanceElement element) {
862+
_InstanceElementContext _getElementContext(InstanceElementImpl element) {
866863
return context._instanceElementContexts[element] ??=
867864
_InstanceElementContext();
868865
}
869866

870-
ExecutableElement? _getInheritedMember(
871-
InterfaceElement element, String baseName) {
867+
ExecutableElementOrMember? _getInheritedMember(
868+
InterfaceElementImpl element, String baseName) {
872869
var libraryUri = _currentLibrary.source.uri;
873870

874871
var getterName = Name(libraryUri, baseName);
@@ -881,8 +878,8 @@ class MemberDuplicateDefinitionVerifier {
881878
return _inheritanceManager.getInherited2(element, setterName);
882879
}
883880

884-
ExecutableElement? _getInterfaceMember(
885-
InterfaceElement element, String baseName) {
881+
ExecutableElementOrMember? _getInterfaceMember(
882+
InterfaceElementImpl element, String baseName) {
886883
var libraryUri = _currentLibrary.source.uri;
887884

888885
var getterName = Name(libraryUri, baseName);
@@ -898,7 +895,7 @@ class MemberDuplicateDefinitionVerifier {
898895
static void checkLibrary({
899896
required InheritanceManager3 inheritance,
900897
required LibraryVerificationContext libraryVerificationContext,
901-
required LibraryElement libraryElement,
898+
required LibraryElementImpl libraryElement,
902899
required Map<FileState, FileAnalysis> files,
903900
}) {
904901
MemberDuplicateDefinitionVerifier forUnit(FileAnalysis fileAnalysis) {
@@ -922,8 +919,8 @@ class MemberDuplicateDefinitionVerifier {
922919
}
923920
}
924921

925-
static bool _isGetterSetterPair(Element a, Element b) {
926-
if (a is PropertyAccessorElement && b is PropertyAccessorElement) {
922+
static bool _isGetterSetterPair(ElementImpl a, ElementImpl b) {
923+
if (a is PropertyAccessorElementImpl && b is PropertyAccessorElementImpl) {
927924
return a.isGetter && b.isSetter || a.isSetter && b.isGetter;
928925
}
929926
return false;
@@ -933,8 +930,8 @@ class MemberDuplicateDefinitionVerifier {
933930
/// Information accumulated for a single declaration and its augmentations.
934931
class _InstanceElementContext {
935932
final Set<String> constructorNames = {};
936-
final Map<String, Element> instanceGetters = {};
937-
final Map<String, Element> instanceSetters = {};
938-
final Map<String, Element> staticGetters = {};
939-
final Map<String, Element> staticSetters = {};
933+
final Map<String, ElementImpl> instanceGetters = {};
934+
final Map<String, ElementImpl> instanceSetters = {};
935+
final Map<String, ElementImpl> staticGetters = {};
936+
final Map<String, ElementImpl> staticSetters = {};
940937
}

pkg/analyzer/lib/src/summary2/bundle_writer.dart

+1-2
Original file line numberDiff line numberDiff line change
@@ -1006,8 +1006,7 @@ class ResolutionSink extends _SummaryDataWriter {
10061006

10071007
var enclosing = declaration.enclosingElement3;
10081008
if (enclosing is InstanceElement) {
1009-
var typeParameters =
1010-
(enclosing.asElement2! as InstanceElement2).typeParameters2;
1009+
var typeParameters = enclosing.asElement2.typeParameters2;
10111010
if (typeParameters.isEmpty) {
10121011
return const <DartType>[];
10131012
}

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

+18
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,12 @@ extension ExtensionElementExtension on ExtensionElement {
409409
}
410410
}
411411

412+
extension ExtensionElementImplExtension on ExtensionElementImpl {
413+
ExtensionElementImpl2 get asElement2 {
414+
return element;
415+
}
416+
}
417+
412418
extension ExtensionTypeElement2Extension on ExtensionTypeElement2 {
413419
ExtensionTypeElement get asElement {
414420
return firstFragment as ExtensionTypeElement;
@@ -487,6 +493,18 @@ extension InstanceElement2Extension on InstanceElement2 {
487493
}
488494
}
489495

496+
extension InstanceElementExtension on InstanceElement {
497+
InstanceElement2 get asElement2 {
498+
return (this as InstanceElementImpl).element;
499+
}
500+
}
501+
502+
extension InstanceElementImplExtension on InstanceElementImpl {
503+
InstanceElementImpl2 get asElement2 {
504+
return element;
505+
}
506+
}
507+
490508
extension InterfaceElement2Extension on InterfaceElement2 {
491509
InterfaceElement get asElement {
492510
return firstFragment as InterfaceElement;

0 commit comments

Comments
 (0)