Stop using deprecated analyzer 7.x.y APIs. (#176242)

Preparation for landing
https://dart-review.googlesource.com/c/sdk/+/443460


## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [ ] I listed at least one issue that this PR fixes in the description
above.
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [ ] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [ ] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [ ] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

**Note**: The Flutter team is currently trialing the use of [Gemini Code
Assist for
GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code).
Comments from the `gemini-code-assist` bot should not be taken as
authoritative feedback from the Flutter team. If you find its comments
useful you can update your code accordingly, but if you are unsure or
disagree with the feedback, please feel free to wait for a Flutter team
member's review for guidance on which automated comments should be
addressed.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
This commit is contained in:
Konstantin Scheglov 2025-09-30 18:25:35 -07:00 committed by GitHub
parent b719a6c799
commit 495342fa96
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 16 additions and 17 deletions

View File

@ -11,9 +11,8 @@ import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/token.dart';
import 'package:analyzer/dart/ast/visitor.dart';
import 'package:analyzer/dart/constant/value.dart';
import 'package:analyzer/dart/element/element2.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/diagnostic/diagnostic.dart';
import 'package:analyzer/error/error.dart';
import 'package:analyzer/source/line_info.dart';
import '../base/logger.dart';
@ -34,7 +33,7 @@ typedef PreviewDependencyGraph = Map<PreviewPath, LibraryPreviewNode>;
/// Visitor which detects previews and extracts [PreviewDetails] for later code
/// generation.
class _PreviewVisitor extends RecursiveAstVisitor<void> {
_PreviewVisitor({required LibraryElement2 lib})
_PreviewVisitor({required LibraryElement lib})
: packageName = lib.uri.scheme == 'package' ? lib.uri.pathSegments.first : null;
late final String? packageName;
@ -208,7 +207,7 @@ final class LibraryPreviewNode {
bool get hasErrors => errors.isNotEmpty;
/// The set of errors found in this library.
final errors = <AnalysisError>[];
final errors = <Diagnostic>[];
/// Determines the set of errors found in this library.
///
@ -217,8 +216,8 @@ final class LibraryPreviewNode {
errors.clear();
for (final String file in files) {
errors.addAll(
((await context.currentSession.getErrors(file)) as ErrorsResult).errors
.where((AnalysisError error) => error.severity == Severity.error)
((await context.currentSession.getErrors(file)) as ErrorsResult).diagnostics
.where((error) => error.severity == Severity.error)
.toList(),
);
}

View File

@ -3,8 +3,8 @@
// found in the LICENSE file.
import 'package:analyzer/dart/constant/value.dart';
import 'package:analyzer/dart/element/element2.dart' as analyzer;
import 'package:analyzer/dart/element/element2.dart';
import 'package:analyzer/dart/element/element.dart' as analyzer;
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/type.dart';
import 'package:built_collection/built_collection.dart';
import 'package:code_builder/code_builder.dart' as cb;
@ -210,7 +210,7 @@ extension on DartObject {
DartType(isDartCoreInt: true) => cb.literalNum(toIntValue()!),
DartType(isDartCoreString: true) => cb.literalString(toStringValue()!),
DartType(isDartCoreNull: true) => cb.literalNull,
InterfaceType(element3: EnumElement()) => _createEnumInstance(this),
InterfaceType(element: EnumElement()) => _createEnumInstance(this),
InterfaceType() => _createInstance(type, this),
FunctionType() => _createTearoff(toFunctionValue()!),
_ => throw UnsupportedError('Unexpected DartObject type: $runtimeType'),
@ -242,10 +242,10 @@ extension on DartObject {
final ConstructorInvocation constructorInvocation = object.constructorInvocation!;
final ConstructorElement constructor = constructorInvocation.constructor;
final cb.Expression type = cb.refer(
dartType.element3.name3!,
_elementToLibraryIdentifier(dartType.element3),
dartType.element.name!,
_elementToLibraryIdentifier(dartType.element),
);
final String? name = constructor.name3 == 'new' ? null : constructor.name3;
final String? name = constructor.name == 'new' ? null : constructor.name;
final List<cb.Expression> positionalArguments = constructorInvocation.positionalArguments
.map((e) => e.toExpression())

View File

@ -8,7 +8,7 @@ import 'dart:collection';
import 'package:analyzer/dart/analysis/results.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/token.dart';
import 'package:analyzer/dart/element/element2.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/type.dart';
import 'package:analyzer/source/source.dart';
import 'package:collection/collection.dart';

View File

@ -104,24 +104,24 @@ class PreviewMatcher extends Matcher {
);
checkPropertyMatch(
name: kWrapper,
actual: item.getFirstField(kWrapper)?.toFunctionValue2()?.displayName,
actual: item.getFirstField(kWrapper)?.toFunctionValue()?.displayName,
expected: wrapper,
);
checkPropertyMatch(
name: kTheme,
actual: item.getFirstField(kTheme)?.toFunctionValue2()?.displayName,
actual: item.getFirstField(kTheme)?.toFunctionValue()?.displayName,
expected: theme,
);
final DartObject? actualBrightness = item.getFirstField(kBrightness);
checkPropertyMatch(
name: kBrightness,
actual: (actualBrightness?.isNull ?? true) ? null : actualBrightness!.variable2!.toString(),
actual: (actualBrightness?.isNull ?? true) ? null : actualBrightness!.variable!.toString(),
expected: brightness,
);
checkPropertyMatch(
name: kLocalizations,
actual: item.getFirstField(kLocalizations)?.toFunctionValue2()?.displayName,
actual: item.getFirstField(kLocalizations)?.toFunctionValue()?.displayName,
expected: localizations,
);
return matches;