8000 Migrate to `analyzer` Element2 APIs by davidmorgan · Pull Request #4053 · dart-lang/build · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Migrate to analyzer Element2 APIs #4053

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions build/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 3.0.0

- Breaking: use the new `element2` APIs in `analyzer`. Builders that do
resolution need to switch to the new API, see
https://github.com/dart-lang/sdk/blob/main/pkg/analyzer/doc/element_model_migration_guide.md.
For questions please use https://github.com/dart-lang/build/discussions.

## 2.5.3

- Use `build_runner_core` 9.1.1.
Expand Down
15 changes: 7 additions & 8 deletions build/lib/src/analyzer/resolver.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// ignore_for_file: deprecated_member_use

import 'package:analyzer/dart/analysis/results.dart';
import 'package:analyzer/dart/analysis/session.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/element2.dart';
import 'package:analyzer/error/error.dart';

import '../asset/id.dart';
Expand All @@ -29,9 +28,9 @@ abstract class Resolver {
/// - Every public `dart:` library part of the SDK.
/// - All libraries recursively accessible from the mentioned sources, for
/// instance because due to imports or exports.
Stream<LibraryElement> get libraries;
Stream<LibraryElement2> get libraries;

/// Returns the parsed [AstNode] for [Element].
/// Returns the parsed [AstNode] for [fragment].
///
/// This should always be preferred over using the [AnalysisSession]
/// directly, because it avoids [InconsistentAnalysisException] issues.
Expand All @@ -42,7 +41,7 @@ abstract class Resolver {
/// Returns `null` if the ast node can not be found. This can happen if an
/// element is coming from a summary, or is unavailable for some other
/// reason.
Future<AstNode?> astNodeFor(Element element, {bool resolve = false});
Future<AstNode?> astNodeFor(Fragment fragment, {bool resolve = false});

/// Returns a parsed AST structor representing the file defined in [assetId].
///
Expand All @@ -61,7 +60,7 @@ abstract class Resolver {
/// * Throws [NonLibraryAssetException] if [assetId] is not a Dart library.
/// * If the [assetId] has syntax errors, and [allowSyntaxErrors] is set to
/// `false` (the default), throws a [SyntaxErrorInAssetException].
Future<LibraryElement> libraryFor(
Future<LibraryElement2> libraryFor(
AssetId assetId, {
bool allowSyntaxErrors = false,
});
Expand All @@ -76,7 +75,7 @@ abstract class Resolver {
/// **NOTE**: In general, its recommended to use [libraryFor] with an absolute
/// asset id instead of a named identifier that has the possibility of not
/// being unique.
Future<LibraryElement?> findLibraryByName(String libraryName);
Future<LibraryElement2?> findLibraryByName(String libraryName);

/// Returns the [AssetId] of the Dart library or part declaring [element].
///
Expand All @@ -86,7 +85,7 @@ abstract class Resolver {
///
/// The returned asset is not necessarily the asset that should be imported to
/// use the element, it may be a part file instead of the library.
Future<AssetId> assetIdForElement(Element element);
Future<AssetId> assetIdForElement(Element2 element);
}

/// A resolver that should be manually released at the end of a build step.
Expand Down
5 changes: 2 additions & 3 deletions build/lib/src/builder/build_step.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// ignore_for_file: deprecated_member_use

import 'dart:async';
import 'dart:convert';

import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/element2.dart';
import 'package:package_config/package_config_types.dart';

import '../analyzer/resolver.dart';
Expand Down Expand Up @@ -37,7 +36,7 @@ abstract class BuildStep implements AssetReader, AssetWriter {
/// await step.resolver.libraryFor(step.inputId, allowSyntaxErrors: true);
/// }
/// ```
Future<LibraryElement> get inputLibrary;
Future<LibraryElement2> get inputLibrary;

/// Gets an instance provided by [resource] which is guaranteed to be unique
/// within a single build, and may be reused across build steps within a
Expand Down
9 changes: 4 additions & 5 deletions build/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: build
version: 2.5.3
version: 3.0.0
description: A package for authoring build_runner compatible code generators.
repository: https://github.com/dart-lang/build/tree/master/build
resolution: workspace
Expand All @@ -8,9 +8,9 @@ environment:
sdk: ^3.7.0

dependencies:
analyzer: '>=6.9.0 <8.0.0'
analyzer: '>=7.4.0 <8.0.0'
async: ^2.5.0
build_runner_core: '9.1.1'
build_runner_core: '9.2.0'
built_collection: ^5.1.1
built_value: ^8.9.5
convert: ^3.0.0
Expand All @@ -24,9 +24,8 @@ dependencies:
pool: ^1.5.0

dev_dependencies:
build_resolvers: '2.5.3'
build_resolvers: '3.0.0'
build_test: ^3.1.0
built_value_generator: ^8.9.5
dart_flutter_team_lints: ^3.1.0
test: ^1.16.0

Expand Down
1 change: 0 additions & 1 deletion build_config/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ dependencies:

dev_dependencies:
build_runner: ^2.0.0
json_serializable: ^6.0.0
term_glyph: ^1.2.0
test: ^1.16.0

Expand Down
7 changes: 5 additions & 2 deletions build_daemon/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ dependencies:
dev_dependencies:
analyzer: '>=3.4.0 <8.0.0'
build_runner: ^2.0.0
# TODO: untangle analyzer dependency
built_value_generator: ^8.1.0
mockito: ^5.0.0
test: ^1.25.5
test_descriptor: ^2.0.0

# TODO(davidmorgan): remove when these are released for build 3.0.0.
dependency_overrides:
mockito: '5.4.6'
source_gen: '2.0.0'

topics:
- build-runner
4 changes: 4 additions & 0 deletions build_modules/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 5.0.14

- Allow `build` 3.0.0.

## 5.0.13

- Allow Dart SDK 3.8.x and 3.9 prerelease.
Expand Down
8 changes: 4 additions & 4 deletions build_modules/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: build_modules
version: 5.0.13
version: 5.0.14
description: >-
Builders to analyze and split Dart code into individually compilable modules
based on imports.
Expand All @@ -13,7 +13,7 @@ dependencies:
analyzer: '>=5.1.0 <8.0.0'
async: ^2.5.0
bazel_worker: ^1.0.0
build: ^2.0.0
build: '>=2.0.0 <4.0.0'
build_config: ^1.0.0
collection: ^1.15.0
crypto: ^3.0.0
Expand All @@ -30,11 +30,11 @@ dev_dependencies:
path: test/fixtures/a
b:
path: test/fixtures/b
# Used inside tests
build_runner: ^2.0.0
build_runner_core: ^9.0.0
build_test: ^3.1.0
json_serializable: ^6.9.1
# TODO(davidmorgan): uncomment when it's released for build 3.0.0.
# json_serializable: ^6.9.1
test: ^1.16.0

topics:
Expand Down
7 changes: 7 additions & 0 deletions build_resolvers/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 3.0.0

- Breaking: use the new `element2` APIs in `analyzer`. Builders that do
resolution need to switch to the new API, see
https://github.com/dart-lang/sdk/blob/main/pkg/analyzer/doc/element_model_migration_guide.md.
For questions please use https://github.com/dart-lang/build/discussions.

## 2.5.3

- Use `build_runner_core` 9.1.1.
Expand Down
Loading
Loading
0