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) {

lib/src/model/model_function.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class ModelFunctionTypedef extends ModelFunctionTyped {
2929
ModelFunctionTypedef(super.element, super.library, super.packageGraph);
3030

3131
@override
32-
String get name => element.enclosingElement!.name!;
32+
String get name => element.enclosingElement3!.name!;
3333
}
3434

3535
class ModelFunctionTyped extends ModelElement with TypeParameters {

lib/src/model/package_graph.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ class PackageGraph with CommentReferable, Nameable {
778778
lib = preferredClass.canonicalLibrary;
779779
}
780780
// For elements defined in extensions, they are canonical.
781-
var enclosingElement = element.enclosingElement;
781+
var enclosingElement = element.enclosingElement3;
782782
if (enclosingElement is ExtensionElement) {
783783
lib ??= getModelForElement(enclosingElement.library) as Library?;
784784
// TODO(keertip): Find a better way to exclude members of extensions

lib/src/model/parameter.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Parameter extends ModelElement with HasNoPage {
2020

2121
@override
2222
ModelElement? get enclosingElement {
23-
final enclosingElement = element.enclosingElement;
23+
final enclosingElement = element.enclosingElement3;
2424
return enclosingElement == null
2525
? null
2626
: getModelFor(enclosingElement, library);
@@ -36,7 +36,7 @@ class Parameter extends ModelElement with HasNoPage {
3636

3737
@override
3838
String get htmlId {
39-
final enclosingElement = element.enclosingElement;
39+
final enclosingElement = element.enclosingElement3;
4040
if (enclosingElement == null) {
4141
return 'param-$name';
4242
}
@@ -46,8 +46,8 @@ class Parameter extends ModelElement with HasNoPage {
4646
// name. Also, allowing null here is allowed as a workaround for
4747
// dart-lang/sdk#32005.
4848
for (Element e = enclosingElement;
49-
e.enclosingElement != null;
50-
e = e.enclosingElement!) {
49+
e.enclosingElement3 != null;
50+
e = e.enclosingElement3!) {
5151
enclosingName = e.name;
5252
if (enclosingName != null && enclosingName.isNotEmpty) break;
5353
}

lib/src/model/type_parameter.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class TypeParameter extends ModelElement with HasNoPage {
1515

1616
@override
1717
ModelElement get enclosingElement =>
18-
getModelFor(element.enclosingElement!, library);
18+
getModelFor(element.enclosingElement3!, library);
1919

2020
/// [TypeParameter]s don't have documentation pages, and don't link to the
2121
/// element on which they are declared.

lib/src/model_utils.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ extension ElementExtension on Element {
6666
// GenericFunctionTypeElements have the name we care about in the enclosing
6767
// element.
6868
if (self is GenericFunctionTypeElement) {
69-
var enclosingElementName = self.enclosingElement?.name;
69+
var enclosingElementName = self.enclosingElement3?.name;
7070
if (enclosingElementName != null &&
7171
enclosingElementName.startsWith('_')) {
7272
return true;

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ environment:
77
sdk: ^3.2.0
88

99
dependencies:
10-
analyzer: ^6.5.0
10+
analyzer: ^6.9.0
1111
args: ^2.4.1
1212
collection: ^1.17.0
1313
crypto: ^3.0.3

test/end2end/model_test.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,13 +1083,13 @@ void main() async {
10831083
});
10841084

10851085
test('Verify behavior of imperfect resolver', () {
1086-
expect(aImplementingThingy.element.enclosingElement,
1086+
expect(aImplementingThingy.element.enclosingElement3,
10871087
equals(BaseThingy2.element));
1088-
expect(aImplementingThingyMethod.element.enclosingElement,
1088+
expect(aImplementingThingyMethod.element.enclosingElement3,
10891089
equals(BaseThingy.element));
1090-
expect(aImplementingThingyField.element.enclosingElement,
1090+
expect(aImplementingThingyField.element.enclosingElement3,
10911091
equals(BaseThingy.element));
1092-
expect(aImplementingThingyAccessor.element.enclosingElement,
1092+
expect(aImplementingThingyAccessor.element.enclosingElement3,
10931093
equals(BaseThingy.element));
10941094
});
10951095
});
@@ -1698,7 +1698,7 @@ void main() async {
16981698
fakeLibrary.classes.wherePublic.named('MIEEMixinWithOverride');
16991699
var problematicOperator =
17001700
MIEEMixinWithOverride.inheritedOperators.named('operator []=');
1701-
expect(problematicOperator.element.enclosingElement.name,
1701+
expect(problematicOperator.element.enclosingElement3.name,
17021702
equals('_MIEEPrivateOverride'));
17031703
expect(problematicOperator.canonicalModelElement!.enclosingElement!.name,
17041704
equals('MIEEMixinWithOverride'));

tool/mustachio/builder.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Future<void> build(
4747
var typeSystem = library.typeSystem;
4848
var rendererSpecs = <RendererSpec>{};
4949
for (var renderer in library.metadata
50-
.where((e) => e.element!.enclosingElement!.name == 'Renderer')) {
50+
.where((e) => e.element!.enclosingElement3!.name == 'Renderer')) {
5151
rendererSpecs.add(_buildRendererSpec(renderer));
5252
}
5353

0 commit comments

Comments
 (0)