Skip to content

Commit 4cb5274

Browse files
srawlinsCommit Queue
authored andcommitted
analyzer: Move AnalysisErrorInfo into the linter test utilities
Change-Id: If6115cd0d3ffe4416f13567b79c835d0ab90bc79 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/392280 Commit-Queue: Samuel Rawlins <[email protected]> Reviewed-by: Phil Quitslund <[email protected]>
1 parent e573f64 commit 4cb5274

File tree

14 files changed

+42
-71
lines changed

14 files changed

+42
-71
lines changed

pkg/analyzer/lib/src/generated/engine.dart

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
import 'package:_fe_analyzer_shared/src/scanner/string_canonicalizer.dart';
66
import 'package:analyzer/dart/analysis/analysis_options.dart';
77
import 'package:analyzer/dart/analysis/declared_variables.dart';
8-
import 'package:analyzer/error/error.dart';
98
import 'package:analyzer/file_system/file_system.dart';
109
import 'package:analyzer/instrumentation/instrumentation.dart';
11-
import 'package:analyzer/source/line_info.dart';
1210
import 'package:analyzer/src/generated/source.dart' show SourceFactory;
1311
import 'package:meta/meta.dart';
1412

@@ -108,31 +106,3 @@ class AnalysisEngine {
108106
pruneStringCanonicalizationCache();
109107
}
110108
}
111-
112-
/// The analysis errors and line information for the errors.
113-
abstract class AnalysisErrorInfo {
114-
/// Return the errors that as a result of the analysis, or `null` if there were
115-
/// no errors.
116-
List<AnalysisError> get errors;
117-
118-
/// Return the line information associated with the errors, or `null` if there
119-
/// were no errors.
120-
LineInfo get lineInfo;
121-
}
122-
123-
/// The analysis errors and line info associated with a source.
124-
class AnalysisErrorInfoImpl implements AnalysisErrorInfo {
125-
/// The analysis errors associated with a source, or `null` if there are no
126-
/// errors.
127-
@override
128-
final List<AnalysisError> errors;
129-
130-
/// The line information associated with the errors, or `null` if there are no
131-
/// errors.
132-
@override
133-
final LineInfo lineInfo;
134-
135-
/// Initialize an newly created error info with the given [errors] and
136-
/// [lineInfo].
137-
AnalysisErrorInfoImpl(this.errors, this.lineInfo);
138-
}

