Skip to content

Commit

Permalink
Comply with analyzer 6.9.0 APIs (#3874)
Browse files Browse the repository at this point in the history
  • Loading branch information
srawlins authored Sep 10, 2024
1 parent ca98b89 commit 2a26281
Show file tree
Hide file tree
Showing 18 changed files with 52 additions and 52 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
sdk: [dev, stable]
# TODO(srawlins): Re-enable stable when stable works with analyzer 6.9.0
# (Dart 3.6.0).
sdk: [dev]
job: [main, flutter, packages, sdk-docs]
include:
- os: macos-latest
Expand Down
14 changes: 6 additions & 8 deletions lib/src/model/accessor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,11 @@ class Accessor extends ModelElement {
}

@override
ModelElement get enclosingElement {
if (element.enclosingElement is CompilationUnitElement) {
return getModelForElement(element.enclosingElement.enclosingElement!);
}

return getModelFor(element.enclosingElement, library);
}
ModelElement get enclosingElement => switch (element.enclosingElement3) {
CompilationUnitElement enclosingCompilationUnit =>
getModelForElement(enclosingCompilationUnit.library),
_ => getModelFor(element.enclosingElement3, library)
};

@override
String get filePath => enclosingCombo.filePath;
Expand Down Expand Up @@ -207,7 +205,7 @@ class ContainerAccessor extends Accessor with ContainerMember, Inheritable {
@override
ContainerAccessor? get overriddenElement {
assert(packageGraph.allLibrariesAdded);
final parent = element.enclosingElement;
final parent = element.enclosingElement3;
if (parent is! InterfaceElement) {
return null;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/src/model/constructor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Constructor extends ModelElement with ContainerMember, TypeParameters {
bool get isPublic {
if (!super.isPublic) return false;
if (element.hasPrivateName) return false;
var class_ = element.enclosingElement;
var class_ = element.enclosingElement3;
// Enums cannot be explicitly constructed or extended.
if (class_ is EnumElement) return false;
if (class_ is ClassElement) {
Expand All @@ -53,7 +53,7 @@ class Constructor extends ModelElement with ContainerMember, TypeParameters {

@override
Container get enclosingElement =>
getModelFor(element.enclosingElement, library) as Container;
getModelFor(element.enclosingElement3, library) as Container;

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

String? get shortName {
if (name.contains('.')) {
return name.substring(element.enclosingElement.name.length + 1);
return name.substring(element.enclosingElement3.name.length + 1);
} else {
return name;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/model/container_member.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ mixin ContainerMember on ModelElement {
@protected
@visibleForTesting
late final Container definingEnclosingContainer =
getModelForElement(element.enclosingElement!) as Container;
getModelForElement(element.enclosingElement3!) as Container;

@override
Set<Attribute> get attributes => {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/model/enum.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class EnumField extends Field {

@override
bool get hasConstantValueForDisplay {
final enum_ = element.enclosingElement as EnumElement;
final enum_ = element.enclosingElement3 as EnumElement;
final enumHasDefaultConstructor =
enum_.constructors.any((c) => c.isDefaultConstructor);
// If this enum does not have any explicit constructors (and so only has a
Expand Down
2 changes: 1 addition & 1 deletion lib/src/model/extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class Extension extends Container {
late final List<TypeParameter> typeParameters = element.typeParameters
.map((typeParameter) => getModelFor(
typeParameter,
getModelForElement(typeParameter.enclosingElement!.library!)
getModelForElement(typeParameter.enclosingElement3!.library!)
as Library) as TypeParameter)
.toList(growable: false);

Expand Down
4 changes: 2 additions & 2 deletions lib/src/model/field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Field extends ModelElement
this.setter,
) : isInherited = false,
enclosingElement =
ModelElement.for_(element.enclosingElement, library, packageGraph)
ModelElement.for_(element.enclosingElement3, library, packageGraph)
as Container,
assert(getter != null || setter != null) {
getter?.enclosingCombo = this;
Expand Down Expand Up @@ -126,7 +126,7 @@ class Field extends ModelElement
element.isAbstract ? 'abstract $kind' : kind.toString();

bool get isProvidedByExtension =>
element.enclosingElement is ExtensionElement;
element.enclosingElement3 is ExtensionElement;

/// The [enclosingElement], which is expected to be an [Extension].
Extension get enclosingExtension => enclosingElement as Extension;
Expand Down
6 changes: 3 additions & 3 deletions lib/src/model/inheriting_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ abstract class InheritingContainer extends Container {
// Elements in the inheritance chain starting from `this.element` up to,
// but not including, `Object`.
var enclosingElement =
inheritedElement.enclosingElement as InterfaceElement;
inheritedElement.enclosingElement3 as InterfaceElement;
assert(inheritanceChainElements.contains(enclosingElement) ||
enclosingElement.isDartCoreObject);

Expand All @@ -183,7 +183,7 @@ abstract class InheritingContainer extends Container {
// accounts for intermediate abstract classes that have method/field
// implementations.
var enclosingElementFromCombined =
combinedMapElement.enclosingElement as InterfaceElement;
combinedMapElement.enclosingElement3 as InterfaceElement;
if (inheritanceChainElements.indexOf(enclosingElementFromCombined) <
inheritanceChainElements.indexOf(enclosingElement)) {
combinedMap[name.name] = inheritedElement;
Expand Down Expand Up @@ -257,7 +257,7 @@ abstract class InheritingContainer extends Container {
late final List<TypeParameter> typeParameters = element.typeParameters
.map((typeParameter) => getModelFor(
typeParameter,
getModelForElement(typeParameter.enclosingElement!.library!)
getModelForElement(typeParameter.enclosingElement3!.library!)
as Library) as TypeParameter)
.toList(growable: false);

Expand Down
14 changes: 7 additions & 7 deletions lib/src/model/method.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Method extends ModelElement

@override
Container get enclosingElement => _enclosingContainer ??=
getModelFor(element.enclosingElement, library) as Container;
getModelFor(element.enclosingElement3, library) as Container;

@override
String get aboveSidebarPath => enclosingElement.sidebarPath;
Expand Down Expand Up @@ -94,7 +94,7 @@ class Method extends ModelElement
bool get isOperator => false;

bool get isProvidedByExtension =>
element.enclosingElement is ExtensionElement;
element.enclosingElement3 is ExtensionElement;

/// The [enclosingElement], which is expected to be an [Extension].
Extension get enclosingExtension => enclosingElement as Extension;
Expand All @@ -120,17 +120,17 @@ class Method extends ModelElement
@override
Method? get overriddenElement {
if (_enclosingContainer is Extension ||
element.enclosingElement is ExtensionElement) {
element.enclosingElement3 is ExtensionElement) {
return null;
}
var parent = element.enclosingElement as InterfaceElement;
var parent = element.enclosingElement3 as InterfaceElement;
for (var t in parent.augmented.declaration.allSupertypes) {
Element? e = t.getMethod(element.name);
if (e != null) {
assert(
e.enclosingElement is InterfaceElement,
'Expected "${e.enclosingElement?.name}" to be a InterfaceElement, '
'but was ${e.enclosingElement.runtimeType}',
e.enclosingElement3 is InterfaceElement,
'Expected "${e.enclosingElement3?.name}" to be a InterfaceElement, '
'but was ${e.enclosingElement3.runtimeType}',
);
return getModelForElement(e) as Method?;
}
Expand Down
20 changes: 10 additions & 10 deletions lib/src/model/model_element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ abstract class ModelElement
var index = constantIndex.toIntValue()!;
newModelElement =
EnumField.forConstant(index, e, library, packageGraph, getter);
} else if (e.enclosingElement is ExtensionElement) {
} else if (e.enclosingElement3 is ExtensionElement) {
newModelElement = Field(e, library, packageGraph,
getter as ContainerAccessor?, setter as ContainerAccessor?);
} else {
Expand All @@ -169,7 +169,7 @@ abstract class ModelElement
} else {
// Enum fields and extension getters can't be inherited, so this case is
// simpler.
if (e.enclosingElement is ExtensionElement) {
if (e.enclosingElement3 is ExtensionElement) {
newModelElement = Field.providedByExtension(
e,
enclosingContainer,
Expand Down Expand Up @@ -310,7 +310,7 @@ abstract class ModelElement
MethodElement(isOperator: true) when enclosingContainer == null =>
Operator(e, library, packageGraph),
MethodElement(isOperator: true)
when e.enclosingElement is ExtensionElement =>
when e.enclosingElement3 is ExtensionElement =>
Operator.providedByExtension(
e, enclosingContainer, library, packageGraph),
MethodElement(isOperator: true) => Operator.inherited(
Expand All @@ -319,7 +319,7 @@ abstract class ModelElement
MethodElement(isOperator: false) when enclosingContainer == null =>
Method(e, library, packageGraph),
MethodElement(isOperator: false)
when e.enclosingElement is ExtensionElement =>
when e.enclosingElement3 is ExtensionElement =>
Method.providedByExtension(
e, enclosingContainer, library, packageGraph),
MethodElement(isOperator: false) => Method.inherited(
Expand Down Expand Up @@ -348,8 +348,8 @@ abstract class ModelElement
required Member? originalMember,
}) {
// Accessors can be part of a [Container], or a part of a [Library].
if (e.enclosingElement is ExtensionElement ||
e.enclosingElement is InterfaceElement ||
if (e.enclosingElement3 is ExtensionElement ||
e.enclosingElement3 is InterfaceElement ||
e is MultiplyInheritedExecutableElement) {
if (enclosingContainer == null || enclosingContainer is Extension) {
return ContainerAccessor(e, library, packageGraph, enclosingContainer);
Expand Down Expand Up @@ -543,10 +543,10 @@ abstract class ModelElement
// Since we're looking for a library, find the [Element] immediately
// contained by a [CompilationUnitElement] in the tree.
var topLevelElement = element;
while (topLevelElement.enclosingElement is! LibraryElement &&
topLevelElement.enclosingElement is! CompilationUnitElement &&
topLevelElement.enclosingElement != null) {
topLevelElement = topLevelElement.enclosingElement!;
while (topLevelElement.enclosingElement3 is! LibraryElement &&
topLevelElement.enclosingElement3 is! CompilationUnitElement &&
topLevelElement.enclosingElement3 != null) {
topLevelElement = topLevelElement.enclosingElement3!;
}
var topLevelElementName = topLevelElement.name;
if (topLevelElementName == null) {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/model/model_function.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ModelFunctionTypedef extends ModelFunctionTyped {
ModelFunctionTypedef(super.element, super.library, super.packageGraph);

@override
String get name => element.enclosingElement!.name!;
String get name => element.enclosingElement3!.name!;
}

class ModelFunctionTyped extends ModelElement with TypeParameters {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/model/package_graph.dart
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ class PackageGraph with CommentReferable, Nameable {
lib = preferredClass.canonicalLibrary;
}
// For elements defined in extensions, they are canonical.
var enclosingElement = element.enclosingElement;
var enclosingElement = element.enclosingElement3;
if (enclosingElement is ExtensionElement) {
lib ??= getModelForElement(enclosingElement.library) as Library?;
// TODO(keertip): Find a better way to exclude members of extensions
Expand Down
8 changes: 4 additions & 4 deletions lib/src/model/parameter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Parameter extends ModelElement with HasNoPage {

@override
ModelElement? get enclosingElement {
final enclosingElement = element.enclosingElement;
final enclosingElement = element.enclosingElement3;
return enclosingElement == null
? null
: getModelFor(enclosingElement, library);
Expand All @@ -36,7 +36,7 @@ class Parameter extends ModelElement with HasNoPage {

@override
String get htmlId {
final enclosingElement = element.enclosingElement;
final enclosingElement = element.enclosingElement3;
if (enclosingElement == null) {
return 'param-$name';
}
Expand All @@ -46,8 +46,8 @@ class Parameter extends ModelElement with HasNoPage {
// name. Also, allowing null here is allowed as a workaround for
// dart-lang/sdk#32005.
for (Element e = enclosingElement;
e.enclosingElement != null;
e = e.enclosingElement!) {
e.enclosingElement3 != null;
e = e.enclosingElement3!) {
enclosingName = e.name;
if (enclosingName != null && enclosingName.isNotEmpty) break;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/model/type_parameter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class TypeParameter extends ModelElement with HasNoPage {

@override
ModelElement get enclosingElement =>
getModelFor(element.enclosingElement!, library);
getModelFor(element.enclosingElement3!, library);

/// [TypeParameter]s don't have documentation pages, and don't link to the
/// element on which they are declared.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/model_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ extension ElementExtension on Element {
// GenericFunctionTypeElements have the name we care about in the enclosing
// element.
if (self is GenericFunctionTypeElement) {
var enclosingElementName = self.enclosingElement?.name;
var enclosingElementName = self.enclosingElement3?.name;
if (enclosingElementName != null &&
enclosingElementName.startsWith('_')) {
return true;
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ environment:
sdk: ^3.2.0

dependencies:
analyzer: ^6.5.0
analyzer: ^6.9.0
args: ^2.4.1
collection: ^1.17.0
crypto: ^3.0.3
Expand Down
10 changes: 5 additions & 5 deletions test/end2end/model_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1083,13 +1083,13 @@ void main() async {
});

test('Verify behavior of imperfect resolver', () {
expect(aImplementingThingy.element.enclosingElement,
expect(aImplementingThingy.element.enclosingElement3,
equals(BaseThingy2.element));
expect(aImplementingThingyMethod.element.enclosingElement,
expect(aImplementingThingyMethod.element.enclosingElement3,
equals(BaseThingy.element));
expect(aImplementingThingyField.element.enclosingElement,
expect(aImplementingThingyField.element.enclosingElement3,
equals(BaseThingy.element));
expect(aImplementingThingyAccessor.element.enclosingElement,
expect(aImplementingThingyAccessor.element.enclosingElement3,
equals(BaseThingy.element));
});
});
Expand Down Expand Up @@ -1698,7 +1698,7 @@ void main() async {
fakeLibrary.classes.wherePublic.named('MIEEMixinWithOverride');
var problematicOperator =
MIEEMixinWithOverride.inheritedOperators.named('operator []=');
expect(problematicOperator.element.enclosingElement.name,
expect(problematicOperator.element.enclosingElement3.name,
equals('_MIEEPrivateOverride'));
expect(problematicOperator.canonicalModelElement!.enclosingElement!.name,
equals('MIEEMixinWithOverride'));
Expand Down
2 changes: 1 addition & 1 deletion tool/mustachio/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Future<void> build(
var typeSystem = library.typeSystem;
var rendererSpecs = <RendererSpec>{};
for (var renderer in library.metadata
.where((e) => e.element!.enclosingElement!.name == 'Renderer')) {
.where((e) => e.element!.enclosingElement3!.name == 'Renderer')) {
rendererSpecs.add(_buildRendererSpec(renderer));
}

Expand Down

0 comments on commit 2a26281

Please sign in to comment.