Skip to content

Commit 0519deb

Browse files
stereotype441Commit Queue
authored andcommitted
[analyzer] Generate diagnostic codes into part files.
Previously, diagnostic codes were generated into libraries. This led to a proliferation of imports of those generated libraries throughout the analyzer and analysis server codebases, since the analysis server didn't know that it should suggest adding imports of the correspinding non-generated libraries instead. I tried to fix that problem by marking each generated diagnostic code library as deprecated, and ignoring the deprecation warning at the site where the corresponding non-generated file imports it. But this led to a different problem: it prevented code completion from suggesting elements that came from the generated libraries. In my work toward replacing the analyzer's error reporting API with a more literate API (e.g. `reportError(errorCode.withArguments(...).at(...))`), I've discovered that the lack of code completion makes the more literate API much harder to use. This CL changes the code generator so that diagnostic codes are generated into part files. This neatly prevents unintentional imports of the generated files without having to do any tricks with deprecation. A side benefit of this change is that the code generators no longer need complex logic to determine which `import` directives to generate, since the import directives live in the non-code-generated parent library. Note that in the past, the analyzer code base has heavily discouraged the use of part files. I think they are justified in this case, because the files are generated; if it were not for the desire to code generate these files, we would fold them straight into the libraries they are parts of. Change-Id: I6a6a6964a375ee81f9580b354766bd041c83b3cd Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/445480 Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]> Reviewed-by: Nate Biggs <[email protected]> Commit-Queue: Paul Berry <[email protected]>
1 parent f93aea7 commit 0519deb

29 files changed

+63
-194
lines changed

pkg/_fe_analyzer_shared/lib/src/scanner/errors.dart

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// ignore: deprecated_member_use_from_same_package
6-
import 'package:_fe_analyzer_shared/src/scanner/errors.g.dart';
7-
5+
import '../base/errors.dart';
86
import '../messages/codes.dart';
97
import 'error_token.dart';
108
import 'token.dart' show Token, TokenType;
119
import 'token_constants.dart';
1210

13-
// ignore: deprecated_member_use_from_same_package
14-
export 'package:_fe_analyzer_shared/src/scanner/errors.g.dart';
11+
part 'errors.g.dart';
1512