pkg/analyzer_cli/lib/src/analyzer_impl.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class AnalyzerImpl {
3636
/// All files references by the analyzed library.
3737
final Set<String> files = <String>{};
3838

39-
/// All [AnalysisErrorInfo]s in the analyzed library.
39+
/// All [ErrorsResult]s in the analyzed library.
4040
final List<ErrorsResult> errorsResults = [];
4141

4242
/// If the file specified on the command line is part of a package, the name

pkg/analyzer_cli/test/mocks.dart

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import 'package:analyzer/error/error.dart';
77
import 'package:analyzer/source/line_info.dart';
88
import 'package:analyzer/source/source.dart';
99
import 'package:analyzer/src/diagnostic/diagnostic.dart';
10-
import 'package:analyzer/src/generated/engine.dart';
1110
import 'package:analyzer_cli/src/options.dart';
1211

1312
class MockAnalysisError implements AnalysisError {
@@ -52,16 +51,6 @@ class MockAnalysisError implements AnalysisError {
5251
Severity get severity => Severity.error;
5352
}
5453

55-
class MockAnalysisErrorInfo implements AnalysisErrorInfo {
56-
@override
57-
LineInfo lineInfo;
58-
59-
@override
60-
List<AnalysisError> errors;
61-
62-
MockAnalysisErrorInfo(this.lineInfo, this.errors);
63-
}
64-
6554
class MockCommandLineOptions implements CommandLineOptions {
6655
bool enableTypeChecks = false;
6756
@override

pkg/linter/lib/src/analyzer.dart

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,10 @@ import 'package:analyzer/src/lint/util.dart' as util;
1010

1111
export 'package:analyzer/dart/element/type_system.dart';
1212
export 'package:analyzer/source/line_info.dart';
13-
export 'package:analyzer/source/source.dart';
1413
export 'package:analyzer/src/dart/ast/token.dart';
1514
export 'package:analyzer/src/dart/element/inheritance_manager3.dart'
1615
show InheritanceManager3, Name;
1716
export 'package:analyzer/src/dart/error/lint_codes.dart';
18-
export 'package:analyzer/src/dart/resolver/exit_detector.dart';
19-
export 'package:analyzer/src/generated/engine.dart' show AnalysisErrorInfo;
20-
export 'package:analyzer/src/lint/lint_rule_timers.dart';
2117
export 'package:analyzer/src/lint/linter.dart'
2218
show
2319
dart2_12,
@@ -29,7 +25,6 @@ export 'package:analyzer/src/lint/linter.dart'
2925
NodeLintRegistry,
3026
State;
3127
export 'package:analyzer/src/lint/pub.dart' show PSEntry, PubspecVisitor;
32-
export 'package:analyzer/src/lint/util.dart' show FileSpelunker;
3328
export 'package:analyzer/src/utilities/extensions/ast.dart';
3429
export 'package:analyzer/src/workspace/pub.dart' show PubPackage;
3530

pkg/linter/lib/src/rules/use_build_context_synchronously.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import 'package:analyzer/dart/ast/token.dart';
77
import 'package:analyzer/dart/ast/visitor.dart';
88
import 'package:analyzer/dart/element/element.dart';
99
// ignore: implementation_imports
10+
import 'package:analyzer/src/dart/resolver/exit_detector.dart';
11+
// ignore: implementation_imports
1012
import 'package:analyzer/src/lint/linter.dart';
1113
import 'package:collection/collection.dart';
1214
import 'package:meta/meta.dart';
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:analyzer/error/error.dart';
6+
import 'package:analyzer/source/line_info.dart';
7+
8+
/// The analysis errors and line info associated with a source.
9+
class AnalysisErrorInfo {
10+
/// The analysis errors associated with a source, or `null` if there are no
11+
/// errors.
12+
final List<AnalysisError> errors;
13+
14+
/// The line information associated with the errors, or `null` if there are no
15+
/// errors.
16+
final LineInfo lineInfo;
17+
18+
AnalysisErrorInfo(this.errors, this.lineInfo);
19+
}

pkg/linter/lib/src/test_utilities/formatter.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ import 'dart:io';
66
import 'dart:math';
77

88
import 'package:analyzer/error/error.dart';
9+
// ignore: implementation_imports
10+
import 'package:analyzer/src/lint/lint_rule_timers.dart';
911

1012
import '../analyzer.dart';
1113
import '../util/charcodes.dart' show $backslash, $pipe;
14+
import 'analysis_error_info.dart';
1215

1316
// Number of times to perform linting to get stable benchmarks.
1417
const benchmarkRuns = 10;

pkg/linter/lib/src/test_utilities/lint_driver.dart

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ import 'package:analyzer/instrumentation/instrumentation.dart';
1010
// ignore: implementation_imports
1111
import 'package:analyzer/src/dart/analysis/analysis_context_collection.dart';
1212
// ignore: implementation_imports
13-
import 'package:analyzer/src/generated/engine.dart';
13+
import 'package:analyzer/src/generated/engine.dart' show AnalysisEngine;
1414
// ignore: implementation_imports
1515
import 'package:analyzer/src/lint/io.dart';
1616
// ignore: implementation_imports
1717
import 'package:analyzer/src/lint/linter.dart';
1818

19+
import 'analysis_error_info.dart';
20+
1921
class LintDriver {
2022
/// The files which have been analyzed so far. This is used to compute the
2123
/// total number of files analyzed for statistics.
@@ -60,10 +62,7 @@ class LintDriver {
6062
var errorsResult = await analysisSession.getErrors(path);
6163
if (errorsResult is ErrorsResult) {
6264
result.add(
63-
AnalysisErrorInfoImpl(
64-
errorsResult.errors,
65-
errorsResult.lineInfo,
66-
),
65+
AnalysisErrorInfo(errorsResult.errors, errorsResult.lineInfo),
6766
);
6867
}
6968
}

pkg/linter/lib/src/test_utilities/test_linter.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import 'package:analyzer/file_system/physical_file_system.dart' as file_system;
1111
import 'package:analyzer/source/file_source.dart';
1212
import 'package:analyzer/source/source.dart';
1313
// ignore: implementation_imports
14-
import 'package:analyzer/src/generated/engine.dart' show AnalysisErrorInfo;
15-
// ignore: implementation_imports
1614
import 'package:analyzer/src/lint/io.dart';
1715
// ignore: implementation_imports
1816
import 'package:analyzer/src/lint/linter.dart';
@@ -21,6 +19,7 @@ import 'package:analyzer/src/lint/pub.dart';
2119
import 'package:meta/meta.dart';
2220
import 'package:path/path.dart' as path;
2321

22+
import 'analysis_error_info.dart';
2423
import 'lint_driver.dart';
2524

2625
Source createSource(Uri uri) {

pkg/linter/test/formatter_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:analyzer/error/error.dart';
6-
import 'package:analyzer/src/generated/engine.dart';
76
import 'package:linter/src/analyzer.dart';
7+
import 'package:linter/src/test_utilities/analysis_error_info.dart';
88
import 'package:linter/src/test_utilities/formatter.dart';
99
import 'package:test/test.dart';
1010

@@ -38,7 +38,7 @@ void defineTests() {
3838
var error = AnalysisError.tmp(
3939
source: source, offset: 10, length: 3, errorCode: code);
4040

41-
var info = AnalysisErrorInfoImpl([error], lineInfo);
41+
var info = AnalysisErrorInfo([error], lineInfo);
4242

4343
var out = StringBuffer();
4444

@@ -87,7 +87,7 @@ mock_code 1
8787
var error = AnalysisError.tmp(
8888
source: source, offset: 12, length: 13, errorCode: code);
8989

90-
var info = AnalysisErrorInfoImpl([error], lineInfo);
90+
var info = AnalysisErrorInfo([error], lineInfo);
9191

9292
var out = StringBuffer();
9393

0 commit comments

Comments
 (0)