Skip to content

Commit 4f5b40c

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Migrate BundleReader.
Change-Id: I8a8c4b81e08a1c9c1ed7b0205bffc1249efbe4be Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/417940 Reviewed-by: Paul Berry <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent ffd08a3 commit 4f5b40c

File tree

4 files changed

+45
-50
lines changed

4 files changed

+45
-50
lines changed

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1709,6 +1709,9 @@ mixin ConstructorElementMixin
17091709
@override
17101710
ConstructorElementImpl get declaration;
17111711

1712+
@override
1713+
InterfaceElementImpl get enclosingElement3;
1714+
17121715
@override
17131716
bool get isDefaultConstructor {
17141717
// unnamed
@@ -2619,7 +2622,7 @@ abstract class ElementImpl implements Element, ElementOrMember {
26192622
}
26202623

26212624
@override
2622-
Element? get enclosingElement3 => _enclosingElement3;
2625+
ElementImpl? get enclosingElement3 => _enclosingElement3;
26232626

26242627
/// Set the enclosing element of this element to the given [element].
26252628
set enclosingElement3(Element? element) {
@@ -3629,7 +3632,7 @@ abstract class ExecutableElementImpl extends _ExistingElementImpl
36293632
ExecutableElementImpl2 get element;
36303633

36313634
@override
3632-
Element get enclosingElement3 {
3635+
ElementImpl get enclosingElement3 {
36333636
return super.enclosingElement3!;
36343637
}
36353638

@@ -6784,8 +6787,8 @@ class LabelElementImpl extends ElementImpl
67846787
LabelElement2 get element => element2;
67856788

67866789
@override
6787-
ExecutableElement get enclosingElement3 =>
6788-
super.enclosingElement3 as ExecutableElement;
6790+
ExecutableElementImpl get enclosingElement3 =>
6791+
super.enclosingElement3 as ExecutableElementImpl;
67896792

67906793
@override
67916794
ExecutableFragment get enclosingFragment =>
@@ -9924,11 +9927,6 @@ sealed class PropertyAccessorElementImpl extends ExecutableElementImpl
99249927
@override
99259928
PropertyAccessorElementImpl2 get element;
99269929

9927-
@override
9928-
ElementImpl get enclosingElement3 {
9929-
return super.enclosingElement3 as ElementImpl;
9930-
}
9931-
99329930
@override
99339931
Fragment get enclosingFragment {
99349932
var enclosing = enclosingElement3;
@@ -10981,8 +10979,8 @@ class TypeAliasElementImpl extends _ExistingElementImpl
1098110979
String get displayName => name;
1098210980

1098310981
@override
10984-
CompilationUnitElement get enclosingElement3 =>
10985-
super.enclosingElement3 as CompilationUnitElement;
10982+
CompilationUnitElementImpl get enclosingElement3 =>
10983+
super.enclosingElement3 as CompilationUnitElementImpl;
1098610984

1098710985
@override
1098810986
LibraryFragment? get enclosingFragment =>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class ConstructorMember extends ExecutableMember
4848
InterfaceElementImpl2 get enclosingElement2 => _element2.enclosingElement2;
4949

5050
@override
51-
InterfaceElement get enclosingElement3 => declaration.enclosingElement3;
51+
InterfaceElementImpl get enclosingElement3 => declaration.enclosingElement3;
5252

5353
@override
5454
ConstructorFragment get firstFragment => _element2.firstFragment;

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

Lines changed: 34 additions & 37 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 'dart:typed_data';
86

97
import 'package:_fe_analyzer_shared/src/type_inference/type_analyzer_operations.dart';
@@ -276,7 +274,7 @@ abstract class ElementLinkedData<E extends ElementImpl> {
276274
}
277275

278276
/// Ensure that all members of the [element] are available. This includes
279-
/// being able to ask them for example using [ClassElement.methods], and
277+
/// being able to ask them for example using [ClassElement2.methods2], and
280278
/// as well access them through their [Reference]s. For a class declaration
281279
/// this means reading them, for a named mixin application this means
282280
/// computing constructors.
@@ -287,15 +285,15 @@ abstract class ElementLinkedData<E extends ElementImpl> {
287285
ElementImpl element,
288286
) {
289287
var enclosing = element.enclosingElement3;
290-
if (enclosing is InstanceElement) {
288+
if (enclosing is InstanceElementImpl) {
291289
reader._addTypeParameters(enclosing.typeParameters);
292-
} else if (enclosing is CompilationUnitElement) {
290+
} else if (enclosing is CompilationUnitElementImpl) {
293291
// Nothing.
294-
} else if (enclosing is EnumElement) {
292+
} else if (enclosing is EnumElementImpl) {
295293
reader._addTypeParameters(enclosing.typeParameters);
296-
} else if (enclosing is ExtensionElement) {
294+
} else if (enclosing is ExtensionElementImpl) {
297295
reader._addTypeParameters(enclosing.typeParameters);
298-
} else if (enclosing is MixinElement) {
296+
} else if (enclosing is MixinElementImpl) {
299297
reader._addTypeParameters(enclosing.typeParameters);
300298
} else {
301299
throw UnimplementedError('${enclosing.runtimeType}');
@@ -308,10 +306,9 @@ abstract class ElementLinkedData<E extends ElementImpl> {
308306

309307
void _readFormalParameters(
310308
ResolutionReader reader,
311-
List<ParameterElement> parameters,
309+
List<ParameterElementImpl> parameters,
312310
) {
313311
for (var parameter in parameters) {
314-
parameter as ParameterElementImpl;
315312
parameter.metadata = reader._readAnnotationList(
316313
unitElement: unitElement,
317314
);
@@ -333,11 +330,10 @@ abstract class ElementLinkedData<E extends ElementImpl> {
333330

334331
void _readTypeParameters(
335332
ResolutionReader reader,
336-
List<TypeParameterElement> typeParameters,
333+
List<TypeParameterElementImpl> typeParameters,
337334
) {
338335
reader._addTypeParameters(typeParameters);
339336
for (var typeParameter in typeParameters) {
340-
typeParameter as TypeParameterElementImpl;
341337
typeParameter.metadata = reader._readAnnotationList(
342338
unitElement: unitElement,
343339
);
@@ -1126,10 +1122,10 @@ class LibraryReader {
11261122
CompilationUnitElementImpl unitElement,
11271123
ElementImpl classElement,
11281124
Reference classReference,
1129-
List<PropertyAccessorElement> accessors,
1130-
List<FieldElement> variables,
1125+
List<PropertyAccessorElementImpl> accessors,
1126+
List<FieldElementImpl> variables,
11311127
) {
1132-
var createdElements = <FieldElement>[];
1128+
var createdElements = <FieldElementImpl>[];
11331129
var variableElementCount = _reader.readUInt30();
11341130
for (var i = 0; i < variableElementCount; i++) {
11351131
var variable =
@@ -1520,8 +1516,8 @@ class LibraryReader {
15201516
CompilationUnitElementImpl unitElement,
15211517
ElementImpl enclosingElement,
15221518
Reference enclosingReference,
1523-
List<PropertyAccessorElement> accessorFragments,
1524-
List<PropertyInducingElement> propertyFragments,
1519+
List<PropertyAccessorElementImpl> accessorFragments,
1520+
List<PropertyInducingElementImpl> propertyFragments,
15251521
String containerRefName, {
15261522
List<TopLevelVariableElementImpl2>? variables2,
15271523
}) {
@@ -1545,7 +1541,7 @@ class LibraryReader {
15451541

15461542
var name = accessor.displayName;
15471543

1548-
bool canUseExisting(PropertyInducingElement property) {
1544+
bool canUseExisting(PropertyInducingElementImpl property) {
15491545
return property.isSynthetic ||
15501546
accessor.isSetter && property.setter == null;
15511547
}
@@ -1949,12 +1945,12 @@ class ResolutionReader {
19491945
final _ReferenceReader _referenceReader;
19501946
final SummaryDataReader _reader;
19511947

1952-
/// The stack of [TypeParameterElement]s and [ParameterElement] that are
1948+
/// The stack of [TypeParameterElementImpl]s and [ParameterElementImpl] that are
19531949
/// available in the scope of [readElement] and [readType].
19541950
///
19551951
/// This stack is shared with the client of the reader, and update mostly
19561952
/// by the client. However it is also updated during [_readFunctionType].
1957-
final List<Element> _localElements = [];
1953+
final List<ElementImpl> _localElements = [];
19581954

19591955
ResolutionReader(
19601956
this._elementFactory,
@@ -1987,7 +1983,7 @@ class ResolutionReader {
19871983
}
19881984

19891985
if (memberFlags == Tag.RawElement) {
1990-
return element as ElementOrMember;
1986+
return element;
19911987
}
19921988

19931989
if (memberFlags == Tag.MemberWithTypeArguments) {
@@ -2006,28 +2002,29 @@ class ResolutionReader {
20062002
);
20072003
}
20082004

2009-
if (element is ExecutableElementOrMember) {
2010-
element = ExecutableMember.from2(element, substitution);
2005+
if (element is ExecutableElementImpl) {
2006+
return ExecutableMember.from2(element, substitution);
20112007
} else {
20122008
element as FieldElementImpl;
2013-
element = FieldMember.from2(element, substitution);
2009+
return FieldMember.from2(element, substitution);
20142010
}
20152011
}
20162012

2017-
if (memberFlags == Tag.MemberWithTypeArguments) {
2018-
return element as ElementOrMember;
2019-
}
2020-
20212013
throw UnimplementedError('memberFlags: $memberFlags');
20222014
}
20232015

20242016
Element2? readElement2() {
2025-
var element = readElement() as Element?;
2026-
return element?.asElement2;
2027-
}
2028-
2029-
List<T> readElementList<T extends Element>() {
2030-
return _reader.readTypedListCast<T>(readElement);
2017+
var element = readElement();
2018+
switch (element) {
2019+
case null:
2020+
return null;
2021+
case ElementImpl():
2022+
return element.asElement2;
2023+
case ExecutableMember():
2024+
return element;
2025+
default:
2026+
throw UnimplementedError('${element.runtimeType}');
2027+
}
20312028
}
20322029

20332030
List<T> readElementList2<T extends Element2>() {
@@ -2157,13 +2154,13 @@ class ResolutionReader {
21572154
_reader.offset = offset;
21582155
}
21592156

2160-
void _addFormalParameters(List<ParameterElement> parameters) {
2157+
void _addFormalParameters(List<ParameterElementImpl> parameters) {
21612158
for (var parameter in parameters) {
21622159
_localElements.add(parameter);
21632160
}
21642161
}
21652162

2166-
void _addTypeParameters(List<TypeParameterElement> typeParameters) {
2163+
void _addTypeParameters(List<TypeParameterElementImpl> typeParameters) {
21672164
for (var typeParameter in typeParameters) {
21682165
_localElements.add(typeParameter);
21692166
}
@@ -2368,7 +2365,7 @@ class ResolutionReader {
23682365
return readType() as InterfaceType?;
23692366
}
23702367

2371-
Element? _readRawElement() {
2368+
ElementImpl? _readRawElement() {
23722369
var index = _reader.readUInt30();
23732370

23742371
if ((index & 0x1) == 0x1) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ extension Element2OrNullExtension on Element2? {
275275
}
276276

277277
extension ElementImplExtension on ElementImpl {
278-
ElementImpl? get enclosingElementImpl => enclosingElement3 as ElementImpl?;
278+
ElementImpl? get enclosingElementImpl => enclosingElement3;
279279

280280
AnnotationImpl annotationAst(int index) {
281281
return metadata[index].annotationAst;

0 commit comments

Comments
 (0)