Skip to content

Commit 22fe194

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Migrate ThisLookup and LexicalLookup.
Change-Id: I29d36ed43907871a0ffed8bd71619ef55a336530 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/404240 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Phil Quitslund <[email protected]>
1 parent 0f82db5 commit 22fe194

File tree

5 files changed

+71
-46
lines changed

5 files changed

+71
-46
lines changed

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

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,6 +1661,11 @@ class ConstructorElementImpl2 extends ExecutableElementImpl2
16611661
@override
16621662
ElementKind get kind => ElementKind.CONSTRUCTOR;
16631663

1664+
@override
1665+
ConstructorElementImpl get lastFragment {
1666+
return super.lastFragment as ConstructorElementImpl;
1667+
}
1668+
16641669
@override
16651670
Element2 get nonSynthetic2 {
16661671
if (isSynthetic) {
@@ -3855,6 +3860,17 @@ abstract class ExecutableElementImpl2 extends FunctionTypedElementImpl2
38553860
return firstFragment.hasModifier(Modifier.INVOKES_SUPER_SELF);
38563861
}
38573862

3863+
ExecutableElementImpl get lastFragment {
3864+
var result = firstFragment as ExecutableElementImpl;
3865+
while (true) {
3866+
if (result.nextFragment case ExecutableElementImpl nextFragment) {
3867+
result = nextFragment;
3868+
} else {
3869+
return result;
3870+
}
3871+
}
3872+
}
3873+
38583874
@override
38593875
LibraryElement2 get library2 {
38603876
var firstFragment = this.firstFragment as ExecutableElementImpl;
@@ -5601,9 +5617,7 @@ abstract class InstanceElementImpl2 extends ElementImpl2
56015617

56025618
@override
56035619
List<TypeParameterElementImpl2> get typeParameters2 =>
5604-
firstFragment.typeParameters
5605-
.map((fragment) => fragment.element)
5606-
.toList();
5620+
firstFragment.typeParameters.map((fragment) => fragment.element).toList();
56075621

56085622
@override
56095623
String displayString2(
@@ -8124,6 +8138,11 @@ class MethodElementImpl2 extends ExecutableElementImpl2
81248138
@override
81258139
ElementKind get kind => ElementKind.METHOD;
81268140

8141+
@override
8142+
MethodElementImpl get lastFragment {
8143+
return super.lastFragment as MethodElementImpl;
8144+
}
8145+
81278146
@override
81288147
String? get lookupName {
81298148
if (name3 == '-' && formalParameters.isEmpty) {
@@ -9762,6 +9781,11 @@ abstract class PropertyAccessorElementImpl2 extends ExecutableElementImpl2
97629781
@override
97639782
bool get isExternal => firstFragment.isExternal;
97649783

9784+
@override
9785+
PropertyAccessorElementImpl get lastFragment {
9786+
return super.lastFragment as PropertyAccessorElementImpl;
9787+
}
9788+
97659789
@override
97669790
String? get name3 => firstFragment.name2;
97679791

@@ -10320,6 +10344,11 @@ class TopLevelFunctionElementImpl extends ExecutableElementImpl2
1032010344
@override
1032110345
ElementKind get kind => ElementKind.FUNCTION;
1032210346

10347+
@override
10348+
FunctionElementImpl get lastFragment {
10349+
return super.lastFragment as FunctionElementImpl;
10350+
}
10351+
1032310352
@override
1032410353
LibraryElement2 get library2 {
1032510354
return firstFragment.library2!;

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
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-
7-
import 'package:analyzer/dart/element/element.dart';
5+
import 'package:analyzer/dart/element/element2.dart';
86
import 'package:analyzer/dart/element/scope.dart';
97
import 'package:analyzer/dart/element/type.dart';
108
import 'package:analyzer/src/dart/element/extensions.dart';
@@ -21,8 +19,8 @@ class LexicalLookup {
2119
/// a getter. If a matching element is found, a [LexicalLookupResult] is
2220
/// returned. Otherwise `null` is returned.
2321
static LexicalLookupResult? resolveGetter(ScopeLookupResult scopeResult) {
24-
var scopeGetter = scopeResult.getter;
25-
var scopeSetter = scopeResult.setter;
22+
var scopeGetter = scopeResult.getter2;
23+
var scopeSetter = scopeResult.setter2;
2624
if (scopeGetter != null || scopeSetter != null) {
2725
if (scopeGetter != null) {
2826
return LexicalLookupResult(requested: scopeGetter);
@@ -39,10 +37,10 @@ class LexicalLookup {
3937
/// a setter. If a matching element is found, a [LexicalLookupResult] is
4038
/// returned. Otherwise `null` is returned.
4139
static LexicalLookupResult? resolveSetter(ScopeLookupResult scopeResult) {
42-
var scopeGetter = scopeResult.getter;
43-
var scopeSetter = scopeResult.setter;
40+
var scopeGetter = scopeResult.getter2;
41+
var scopeSetter = scopeResult.setter2;
4442
if (scopeGetter != null || scopeSetter != null) {
45-
if (scopeGetter is VariableElement) {
43+
if (scopeGetter is VariableElement2) {
4644
return LexicalLookupResult(requested: scopeGetter);
4745
}
4846
if (scopeSetter != null) {
@@ -58,8 +56,8 @@ class LexicalLookup {
5856
}
5957

6058
class LexicalLookupResult {
61-
final Element? requested;
62-
final Element? recovery;
59+
final Element2? requested;
60+
final Element2? recovery;
6361

6462
/// The type, usually [FunctionType] referenced with `call`.
6563
final DartType? callFunctionType;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ class PropertyElementResolver with ScopeHelpers {
266266
);
267267
}
268268

269-
readElementRequested = readLookup?.requested;
269+
readElementRequested = readLookup?.requested.asElement;
270270
if (readElementRequested is PropertyAccessorElement &&
271271
!readElementRequested.isStatic) {
272272
var unpromotedType = readElementRequested.returnType;
@@ -285,8 +285,8 @@ class PropertyElementResolver with ScopeHelpers {
285285
if (hasWrite) {
286286
var writeLookup = LexicalLookup.resolveSetter(scopeLookupResult) ??
287287
_resolver.thisLookupSetter(node);
288-
writeElementRequested = writeLookup?.requested;
289-
writeElementRecovery = writeLookup?.recovery;
288+
writeElementRequested = writeLookup?.requested.asElement;
289+
writeElementRecovery = writeLookup?.recovery.asElement;
290290

291291
AssignmentVerifier(errorReporter).verify(
292292
node: node,

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
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/ast/ast.dart';
86
import 'package:analyzer/src/dart/resolver/lexical_lookup.dart';
97
import 'package:analyzer/src/generated/resolver.dart';
@@ -51,11 +49,11 @@ class ThisLookup {
5149
);
5250
}
5351

54-
var getterElement = propertyResult.getter;
52+
var getterElement = propertyResult.getter2;
5553
if (getterElement != null) {
5654
return LexicalLookupResult(requested: getterElement);
5755
} else {
58-
return LexicalLookupResult(recovery: propertyResult.setter);
56+
return LexicalLookupResult(recovery: propertyResult.setter2);
5957
}
6058
}
6159

@@ -80,11 +78,11 @@ class ThisLookup {
8078
nameErrorEntity: node,
8179
);
8280

83-
var setterElement = propertyResult.setter;
81+
var setterElement = propertyResult.setter2;
8482
if (setterElement != null) {
8583
return LexicalLookupResult(requested: setterElement);
8684
} else {
87-
return LexicalLookupResult(recovery: propertyResult.getter);
85+
return LexicalLookupResult(recovery: propertyResult.getter2);
8886
}
8987
}
9088
}

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

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ extension ConstructorElement2Extension on ConstructorElement2 {
5151
if (this case ConstructorMember member) {
5252
return member;
5353
}
54-
return baseElement.firstFragment as ConstructorElement;
54+
return (this as ConstructorElementImpl2).lastFragment;
5555
}
5656
}
5757

@@ -142,46 +142,46 @@ extension Element2OrNullExtension on Element2? {
142142
switch (self) {
143143
case null:
144144
return null;
145-
case ConstructorElementImpl2():
146-
return self.firstFragment as Element;
145+
case ConstructorElementImpl2 element2:
146+
return element2.asElement;
147147
case DynamicElementImpl2():
148148
return self.firstFragment;
149-
case ExecutableMember():
150-
return self.declaration as Element;
151-
case ExtensionElementImpl2():
152-
return self.firstFragment as Element;
153-
case FieldElementImpl2():
154-
return self.firstFragment as Element;
149+
case ExecutableMember element2:
150+
return element2.asElement;
151+
case ExtensionElementImpl2 element2:
152+
return element2.asElement;
153+
case FieldElementImpl2 element2:
154+
return element2.asElement;
155155
case FieldMember():
156156
return self.declaration as Element;
157157
case FormalParameterElement element2:
158158
return element2.asElement;
159-
case GetterElementImpl():
160-
return self.firstFragment as Element;
159+
case GetterElementImpl element2:
160+
return element2.asElement;
161161
case LabelElementImpl2 element2:
162162
return element2.asElement;
163163
case LibraryElementImpl():
164164
return self as Element;
165165
case LibraryImportElementImpl():
166166
return self as Element;
167-
case LocalFunctionElementImpl():
168-
return self.wrappedElement as Element;
167+
case LocalFunctionElementImpl element2:
168+
return element2.asElement;
169169
case LocalVariableElementImpl2():
170170
return self.wrappedElement as Element;
171-
case MethodElementImpl2():
172-
return self.firstFragment as Element;
171+
case MethodElementImpl2 element2:
172+
return element2.asElement;
173173
case MultiplyDefinedElementImpl2 element2:
174174
return element2.asElement;
175175
case NeverElementImpl2():
176176
return NeverElementImpl.instance;
177177
case PrefixElement2 element2:
178178
return element2.asElement;
179-
case SetterElementImpl():
180-
return self.firstFragment as Element;
181-
case TopLevelFunctionElementImpl():
182-
return self.firstFragment as Element;
183-
case TopLevelVariableElementImpl2():
184-
return self.firstFragment as Element;
179+
case SetterElementImpl element2:
180+
return element2.asElement;
181+
case TopLevelFunctionElementImpl element2:
182+
return element2.asElement;
183+
case TopLevelVariableElementImpl2 element2:
184+
return element2.asElement;
185185
case TypeDefiningElement2():
186186
return self.firstFragment as Element;
187187
default:
@@ -454,7 +454,7 @@ extension MethodElement2Extension on MethodElement2 {
454454
if (this case MethodMember member) {
455455
return member;
456456
}
457-
return baseElement.firstFragment as MethodElement;
457+
return (this as MethodElementImpl2).lastFragment;
458458
}
459459
}
460460

@@ -511,7 +511,7 @@ extension PropertyAccessorElement2Extension on PropertyAccessorElement2 {
511511
if (this case PropertyAccessorMember member) {
512512
return member;
513513
}
514-
return firstFragment as PropertyAccessorElement;
514+
return (this as PropertyAccessorElementImpl2).lastFragment;
515515
}
516516
}
517517

@@ -527,7 +527,7 @@ extension PropertyAccessorElementExtension on PropertyAccessorElement {
527527

528528
extension TopLevelFunctionElementExtension on TopLevelFunctionElement {
529529
FunctionElement get asElement {
530-
return firstFragment as FunctionElement;
530+
return (this as TopLevelFunctionElementImpl).lastFragment;
531531
}
532532
}
533533

0 commit comments

Comments
 (0)