Skip to content

Commit 2a26281

Browse files
authored
Comply with analyzer 6.9.0 APIs (#3874)
1 parent ca98b89 commit 2a26281

18 files changed

+52
-52
lines changed

.github/workflows/test.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ jobs:
2222
fail-fast: false
2323
matrix:
2424
os: [ubuntu-latest]
25-
sdk: [dev, stable]
25+
# TODO(srawlins): Re-enable stable when stable works with analyzer 6.9.0
26+
# (Dart 3.6.0).
27+
sdk: [dev]
2628
job: [main, flutter, packages, sdk-docs]
2729
include:
2830
- os: macos-latest

lib/src/model/accessor.dart

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,11 @@ class Accessor extends ModelElement {
115115
}
116116

117117
@override
118-
ModelElement get enclosingElement {
119-
if (element.enclosingElement is CompilationUnitElement) {
120-
return getModelForElement(element.enclosingElement.enclosingElement!);
121-
}
122-
123-
return getModelFor(element.enclosingElement, library);
124-
}
118+
ModelElement get enclosingElement => switch (element.enclosingElement3) {
119+
CompilationUnitElement enclosingCompilationUnit =>
120+
getModelForElement(enclosingCompilationUnit.library),
121+
_ => getModelFor(element.enclosingElement3, library)
122+
};
125123

126124
@override
127125
String get filePath => enclosingCombo.filePath;
@@ -207,7 +205,7 @@ class ContainerAccessor extends Accessor with ContainerMember, Inheritable {
207205
@override
208206
ContainerAccessor? get overriddenElement {
209207
assert(packageGraph.allLibrariesAdded);
210-
final parent = element.enclosingElement;
208+
final parent = element.enclosingElement3;
211209
if (parent is! InterfaceElement) {
212210
return null;
213211
}

lib/src/model/constructor.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Constructor extends ModelElement with ContainerMember, TypeParameters {
3030
bool get isPublic {
3131
if (!super.isPublic) return false;
3232
if (element.hasPrivateName) return false;
33-
var class_ = element.enclosingElement;
33+
var class_ = element.enclosingElement3;
3434
// Enums cannot be explicitly constructed or extended.
3535
if (class_ is EnumElement) return false;
3636
if (class_ is ClassElement) {
@@ -53,7 +53,7 @@ class Constructor extends ModelElement with ContainerMember, TypeParameters {
5353

5454
@override
5555
Container get enclosingElement =>
56-
getModelFor(element.enclosingElement, library) as Container;
56+
getModelFor(element.enclosingElement3, library) as Container;
5757

5858
@override
5959
String get aboveSidebarPath => enclosingElement.sidebarPath;
@@ -108,7 +108,7 @@ class Constructor extends ModelElement with ContainerMember, TypeParameters {
108108

109109
String? get shortName {
110110
if (name.contains('.')) {
111-
return name.substring(element.enclosingElement.name.length + 1);
111+
return name.substring(element.enclosingElement3.name.length + 1);
112112
} else {
113113
return name;
114114
}

lib/src/model/container_member.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ mixin ContainerMember on ModelElement {
2929
@protected
3030
@visibleForTesting
3131
late final Container definingEnclosingContainer =
32-
getModelForElement(element.enclosingElement!) as Container;
32+
getModelForElement(element.enclosingElement3!) as Container;
3333

3434
@override
3535
Set<Attribute> get attributes => {

lib/src/model/enum.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class EnumField extends Field {
8585

8686
@override
8787
bool get hasConstantValueForDisplay {
88-
final enum_ = element.enclosingElement as EnumElement;
88+
final enum_ = element.enclosingElement3 as EnumElement;
8989
final enumHasDefaultConstructor =
9090
enum_.constructors.any((c) => c.isDefaultConstructor);
9191
// If this enum does not have any explicit constructors (and so only has a

lib/src/model/extension.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class Extension extends Container {
116116
late final List<TypeParameter> typeParameters = element.typeParameters
117117
.map((typeParameter) => getModelFor(
118118
typeParameter,
119-
getModelForElement(typeParameter.enclosingElement!.library!)
119+
getModelForElement(typeParameter.enclosingElement3!.library!)
120120
as Library) as TypeParameter)
121121
.toList(growable: false);
122122

lib/src/model/field.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Field extends ModelElement
3333
this.setter,
3434
) : isInherited = false,
3535
enclosingElement =
36-
ModelElement.for_(element.enclosingElement, library, packageGraph)
36+
ModelElement.for_(element.enclosingElement3, library, packageGraph)
3737
as Container,
3838
assert(getter != null || setter != null) {
3939
getter?.enclosingCombo = this;
@@ -126,7 +126,7 @@ class Field extends ModelElement
126126
element.isAbstract ? 'abstract $kind' : kind.toString();
127127

128128
bool get isProvidedByExtension =>
129-
element.enclosingElement is ExtensionElement;
129+
element.enclosingElement3 is ExtensionElement;
130130

131131
/// The [enclosingElement], which is expected to be an [Extension].
132132
Extension get enclosingExtension => enclosingElement as Extension;

lib/src/model/inheriting_container.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ abstract class InheritingContainer extends Container {
173173
// Elements in the inheritance chain starting from `this.element` up to,
174174
// but not including, `Object`.
175175
var enclosingElement =
176-
inheritedElement.enclosingElement as InterfaceElement;
176+
inheritedElement.enclosingElement3 as InterfaceElement;
177177
assert(inheritanceChainElements.contains(enclosingElement) ||
178178
enclosingElement.isDartCoreObject);
179179

@@ -183,7 +183,7 @@ abstract class InheritingContainer extends Container {
183183
// accounts for intermediate abstract classes that have method/field
184184
// implementations.
185185
var enclosingElementFromCombined =
186-
combinedMapElement.enclosingElement as InterfaceElement;
186+
combinedMapElement.enclosingElement3 as InterfaceElement;
187187
if (inheritanceChainElements.indexOf(enclosingElementFromCombined) <
188188
inheritanceChainElements.indexOf(enclosingElement)) {
189189
combinedMap[name.name] = inheritedElement;
@@ -257,7 +257,7 @@ abstract class InheritingContainer extends Container {
257257
late final List<TypeParameter> typeParameters = element.typeParameters
258258
.map((typeParameter) => getModelFor(
259259
typeParameter,
260-
getModelForElement(typeParameter.enclosingElement!.library!)
260+
getModelForElement(typeParameter.enclosingElement3!.library!)
261261
as Library) as TypeParameter)
262262
.toList(growable: false);
263263

lib/src/model/method.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class Method extends ModelElement
6666

6767
@override
6868
Container get enclosingElement => _enclosingContainer ??=
69-
getModelFor(element.enclosingElement, library) as Container;
69+
getModelFor(element.enclosingElement3, library) as Container;
7070

7171
@override
7272
String get aboveSidebarPath => enclosingElement.sidebarPath;
@@ -94,7 +94,7 @@ class Method extends ModelElement
9494
bool get isOperator => false;
9595

9696
bool get isProvidedByExtension =>
97-
element.enclosingElement is ExtensionElement;
97+
element.enclosingElement3 is ExtensionElement;
9898

9999
/// The [enclosingElement], which is expected to be an [Extension].
100100
Extension get enclosingExtension => enclosingElement as Extension;
@@ -120,17 +120,17 @@ class Method extends ModelElement
120120
@override
121121
Method? get overriddenElement {
122122
if (_enclosingContainer is Extension ||
123-
element.enclosingElement is ExtensionElement) {
123+
element.enclosingElement3 is ExtensionElement) {
124124
return null;
125125
}
126-
var parent = element.enclosingElement as InterfaceElement;
126+
var parent = element.enclosingElement3 as InterfaceElement;
127127
for (var t in parent.augmented.declaration.allSupertypes) {
128128
Element? e = t.getMethod(element.name);
129129
if (e != null) {
130130
assert(
131-
e.enclosingElement is InterfaceElement,
132-
'Expected "${e.enclosingElement?.name}" to be a InterfaceElement, '
133-
'but was ${e.enclosingElement.runtimeType}',
131+
e.enclosingElement3 is InterfaceElement,
132+
'Expected "${e.enclosingElement3?.name}" to be a InterfaceElement, '
133+
'but was ${e.enclosingElement3.runtimeType}',
134134
);
135135
return getModelForElement(e) as Method?;
136136
}

lib/src/model/model_element.dart

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ abstract class ModelElement
159159
var index = constantIndex.toIntValue()!;
160160
newModelElement =
161161
EnumField.forConstant(index, e, library, packageGraph, getter);
162-
} else if (e.enclosingElement is ExtensionElement) {
162+
} else if (e.enclosingElement3 is ExtensionElement) {
163163
newModelElement = Field(e, library, packageGraph,
164164
getter as ContainerAccessor?, setter as ContainerAccessor?);
165165
} else {
@@ -169,7 +169,7 @@ abstract class ModelElement
169169
} else {
170170
// Enum fields and extension getters can't be inherited, so this case is
171171
// simpler.
172-
if (e.enclosingElement is ExtensionElement) {
172+
if (e.enclosingElement3 is ExtensionElement) {
173173
newModelElement = Field.providedByExtension(
174174
e,
175175
enclosingContainer,
@@ -310,7 +310,7 @@ abstract class ModelElement
310310
MethodElement(isOperator: true) when enclosingContainer == null =>
311311
Operator(e, library, packageGraph),
312312
MethodElement(isOperator: true)
313-
when e.enclosingElement is ExtensionElement =>
313+
when e.enclosingElement3 is ExtensionElement =>
314314
Operator.providedByExtension(
315315
e, enclosingContainer, library, packageGraph),
316316
MethodElement(isOperator: true) => Operator.inherited(
@@ -319,7 +319,7 @@ abstract class ModelElement
319319
MethodElement(isOperator: false) when enclosingContainer == null =>
320320
Method(e, library, packageGraph),
321321
MethodElement(isOperator: false)
322-
when e.enclosingElement is ExtensionElement =>
322+
when e.enclosingElement3 is ExtensionElement =>
323323
Method.providedByExtension(
324324
e, enclosingContainer, library, packageGraph),
325325
MethodElement(isOperator: false) => Method.inherited(
@@ -348,8 +348,8 @@ abstract class ModelElement
348348
required Member? originalMember,
349349
}) {
350350
// Accessors can be part of a [Container], or a part of a [Library].
351-
if (e.enclosingElement is ExtensionElement ||
352-
e.enclosingElement is InterfaceElement ||
351+
if (e.enclosingElement3 is ExtensionElement ||
352+
e.enclosingElement3 is InterfaceElement ||
353353
e is MultiplyInheritedExecutableElement) {
354354
if (enclosingContainer == null || enclosingContainer is Extension) {
355355
return ContainerAccessor(e, library, packageGraph, enclosingContainer);
@@ -543,10 +543,10 @@ abstract class ModelElement
543543
// Since we're looking for a library, find the [Element] immediately
544544
// contained by a [CompilationUnitElement] in the tree.
545545
var topLevelElement = element;
546-
while (topLevelElement.enclosingElement is! LibraryElement &&
547-
topLevelElement.enclosingElement is! CompilationUnitElement &&
548-
topLevelElement.enclosingElement != null) {
549-
topLevelElement = topLevelElement.enclosingElement!;
546+
while (topLevelElement.enclosingElement3 is! LibraryElement &&
547+
topLevelElement.enclosingElement3 is! CompilationUnitElement &&
548+
topLevelElement.enclosingElement3 != null) {
549+
topLevelElement = topLevelElement.enclosingElement3!;
550550
}
551551
var topLevelElementName = topLevelElement.name;
552552
if (topLevelElementName == null) {

0 commit comments

Comments
 (0)