1613
/**
1714
* Translates the given error [token] into an analyzer error and reports it

pkg/_fe_analyzer_shared/lib/src/scanner/errors.g.dart

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,7 @@
1414
// Generated comments don't quite align with flutter style.
1515
// ignore_for_file: flutter_style_todos
1616

17-
/// @docImport 'package:analyzer/src/dart/error/syntactic_errors.g.dart';
18-
/// @docImport 'package:analyzer/src/error/inference_error.dart';
19-
@Deprecated(
20-
// This library is deprecated to prevent it from being accidentally imported
21-
// It should only be imported by the corresponding non-code-generated library
22-
// (which suppresses the deprecation warning using an "ignore" comment).
23-
'Use package:_fe_analyzer_shared/src/scanner/errors.dart instead',
24-
)
25-
library;
26-
27-
import "package:_fe_analyzer_shared/src/base/errors.dart";
17+
part of "package:_fe_analyzer_shared/src/scanner/errors.dart";
2818

2919
class ScannerErrorCode extends DiagnosticCode {
3020
/// Parameters:

pkg/analysis_server/lib/src/services/correction/fix/data_driven/transform_set_error_code.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// ignore: deprecated_member_use_from_same_package
6-
export 'package:analysis_server/src/services/correction/fix/data_driven/transform_set_error_code.g.dart'
7-
show TransformSetErrorCode;
5+
import 'package:analyzer/error/error.dart';
6+
7+
part 'package:analysis_server/src/services/correction/fix/data_driven/transform_set_error_code.g.dart';

pkg/analysis_server/lib/src/services/correction/fix/data_driven/transform_set_error_code.g.dart

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,7 @@
1515
// Generated comments don't quite align with flutter style.
1616
// ignore_for_file: flutter_style_todos
1717

18-
/// @docImport 'package:analyzer/src/dart/error/syntactic_errors.g.dart';
19-
/// @docImport 'package:analyzer/src/error/inference_error.dart';
20-
@Deprecated(
21-
// This library is deprecated to prevent it from being accidentally imported
22-
// It should only be imported by the corresponding non-code-generated library
23-
// (which suppresses the deprecation warning using an "ignore" comment).
24-
'Use package:analysis_server/src/services/correction/fix/data_driven/transform_set_error_code.dart instead',
25-
)
26-
library;
27-
28-
import "package:_fe_analyzer_shared/src/base/errors.dart";
18+
part of "package:analysis_server/src/services/correction/fix/data_driven/transform_set_error_code.dart";
2919

3020
/// An error code representing a problem in a file containing an encoding of a
3121
/// transform set.

pkg/analyzer/lib/src/analysis_options/error/option_codes.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// ignore: deprecated_member_use_from_same_package
6-
export 'package:analyzer/src/analysis_options/error/option_codes.g.dart';
5+
import 'package:analyzer/error/error.dart';
6+
7+
part 'package:analyzer/src/analysis_options/error/option_codes.g.dart';

pkg/analyzer/lib/src/analysis_options/error/option_codes.g.dart

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,7 @@
1414
// Generated comments don't quite align with flutter style.
1515
// ignore_for_file: flutter_style_todos
1616

17-
/// @docImport 'package:analyzer/src/dart/error/syntactic_errors.g.dart';
18-
/// @docImport 'package:analyzer/src/error/inference_error.dart';
19-
@Deprecated(
20-
// This library is deprecated to prevent it from being accidentally imported
21-
// It should only be imported by the corresponding non-code-generated library
22-
// (which suppresses the deprecation warning using an "ignore" comment).
23-
'Use package:analyzer/src/analysis_options/error/option_codes.dart instead',
24-
)
25-
library;
26-
27-
import "package:_fe_analyzer_shared/src/base/errors.dart";
17+
part of "package:analyzer/src/analysis_options/error/option_codes.dart";
2818

2919
class AnalysisOptionsErrorCode extends DiagnosticCode {
3020
/// An error code indicating that there is a syntactic error in the included

pkg/analyzer/lib/src/dart/error/ffi_code.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// ignore: deprecated_member_use_from_same_package
6-
export 'package:analyzer/src/dart/error/ffi_code.g.dart';
5+
import 'package:analyzer/error/error.dart';
6+
7+
part 'package:analyzer/src/dart/error/ffi_code.g.dart';

pkg/analyzer/lib/src/dart/error/ffi_code.g.dart

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,7 @@
1414
// Generated comments don't quite align with flutter style.
1515
// ignore_for_file: flutter_style_todos
1616

17-
/// @docImport 'package:analyzer/src/dart/error/syntactic_errors.g.dart';
18-
/// @docImport 'package:analyzer/src/error/inference_error.dart';
19-
@Deprecated(
20-
// This library is deprecated to prevent it from being accidentally imported
21-
// It should only be imported by the corresponding non-code-generated library
22-
// (which suppresses the deprecation warning using an "ignore" comment).
23-
'Use package:analyzer/src/dart/error/ffi_code.dart instead',
24-
)
25-
library;
26-
27-
import "package:_fe_analyzer_shared/src/base/errors.dart";
17+
part of "package:analyzer/src/dart/error/ffi_code.dart";
2818

2919
class FfiCode extends DiagnosticCode {
3020
/// No parameters.

pkg/analyzer/lib/src/dart/error/hint_codes.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// ignore: deprecated_member_use_from_same_package
6-
export 'package:analyzer/src/dart/error/hint_codes.g.dart';
5+
import 'package:analyzer/error/error.dart';
6+
7+
part 'package:analyzer/src/dart/error/hint_codes.g.dart';

pkg/analyzer/lib/src/dart/error/hint_codes.g.dart

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,7 @@
1414
// Generated comments don't quite align with flutter style.
1515
// ignore_for_file: flutter_style_todos
1616

17-
/// @docImport 'package:analyzer/src/dart/error/syntactic_errors.g.dart';
18-
/// @docImport 'package:analyzer/src/error/inference_error.dart';
19-
@Deprecated(
20-
// This library is deprecated to prevent it from being accidentally imported
21-
// It should only be imported by the corresponding non-code-generated library
22-
// (which suppresses the deprecation warning using an "ignore" comment).
23-
'Use package:analyzer/src/dart/error/hint_codes.dart instead',
24-
)
25-
library;
26-
27-
import "package:_fe_analyzer_shared/src/base/errors.dart";
17+
part of "package:analyzer/src/dart/error/hint_codes.dart";
2818

2919
class HintCode extends DiagnosticCode {
3020
/// Note: Since this diagnostic is only produced in pre-3.0 code, we do not

0 commit comments

Comments
 (0)