4
4
5
5
library analysis;
6
6
7
+ import 'dart:collection' ;
7
8
import 'dart:io' ;
8
9
9
10
import 'package:analyzer/file_system/file_system.dart' show Folder;
10
11
import 'package:analyzer/file_system/physical_file_system.dart' ;
11
12
import 'package:analyzer/source/package_map_provider.dart' ;
12
13
import 'package:analyzer/source/package_map_resolver.dart' ;
13
14
import 'package:analyzer/source/pub_package_map_provider.dart' ;
15
+ import 'package:analyzer/src/generated/element.dart' ;
14
16
import 'package:analyzer/src/generated/engine.dart' ;
15
17
import 'package:analyzer/src/generated/java_io.dart' ;
16
18
import 'package:analyzer/src/generated/sdk.dart' ;
@@ -34,6 +36,7 @@ AnalysisOptions _buildAnalyzerOptions(DriverOptions options) {
34
36
35
37
class AnalysisDriver {
36
38
final DriverOptions options;
39
+
37
40
AnalysisDriver (this .options);
38
41
39
42
List <UriResolver > get resolvers {
@@ -86,13 +89,42 @@ class AnalysisDriver {
86
89
87
90
List <AnalysisErrorInfo > errors = [];
88
91
92
+ Set <Source > sourcesAnalyzed = new HashSet <Source >();
93
+
89
94
for (Source source in sources) {
90
95
context.computeErrors (source);
91
96
errors.add (context.getErrors (source));
97
+ sourcesAnalyzed.add (source);
98
+ }
99
+
100
+ if (options.visitTransitiveClosure) {
101
+ // In the process of computing errors for all the sources in [sources],
102
+ // the analyzer has visited the transitive closure of all libraries
103
+ // referenced by those sources. So now we simply need to visit all
104
+ // library sources known to the analysis context, and all parts they
105
+ // refer to.
106
+ for (Source librarySource in context.librarySources) {
107
+ for (Source source in _getAllUnitSources (context, librarySource)) {
108
+ if (! sourcesAnalyzed.contains (source)) {
109
+ context.computeErrors (source);
110
+ errors.add (context.getErrors (source));
111
+ sourcesAnalyzed.add (source);
112
+ }
113
+ }
114
+ }
92
115
}
93
116
94
117
return errors;
95
118
}
119
+
120
+ /// Yield the sources for all the compilation units constituting
121
+ /// [librarySource] (including the defining compilation unit).
122
+ Iterable <Source > _getAllUnitSources (
123
+ AnalysisContext context, Source librarySource) sync * {
124
+ yield librarySource;
125
+ yield * context.getLibraryElement (librarySource).parts
126
+ .map ((CompilationUnitElement e) => e.source);
127
+ }
96
128
}
97
129
98
130
class DriverOptions {
@@ -112,6 +144,10 @@ class DriverOptions {
112
144
113
145
/// Whether to show SDK warnings.
114
146
bool showSdkWarnings = false ;
147
+
148
+ /// Whether to show lints for the transitive closure of imported and exported
149
+ /// libraries.
150
+ bool visitTransitiveClosure = false ;
115
151
}
116
152
117
153
/// Prints logging information comments to the [outSink] and error messages to
0 commit comments