Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(274)

Side by Side Diff: packages/analyzer/lib/src/task/dart.dart

Issue 2990843002: Removed fixed dependencies (Closed)
Patch Set: Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library analyzer.src.task.dart; 5 library analyzer.src.task.dart;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/token.dart';
11 import 'package:analyzer/dart/ast/visitor.dart';
12 import 'package:analyzer/dart/element/element.dart';
13 import 'package:analyzer/dart/element/type.dart';
14 import 'package:analyzer/error/error.dart';
15 import 'package:analyzer/error/listener.dart';
16 import 'package:analyzer/exception/exception.dart';
9 import 'package:analyzer/src/context/cache.dart'; 17 import 'package:analyzer/src/context/cache.dart';
10 import 'package:analyzer/src/generated/ast.dart'; 18 import 'package:analyzer/src/dart/ast/ast.dart'
19 show NamespaceDirectiveImpl, UriBasedDirectiveImpl, UriValidationCode;
20 import 'package:analyzer/src/dart/ast/utilities.dart';
21 import 'package:analyzer/src/dart/element/builder.dart';
22 import 'package:analyzer/src/dart/element/element.dart';
23 import 'package:analyzer/src/dart/resolver/inheritance_manager.dart';
24 import 'package:analyzer/src/dart/scanner/reader.dart';
25 import 'package:analyzer/src/dart/scanner/scanner.dart';
26 import 'package:analyzer/src/error/codes.dart';
27 import 'package:analyzer/src/error/pending_error.dart';
11 import 'package:analyzer/src/generated/constant.dart'; 28 import 'package:analyzer/src/generated/constant.dart';
12 import 'package:analyzer/src/generated/element.dart'; 29 import 'package:analyzer/src/generated/engine.dart';
13 import 'package:analyzer/src/generated/engine.dart'
14 hide AnalysisCache, AnalysisTask;
15 import 'package:analyzer/src/generated/error.dart';
16 import 'package:analyzer/src/generated/error_verifier.dart'; 30 import 'package:analyzer/src/generated/error_verifier.dart';
17 import 'package:analyzer/src/generated/incremental_resolver.dart'; 31 import 'package:analyzer/src/generated/incremental_resolver.dart';
18 import 'package:analyzer/src/generated/java_engine.dart';
19 import 'package:analyzer/src/generated/parser.dart'; 32 import 'package:analyzer/src/generated/parser.dart';
20 import 'package:analyzer/src/generated/resolver.dart'; 33 import 'package:analyzer/src/generated/resolver.dart';
21 import 'package:analyzer/src/generated/scanner.dart';
22 import 'package:analyzer/src/generated/sdk.dart'; 34 import 'package:analyzer/src/generated/sdk.dart';
23 import 'package:analyzer/src/generated/source.dart'; 35 import 'package:analyzer/src/generated/source.dart';
24 import 'package:analyzer/src/generated/visitors.dart'; 36 import 'package:analyzer/src/generated/utilities_dart.dart';
25 import 'package:analyzer/src/plugin/engine_plugin.dart'; 37 import 'package:analyzer/src/plugin/engine_plugin.dart';
26 import 'package:analyzer/src/services/lint.dart'; 38 import 'package:analyzer/src/services/lint.dart';
27 import 'package:analyzer/src/task/driver.dart'; 39 import 'package:analyzer/src/task/driver.dart';
28 import 'package:analyzer/src/task/general.dart'; 40 import 'package:analyzer/src/task/general.dart';
29 import 'package:analyzer/src/task/html.dart'; 41 import 'package:analyzer/src/task/html.dart';
42 import 'package:analyzer/src/task/incremental_element_builder.dart';
30 import 'package:analyzer/src/task/inputs.dart'; 43 import 'package:analyzer/src/task/inputs.dart';
31 import 'package:analyzer/src/task/model.dart'; 44 import 'package:analyzer/src/task/model.dart';
32 import 'package:analyzer/src/task/strong/checker.dart'; 45 import 'package:analyzer/src/task/strong/checker.dart';
33 import 'package:analyzer/src/task/strong/rules.dart';
34 import 'package:analyzer/src/task/strong_mode.dart'; 46 import 'package:analyzer/src/task/strong_mode.dart';
35 import 'package:analyzer/task/dart.dart'; 47 import 'package:analyzer/task/dart.dart';
36 import 'package:analyzer/task/general.dart'; 48 import 'package:analyzer/task/general.dart';
37 import 'package:analyzer/task/model.dart'; 49 import 'package:analyzer/task/model.dart';
38 50
39 /** 51 /**
40 * The [ResultCachingPolicy] for ASTs. 52 * The [ResultCachingPolicy] for ASTs.
41 */ 53 */
42 const ResultCachingPolicy AST_CACHING_POLICY = 54 const ResultCachingPolicy<CompilationUnit> AST_CACHING_POLICY =
43 const SimpleResultCachingPolicy(8192, 8192); 55 const SimpleResultCachingPolicy(16384, 32);
56
57 /**
58 * The [ResultCachingPolicy] for fully resolved ASTs. It is separated from
59 * [AST_CACHING_POLICY] because we want to keep some number of fully resolved
60 * ASTs when users switch between contexts, and they should not be pushed out
61 * of the cache by temporary partially resolved ASTs.
62 */
63 const ResultCachingPolicy<CompilationUnit> AST_RESOLVED_CACHING_POLICY =
64 const SimpleResultCachingPolicy(1024, 32);
65
66 /**
67 * The [ResultCachingPolicy] for ASTs that can be reused when a library
68 * on which the source depends is changed. It is worth to keep some number
69 * of these ASTs in memory in order to avoid parsing sources. In contrast,
70 * none of [AST_CACHING_POLICY] managed ASTs can be reused after a change, so
71 * it is worth to keep them in memory while analysis is being performed, but
72 * once analysis is done, they can be flushed.
73 */
74 const ResultCachingPolicy<CompilationUnit> AST_REUSABLE_CACHING_POLICY =
75 const SimpleResultCachingPolicy(1024, 64);
76
77 /**
78 * The [ResultCachingPolicy] for lists of [ConstantEvaluationTarget]s.
79 */
80 const ResultCachingPolicy<List<ConstantEvaluationTarget>>
81 CONSTANT_EVALUATION_TARGET_LIST_POLICY =
82 const SimpleResultCachingPolicy(-1, -1);
83
84 /**
85 * The [ResultCachingPolicy] for [ConstantEvaluationTarget]s.
86 */
87 const ResultCachingPolicy<ConstantEvaluationTarget>
88 CONSTANT_EVALUATION_TARGET_POLICY = const SimpleResultCachingPolicy(-1, -1);
44 89
45 /** 90 /**
46 * The [ResultCachingPolicy] for [Element]s. 91 * The [ResultCachingPolicy] for [Element]s.
47 */ 92 */
48 const ResultCachingPolicy ELEMENT_CACHING_POLICY = 93 const ResultCachingPolicy<Element> ELEMENT_CACHING_POLICY =
49 const SimpleResultCachingPolicy(-1, -1); 94 const SimpleResultCachingPolicy(-1, -1);
50 95
51 /** 96 /**
52 * The [ResultCachingPolicy] for [TOKEN_STREAM]. 97 * The [ResultCachingPolicy] for [TOKEN_STREAM].
53 */ 98 */
54 const ResultCachingPolicy TOKEN_STREAM_CACHING_POLICY = 99 const ResultCachingPolicy<Token> TOKEN_STREAM_CACHING_POLICY =
55 const SimpleResultCachingPolicy(1, 1); 100 const SimpleResultCachingPolicy(1, 1);
56 101
57 /** 102 /**
103 * The [ResultCachingPolicy] for [UsedImportedElements]s.
104 */
105 const ResultCachingPolicy<UsedImportedElements> USED_IMPORTED_ELEMENTS_POLICY =
106 const SimpleResultCachingPolicy(-1, -1);
107
108 /**
109 * The [ResultCachingPolicy] for [UsedLocalElements]s.
110 */
111 const ResultCachingPolicy<UsedLocalElements> USED_LOCAL_ELEMENTS_POLICY =
112 const SimpleResultCachingPolicy(-1, -1);
113
114 /**
58 * The errors produced while resolving a library directives. 115 * The errors produced while resolving a library directives.
59 * 116 *
60 * The list will be empty if there were no errors, but will not be `null`. 117 * The list will be empty if there were no errors, but will not be `null`.
61 * 118 *
62 * The result is only available for [Source]s representing a library. 119 * The result is only available for [Source]s representing a library.
63 */ 120 */
64 final ListResultDescriptor<AnalysisError> BUILD_DIRECTIVES_ERRORS = 121 final ListResultDescriptor<AnalysisError> BUILD_DIRECTIVES_ERRORS =
65 new ListResultDescriptor<AnalysisError>( 122 new ListResultDescriptor<AnalysisError>(
66 'BUILD_DIRECTIVES_ERRORS', AnalysisError.NO_ERRORS); 123 'BUILD_DIRECTIVES_ERRORS', AnalysisError.NO_ERRORS);
67 124
68 /** 125 /**
69 * The errors produced while building a library element. 126 * The errors produced while building a library element.
70 * 127 *
71 * The list will be empty if there were no errors, but will not be `null`. 128 * The list will be empty if there were no errors, but will not be `null`.
72 * 129 *
73 * The result is only available for [Source]s representing a library. 130 * The result is only available for [Source]s representing a library.
74 */ 131 */
75 final ListResultDescriptor<AnalysisError> BUILD_LIBRARY_ERRORS = 132 final ListResultDescriptor<AnalysisError> BUILD_LIBRARY_ERRORS =
76 new ListResultDescriptor<AnalysisError>( 133 new ListResultDescriptor<AnalysisError>(
77 'BUILD_LIBRARY_ERRORS', AnalysisError.NO_ERRORS); 134 'BUILD_LIBRARY_ERRORS', AnalysisError.NO_ERRORS);
78 135
79 /** 136 /**
80 * A list of the [ConstantEvaluationTarget]s defined in a unit. This includes 137 * A list of the [ConstantEvaluationTarget]s defined in a unit. This includes
81 * constants defined at top level, statically inside classes, and local to 138 * constants defined at top level, statically inside classes, and local to
82 * functions, as well as constant constructors, annotations, and default values 139 * functions, as well as constant constructors, annotations, and default values
83 * of parameters to constant constructors. 140 * of parameters.
84 * 141 *
85 * The result is only available for [LibrarySpecificUnit]s. 142 * The result is only available for [LibrarySpecificUnit]s.
86 */ 143 */
87 final ListResultDescriptor< 144 final ListResultDescriptor<ConstantEvaluationTarget>
88 ConstantEvaluationTarget> COMPILATION_UNIT_CONSTANTS = 145 COMPILATION_UNIT_CONSTANTS =
89 new ListResultDescriptor<ConstantEvaluationTarget>( 146 new ListResultDescriptor<ConstantEvaluationTarget>(
90 'COMPILATION_UNIT_CONSTANTS', null, 147 'COMPILATION_UNIT_CONSTANTS', null,
91 cachingPolicy: ELEMENT_CACHING_POLICY); 148 cachingPolicy: CONSTANT_EVALUATION_TARGET_LIST_POLICY);
92 149
93 /** 150 /**
94 * The element model associated with a single compilation unit. 151 * The element model associated with a single compilation unit.
95 * 152 *
96 * The result is only available for [LibrarySpecificUnit]s. 153 * The result is only available for [LibrarySpecificUnit]s.
97 */ 154 */
98 final ResultDescriptor<CompilationUnitElement> COMPILATION_UNIT_ELEMENT = 155 final ResultDescriptor<CompilationUnitElement> COMPILATION_UNIT_ELEMENT =
99 new ResultDescriptor<CompilationUnitElement>( 156 new ResultDescriptor<CompilationUnitElement>(
100 'COMPILATION_UNIT_ELEMENT', null, 157 'COMPILATION_UNIT_ELEMENT', null,
101 cachingPolicy: ELEMENT_CACHING_POLICY); 158 cachingPolicy: ELEMENT_CACHING_POLICY);
102 159
103 /** 160 /**
104 * The list of [ConstantEvaluationTarget]s on which the target constant element 161 * The list of [ConstantEvaluationTarget]s on which the target constant element
105 * depends. 162 * depends.
106 * 163 *
107 * The result is only available for targets representing a 164 * The result is only available for targets representing a
108 * [ConstantEvaluationTarget] (i.e. a constant variable declaration, a constant 165 * [ConstantEvaluationTarget] (i.e. a constant variable declaration, a constant
109 * constructor, or a parameter element with a default value). 166 * constructor, or a parameter element with a default value).
110 */ 167 */
111 final ListResultDescriptor<ConstantEvaluationTarget> CONSTANT_DEPENDENCIES = 168 final ListResultDescriptor<ConstantEvaluationTarget> CONSTANT_DEPENDENCIES =
112 new ListResultDescriptor<ConstantEvaluationTarget>( 169 new ListResultDescriptor<ConstantEvaluationTarget>(
113 'CONSTANT_DEPENDENCIES', const <ConstantEvaluationTarget>[]); 170 'CONSTANT_DEPENDENCIES', const <ConstantEvaluationTarget>[]);
114 171
115 /** 172 /**
173 * The flag specifying that the target constant element expression AST is
174 * resolved, i.e. identifiers have all required elements set.
175 *
176 * The result is only available for targets representing a
177 * [ConstantEvaluationTarget] (i.e. a constant variable declaration, a constant
178 * constructor, or a parameter element with a default value).
179 */
180 final ResultDescriptor<bool> CONSTANT_EXPRESSION_RESOLVED =
181 new ResultDescriptor<bool>('CONSTANT_EXPRESSION_RESOLVED', false);
182
183 /**
184 * The list of [ConstantEvaluationTarget]s on which constant expressions of a
185 * unit depend.
186 *
187 * The result is only available for [LibrarySpecificUnit]s.
188 */
189 final ListResultDescriptor<ConstantEvaluationTarget>
190 CONSTANT_EXPRESSIONS_DEPENDENCIES =
191 new ListResultDescriptor<ConstantEvaluationTarget>(
192 'CONSTANT_EXPRESSIONS_DEPENDENCIES',
193 const <ConstantEvaluationTarget>[]);
194
195 /**
116 * A [ConstantEvaluationTarget] that has been successfully constant-evaluated. 196 * A [ConstantEvaluationTarget] that has been successfully constant-evaluated.
117 * 197 *
118 * TODO(paulberry): is ELEMENT_CACHING_POLICY the correct caching policy? 198 * TODO(paulberry): is ELEMENT_CACHING_POLICY the correct caching policy?
119 * 199 *
120 * The result is only available for [ConstantEvaluationTarget]s. 200 * The result is only available for [ConstantEvaluationTarget]s.
121 * 201 *
122 */ 202 */
123 final ResultDescriptor<ConstantEvaluationTarget> CONSTANT_VALUE = 203 final ResultDescriptor<ConstantEvaluationTarget> CONSTANT_VALUE =
124 new ResultDescriptor<ConstantEvaluationTarget>('CONSTANT_VALUE', null, 204 new ResultDescriptor<ConstantEvaluationTarget>('CONSTANT_VALUE', null,
125 cachingPolicy: ELEMENT_CACHING_POLICY); 205 cachingPolicy: CONSTANT_EVALUATION_TARGET_POLICY);
126 206
127 /** 207 /**
128 * The sources representing the libraries that include a given source as a part. 208 * The sources representing the libraries that include a given source as a part.
129 * 209 *
130 * The result is only available for [Source]s representing a compilation unit. 210 * The result is only available for [Source]s representing a compilation unit.
131 */ 211 */
132 final ListResultDescriptor<Source> CONTAINING_LIBRARIES = 212 final ListResultDescriptor<Source> CONTAINING_LIBRARIES =
133 new ListResultDescriptor<Source>('CONTAINING_LIBRARIES', Source.EMPTY_LIST); 213 new ListResultDescriptor<Source>('CONTAINING_LIBRARIES', Source.EMPTY_LIST);
134 214
135 /** 215 /**
216 * The flag specifying that [RESOLVED_UNIT] has been been computed for this
217 * compilation unit (without requiring that the AST for it still be in cache).
218 *
219 * The result is only available for [LibrarySpecificUnit]s.
220 */
221 final ResultDescriptor<bool> CREATED_RESOLVED_UNIT =
222 new ResultDescriptor<bool>('CREATED_RESOLVED_UNIT', false);
223
224 /**
225 * The flag specifying that [RESOLVED_UNIT1] has been been computed for this
226 * compilation unit (without requiring that the AST for it still be in cache).
227 *
228 * The result is only available for [LibrarySpecificUnit]s.
229 */
230 final ResultDescriptor<bool> CREATED_RESOLVED_UNIT1 =
231 new ResultDescriptor<bool>('CREATED_RESOLVED_UNIT1', false);
232
233 /**
234 * The flag specifying that [RESOLVED_UNIT10] has been been computed for this
235 * compilation unit (without requiring that the AST for it still be in cache).
236 *
237 * The result is only available for [LibrarySpecificUnit]s.
238 */
239 final ResultDescriptor<bool> CREATED_RESOLVED_UNIT10 =
240 new ResultDescriptor<bool>('CREATED_RESOLVED_UNIT10', false);
241
242 /**
243 * The flag specifying that [RESOLVED_UNIT11] has been been computed for this
244 * compilation unit (without requiring that the AST for it still be in cache).
245 *
246 * The result is only available for [LibrarySpecificUnit]s.
247 */
248 final ResultDescriptor<bool> CREATED_RESOLVED_UNIT11 =
249 new ResultDescriptor<bool>('CREATED_RESOLVED_UNIT11', false);
250
251 /**
252 * The flag specifying that [RESOLVED_UNIT12] has been been computed for this
253 * compilation unit (without requiring that the AST for it still be in cache).
254 *
255 * The result is only available for [LibrarySpecificUnit]s.
256 */
257 final ResultDescriptor<bool> CREATED_RESOLVED_UNIT12 =
258 new ResultDescriptor<bool>('CREATED_RESOLVED_UNIT12', false);
259
260 /**
261 * The flag specifying that [RESOLVED_UNIT2] has been been computed for this
262 * compilation unit (without requiring that the AST for it still be in cache).
263 *
264 * The result is only available for [LibrarySpecificUnit]s.
265 */
266 final ResultDescriptor<bool> CREATED_RESOLVED_UNIT2 =
267 new ResultDescriptor<bool>('CREATED_RESOLVED_UNIT2', false);
268
269 /**
270 * The flag specifying that [RESOLVED_UNIT3] has been been computed for this
271 * compilation unit (without requiring that the AST for it still be in cache).
272 *
273 * The result is only available for [LibrarySpecificUnit]s.
274 */
275 final ResultDescriptor<bool> CREATED_RESOLVED_UNIT3 =
276 new ResultDescriptor<bool>('CREATED_RESOLVED_UNIT3', false);
277
278 /**
279 * The flag specifying that [RESOLVED_UNIT4] has been been computed for this
280 * compilation unit (without requiring that the AST for it still be in cache).
281 *
282 * The result is only available for [LibrarySpecificUnit]s.
283 */
284 final ResultDescriptor<bool> CREATED_RESOLVED_UNIT4 =
285 new ResultDescriptor<bool>('CREATED_RESOLVED_UNIT4', false);
286
287 /**
288 * The flag specifying that [RESOLVED_UNIT5] has been been computed for this
289 * compilation unit (without requiring that the AST for it still be in cache).
290 *
291 * The result is only available for [LibrarySpecificUnit]s.
292 */
293 final ResultDescriptor<bool> CREATED_RESOLVED_UNIT5 =
294 new ResultDescriptor<bool>('CREATED_RESOLVED_UNIT5', false);
295
296 /**
297 * The flag specifying that [RESOLVED_UNIT6] has been been computed for this
298 * compilation unit (without requiring that the AST for it still be in cache).
299 *
300 * The result is only available for [LibrarySpecificUnit]s.
301 */
302 final ResultDescriptor<bool> CREATED_RESOLVED_UNIT6 =
303 new ResultDescriptor<bool>('CREATED_RESOLVED_UNIT6', false);
304
305 /**
306 * The flag specifying that [RESOLVED_UNIT7] has been been computed for this
307 * compilation unit (without requiring that the AST for it still be in cache).
308 *
309 * The result is only available for [LibrarySpecificUnit]s.
310 */
311 final ResultDescriptor<bool> CREATED_RESOLVED_UNIT7 =
312 new ResultDescriptor<bool>('CREATED_RESOLVED_UNIT7', false);
313
314 /**
315 * The flag specifying that [RESOLVED_UNIT8] has been been computed for this
316 * compilation unit (without requiring that the AST for it still be in cache).
317 *
318 * The result is only available for [LibrarySpecificUnit]s.
319 */
320 final ResultDescriptor<bool> CREATED_RESOLVED_UNIT8 =
321 new ResultDescriptor<bool>('CREATED_RESOLVED_UNIT8', false);
322
323 /**
324 * The flag specifying that [RESOLVED_UNIT9] has been been computed for this
325 * compilation unit (without requiring that the AST for it still be in cache).
326 *
327 * The result is only available for [LibrarySpecificUnit]s.
328 */
329 final ResultDescriptor<bool> CREATED_RESOLVED_UNIT9 =
330 new ResultDescriptor<bool>('CREATED_RESOLVED_UNIT9', false);
331
332 /**
333 * All [AnalysisError]s results for [Source]s.
334 */
335 final List<ListResultDescriptor<AnalysisError>> ERROR_SOURCE_RESULTS =
336 <ListResultDescriptor<AnalysisError>>[
337 BUILD_DIRECTIVES_ERRORS,
338 BUILD_LIBRARY_ERRORS,
339 PARSE_ERRORS,
340 SCAN_ERRORS,
341 ];
342
343 /**
344 * All [AnalysisError]s results in for [LibrarySpecificUnit]s.
345 */
346 final List<ListResultDescriptor<AnalysisError>> ERROR_UNIT_RESULTS =
347 <ListResultDescriptor<AnalysisError>>[
348 HINTS,
349 LIBRARY_UNIT_ERRORS,
350 LINTS,
351 RESOLVE_TYPE_BOUNDS_ERRORS,
352 RESOLVE_TYPE_NAMES_ERRORS,
353 RESOLVE_UNIT_ERRORS,
354 STRONG_MODE_ERRORS,
355 VARIABLE_REFERENCE_ERRORS,
356 VERIFY_ERRORS
357 ];
358
359 /**
136 * The sources representing the export closure of a library. 360 * The sources representing the export closure of a library.
137 * The [Source]s include only library sources, not their units. 361 * The [Source]s include only library sources, not their units.
138 * 362 *
139 * The result is only available for [Source]s representing a library. 363 * The result is only available for [Source]s representing a library.
140 */ 364 */
141 final ListResultDescriptor<Source> EXPORT_SOURCE_CLOSURE = 365 final ListResultDescriptor<Source> EXPORT_SOURCE_CLOSURE =
142 new ListResultDescriptor<Source>('EXPORT_SOURCE_CLOSURE', null); 366 new ListResultDescriptor<Source>('EXPORT_SOURCE_CLOSURE', null);
143 367
144 /** 368 /**
145 * The errors produced while generating hints a compilation unit. 369 * The errors produced while generating hints a compilation unit.
146 * 370 *
147 * The list will be empty if there were no errors, but will not be `null`. 371 * The list will be empty if there were no errors, but will not be `null`.
148 * 372 *
149 * The result is only available for [LibrarySpecificUnit]s. 373 * The result is only available for [LibrarySpecificUnit]s.
150 */ 374 */
151 final ListResultDescriptor<AnalysisError> HINTS = 375 final ListResultDescriptor<AnalysisError> HINTS =
152 new ListResultDescriptor<AnalysisError>( 376 new ListResultDescriptor<AnalysisError>(
153 'HINT_ERRORS', AnalysisError.NO_ERRORS); 377 'HINT_ERRORS', AnalysisError.NO_ERRORS);
154 378
155 /** 379 /**
156 * The sources representing the combined import/export closure of a library. 380 * The ignore information for a [Source].
157 * The [Source]s include only library sources, not their units.
158 *
159 * The result is only available for [Source]s representing a library.
160 */ 381 */
161 final ListResultDescriptor<Source> IMPORT_EXPORT_SOURCE_CLOSURE = 382 final ResultDescriptor<IgnoreInfo> IGNORE_INFO =
162 new ListResultDescriptor<Source>('IMPORT_EXPORT_SOURCE_CLOSURE', null); 383 new ResultDescriptor<IgnoreInfo>('IGNORE_INFO', null);
163 384
164 /** 385 /**
165 * A list of the [VariableElement]s whose type should be inferred that another 386 * A list of the [VariableElement]s whose type should be inferred that another
166 * inferable static variable (the target) depends on. 387 * inferable static variable (the target) depends on.
167 * 388 *
168 * The result is only available for [VariableElement]s, and only when strong 389 * The result is only available for [VariableElement]s, and only when strong
169 * mode is enabled. 390 * mode is enabled.
170 */ 391 */
171 final ListResultDescriptor< 392 final ListResultDescriptor<VariableElement>
172 VariableElement> INFERABLE_STATIC_VARIABLE_DEPENDENCIES = 393 INFERABLE_STATIC_VARIABLE_DEPENDENCIES =
173 new ListResultDescriptor<VariableElement>( 394 new ListResultDescriptor<VariableElement>(
174 'INFERABLE_STATIC_VARIABLE_DEPENDENCIES', null); 395 'INFERABLE_STATIC_VARIABLE_DEPENDENCIES', null);
175 396
176 /** 397 /**
177 * A list of the [VariableElement]s defined in a unit whose type should be 398 * A list of the [VariableElement]s defined in a unit whose type should be
178 * inferred. This includes variables defined at the library level as well as 399 * inferred. This includes variables defined at the library level as well as
179 * static members inside classes. 400 * static members inside classes.
180 * 401 *
181 * The result is only available for [LibrarySpecificUnit]s, and only when strong 402 * The result is only available for [LibrarySpecificUnit]s, and only when strong
182 * mode is enabled. 403 * mode is enabled.
183 */ 404 */
184 final ListResultDescriptor<VariableElement> INFERABLE_STATIC_VARIABLES_IN_UNIT = 405 final ListResultDescriptor<VariableElement> INFERABLE_STATIC_VARIABLES_IN_UNIT =
185 new ListResultDescriptor<VariableElement>( 406 new ListResultDescriptor<VariableElement>(
186 'INFERABLE_STATIC_VARIABLES_IN_UNIT', null); 407 'INFERABLE_STATIC_VARIABLES_IN_UNIT', null);
187 408
188 /** 409 /**
189 * An inferrable static variable ([VariableElement]) whose type has been 410 * An inferable static variable ([VariableElement]) whose type has been
190 * inferred. 411 * inferred.
191 * 412 *
192 * The result is only available for [VariableElement]s, and only when strong 413 * The result is only available for [VariableElement]s, and only when strong
193 * mode is enabled. 414 * mode is enabled.
194 */ 415 */
195 final ResultDescriptor<VariableElement> INFERRED_STATIC_VARIABLE = 416 final ResultDescriptor<VariableElement> INFERRED_STATIC_VARIABLE =
196 new ResultDescriptor<VariableElement>('INFERRED_STATIC_VARIABLE', null, 417 new ResultDescriptor<VariableElement>('INFERRED_STATIC_VARIABLE', null,
197 cachingPolicy: ELEMENT_CACHING_POLICY); 418 cachingPolicy: ELEMENT_CACHING_POLICY);
198 419
199 /** 420 /**
200 * A list of the [LibraryElement]s that make up the strongly connected 421 * A list of the [LibraryElement]s that make up the strongly connected
201 * component in the import/export graph in which the target resides. 422 * component in the import/export graph in which the target resides.
202 * 423 *
203 * Only non-empty in strongMode. 424 * Only non-empty in strongMode.
204 * 425 *
205 * The result is only available for [LibrarySpecificUnit]s. 426 * The result is only available for [Source]s representing a library.
206 */ 427 */
207 final ListResultDescriptor<LibraryElement> LIBRARY_CYCLE = 428 final ListResultDescriptor<LibraryElement> LIBRARY_CYCLE =
208 new ListResultDescriptor<LibraryElement>('LIBRARY_CYCLE', null); 429 new ListResultDescriptor<LibraryElement>('LIBRARY_CYCLE', null);
209 430
210 /** 431 /**
211 * A list of the [CompilationUnitElement]s that comprise all of the parts and 432 * A list of the [LibrarySpecificUnit]s that comprise all of the parts and
212 * libraries in the direct import/export dependencies of the library cycle 433 * libraries in the direct import/export dependencies of the library cycle
213 * of the target, with the intra-component dependencies excluded. 434 * of the target, with the intra-component dependencies excluded.
214 * 435 *
215 * Only non-empty in strongMode. 436 * Only non-empty in strongMode.
216 * 437 *
217 * The result is only available for [LibrarySpecificUnit]s. 438 * The result is only available for [Source]s representing a library.
218 */ 439 */
219 final ListResultDescriptor<CompilationUnitElement> LIBRARY_CYCLE_DEPENDENCIES = 440 final ListResultDescriptor<LibrarySpecificUnit> LIBRARY_CYCLE_DEPENDENCIES =
220 new ListResultDescriptor<CompilationUnitElement>( 441 new ListResultDescriptor<LibrarySpecificUnit>(
221 'LIBRARY_CYCLE_DEPENDENCIES', null); 442 'LIBRARY_CYCLE_DEPENDENCIES', null);
222 443
223 /** 444 /**
224 * A list of the [CompilationUnitElement]s (including all parts) that make up 445 * A list of the [LibrarySpecificUnit]s (including all parts) that make up
225 * the strongly connected component in the import/export graph in which the 446 * the strongly connected component in the import/export graph in which the
226 * target resides. 447 * target resides.
227 * 448 *
228 * Only non-empty in strongMode. 449 * Only non-empty in strongMode.
229 * 450 *
230 * The result is only available for [LibrarySpecificUnit]s. 451 * The result is only available for [Source]s representing a library.
231 */ 452 */
232 final ListResultDescriptor<CompilationUnitElement> LIBRARY_CYCLE_UNITS = 453 final ListResultDescriptor<LibrarySpecificUnit> LIBRARY_CYCLE_UNITS =
233 new ListResultDescriptor<CompilationUnitElement>( 454 new ListResultDescriptor<LibrarySpecificUnit>('LIBRARY_CYCLE_UNITS', null);
234 'LIBRARY_CYCLE_UNITS', null);
235 455
236 /** 456 /**
237 * The partial [LibraryElement] associated with a library. 457 * The partial [LibraryElement] associated with a library.
238 * 458 *
239 * The [LibraryElement] and its [CompilationUnitElement]s are attached to each 459 * The [LibraryElement] and its [CompilationUnitElement]s are attached to each
240 * other. Directives 'library', 'part' and 'part of' are resolved. 460 * other. Directives 'library', 'part' and 'part of' are resolved.
241 * 461 *
242 * The result is only available for [Source]s representing a library. 462 * The result is only available for [Source]s representing a library.
243 */ 463 */
244 final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT1 = 464 final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT1 =
245 new ResultDescriptor<LibraryElement>('LIBRARY_ELEMENT1', null, 465 new ResultDescriptor<LibraryElement>('LIBRARY_ELEMENT1', null,
246 cachingPolicy: ELEMENT_CACHING_POLICY); 466 cachingPolicy: ELEMENT_CACHING_POLICY);
247 467
248 /** 468 /**
249 * The partial [LibraryElement] associated with a library. 469 * The partial [LibraryElement] associated with a library.
250 * 470 *
251 * In addition to [LIBRARY_ELEMENT1] [LibraryElement.imports] and 471 * In addition to [LIBRARY_ELEMENT1] also [LibraryElement.imports] and
252 * [LibraryElement.exports] are set. 472 * [LibraryElement.exports] are set.
253 * 473 *
254 * The result is only available for [Source]s representing a library. 474 * The result is only available for [Source]s representing a library.
255 */ 475 */
256 final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT2 = 476 final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT2 =
257 new ResultDescriptor<LibraryElement>('LIBRARY_ELEMENT2', null, 477 new ResultDescriptor<LibraryElement>('LIBRARY_ELEMENT2', null,
258 cachingPolicy: ELEMENT_CACHING_POLICY); 478 cachingPolicy: ELEMENT_CACHING_POLICY);
259 479
260 /** 480 /**
261 * The partial [LibraryElement] associated with a library. 481 * The partial [LibraryElement] associated with a library.
(...skipping 17 matching lines...) Expand all
279 * 499 *
280 * The result is only available for [Source]s representing a library. 500 * The result is only available for [Source]s representing a library.
281 */ 501 */
282 final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT4 = 502 final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT4 =
283 new ResultDescriptor<LibraryElement>('LIBRARY_ELEMENT4', null, 503 new ResultDescriptor<LibraryElement>('LIBRARY_ELEMENT4', null,
284 cachingPolicy: ELEMENT_CACHING_POLICY); 504 cachingPolicy: ELEMENT_CACHING_POLICY);
285 505
286 /** 506 /**
287 * The partial [LibraryElement] associated with a library. 507 * The partial [LibraryElement] associated with a library.
288 * 508 *
289 * [LIBRARY_ELEMENT4] plus resolved types for every element. 509 * [LIBRARY_ELEMENT5] plus resolved types type parameter bounds.
290 * 510 *
291 * The result is only available for [Source]s representing a library. 511 * The result is only available for [Source]s representing a library.
292 */ 512 */
293 final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT5 = 513 final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT5 =
294 new ResultDescriptor<LibraryElement>('LIBRARY_ELEMENT5', null, 514 new ResultDescriptor<LibraryElement>('LIBRARY_ELEMENT5', null,
295 cachingPolicy: ELEMENT_CACHING_POLICY); 515 cachingPolicy: ELEMENT_CACHING_POLICY);
296 516
297 /** 517 /**
518 * The partial [LibraryElement] associated with a library.
519 *
520 * [LIBRARY_ELEMENT5] plus resolved types for every element.
521 *
522 * The result is only available for [Source]s representing a library.
523 */
524 final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT6 =
525 new ResultDescriptor<LibraryElement>('LIBRARY_ELEMENT6', null,
526 cachingPolicy: ELEMENT_CACHING_POLICY);
527
528 /**
529 * The partial [LibraryElement] associated with a library.
530 *
531 * [LIBRARY_ELEMENT6] plus [RESOLVED_UNIT7] for all library units.
532 *
533 * The result is only available for [Source]s representing a library.
534 */
535 final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT7 =
536 new ResultDescriptor<LibraryElement>('LIBRARY_ELEMENT7', null,
537 cachingPolicy: ELEMENT_CACHING_POLICY);
538
539 /**
540 * The partial [LibraryElement] associated with a library.
541 *
542 * [LIBRARY_ELEMENT7] for the library and its import/export closure.
543 *
544 * The result is only available for [Source]s representing a library.
545 */
546 final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT8 =
547 new ResultDescriptor<LibraryElement>('LIBRARY_ELEMENT8', null,
548 cachingPolicy: ELEMENT_CACHING_POLICY);
549
550 /**
551 * The partial [LibraryElement] associated with a library.
552 *
553 * The same as a [LIBRARY_ELEMENT8].
554 *
555 * The result is only available for [Source]s representing a library.
556 */
557 final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT9 =
558 new ResultDescriptor<LibraryElement>('LIBRARY_ELEMENT9', null,
559 cachingPolicy: ELEMENT_CACHING_POLICY);
560
561 /**
562 * List of all `LIBRARY_ELEMENT` results.
563 */
564 final List<ResultDescriptor<LibraryElement>> LIBRARY_ELEMENT_RESULTS =
565 <ResultDescriptor<LibraryElement>>[
566 LIBRARY_ELEMENT1,
567 LIBRARY_ELEMENT2,
568 LIBRARY_ELEMENT3,
569 LIBRARY_ELEMENT4,
570 LIBRARY_ELEMENT5,
571 LIBRARY_ELEMENT6,
572 LIBRARY_ELEMENT7,
573 LIBRARY_ELEMENT8,
574 LIBRARY_ELEMENT9,
575 LIBRARY_ELEMENT
576 ];
577
578 /**
298 * The flag specifying whether all analysis errors are computed in a specific 579 * The flag specifying whether all analysis errors are computed in a specific
299 * library. 580 * library.
300 * 581 *
301 * The result is only available for [Source]s representing a library. 582 * The result is only available for [Source]s representing a library.
302 */ 583 */
303 final ResultDescriptor<bool> LIBRARY_ERRORS_READY = 584 final ResultDescriptor<bool> LIBRARY_ERRORS_READY =
304 new ResultDescriptor<bool>('LIBRARY_ERRORS_READY', false); 585 new ResultDescriptor<bool>('LIBRARY_ERRORS_READY', false);
305 586
306 /** 587 /**
588 * The [LibrarySpecificUnit]s that a library consists of.
589 *
590 * The list will include the defining unit and units for [INCLUDED_PARTS].
591 * So, it is never empty or `null`.
592 *
593 * The result is only available for [Source]s representing a library.
594 */
595 final ListResultDescriptor<LibrarySpecificUnit> LIBRARY_SPECIFIC_UNITS =
596 new ListResultDescriptor<LibrarySpecificUnit>(
597 'LIBRARY_SPECIFIC_UNITS', LibrarySpecificUnit.EMPTY_LIST);
598
599 /**
307 * The analysis errors associated with a compilation unit in a specific library. 600 * The analysis errors associated with a compilation unit in a specific library.
308 * 601 *
309 * The result is only available for [LibrarySpecificUnit]s. 602 * The result is only available for [LibrarySpecificUnit]s.
310 */ 603 */
311 final ListResultDescriptor<AnalysisError> LIBRARY_UNIT_ERRORS = 604 final ListResultDescriptor<AnalysisError> LIBRARY_UNIT_ERRORS =
312 new ListResultDescriptor<AnalysisError>( 605 new ListResultDescriptor<AnalysisError>(
313 'LIBRARY_UNIT_ERRORS', AnalysisError.NO_ERRORS); 606 'LIBRARY_UNIT_ERRORS', AnalysisError.NO_ERRORS);
314 607
315 /** 608 /**
316 * The errors produced while generating lints for a compilation unit. 609 * The errors produced while generating lints for a compilation unit.
(...skipping 11 matching lines...) Expand all
328 * 621 *
329 * The list will be empty if there were no errors, but will not be `null`. 622 * The list will be empty if there were no errors, but will not be `null`.
330 * 623 *
331 * The result is only available for [Source]s representing a compilation unit. 624 * The result is only available for [Source]s representing a compilation unit.
332 */ 625 */
333 final ListResultDescriptor<AnalysisError> PARSE_ERRORS = 626 final ListResultDescriptor<AnalysisError> PARSE_ERRORS =
334 new ListResultDescriptor<AnalysisError>( 627 new ListResultDescriptor<AnalysisError>(
335 'PARSE_ERRORS', AnalysisError.NO_ERRORS); 628 'PARSE_ERRORS', AnalysisError.NO_ERRORS);
336 629
337 /** 630 /**
631 * The list of [PendingError]s for a compilation unit.
632 *
633 * The result is only available for [LibrarySpecificUnit]s.
634 */
635 final ListResultDescriptor<PendingError> PENDING_ERRORS =
636 new ListResultDescriptor<PendingError>(
637 'PENDING_ERRORS', const <PendingError>[]);
638
639 /**
640 * The flag specifying that [LIBRARY_ELEMENT2] is ready for a library and its
641 * import/export closure.
642 *
643 * The result is only available for [Source]s representing a library.
644 */
645 final ResultDescriptor<bool> READY_LIBRARY_ELEMENT2 =
646 new ResultDescriptor<bool>('READY_LIBRARY_ELEMENT2', false);
647
648 /**
649 * The flag specifying that [LIBRARY_ELEMENT6] is ready for a library and its
650 * import/export closure.
651 *
652 * The result is only available for [Source]s representing a library.
653 */
654 final ResultDescriptor<bool> READY_LIBRARY_ELEMENT6 =
655 new ResultDescriptor<bool>('READY_LIBRARY_ELEMENT6', false);
656
657 /**
658 * The flag specifying that [LIBRARY_ELEMENT7] is ready for a library and its
659 * import/export closure.
660 *
661 * The result is only available for [Source]s representing a library.
662 */
663 final ResultDescriptor<bool> READY_LIBRARY_ELEMENT7 =
664 new ResultDescriptor<bool>('READY_LIBRARY_ELEMENT7', false);
665
666 /**
667 * The flag specifying that [RESOLVED_UNIT] is ready for all of the units of a
668 * library.
669 *
670 * The result is only available for [Source]s representing a library.
671 */
672 final ResultDescriptor<bool> READY_RESOLVED_UNIT =
673 new ResultDescriptor<bool>('READY_RESOLVED_UNIT', false);
674
675 /**
338 * The names (resolved and not) referenced by a unit. 676 * The names (resolved and not) referenced by a unit.
339 * 677 *
340 * The result is only available for [Source]s representing a compilation unit. 678 * The result is only available for [Source]s representing a compilation unit.
341 */ 679 */
342 final ResultDescriptor<ReferencedNames> REFERENCED_NAMES = 680 final ResultDescriptor<ReferencedNames> REFERENCED_NAMES =
343 new ResultDescriptor<ReferencedNames>('REFERENCED_NAMES', null); 681 new ResultDescriptor<ReferencedNames>('REFERENCED_NAMES', null);
344 682
345 /** 683 /**
684 * The sources of the Dart files that a library references.
685 *
686 * The list is the union of [IMPORTED_LIBRARIES], [EXPORTED_LIBRARIES] and
687 * [UNITS] of the defining unit and [INCLUDED_PARTS]. Never empty or `null`.
688 *
689 * The result is only available for [Source]s representing a library.
690 */
691 final ListResultDescriptor<Source> REFERENCED_SOURCES =
692 new ListResultDescriptor<Source>('REFERENCED_SOURCES', Source.EMPTY_LIST);
693
694 /**
695 * The list of [ConstantEvaluationTarget]s on which error verification depends.
696 *
697 * The result is only available for [LibrarySpecificUnit]s.
698 */
699 final ListResultDescriptor<ConstantEvaluationTarget> REQUIRED_CONSTANTS =
700 new ListResultDescriptor<ConstantEvaluationTarget>(
701 'REQUIRED_CONSTANTS', const <ConstantEvaluationTarget>[]);
702
703 /**
704 * The errors produced while resolving bounds of type parameters of classes,
705 * class and function aliases.
706 *
707 * The list will be empty if there were no errors, but will not be `null`.
708 *
709 * The result is only available for [LibrarySpecificUnit]s.
710 */
711 final ListResultDescriptor<AnalysisError> RESOLVE_TYPE_BOUNDS_ERRORS =
712 new ListResultDescriptor<AnalysisError>(
713 'RESOLVE_TYPE_BOUNDS_ERRORS', AnalysisError.NO_ERRORS);
714
715 /**
346 * The errors produced while resolving type names. 716 * The errors produced while resolving type names.
347 * 717 *
348 * The list will be empty if there were no errors, but will not be `null`. 718 * The list will be empty if there were no errors, but will not be `null`.
349 * 719 *
350 * The result is only available for [LibrarySpecificUnit]s. 720 * The result is only available for [LibrarySpecificUnit]s.
351 */ 721 */
352 final ListResultDescriptor<AnalysisError> RESOLVE_TYPE_NAMES_ERRORS = 722 final ListResultDescriptor<AnalysisError> RESOLVE_TYPE_NAMES_ERRORS =
353 new ListResultDescriptor<AnalysisError>( 723 new ListResultDescriptor<AnalysisError>(
354 'RESOLVE_TYPE_NAMES_ERRORS', AnalysisError.NO_ERRORS); 724 'RESOLVE_TYPE_NAMES_ERRORS', AnalysisError.NO_ERRORS);
355 725
(...skipping 12 matching lines...) Expand all
368 * The partially resolved [CompilationUnit] associated with a compilation unit. 738 * The partially resolved [CompilationUnit] associated with a compilation unit.
369 * 739 *
370 * Tasks that use this value as an input can assume that the [SimpleIdentifier]s 740 * Tasks that use this value as an input can assume that the [SimpleIdentifier]s
371 * at all declaration sites have been bound to the element defined by the 741 * at all declaration sites have been bound to the element defined by the
372 * declaration, except for the constants defined in an 'enum' declaration. 742 * declaration, except for the constants defined in an 'enum' declaration.
373 * 743 *
374 * The result is only available for [LibrarySpecificUnit]s. 744 * The result is only available for [LibrarySpecificUnit]s.
375 */ 745 */
376 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT1 = 746 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT1 =
377 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT1', null, 747 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT1', null,
748 cachingPolicy: AST_REUSABLE_CACHING_POLICY);
749
750 /**
751 * The resolved [CompilationUnit] associated with a compilation unit in which
752 * the types of class members have been inferred in addition to everything that
753 * is true of a [RESOLVED_UNIT9].
754 *
755 * The result is only available for [LibrarySpecificUnit]s.
756 */
757 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT10 =
758 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT10', null,
378 cachingPolicy: AST_CACHING_POLICY); 759 cachingPolicy: AST_CACHING_POLICY);
379 760
380 /** 761 /**
762 * The resolved [CompilationUnit] associated with a compilation unit, with
763 * constants not yet resolved.
764 *
765 * The result is only available for [LibrarySpecificUnit]s.
766 */
767 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT11 =
768 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT11', null,
769 cachingPolicy: AST_CACHING_POLICY);
770
771 /**
381 * The resolved [CompilationUnit] associated with a compilation unit, with 772 * The resolved [CompilationUnit] associated with a compilation unit, with
382 * constants resolved. 773 * constants resolved.
383 * 774 *
384 * The result is only available for [LibrarySpecificUnit]s. 775 * The result is only available for [LibrarySpecificUnit]s.
385 */ 776 */
386 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT10 = 777 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT12 =
387 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT10', null, 778 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT12', null,
388 cachingPolicy: AST_CACHING_POLICY); 779 cachingPolicy: AST_CACHING_POLICY);
389 780
390 /** 781 /**
391 * The partially resolved [CompilationUnit] associated with a compilation unit. 782 * The partially resolved [CompilationUnit] associated with a compilation unit.
392 * 783 *
784 * In addition to what is true of a [RESOLVED_UNIT1], tasks that use this value
785 * as an input can assume that its directives have been resolved.
786 *
787 * The result is only available for [LibrarySpecificUnit]s.
788 */
789 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT2 =
790 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT2', null,
791 cachingPolicy: AST_REUSABLE_CACHING_POLICY);
792
793 /**
794 * The partially resolved [CompilationUnit] associated with a compilation unit.
795 *
393 * Tasks that use this value as an input can assume that the [SimpleIdentifier]s 796 * Tasks that use this value as an input can assume that the [SimpleIdentifier]s
394 * at all declaration sites have been bound to the element defined by the 797 * at all declaration sites have been bound to the element defined by the
395 * declaration, including the constants defined in an 'enum' declaration. 798 * declaration, including the constants defined in an 'enum' declaration.
396 * 799 *
397 * The result is only available for [LibrarySpecificUnit]s. 800 * The result is only available for [LibrarySpecificUnit]s.
398 */ 801 */
399 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT2 =
400 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT2', null,
401 cachingPolicy: AST_CACHING_POLICY);
402
403 /**
404 * The partially resolved [CompilationUnit] associated with a compilation unit.
405 *
406 * In addition to what is true of a [RESOLVED_UNIT2], tasks that use this value
407 * as an input can assume that the types associated with declarations have been
408 * resolved. This includes the types of superclasses, mixins, interfaces,
409 * fields, return types, parameters, and local variables.
410 *
411 * The result is only available for [LibrarySpecificUnit]s.
412 */
413 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT3 = 802 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT3 =
414 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT3', null, 803 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT3', null,
415 cachingPolicy: AST_CACHING_POLICY); 804 cachingPolicy: AST_REUSABLE_CACHING_POLICY);
416 805
417 /** 806 /**
418 * The partially resolved [CompilationUnit] associated with a compilation unit. 807 * The partially resolved [CompilationUnit] associated with a compilation unit.
419 * 808 *
420 * In addition to what is true of a [RESOLVED_UNIT3], tasks that use this value 809 * In addition to what is true of a [RESOLVED_UNIT3], tasks that use this value
421 * as an input can assume that references to local variables and formal 810 * as an input can assume that the types associated with type bounds have been
422 * parameters have been resolved. 811 * resolved.
423 * 812 *
424 * The result is only available for [LibrarySpecificUnit]s. 813 * The result is only available for [LibrarySpecificUnit]s.
425 */ 814 */
426 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT4 = 815 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT4 =
427 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT4', null, 816 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT4', null,
428 cachingPolicy: AST_CACHING_POLICY); 817 cachingPolicy: AST_CACHING_POLICY);
429 818
430 /** 819 /**
431 * The partially resolved [CompilationUnit] associated with a compilation unit. 820 * The partially resolved [CompilationUnit] associated with a compilation unit.
432 * 821 *
433 * In addition to what is true of a [RESOLVED_UNIT4], tasks that use this value 822 * In addition to what is true of a [RESOLVED_UNIT4], tasks that use this value
434 * as an input can assume that elements and types associated with expressions 823 * as an input can assume that the types associated with declarations have been
435 * outside of method bodies (essentially initializers) have been initially 824 * resolved. This includes the types of superclasses, mixins, interfaces,
436 * resolved. 825 * fields, return types, parameters, and local variables.
437 * 826 *
438 * The result is only available for [LibrarySpecificUnit]s. 827 * The result is only available for [LibrarySpecificUnit]s.
439 */ 828 */
440 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT5 = 829 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT5 =
441 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT5', null, 830 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT5', null,
442 cachingPolicy: AST_CACHING_POLICY); 831 cachingPolicy: AST_CACHING_POLICY);
443 832
444 /** 833 /**
445 * The partially resolved [CompilationUnit] associated with a compilation unit. 834 * The partially resolved [CompilationUnit] associated with a compilation unit.
446 * 835 *
447 * In addition to what is true of a [RESOLVED_UNIT5], tasks that use this value 836 * In addition to what is true of a [RESOLVED_UNIT5], tasks that use this value
448 * as an input can assume that the types of static variables have been inferred. 837 * as an input can assume that references to local variables and formal
838 * parameters have been resolved.
449 * 839 *
450 * The result is only available for [LibrarySpecificUnit]s. 840 * The result is only available for [LibrarySpecificUnit]s.
451 */ 841 */
452 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT6 = 842 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT6 =
453 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT6', null, 843 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT6', null,
454 cachingPolicy: AST_CACHING_POLICY); 844 cachingPolicy: AST_CACHING_POLICY);
455 845
456 /** 846 /**
457 * The partially resolved [CompilationUnit] associated with a compilation unit. 847 * The partially resolved [CompilationUnit] associated with a compilation unit.
458 * 848 *
459 * In addition to what is true of a [RESOLVED_UNIT6], tasks that use this value 849 * In addition to what is true of a [RESOLVED_UNIT6], tasks that use this value
460 * as an input can assume that the initializers of instance variables have been 850 * as an input can assume that elements and types associated with expressions
461 * re-resolved. 851 * outside of method bodies (essentially initializers) have been initially
852 * resolved.
462 * 853 *
463 * The result is only available for [LibrarySpecificUnit]s. 854 * The result is only available for [LibrarySpecificUnit]s.
464 */ 855 */
465 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT7 = 856 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT7 =
466 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT7', null, 857 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT7', null,
467 cachingPolicy: AST_CACHING_POLICY); 858 cachingPolicy: AST_CACHING_POLICY);
468 859
469 /** 860 /**
470 * The resolved [CompilationUnit] associated with a compilation unit in which 861 * The partially resolved [CompilationUnit] associated with a compilation unit.
471 * the types of class members have been inferred in addition to everything that 862 *
472 * is true of a [RESOLVED_UNIT7]. 863 * In addition to what is true of a [RESOLVED_UNIT7], tasks that use this value
864 * as an input can assume that the types of static variables have been inferred.
473 * 865 *
474 * The result is only available for [LibrarySpecificUnit]s. 866 * The result is only available for [LibrarySpecificUnit]s.
475 */ 867 */
476 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT8 = 868 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT8 =
477 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT8', null, 869 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT8', null,
478 cachingPolicy: AST_CACHING_POLICY); 870 cachingPolicy: AST_CACHING_POLICY);
479 871
480 /** 872 /**
481 * The resolved [CompilationUnit] associated with a compilation unit, with 873 * The partially resolved [CompilationUnit] associated with a compilation unit.
482 * constants not yet resolved. 874 *
875 * In addition to what is true of a [RESOLVED_UNIT8], tasks that use this value
876 * as an input can assume that the initializers of instance variables have been
877 * re-resolved.
483 * 878 *
484 * The result is only available for [LibrarySpecificUnit]s. 879 * The result is only available for [LibrarySpecificUnit]s.
485 */ 880 */
486 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT9 = 881 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT9 =
487 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT9', null, 882 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT9', null,
488 cachingPolicy: AST_CACHING_POLICY); 883 cachingPolicy: AST_CACHING_POLICY);
489 884
490 /** 885 /**
886 * List of all `RESOLVED_UNITx` results.
887 */
888 final List<ResultDescriptor<CompilationUnit>> RESOLVED_UNIT_RESULTS =
889 <ResultDescriptor<CompilationUnit>>[
890 RESOLVED_UNIT1,
891 RESOLVED_UNIT2,
892 RESOLVED_UNIT3,
893 RESOLVED_UNIT4,
894 RESOLVED_UNIT5,
895 RESOLVED_UNIT6,
896 RESOLVED_UNIT7,
897 RESOLVED_UNIT8,
898 RESOLVED_UNIT9,
899 RESOLVED_UNIT10,
900 RESOLVED_UNIT11,
901 RESOLVED_UNIT12,
902 RESOLVED_UNIT
903 ];
904
905 /**
491 * The errors produced while scanning a compilation unit. 906 * The errors produced while scanning a compilation unit.
492 * 907 *
493 * The list will be empty if there were no errors, but will not be `null`. 908 * The list will be empty if there were no errors, but will not be `null`.
494 * 909 *
495 * The result is only available for [Source]s representing a compilation unit. 910 * The result is only available for [Source]s representing a compilation unit.
496 */ 911 */
497 final ListResultDescriptor<AnalysisError> SCAN_ERRORS = 912 final ListResultDescriptor<AnalysisError> SCAN_ERRORS =
498 new ListResultDescriptor<AnalysisError>( 913 new ListResultDescriptor<AnalysisError>(
499 'SCAN_ERRORS', AnalysisError.NO_ERRORS); 914 'SCAN_ERRORS', AnalysisError.NO_ERRORS);
500 915
501 /** 916 /**
917 * The errors produced while resolving a static [VariableElement] initializer.
918 *
919 * The result is only available for [VariableElement]s, and only when strong
920 * mode is enabled.
921 */
922 final ListResultDescriptor<AnalysisError> STATIC_VARIABLE_RESOLUTION_ERRORS =
923 new ListResultDescriptor<AnalysisError>(
924 'STATIC_VARIABLE_RESOLUTION_ERRORS', AnalysisError.NO_ERRORS);
925
926 /**
927 * A list of the [AnalysisError]s reported while resolving static
928 * [INFERABLE_STATIC_VARIABLES_IN_UNIT] defined in a unit.
929 *
930 * The result is only available for [LibrarySpecificUnit]s, and only when strong
931 * mode is enabled.
932 */
933 final ListResultDescriptor<AnalysisError>
934 STATIC_VARIABLE_RESOLUTION_ERRORS_IN_UNIT =
935 new ListResultDescriptor<AnalysisError>(
936 'STATIC_VARIABLE_RESOLUTION_ERRORS_IN_UNIT', AnalysisError.NO_ERRORS);
937
938 /**
502 * The additional strong mode errors produced while verifying a 939 * The additional strong mode errors produced while verifying a
503 * compilation unit. 940 * compilation unit.
504 * 941 *
505 * The list will be empty if there were no errors, but will not be `null`. 942 * The list will be empty if there were no errors, but will not be `null`.
506 * 943 *
507 * The result is only available for [LibrarySpecificUnits]s representing a 944 * The result is only available for [LibrarySpecificUnits]s representing a
508 * compilation unit. 945 * compilation unit.
509 * 946 *
510 */ 947 */
511 final ListResultDescriptor<AnalysisError> STRONG_MODE_ERRORS = 948 final ListResultDescriptor<AnalysisError> STRONG_MODE_ERRORS =
512 new ListResultDescriptor<AnalysisError>( 949 new ListResultDescriptor<AnalysisError>(
513 'STRONG_MODE_ERRORS', AnalysisError.NO_ERRORS); 950 'STRONG_MODE_ERRORS', AnalysisError.NO_ERRORS);
514 951
515 /** 952 /**
516 * The [TypeProvider] of the [AnalysisContext]. 953 * The [TypeProvider] of the [AnalysisContext].
517 */ 954 */
518 final ResultDescriptor<TypeProvider> TYPE_PROVIDER = 955 final ResultDescriptor<TypeProvider> TYPE_PROVIDER =
519 new ResultDescriptor<TypeProvider>('TYPE_PROVIDER', null); 956 new ResultDescriptor<TypeProvider>('TYPE_PROVIDER', null);
520 957
521 /** 958 /**
522 * The [UsedImportedElements] of a [LibrarySpecificUnit]. 959 * The [UsedImportedElements] of a [LibrarySpecificUnit].
523 */ 960 */
524 final ResultDescriptor<UsedImportedElements> USED_IMPORTED_ELEMENTS = 961 final ResultDescriptor<UsedImportedElements> USED_IMPORTED_ELEMENTS =
525 new ResultDescriptor<UsedImportedElements>('USED_IMPORTED_ELEMENTS', null, 962 new ResultDescriptor<UsedImportedElements>('USED_IMPORTED_ELEMENTS', null,
526 cachingPolicy: ELEMENT_CACHING_POLICY); 963 cachingPolicy: USED_IMPORTED_ELEMENTS_POLICY);
527 964
528 /** 965 /**
529 * The [UsedLocalElements] of a [LibrarySpecificUnit]. 966 * The [UsedLocalElements] of a [LibrarySpecificUnit].
530 */ 967 */
531 final ResultDescriptor<UsedLocalElements> USED_LOCAL_ELEMENTS = 968 final ResultDescriptor<UsedLocalElements> USED_LOCAL_ELEMENTS =
532 new ResultDescriptor<UsedLocalElements>('USED_LOCAL_ELEMENTS', null, 969 new ResultDescriptor<UsedLocalElements>('USED_LOCAL_ELEMENTS', null,
533 cachingPolicy: ELEMENT_CACHING_POLICY); 970 cachingPolicy: USED_LOCAL_ELEMENTS_POLICY);
534 971
535 /** 972 /**
536 * The errors produced while resolving variable references in a compilation unit . 973 * The errors produced while resolving variable references in a compilation unit .
537 * 974 *
538 * The list will be empty if there were no errors, but will not be `null`. 975 * The list will be empty if there were no errors, but will not be `null`.
539 * 976 *
540 * The result is only available for [LibrarySpecificUnit]s. 977 * The result is only available for [LibrarySpecificUnit]s.
541 */ 978 */
542 final ListResultDescriptor<AnalysisError> VARIABLE_REFERENCE_ERRORS = 979 final ListResultDescriptor<AnalysisError> VARIABLE_REFERENCE_ERRORS =
543 new ListResultDescriptor<AnalysisError>( 980 new ListResultDescriptor<AnalysisError>(
544 'VARIABLE_REFERENCE_ERRORS', AnalysisError.NO_ERRORS); 981 'VARIABLE_REFERENCE_ERRORS', AnalysisError.NO_ERRORS);
545 982
546 /** 983 /**
547 * The errors produced while verifying a compilation unit. 984 * The errors produced while verifying a compilation unit.
548 * 985 *
549 * The list will be empty if there were no errors, but will not be `null`. 986 * The list will be empty if there were no errors, but will not be `null`.
550 * 987 *
551 * The result is only available for [LibrarySpecificUnit]s. 988 * The result is only available for [LibrarySpecificUnit]s.
552 */ 989 */
553 final ListResultDescriptor<AnalysisError> VERIFY_ERRORS = 990 final ListResultDescriptor<AnalysisError> VERIFY_ERRORS =
554 new ListResultDescriptor<AnalysisError>( 991 new ListResultDescriptor<AnalysisError>(
555 'VERIFY_ERRORS', AnalysisError.NO_ERRORS); 992 'VERIFY_ERRORS', AnalysisError.NO_ERRORS);
556 993
557 /** 994 /**
995 * Return a list of unique errors for the [Source] of the given [target].
996 */
997 List<AnalysisError> getTargetSourceErrors(
998 RecordingErrorListener listener, AnalysisTarget target) {
999 Source source = target.source;
1000 List<AnalysisError> errors = listener.getErrorsForSource(source);
1001 return getUniqueErrors(errors);
1002 }
1003
1004 /**
558 * Return a list of errors containing the errors from the given [errors] list 1005 * Return a list of errors containing the errors from the given [errors] list
559 * but with duplications removed. 1006 * but with duplications removed.
560 */ 1007 */
561 List<AnalysisError> removeDuplicateErrors(List<AnalysisError> errors) { 1008 List<AnalysisError> getUniqueErrors(List<AnalysisError> errors) {
562 if (errors.isEmpty) { 1009 if (errors.isEmpty) {
563 return errors; 1010 return errors;
564 } 1011 }
565 return errors.toSet().toList(); 1012 return errors.toSet().toList();
566 } 1013 }
567 1014
568 /** 1015 /**
569 * A task that builds a compilation unit element for a single compilation unit. 1016 * A task that builds a compilation unit element for a single compilation unit.
570 */ 1017 */
571 class BuildCompilationUnitElementTask extends SourceBasedAnalysisTask { 1018 class BuildCompilationUnitElementTask extends SourceBasedAnalysisTask {
572 /** 1019 /**
573 * The name of the input whose value is the AST for the compilation unit. 1020 * The name of the input whose value is the AST for the compilation unit.
574 */ 1021 */
575 static const String PARSED_UNIT_INPUT_NAME = 'PARSED_UNIT_INPUT_NAME'; 1022 static const String PARSED_UNIT_INPUT_NAME = 'PARSED_UNIT_INPUT_NAME';
576 1023
577 /** 1024 /**
578 * The task descriptor describing this kind of task. 1025 * The task descriptor describing this kind of task.
579 */ 1026 */
580 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 1027 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
581 'BuildCompilationUnitElementTask', 1028 'BuildCompilationUnitElementTask',
582 createTask, 1029 createTask,
583 buildInputs, <ResultDescriptor>[ 1030 buildInputs, <ResultDescriptor>[
584 COMPILATION_UNIT_CONSTANTS, 1031 COMPILATION_UNIT_CONSTANTS,
585 COMPILATION_UNIT_ELEMENT, 1032 COMPILATION_UNIT_ELEMENT,
1033 CREATED_RESOLVED_UNIT1,
586 RESOLVED_UNIT1 1034 RESOLVED_UNIT1
587 ]); 1035 ]);
588 1036
589 /** 1037 /**
590 * Initialize a newly created task to build a compilation unit element for 1038 * Initialize a newly created task to build a compilation unit element for
591 * the given [target] in the given [context]. 1039 * the given [target] in the given [context].
592 */ 1040 */
593 BuildCompilationUnitElementTask( 1041 BuildCompilationUnitElementTask(
594 InternalAnalysisContext context, AnalysisTarget target) 1042 InternalAnalysisContext context, AnalysisTarget target)
595 : super(context, target); 1043 : super(context, target);
596 1044
597 @override 1045 @override
598 TaskDescriptor get descriptor => DESCRIPTOR; 1046 TaskDescriptor get descriptor => DESCRIPTOR;
599 1047
600 @override 1048 @override
601 void internalPerform() { 1049 void internalPerform() {
602 // 1050 //
603 // Prepare inputs. 1051 // Prepare inputs.
604 // 1052 //
605 LibrarySpecificUnit librarySpecificUnit = target; 1053 LibrarySpecificUnit librarySpecificUnit = target;
606 Source source = getRequiredSource(); 1054 Source source = getRequiredSource();
607 CompilationUnit unit = getRequiredInput(PARSED_UNIT_INPUT_NAME); 1055 CompilationUnit unit = getRequiredInput(PARSED_UNIT_INPUT_NAME);
608 // 1056 //
1057 // Try to get the existing CompilationUnitElement.
1058 //
1059 CompilationUnitElement element;
1060 {
1061 InternalAnalysisContext internalContext =
1062 context as InternalAnalysisContext;
1063 AnalysisCache analysisCache = internalContext.analysisCache;
1064 CacheEntry cacheEntry = internalContext.getCacheEntry(target);
1065 element = analysisCache.getValue(target, COMPILATION_UNIT_ELEMENT);
1066 if (element == null &&
1067 internalContext.aboutToComputeResult(
1068 cacheEntry, COMPILATION_UNIT_ELEMENT)) {
1069 element = analysisCache.getValue(target, COMPILATION_UNIT_ELEMENT);
1070 }
1071 }
1072 //
609 // Build or reuse CompilationUnitElement. 1073 // Build or reuse CompilationUnitElement.
610 // 1074 //
611 // unit = AstCloner.clone(unit);
612 AnalysisCache analysisCache =
613 (context as InternalAnalysisContext).analysisCache;
614 CompilationUnitElement element =
615 analysisCache.getValue(target, COMPILATION_UNIT_ELEMENT);
616 if (element == null) { 1075 if (element == null) {
617 CompilationUnitBuilder builder = new CompilationUnitBuilder(); 1076 CompilationUnitBuilder builder = new CompilationUnitBuilder();
618 element = builder.buildCompilationUnit( 1077 element = builder.buildCompilationUnit(
619 source, unit, librarySpecificUnit.library); 1078 source, unit, librarySpecificUnit.library);
620 } else { 1079 } else {
621 new DeclarationResolver().resolve(unit, element); 1080 new DeclarationResolver().resolve(unit, element);
622 } 1081 }
623 // 1082 //
624 // Prepare constants. 1083 // Prepare constants.
625 // 1084 //
626 ConstantFinder constantFinder = 1085 ConstantFinder constantFinder = new ConstantFinder();
627 new ConstantFinder(context, source, librarySpecificUnit.library);
628 unit.accept(constantFinder); 1086 unit.accept(constantFinder);
629 List<ConstantEvaluationTarget> constants = new List< 1087 List<ConstantEvaluationTarget> constants =
630 ConstantEvaluationTarget>.from(constantFinder.constantsToCompute); 1088 constantFinder.constantsToCompute.toList();
631 // 1089 //
632 // Record outputs. 1090 // Record outputs.
633 // 1091 //
634 outputs[COMPILATION_UNIT_CONSTANTS] = constants; 1092 outputs[COMPILATION_UNIT_CONSTANTS] = constants;
635 outputs[COMPILATION_UNIT_ELEMENT] = element; 1093 outputs[COMPILATION_UNIT_ELEMENT] = element;
636 outputs[RESOLVED_UNIT1] = unit; 1094 outputs[RESOLVED_UNIT1] = unit;
1095 outputs[CREATED_RESOLVED_UNIT1] = true;
637 } 1096 }
638 1097
639 /** 1098 /**
640 * Return a map from the names of the inputs of this kind of task to the task 1099 * Return a map from the names of the inputs of this kind of task to the task
641 * input descriptors describing those inputs for a task with the given 1100 * input descriptors describing those inputs for a task with the given
642 * [target]. 1101 * [target].
643 */ 1102 */
644 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 1103 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
645 LibrarySpecificUnit unit = target; 1104 LibrarySpecificUnit unit = target;
646 return <String, TaskInput>{ 1105 return <String, TaskInput>{
(...skipping 19 matching lines...) Expand all
666 * The name of the input whose value is the defining [LIBRARY_ELEMENT1]. 1125 * The name of the input whose value is the defining [LIBRARY_ELEMENT1].
667 */ 1126 */
668 static const String LIBRARY_INPUT = 'LIBRARY_INPUT'; 1127 static const String LIBRARY_INPUT = 'LIBRARY_INPUT';
669 1128
670 /** 1129 /**
671 * The name of the input for [RESOLVED_UNIT1] of a library unit. 1130 * The name of the input for [RESOLVED_UNIT1] of a library unit.
672 */ 1131 */
673 static const String UNIT_INPUT_NAME = 'UNIT_INPUT_NAME'; 1132 static const String UNIT_INPUT_NAME = 'UNIT_INPUT_NAME';
674 1133
675 /** 1134 /**
1135 * The input with a map from referenced sources to their modification times.
1136 */
1137 static const String SOURCES_MODIFICATION_TIME_INPUT_NAME =
1138 'SOURCES_MODIFICATION_TIME_INPUT_NAME';
1139
1140 /**
676 * The input with a list of [LIBRARY_ELEMENT3]s of imported libraries. 1141 * The input with a list of [LIBRARY_ELEMENT3]s of imported libraries.
677 */ 1142 */
678 static const String IMPORTS_LIBRARY_ELEMENT_INPUT_NAME = 1143 static const String IMPORTS_LIBRARY_ELEMENT_INPUT_NAME =
679 'IMPORTS_LIBRARY_ELEMENT1_INPUT_NAME'; 1144 'IMPORTS_LIBRARY_ELEMENT1_INPUT_NAME';
680 1145
681 /** 1146 /**
682 * The input with a list of [LIBRARY_ELEMENT3]s of exported libraries. 1147 * The input with a list of [LIBRARY_ELEMENT3]s of exported libraries.
683 */ 1148 */
684 static const String EXPORTS_LIBRARY_ELEMENT_INPUT_NAME = 1149 static const String EXPORTS_LIBRARY_ELEMENT_INPUT_NAME =
685 'EXPORTS_LIBRARY_ELEMENT_INPUT_NAME'; 1150 'EXPORTS_LIBRARY_ELEMENT_INPUT_NAME';
(...skipping 21 matching lines...) Expand all
707 1172
708 BuildDirectiveElementsTask( 1173 BuildDirectiveElementsTask(
709 InternalAnalysisContext context, AnalysisTarget target) 1174 InternalAnalysisContext context, AnalysisTarget target)
710 : super(context, target); 1175 : super(context, target);
711 1176
712 @override 1177 @override
713 TaskDescriptor get descriptor => DESCRIPTOR; 1178 TaskDescriptor get descriptor => DESCRIPTOR;
714 1179
715 @override 1180 @override
716 void internalPerform() { 1181 void internalPerform() {
717 List<AnalysisError> errors = <AnalysisError>[];
718 // 1182 //
719 // Prepare inputs. 1183 // Prepare inputs.
720 // 1184 //
721 LibraryElementImpl libraryElement = getRequiredInput(LIBRARY_INPUT); 1185 LibraryElementImpl libraryElement = getRequiredInput(LIBRARY_INPUT);
722 CompilationUnit libraryUnit = getRequiredInput(UNIT_INPUT_NAME); 1186 CompilationUnit libraryUnit = getRequiredInput(UNIT_INPUT_NAME);
1187 Map<Source, int> sourceModificationTimeMap =
1188 getRequiredInput(SOURCES_MODIFICATION_TIME_INPUT_NAME);
723 Map<Source, LibraryElement> importLibraryMap = 1189 Map<Source, LibraryElement> importLibraryMap =
724 getRequiredInput(IMPORTS_LIBRARY_ELEMENT_INPUT_NAME); 1190 getRequiredInput(IMPORTS_LIBRARY_ELEMENT_INPUT_NAME);
725 Map<Source, LibraryElement> exportLibraryMap = 1191 Map<Source, LibraryElement> exportLibraryMap =
726 getRequiredInput(EXPORTS_LIBRARY_ELEMENT_INPUT_NAME); 1192 getRequiredInput(EXPORTS_LIBRARY_ELEMENT_INPUT_NAME);
727 Map<Source, SourceKind> importSourceKindMap = 1193 Map<Source, SourceKind> importSourceKindMap =
728 getRequiredInput(IMPORTS_SOURCE_KIND_INPUT_NAME); 1194 getRequiredInput(IMPORTS_SOURCE_KIND_INPUT_NAME);
729 Map<Source, SourceKind> exportSourceKindMap = 1195 Map<Source, SourceKind> exportSourceKindMap =
730 getRequiredInput(EXPORTS_SOURCE_KIND_INPUT_NAME); 1196 getRequiredInput(EXPORTS_SOURCE_KIND_INPUT_NAME);
731 Source librarySource = libraryElement.source;
732 // 1197 //
733 // Resolve directives. 1198 // Try to get the existing LibraryElement.
734 // 1199 //
735 HashMap<String, PrefixElementImpl> nameToPrefixMap = 1200 LibraryElement element;
736 new HashMap<String, PrefixElementImpl>(); 1201 {
737 List<ImportElement> imports = <ImportElement>[]; 1202 InternalAnalysisContext internalContext =
738 List<ExportElement> exports = <ExportElement>[]; 1203 context as InternalAnalysisContext;
739 bool explicitlyImportsCore = false; 1204 AnalysisCache analysisCache = internalContext.analysisCache;
740 for (Directive directive in libraryUnit.directives) { 1205 CacheEntry cacheEntry = internalContext.getCacheEntry(target);
741 if (directive is ImportDirective) { 1206 element = analysisCache.getValue(target, LIBRARY_ELEMENT2);
742 ImportDirective importDirective = directive; 1207 if (element == null &&
743 String uriContent = importDirective.uriContent; 1208 internalContext.aboutToComputeResult(cacheEntry, LIBRARY_ELEMENT2)) {
744 if (DartUriResolver.isDartExtUri(uriContent)) { 1209 element = analysisCache.getValue(target, LIBRARY_ELEMENT2);
745 libraryElement.hasExtUri = true;
746 }
747 Source importedSource = importDirective.source;
748 if (importedSource != null && context.exists(importedSource)) {
749 // The imported source will be null if the URI in the import
750 // directive was invalid.
751 LibraryElement importedLibrary = importLibraryMap[importedSource];
752 if (importedLibrary != null) {
753 if (importedLibrary.isDartCore) {
754 explicitlyImportsCore = true;
755 }
756 ImportElementImpl importElement =
757 new ImportElementImpl(directive.offset);
758 StringLiteral uriLiteral = importDirective.uri;
759 if (uriLiteral != null) {
760 importElement.uriOffset = uriLiteral.offset;
761 importElement.uriEnd = uriLiteral.end;
762 }
763 importElement.uri = uriContent;
764 importElement.deferred = importDirective.deferredKeyword != null;
765 importElement.combinators = _buildCombinators(importDirective);
766 importElement.importedLibrary = importedLibrary;
767 SimpleIdentifier prefixNode = directive.prefix;
768 if (prefixNode != null) {
769 importElement.prefixOffset = prefixNode.offset;
770 String prefixName = prefixNode.name;
771 PrefixElementImpl prefix = nameToPrefixMap[prefixName];
772 if (prefix == null) {
773 prefix = new PrefixElementImpl.forNode(prefixNode);
774 nameToPrefixMap[prefixName] = prefix;
775 }
776 importElement.prefix = prefix;
777 prefixNode.staticElement = prefix;
778 }
779 directive.element = importElement;
780 imports.add(importElement);
781 if (importSourceKindMap[importedSource] != SourceKind.LIBRARY) {
782 ErrorCode errorCode = (importElement.isDeferred
783 ? StaticWarningCode.IMPORT_OF_NON_LIBRARY
784 : CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY);
785 errors.add(new AnalysisError(importedSource, uriLiteral.offset,
786 uriLiteral.length, errorCode, [uriLiteral.toSource()]));
787 }
788 }
789 }
790 } else if (directive is ExportDirective) {
791 ExportDirective exportDirective = directive;
792 Source exportedSource = exportDirective.source;
793 if (exportedSource != null && context.exists(exportedSource)) {
794 // The exported source will be null if the URI in the export
795 // directive was invalid.
796 LibraryElement exportedLibrary = exportLibraryMap[exportedSource];
797 if (exportedLibrary != null) {
798 ExportElementImpl exportElement =
799 new ExportElementImpl(directive.offset);
800 StringLiteral uriLiteral = exportDirective.uri;
801 if (uriLiteral != null) {
802 exportElement.uriOffset = uriLiteral.offset;
803 exportElement.uriEnd = uriLiteral.end;
804 }
805 exportElement.uri = exportDirective.uriContent;
806 exportElement.combinators = _buildCombinators(exportDirective);
807 exportElement.exportedLibrary = exportedLibrary;
808 directive.element = exportElement;
809 exports.add(exportElement);
810 if (exportSourceKindMap[exportedSource] != SourceKind.LIBRARY) {
811 errors.add(new AnalysisError(
812 exportedSource,
813 uriLiteral.offset,
814 uriLiteral.length,
815 CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY,
816 [uriLiteral.toSource()]));
817 }
818 }
819 }
820 } 1210 }
821 } 1211 }
822 // 1212 //
823 // Ensure "dart:core" import. 1213 // Build or reuse the directive elements.
824 // 1214 //
825 Source coreLibrarySource = context.sourceFactory.forUri(DartSdk.DART_CORE); 1215 List<AnalysisError> errors;
826 if (!explicitlyImportsCore && coreLibrarySource != librarySource) { 1216 if (element == null) {
827 ImportElementImpl importElement = new ImportElementImpl(-1); 1217 DirectiveElementBuilder builder = new DirectiveElementBuilder(
828 importElement.importedLibrary = importLibraryMap[coreLibrarySource]; 1218 context,
829 importElement.synthetic = true; 1219 libraryElement,
830 imports.add(importElement); 1220 sourceModificationTimeMap,
1221 importLibraryMap,
1222 importSourceKindMap,
1223 exportLibraryMap,
1224 exportSourceKindMap);
1225 libraryUnit.accept(builder);
1226 // See the commentary in the computation of the LIBRARY_CYCLE result
1227 // for details on library cycle invalidation.
1228 libraryElement.invalidateLibraryCycles();
1229 errors = builder.errors;
1230 } else {
1231 DirectiveResolver resolver = new DirectiveResolver();
1232 libraryUnit.accept(resolver);
831 } 1233 }
832 // 1234 //
833 // Populate the library element.
834 //
835 libraryElement.imports = imports;
836 libraryElement.exports = exports;
837 //
838 // Record outputs. 1235 // Record outputs.
839 // 1236 //
840 outputs[LIBRARY_ELEMENT2] = libraryElement; 1237 outputs[LIBRARY_ELEMENT2] = libraryElement;
841 outputs[BUILD_DIRECTIVES_ERRORS] = errors; 1238 outputs[BUILD_DIRECTIVES_ERRORS] = errors;
842 } 1239 }
843 1240
844 /** 1241 /**
845 * Return a map from the names of the inputs of this kind of task to the task 1242 * Return a map from the names of the inputs of this kind of task to the task
846 * input descriptors describing those inputs for a task with the 1243 * input descriptors describing those inputs for a task with the
847 * given library [libSource]. 1244 * given library [libSource].
848 */ 1245 */
849 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 1246 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
850 Source source = target; 1247 Source source = target;
851 return <String, TaskInput>{ 1248 return <String, TaskInput>{
852 LIBRARY_INPUT: LIBRARY_ELEMENT1.of(source), 1249 LIBRARY_INPUT: LIBRARY_ELEMENT1.of(source),
853 UNIT_INPUT_NAME: 1250 UNIT_INPUT_NAME:
854 RESOLVED_UNIT1.of(new LibrarySpecificUnit(source, source)), 1251 RESOLVED_UNIT1.of(new LibrarySpecificUnit(source, source)),
1252 SOURCES_MODIFICATION_TIME_INPUT_NAME:
1253 REFERENCED_SOURCES.of(source).toMapOf(MODIFICATION_TIME),
855 IMPORTS_LIBRARY_ELEMENT_INPUT_NAME: 1254 IMPORTS_LIBRARY_ELEMENT_INPUT_NAME:
856 IMPORTED_LIBRARIES.of(source).toMapOf(LIBRARY_ELEMENT1), 1255 IMPORTED_LIBRARIES.of(source).toMapOf(LIBRARY_ELEMENT1),
857 EXPORTS_LIBRARY_ELEMENT_INPUT_NAME: 1256 EXPORTS_LIBRARY_ELEMENT_INPUT_NAME:
858 EXPORTED_LIBRARIES.of(source).toMapOf(LIBRARY_ELEMENT1), 1257 EXPORTED_LIBRARIES.of(source).toMapOf(LIBRARY_ELEMENT1),
859 IMPORTS_SOURCE_KIND_INPUT_NAME: 1258 IMPORTS_SOURCE_KIND_INPUT_NAME:
860 IMPORTED_LIBRARIES.of(source).toMapOf(SOURCE_KIND), 1259 IMPORTED_LIBRARIES.of(source).toMapOf(SOURCE_KIND),
861 EXPORTS_SOURCE_KIND_INPUT_NAME: 1260 EXPORTS_SOURCE_KIND_INPUT_NAME:
862 EXPORTED_LIBRARIES.of(source).toMapOf(SOURCE_KIND) 1261 EXPORTED_LIBRARIES.of(source).toMapOf(SOURCE_KIND)
863 }; 1262 };
864 } 1263 }
865 1264
866 /** 1265 /**
867 * Create a [BuildDirectiveElementsTask] based on the given [target] in 1266 * Create a [BuildDirectiveElementsTask] based on the given [target] in
868 * the given [context]. 1267 * the given [context].
869 */ 1268 */
870 static BuildDirectiveElementsTask createTask( 1269 static BuildDirectiveElementsTask createTask(
871 AnalysisContext context, AnalysisTarget target) { 1270 AnalysisContext context, AnalysisTarget target) {
872 return new BuildDirectiveElementsTask(context, target); 1271 return new BuildDirectiveElementsTask(context, target);
873 } 1272 }
874
875 /**
876 * Build the element model representing the combinators declared by
877 * the given [directive].
878 */
879 static List<NamespaceCombinator> _buildCombinators(
880 NamespaceDirective directive) {
881 List<NamespaceCombinator> combinators = <NamespaceCombinator>[];
882 for (Combinator combinator in directive.combinators) {
883 if (combinator is ShowCombinator) {
884 ShowElementCombinatorImpl show = new ShowElementCombinatorImpl();
885 show.offset = combinator.offset;
886 show.end = combinator.end;
887 show.shownNames = _getIdentifiers(combinator.shownNames);
888 combinators.add(show);
889 } else if (combinator is HideCombinator) {
890 HideElementCombinatorImpl hide = new HideElementCombinatorImpl();
891 hide.hiddenNames = _getIdentifiers(combinator.hiddenNames);
892 combinators.add(hide);
893 }
894 }
895 return combinators;
896 }
897
898 /**
899 * Return the lexical identifiers associated with the given [identifiers].
900 */
901 static List<String> _getIdentifiers(NodeList<SimpleIdentifier> identifiers) {
902 return identifiers.map((identifier) => identifier.name).toList();
903 }
904 } 1273 }
905 1274
906 /** 1275 /**
907 * A task that builds the elements representing the members of enum 1276 * A task that builds the elements representing the members of enum
908 * declarations. 1277 * declarations.
909 */ 1278 */
910 class BuildEnumMemberElementsTask extends SourceBasedAnalysisTask { 1279 class BuildEnumMemberElementsTask extends SourceBasedAnalysisTask {
911 /** 1280 /**
912 * The name of the [TYPE_PROVIDER] input. 1281 * The name of the [TYPE_PROVIDER] input.
913 */ 1282 */
914 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT'; 1283 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT';
915 1284
916 /** 1285 /**
917 * The name of the [RESOLVED_UNIT1] input. 1286 * The name of the [RESOLVED_UNIT1] input.
918 */ 1287 */
919 static const String UNIT_INPUT = 'UNIT_INPUT'; 1288 static const String UNIT_INPUT = 'UNIT_INPUT';
920 1289
921 /** 1290 /**
922 * The task descriptor describing this kind of task. 1291 * The task descriptor describing this kind of task.
923 */ 1292 */
924 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 1293 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
925 'BuildEnumMemberElementsTask', 1294 'BuildEnumMemberElementsTask',
926 createTask, 1295 createTask,
927 buildInputs, 1296 buildInputs,
928 <ResultDescriptor>[RESOLVED_UNIT2]); 1297 <ResultDescriptor>[CREATED_RESOLVED_UNIT3, RESOLVED_UNIT3]);
929 1298
930 BuildEnumMemberElementsTask( 1299 BuildEnumMemberElementsTask(
931 InternalAnalysisContext context, AnalysisTarget target) 1300 InternalAnalysisContext context, AnalysisTarget target)
932 : super(context, target); 1301 : super(context, target);
933 1302
934 @override 1303 @override
935 TaskDescriptor get descriptor => DESCRIPTOR; 1304 TaskDescriptor get descriptor => DESCRIPTOR;
936 1305
937 @override 1306 @override
938 void internalPerform() { 1307 void internalPerform() {
939 // 1308 //
940 // Prepare inputs. 1309 // Prepare inputs.
941 // 1310 //
942 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT); 1311 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT);
943 CompilationUnit unit = getRequiredInput(UNIT_INPUT); 1312 CompilationUnit unit = getRequiredInput(UNIT_INPUT);
944 // 1313 //
1314 // Build the enum members if they have not already been created.
1315 //
1316 EnumDeclaration findFirstEnum() {
1317 NodeList<CompilationUnitMember> members = unit.declarations;
1318 int length = members.length;
1319 for (int i = 0; i < length; i++) {
1320 CompilationUnitMember member = members[i];
1321 if (member is EnumDeclaration) {
1322 return member;
1323 }
1324 }
1325 return null;
1326 }
1327
1328 EnumDeclaration firstEnum = findFirstEnum();
1329 if (firstEnum != null && firstEnum.element.accessors.isEmpty) {
1330 EnumMemberBuilder builder = new EnumMemberBuilder(typeProvider);
1331 unit.accept(builder);
1332 }
1333 //
945 // Record outputs. 1334 // Record outputs.
946 // 1335 //
947 EnumMemberBuilder builder = new EnumMemberBuilder(typeProvider); 1336 outputs[CREATED_RESOLVED_UNIT3] = true;
948 unit.accept(builder); 1337 outputs[RESOLVED_UNIT3] = unit;
949 outputs[RESOLVED_UNIT2] = unit;
950 } 1338 }
951 1339
952 /** 1340 /**
953 * Return a map from the names of the inputs of this kind of task to the task 1341 * Return a map from the names of the inputs of this kind of task to the task
954 * input descriptors describing those inputs for a task with the 1342 * input descriptors describing those inputs for a task with the
955 * given [target]. 1343 * given [target].
956 */ 1344 */
957 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 1345 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
958 LibrarySpecificUnit unit = target; 1346 LibrarySpecificUnit unit = target;
959 return <String, TaskInput>{ 1347 return <String, TaskInput>{
960 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request), 1348 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request),
961 UNIT_INPUT: RESOLVED_UNIT1.of(unit) 1349 UNIT_INPUT: RESOLVED_UNIT2.of(unit)
962 }; 1350 };
963 } 1351 }
964 1352
965 /** 1353 /**
966 * Create a [BuildEnumMemberElementsTask] based on the given [target] in 1354 * Create a [BuildEnumMemberElementsTask] based on the given [target] in
967 * the given [context]. 1355 * the given [context].
968 */ 1356 */
969 static BuildEnumMemberElementsTask createTask( 1357 static BuildEnumMemberElementsTask createTask(
970 AnalysisContext context, AnalysisTarget target) { 1358 AnalysisContext context, AnalysisTarget target) {
971 return new BuildEnumMemberElementsTask(context, target); 1359 return new BuildEnumMemberElementsTask(context, target);
(...skipping 24 matching lines...) Expand all
996 1384
997 @override 1385 @override
998 TaskDescriptor get descriptor => DESCRIPTOR; 1386 TaskDescriptor get descriptor => DESCRIPTOR;
999 1387
1000 @override 1388 @override
1001 void internalPerform() { 1389 void internalPerform() {
1002 LibraryElementImpl library = getRequiredInput(LIBRARY_INPUT); 1390 LibraryElementImpl library = getRequiredInput(LIBRARY_INPUT);
1003 // 1391 //
1004 // Compute export namespace. 1392 // Compute export namespace.
1005 // 1393 //
1006 ExportNamespaceBuilder builder = new ExportNamespaceBuilder(); 1394 library.exportNamespace = null;
1007 Namespace namespace = builder.build(library); 1395 NamespaceBuilder builder = new NamespaceBuilder();
1396 Namespace namespace = builder.createExportNamespaceForLibrary(library);
1008 library.exportNamespace = namespace; 1397 library.exportNamespace = namespace;
1009 // 1398 //
1010 // Update entry point. 1399 // Update entry point.
1011 // 1400 //
1012 if (library.entryPoint == null) { 1401 if (library.entryPoint == null) {
1013 Iterable<Element> exportedElements = namespace.definedNames.values; 1402 Iterable<Element> exportedElements = namespace.definedNames.values;
1014 library.entryPoint = exportedElements.firstWhere( 1403 library.entryPoint = exportedElements.firstWhere(
1015 (element) => element is FunctionElement && element.isEntryPoint, 1404 (element) => element is FunctionElement && element.isEntryPoint,
1016 orElse: () => null); 1405 orElse: () => null);
1017 } 1406 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1054 */ 1443 */
1055 static const String DEFINING_UNIT_INPUT = 'DEFINING_UNIT_INPUT'; 1444 static const String DEFINING_UNIT_INPUT = 'DEFINING_UNIT_INPUT';
1056 1445
1057 /** 1446 /**
1058 * The name of the input whose value is a list of built [RESOLVED_UNIT1]s 1447 * The name of the input whose value is a list of built [RESOLVED_UNIT1]s
1059 * of the parts sourced by a library. 1448 * of the parts sourced by a library.
1060 */ 1449 */
1061 static const String PARTS_UNIT_INPUT = 'PARTS_UNIT_INPUT'; 1450 static const String PARTS_UNIT_INPUT = 'PARTS_UNIT_INPUT';
1062 1451
1063 /** 1452 /**
1453 * The name of the input whose value is the modification time of the source.
1454 */
1455 static const String MODIFICATION_TIME_INPUT = 'MODIFICATION_TIME_INPUT';
1456
1457 /**
1064 * The task descriptor describing this kind of task. 1458 * The task descriptor describing this kind of task.
1065 */ 1459 */
1066 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 1460 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
1067 'BuildLibraryElementTask', createTask, buildInputs, <ResultDescriptor>[ 1461 'BuildLibraryElementTask', createTask, buildInputs, <ResultDescriptor>[
1068 BUILD_LIBRARY_ERRORS, 1462 BUILD_LIBRARY_ERRORS,
1069 LIBRARY_ELEMENT1, 1463 LIBRARY_ELEMENT1,
1070 IS_LAUNCHABLE 1464 IS_LAUNCHABLE
1071 ]); 1465 ]);
1072 1466
1073 /** 1467 /**
(...skipping 15 matching lines...) Expand all
1089 @override 1483 @override
1090 void internalPerform() { 1484 void internalPerform() {
1091 List<AnalysisError> errors = <AnalysisError>[]; 1485 List<AnalysisError> errors = <AnalysisError>[];
1092 // 1486 //
1093 // Prepare inputs. 1487 // Prepare inputs.
1094 // 1488 //
1095 Source librarySource = getRequiredSource(); 1489 Source librarySource = getRequiredSource();
1096 CompilationUnit definingCompilationUnit = 1490 CompilationUnit definingCompilationUnit =
1097 getRequiredInput(DEFINING_UNIT_INPUT); 1491 getRequiredInput(DEFINING_UNIT_INPUT);
1098 List<CompilationUnit> partUnits = getRequiredInput(PARTS_UNIT_INPUT); 1492 List<CompilationUnit> partUnits = getRequiredInput(PARTS_UNIT_INPUT);
1493 int modificationTime = getRequiredInput(MODIFICATION_TIME_INPUT);
1099 // 1494 //
1100 // Process inputs. 1495 // Process inputs.
1101 // 1496 //
1102 CompilationUnitElementImpl definingCompilationUnitElement = 1497 CompilationUnitElementImpl definingCompilationUnitElement =
1103 definingCompilationUnit.element; 1498 definingCompilationUnit.element;
1104 Map<Source, CompilationUnit> partUnitMap = 1499 Map<Source, CompilationUnit> partUnitMap =
1105 new HashMap<Source, CompilationUnit>(); 1500 new HashMap<Source, CompilationUnit>();
1106 for (CompilationUnit partUnit in partUnits) { 1501 int partLength = partUnits.length;
1502 for (int i = 0; i < partLength; i++) {
1503 CompilationUnit partUnit = partUnits[i];
1107 Source partSource = partUnit.element.source; 1504 Source partSource = partUnit.element.source;
1108 partUnitMap[partSource] = partUnit; 1505 partUnitMap[partSource] = partUnit;
1109 } 1506 }
1110 // 1507 //
1111 // Update "part" directives. 1508 // Update "part" directives.
1112 // 1509 //
1113 LibraryIdentifier libraryNameNode = null; 1510 LibraryIdentifier libraryNameNode = null;
1114 String partsLibraryName = _UNKNOWN_LIBRARY_NAME; 1511 String partsLibraryName = _UNKNOWN_LIBRARY_NAME;
1115 bool hasPartDirective = false; 1512 bool hasPartDirective = false;
1116 FunctionElement entryPoint = 1513 FunctionElement entryPoint =
1117 _findEntryPoint(definingCompilationUnitElement); 1514 _findEntryPoint(definingCompilationUnitElement);
1118 List<Directive> directivesToResolve = <Directive>[]; 1515 List<Directive> directivesToResolve = <Directive>[];
1119 List<CompilationUnitElementImpl> sourcedCompilationUnits = 1516 List<CompilationUnitElementImpl> sourcedCompilationUnits =
1120 <CompilationUnitElementImpl>[]; 1517 <CompilationUnitElementImpl>[];
1121 for (Directive directive in definingCompilationUnit.directives) { 1518 NodeList<Directive> directives = definingCompilationUnit.directives;
1519 int directiveLength = directives.length;
1520 for (int i = 0; i < directiveLength; i++) {
1521 Directive directive = directives[i];
1122 if (directive is LibraryDirective) { 1522 if (directive is LibraryDirective) {
1123 if (libraryNameNode == null) { 1523 libraryNameNode = directive.name;
1124 libraryNameNode = directive.name; 1524 directivesToResolve.add(directive);
1125 directivesToResolve.add(directive);
1126 }
1127 } else if (directive is PartDirective) { 1525 } else if (directive is PartDirective) {
1128 PartDirective partDirective = directive; 1526 StringLiteral partUri = directive.uri;
1129 StringLiteral partUri = partDirective.uri; 1527 Source partSource = directive.uriSource;
1130 Source partSource = partDirective.source;
1131 hasPartDirective = true; 1528 hasPartDirective = true;
1132 CompilationUnit partUnit = partUnitMap[partSource]; 1529 CompilationUnit partUnit = partUnitMap[partSource];
1133 if (partUnit != null) { 1530 if (partUnit != null) {
1134 CompilationUnitElementImpl partElement = partUnit.element; 1531 CompilationUnitElementImpl partElement = partUnit.element;
1135 partElement.uriOffset = partUri.offset; 1532 partElement.uriOffset = partUri.offset;
1136 partElement.uriEnd = partUri.end; 1533 partElement.uriEnd = partUri.end;
1137 partElement.uri = partDirective.uriContent; 1534 partElement.uri = directive.uriContent;
1138 // 1535 //
1139 // Validate that the part contains a part-of directive with the same 1536 // Validate that the part contains a part-of directive with the same
1140 // name as the library. 1537 // name as the library.
1141 // 1538 //
1142 if (context.exists(partSource)) { 1539 if (context.exists(partSource)) {
1143 String partLibraryName = 1540 String partLibraryName =
1144 _getPartLibraryName(partSource, partUnit, directivesToResolve); 1541 _getPartLibraryName(partSource, partUnit, directivesToResolve);
1145 if (partLibraryName == null) { 1542 if (partLibraryName == null) {
1146 errors.add(new AnalysisError( 1543 errors.add(new AnalysisError(
1147 librarySource, 1544 librarySource,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1186 errors.add(error); 1583 errors.add(error);
1187 } 1584 }
1188 // 1585 //
1189 // Create and populate the library element. 1586 // Create and populate the library element.
1190 // 1587 //
1191 AnalysisContext owningContext = context; 1588 AnalysisContext owningContext = context;
1192 if (context is InternalAnalysisContext) { 1589 if (context is InternalAnalysisContext) {
1193 InternalAnalysisContext internalContext = context; 1590 InternalAnalysisContext internalContext = context;
1194 owningContext = internalContext.getContextFor(librarySource); 1591 owningContext = internalContext.getContextFor(librarySource);
1195 } 1592 }
1196 LibraryElementImpl libraryElement = 1593 //
1197 new LibraryElementImpl.forNode(owningContext, libraryNameNode); 1594 // Try to get the existing LibraryElement.
1198 libraryElement.definingCompilationUnit = definingCompilationUnitElement; 1595 //
1199 libraryElement.entryPoint = entryPoint; 1596 LibraryElementImpl libraryElement;
1200 libraryElement.parts = sourcedCompilationUnits; 1597 {
1201 for (Directive directive in directivesToResolve) { 1598 InternalAnalysisContext internalContext =
1599 context as InternalAnalysisContext;
1600 AnalysisCache analysisCache = internalContext.analysisCache;
1601 CacheEntry cacheEntry = internalContext.getCacheEntry(target);
1602 libraryElement = analysisCache.getValue(target, LIBRARY_ELEMENT1)
1603 as LibraryElementImpl;
1604 if (libraryElement == null &&
1605 internalContext.aboutToComputeResult(cacheEntry, LIBRARY_ELEMENT1)) {
1606 libraryElement = analysisCache.getValue(target, LIBRARY_ELEMENT1)
1607 as LibraryElementImpl;
1608 }
1609 }
1610 //
1611 // Create a new LibraryElement.
1612 //
1613 if (libraryElement == null) {
1614 libraryElement =
1615 new LibraryElementImpl.forNode(owningContext, libraryNameNode);
1616 libraryElement.synthetic = modificationTime < 0;
1617 libraryElement.definingCompilationUnit = definingCompilationUnitElement;
1618 libraryElement.entryPoint = entryPoint;
1619 libraryElement.parts = sourcedCompilationUnits;
1620 libraryElement.hasExtUri = _hasExtUri(definingCompilationUnit);
1621 BuildLibraryElementUtils.patchTopLevelAccessors(libraryElement);
1622 // set the library documentation to the docs associated with the first
1623 // directive in the compilation unit.
1624 if (definingCompilationUnit.directives.isNotEmpty) {
1625 setElementDocumentationComment(
1626 libraryElement, definingCompilationUnit.directives.first);
1627 }
1628 }
1629 //
1630 // Resolve the relevant directives to the library element.
1631 //
1632 // TODO(brianwilkerson) This updates the state of the AST structures but
1633 // does not associate a new result with it.
1634 //
1635 int length = directivesToResolve.length;
1636 for (int i = 0; i < length; i++) {
1637 Directive directive = directivesToResolve[i];
1202 directive.element = libraryElement; 1638 directive.element = libraryElement;
1203 } 1639 }
1204 if (sourcedCompilationUnits.isNotEmpty) {
1205 _patchTopLevelAccessors(libraryElement);
1206 }
1207 // 1640 //
1208 // Record outputs. 1641 // Record outputs.
1209 // 1642 //
1210 outputs[BUILD_LIBRARY_ERRORS] = errors; 1643 outputs[BUILD_LIBRARY_ERRORS] = errors;
1211 outputs[LIBRARY_ELEMENT1] = libraryElement; 1644 outputs[LIBRARY_ELEMENT1] = libraryElement;
1212 outputs[IS_LAUNCHABLE] = entryPoint != null; 1645 outputs[IS_LAUNCHABLE] = entryPoint != null;
1213 } 1646 }
1214 1647
1215 /** 1648 /**
1216 * Add all of the non-synthetic [getters] and [setters] defined in the given
1217 * [unit] that have no corresponding accessor to one of the given collections.
1218 */
1219 void _collectAccessors(Map<String, PropertyAccessorElement> getters,
1220 List<PropertyAccessorElement> setters, CompilationUnitElement unit) {
1221 for (PropertyAccessorElement accessor in unit.accessors) {
1222 if (accessor.isGetter) {
1223 if (!accessor.isSynthetic && accessor.correspondingSetter == null) {
1224 getters[accessor.displayName] = accessor;
1225 }
1226 } else {
1227 if (!accessor.isSynthetic && accessor.correspondingGetter == null) {
1228 setters.add(accessor);
1229 }
1230 }
1231 }
1232 }
1233
1234 /**
1235 * Return the top-level [FunctionElement] entry point, or `null` if the given 1649 * Return the top-level [FunctionElement] entry point, or `null` if the given
1236 * [element] does not define an entry point. 1650 * [element] does not define an entry point.
1237 */ 1651 */
1238 FunctionElement _findEntryPoint(CompilationUnitElementImpl element) { 1652 FunctionElement _findEntryPoint(CompilationUnitElementImpl element) {
1239 for (FunctionElement function in element.functions) { 1653 List<FunctionElement> functions = element.functions;
1654 int length = functions.length;
1655 for (int i = 0; i < length; i++) {
1656 FunctionElement function = functions[i];
1240 if (function.isEntryPoint) { 1657 if (function.isEntryPoint) {
1241 return function; 1658 return function;
1242 } 1659 }
1243 } 1660 }
1244 return null; 1661 return null;
1245 } 1662 }
1246 1663
1247 /** 1664 /**
1248 * Return the name of the library that the given part is declared to be a 1665 * Return the name of the library that the given part is declared to be a
1249 * part of, or `null` if the part does not contain a part-of directive. 1666 * part of, or `null` if the part does not contain a part-of directive.
1250 */ 1667 */
1251 String _getPartLibraryName(Source partSource, CompilationUnit partUnit, 1668 String _getPartLibraryName(Source partSource, CompilationUnit partUnit,
1252 List<Directive> directivesToResolve) { 1669 List<Directive> directivesToResolve) {
1253 for (Directive directive in partUnit.directives) { 1670 NodeList<Directive> directives = partUnit.directives;
1671 int length = directives.length;
1672 for (int i = 0; i < length; i++) {
1673 Directive directive = directives[i];
1254 if (directive is PartOfDirective) { 1674 if (directive is PartOfDirective) {
1255 directivesToResolve.add(directive); 1675 directivesToResolve.add(directive);
1256 LibraryIdentifier libraryName = directive.libraryName; 1676 LibraryIdentifier libraryName = directive.libraryName;
1257 if (libraryName != null) { 1677 if (libraryName != null) {
1258 return libraryName.name; 1678 return libraryName.name;
1259 } 1679 }
1260 } 1680 }
1261 } 1681 }
1262 return null; 1682 return null;
1263 } 1683 }
1264 1684
1265 /** 1685 /**
1266 * Look through all of the compilation units defined for the given [library], 1686 * Return `true` if the given compilation [unit] contains at least one
1267 * looking for getters and setters that are defined in different compilation 1687 * import directive with a `dart-ext:` URI.
1268 * units but that have the same names. If any are found, make sure that they
1269 * have the same variable element.
1270 */ 1688 */
1271 void _patchTopLevelAccessors(LibraryElementImpl library) { 1689 bool _hasExtUri(CompilationUnit unit) {
1272 HashMap<String, PropertyAccessorElement> getters = 1690 NodeList<Directive> directives = unit.directives;
1273 new HashMap<String, PropertyAccessorElement>(); 1691 int length = directives.length;
1274 List<PropertyAccessorElement> setters = <PropertyAccessorElement>[]; 1692 for (int i = 0; i < length; i++) {
1275 _collectAccessors(getters, setters, library.definingCompilationUnit); 1693 Directive directive = directives[i];
1276 for (CompilationUnitElement unit in library.parts) { 1694 if (directive is ImportDirective) {
1277 _collectAccessors(getters, setters, unit); 1695 if (DartUriResolver.isDartExtUri(directive.uriContent)) {
1278 } 1696 return true;
1279 for (PropertyAccessorElement setter in setters) { 1697 }
1280 PropertyAccessorElement getter = getters[setter.displayName];
1281 if (getter != null) {
1282 TopLevelVariableElementImpl variable = getter.variable;
1283 TopLevelVariableElementImpl setterVariable = setter.variable;
1284 CompilationUnitElementImpl setterUnit = setterVariable.enclosingElement;
1285 setterUnit.replaceTopLevelVariable(setterVariable, variable);
1286 variable.setter = setter;
1287 (setter as PropertyAccessorElementImpl).variable = variable;
1288 } 1698 }
1289 } 1699 }
1700 return false;
1290 } 1701 }
1291 1702
1292 /** 1703 /**
1293 * Return a map from the names of the inputs of this kind of task to the task 1704 * Return a map from the names of the inputs of this kind of task to the task
1294 * input descriptors describing those inputs for a task with the given 1705 * input descriptors describing those inputs for a task with the given
1295 * [libSource]. 1706 * [libSource].
1296 */ 1707 */
1297 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 1708 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
1298 Source source = target; 1709 Source source = target;
1299 return <String, TaskInput>{ 1710 return <String, TaskInput>{
1300 DEFINING_UNIT_INPUT: 1711 DEFINING_UNIT_INPUT:
1301 RESOLVED_UNIT1.of(new LibrarySpecificUnit(source, source)), 1712 RESOLVED_UNIT1.of(new LibrarySpecificUnit(source, source)),
1302 PARTS_UNIT_INPUT: INCLUDED_PARTS.of(source).toList((Source unit) { 1713 PARTS_UNIT_INPUT: INCLUDED_PARTS.of(source).toList((Source unit) {
1303 return RESOLVED_UNIT1.of(new LibrarySpecificUnit(source, unit)); 1714 return RESOLVED_UNIT1.of(new LibrarySpecificUnit(source, unit));
1304 }) 1715 }),
1716 MODIFICATION_TIME_INPUT: MODIFICATION_TIME.of(source)
1305 }; 1717 };
1306 } 1718 }
1307 1719
1308 /** 1720 /**
1309 * Create a [BuildLibraryElementTask] based on the given [target] in the 1721 * Create a [BuildLibraryElementTask] based on the given [target] in the
1310 * given [context]. 1722 * given [context].
1311 */ 1723 */
1312 static BuildLibraryElementTask createTask( 1724 static BuildLibraryElementTask createTask(
1313 AnalysisContext context, AnalysisTarget target) { 1725 AnalysisContext context, AnalysisTarget target) {
1314 return new BuildLibraryElementTask(context, target); 1726 return new BuildLibraryElementTask(context, target);
(...skipping 21 matching lines...) Expand all
1336 BuildPublicNamespaceTask( 1748 BuildPublicNamespaceTask(
1337 InternalAnalysisContext context, AnalysisTarget target) 1749 InternalAnalysisContext context, AnalysisTarget target)
1338 : super(context, target); 1750 : super(context, target);
1339 1751
1340 @override 1752 @override
1341 TaskDescriptor get descriptor => DESCRIPTOR; 1753 TaskDescriptor get descriptor => DESCRIPTOR;
1342 1754
1343 @override 1755 @override
1344 void internalPerform() { 1756 void internalPerform() {
1345 LibraryElementImpl library = getRequiredInput(LIBRARY_INPUT); 1757 LibraryElementImpl library = getRequiredInput(LIBRARY_INPUT);
1346 library.publicNamespace = new PublicNamespaceBuilder().build(library); 1758 NamespaceBuilder builder = new NamespaceBuilder();
1759 library.publicNamespace = builder.createPublicNamespaceForLibrary(library);
1347 outputs[LIBRARY_ELEMENT3] = library; 1760 outputs[LIBRARY_ELEMENT3] = library;
1348 } 1761 }
1349 1762
1350 /** 1763 /**
1351 * Return a map from the names of the inputs of this kind of task to the task 1764 * Return a map from the names of the inputs of this kind of task to the task
1352 * input descriptors describing those inputs for a task with the 1765 * input descriptors describing those inputs for a task with the
1353 * given library [libSource]. 1766 * given library [libSource].
1354 */ 1767 */
1355 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 1768 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
1356 Source source = target; 1769 Source source = target;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1417 * Create a [BuildSourceExportClosureTask] based on the given [target] in 1830 * Create a [BuildSourceExportClosureTask] based on the given [target] in
1418 * the given [context]. 1831 * the given [context].
1419 */ 1832 */
1420 static BuildSourceExportClosureTask createTask( 1833 static BuildSourceExportClosureTask createTask(
1421 AnalysisContext context, AnalysisTarget target) { 1834 AnalysisContext context, AnalysisTarget target) {
1422 return new BuildSourceExportClosureTask(context, target); 1835 return new BuildSourceExportClosureTask(context, target);
1423 } 1836 }
1424 } 1837 }
1425 1838
1426 /** 1839 /**
1427 * A task that builds [IMPORT_EXPORT_SOURCE_CLOSURE] of a library, and also
1428 * sets [IS_CLIENT].
1429 */
1430 class BuildSourceImportExportClosureTask extends SourceBasedAnalysisTask {
1431 /**
1432 * The name of the import/export closure.
1433 */
1434 static const String IMPORT_EXPORT_INPUT = 'IMPORT_EXPORT_INPUT';
1435
1436 /**
1437 * The task descriptor describing this kind of task.
1438 */
1439 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
1440 'BuildSourceImportExportClosureTask',
1441 createTask,
1442 buildInputs,
1443 <ResultDescriptor>[IMPORT_EXPORT_SOURCE_CLOSURE, IS_CLIENT]);
1444
1445 BuildSourceImportExportClosureTask(
1446 InternalAnalysisContext context, AnalysisTarget target)
1447 : super(context, target);
1448
1449 @override
1450 TaskDescriptor get descriptor => DESCRIPTOR;
1451
1452 @override
1453 void internalPerform() {
1454 List<Source> importExportClosure = getRequiredInput(IMPORT_EXPORT_INPUT);
1455 Source htmlSource = context.sourceFactory.forUri(DartSdk.DART_HTML);
1456 //
1457 // Record outputs.
1458 //
1459 outputs[IMPORT_EXPORT_SOURCE_CLOSURE] = importExportClosure;
1460 outputs[IS_CLIENT] = importExportClosure.contains(htmlSource);
1461 }
1462
1463 /**
1464 * Return a map from the names of the inputs of this kind of task to the task
1465 * input descriptors describing those inputs for a task with the
1466 * given library [libSource].
1467 */
1468 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
1469 Source source = target;
1470 return <String, TaskInput>{
1471 IMPORT_EXPORT_INPUT:
1472 new _ImportExportSourceClosureTaskInput(source, LIBRARY_ELEMENT2)
1473 };
1474 }
1475
1476 /**
1477 * Create a [BuildSourceImportExportClosureTask] based on the given [target]
1478 * in the given [context].
1479 */
1480 static BuildSourceImportExportClosureTask createTask(
1481 AnalysisContext context, AnalysisTarget target) {
1482 return new BuildSourceImportExportClosureTask(context, target);
1483 }
1484 }
1485
1486 /**
1487 * A task that builds [TYPE_PROVIDER] for a context. 1840 * A task that builds [TYPE_PROVIDER] for a context.
1488 */ 1841 */
1489 class BuildTypeProviderTask extends SourceBasedAnalysisTask { 1842 class BuildTypeProviderTask extends SourceBasedAnalysisTask {
1490 /** 1843 /**
1491 * The [PUBLIC_NAMESPACE] input of the `dart:core` library. 1844 * The [PUBLIC_NAMESPACE] input of the `dart:core` library.
1492 */ 1845 */
1493 static const String CORE_INPUT = 'CORE_INPUT'; 1846 static const String CORE_INPUT = 'CORE_INPUT';
1494 1847
1495 /** 1848 /**
1496 * The [PUBLIC_NAMESPACE] input of the `dart:async` library. 1849 * The [PUBLIC_NAMESPACE] input of the `dart:async` library.
(...skipping 12 matching lines...) Expand all
1509 BuildTypeProviderTask( 1862 BuildTypeProviderTask(
1510 InternalAnalysisContext context, AnalysisContextTarget target) 1863 InternalAnalysisContext context, AnalysisContextTarget target)
1511 : super(context, target); 1864 : super(context, target);
1512 1865
1513 @override 1866 @override
1514 TaskDescriptor get descriptor => DESCRIPTOR; 1867 TaskDescriptor get descriptor => DESCRIPTOR;
1515 1868
1516 @override 1869 @override
1517 void internalPerform() { 1870 void internalPerform() {
1518 LibraryElement coreLibrary = getRequiredInput(CORE_INPUT); 1871 LibraryElement coreLibrary = getRequiredInput(CORE_INPUT);
1519 LibraryElement asyncLibrary = getRequiredInput(ASYNC_INPUT); 1872 LibraryElement asyncLibrary = getOptionalInput(ASYNC_INPUT);
1520 Namespace coreNamespace = coreLibrary.publicNamespace; 1873 Namespace coreNamespace = coreLibrary.publicNamespace;
1521 Namespace asyncNamespace = asyncLibrary.publicNamespace; 1874 Namespace asyncNamespace = asyncLibrary.publicNamespace;
1522 // 1875 //
1523 // Record outputs. 1876 // Record outputs.
1524 // 1877 //
1525 TypeProvider typeProvider = 1878 TypeProvider typeProvider =
1526 new TypeProviderImpl.forNamespaces(coreNamespace, asyncNamespace); 1879 new TypeProviderImpl.forNamespaces(coreNamespace, asyncNamespace);
1527 (context as InternalAnalysisContext).typeProvider = typeProvider; 1880 (context as InternalAnalysisContext).typeProvider = typeProvider;
1528 outputs[TYPE_PROVIDER] = typeProvider; 1881 outputs[TYPE_PROVIDER] = typeProvider;
1529 } 1882 }
1530 1883
1531 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 1884 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
1532 AnalysisContextTarget contextTarget = target; 1885 AnalysisContextTarget contextTarget = target;
1533 SourceFactory sourceFactory = contextTarget.context.sourceFactory; 1886 SourceFactory sourceFactory = contextTarget.context.sourceFactory;
1534 Source coreSource = sourceFactory.forUri(DartSdk.DART_CORE); 1887 Source coreSource = sourceFactory.forUri(DartSdk.DART_CORE);
1535 Source asyncSource = sourceFactory.forUri(DartSdk.DART_ASYNC); 1888 Source asyncSource = sourceFactory.forUri(DartSdk.DART_ASYNC);
1889 if (asyncSource == null) {
1890 return <String, TaskInput>{CORE_INPUT: LIBRARY_ELEMENT3.of(coreSource)};
1891 }
1536 return <String, TaskInput>{ 1892 return <String, TaskInput>{
1537 CORE_INPUT: LIBRARY_ELEMENT3.of(coreSource), 1893 CORE_INPUT: LIBRARY_ELEMENT3.of(coreSource),
1538 ASYNC_INPUT: LIBRARY_ELEMENT3.of(asyncSource) 1894 ASYNC_INPUT: LIBRARY_ELEMENT3.of(asyncSource)
1539 }; 1895 };
1540 } 1896 }
1541 1897
1542 /** 1898 /**
1543 * Create a [BuildTypeProviderTask] based on the given [context]. 1899 * Create a [BuildTypeProviderTask] based on the given [context].
1544 */ 1900 */
1545 static BuildTypeProviderTask createTask( 1901 static BuildTypeProviderTask createTask(
1546 AnalysisContext context, AnalysisTarget target) { 1902 AnalysisContext context, AnalysisTarget target) {
1547 return new BuildTypeProviderTask(context, target); 1903 return new BuildTypeProviderTask(context, target);
1548 } 1904 }
1549 } 1905 }
1550 1906
1551 /** 1907 /**
1552 * A task that computes [CONSTANT_DEPENDENCIES] for a constant. 1908 * A task that computes [CONSTANT_DEPENDENCIES] for a constant.
1553 */ 1909 */
1554 class ComputeConstantDependenciesTask extends ConstantEvaluationAnalysisTask { 1910 class ComputeConstantDependenciesTask extends ConstantEvaluationAnalysisTask {
1555 /** 1911 /**
1556 * The name of the [RESOLVED_UNIT9] input.
1557 */
1558 static const String UNIT_INPUT = 'UNIT_INPUT';
1559
1560 /**
1561 * The name of the [TYPE_PROVIDER] input. 1912 * The name of the [TYPE_PROVIDER] input.
1562 */ 1913 */
1563 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT'; 1914 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT';
1564 1915
1565 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 1916 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
1566 'ComputeConstantDependenciesTask', 1917 'ComputeConstantDependenciesTask',
1567 createTask, 1918 createTask,
1568 buildInputs, 1919 buildInputs,
1569 <ResultDescriptor>[CONSTANT_DEPENDENCIES]); 1920 <ResultDescriptor>[CONSTANT_DEPENDENCIES]);
1570 1921
1571 ComputeConstantDependenciesTask( 1922 ComputeConstantDependenciesTask(
1572 InternalAnalysisContext context, ConstantEvaluationTarget constant) 1923 InternalAnalysisContext context, ConstantEvaluationTarget constant)
1573 : super(context, constant); 1924 : super(context, constant);
1574 1925
1575 @override 1926 @override
1576 TaskDescriptor get descriptor => DESCRIPTOR; 1927 TaskDescriptor get descriptor => DESCRIPTOR;
1577 1928
1578 @override 1929 @override
1579 void internalPerform() { 1930 void internalPerform() {
1580 // 1931 //
1581 // Prepare inputs. 1932 // Prepare inputs.
1582 // 1933 //
1583 // Note: UNIT_INPUT is not needed. It is merely a bookkeeping dependency
1584 // to ensure that resolution has occurred before we attempt to determine
1585 // constant dependencies.
1586 //
1587 ConstantEvaluationTarget constant = target; 1934 ConstantEvaluationTarget constant = target;
1588 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT); 1935 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT);
1589 // 1936 //
1590 // Compute dependencies. 1937 // Compute dependencies.
1591 // 1938 //
1592 List<ConstantEvaluationTarget> dependencies = <ConstantEvaluationTarget>[]; 1939 List<ConstantEvaluationTarget> dependencies = <ConstantEvaluationTarget>[];
1593 new ConstantEvaluationEngine(typeProvider, context.declaredVariables, 1940 new ConstantEvaluationEngine(typeProvider, context.declaredVariables,
1594 typeSystem: context.typeSystem) 1941 typeSystem: context.typeSystem)
1595 .computeDependencies(constant, dependencies.add); 1942 .computeDependencies(constant, dependencies.add);
1596 // 1943 //
1597 // Record outputs. 1944 // Record outputs.
1598 // 1945 //
1599 outputs[CONSTANT_DEPENDENCIES] = dependencies; 1946 outputs[CONSTANT_DEPENDENCIES] = dependencies;
1600 } 1947 }
1601 1948
1602 /** 1949 /**
1603 * Return a map from the names of the inputs of this kind of task to the task 1950 * Return a map from the names of the inputs of this kind of task to the task
1604 * input descriptors describing those inputs for a task with the 1951 * input descriptors describing those inputs for a task with the
1605 * given [target]. 1952 * given [target].
1606 */ 1953 */
1607 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 1954 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
1608 if (target is Element) { 1955 return <String, TaskInput>{
1609 CompilationUnitElementImpl unit = target 1956 'constantExpressionResolved': CONSTANT_EXPRESSION_RESOLVED.of(target),
1610 .getAncestor((Element element) => element is CompilationUnitElement); 1957 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request)
1611 return <String, TaskInput>{ 1958 };
1612 UNIT_INPUT: RESOLVED_UNIT9
1613 .of(new LibrarySpecificUnit(unit.librarySource, target.source)),
1614 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request)
1615 };
1616 } else if (target is ConstantEvaluationTarget_Annotation) {
1617 return <String, TaskInput>{
1618 UNIT_INPUT: RESOLVED_UNIT9
1619 .of(new LibrarySpecificUnit(target.librarySource, target.source)),
1620 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request)
1621 };
1622 }
1623 throw new AnalysisException(
1624 'Cannot build inputs for a ${target.runtimeType}');
1625 } 1959 }
1626 1960
1627 /** 1961 /**
1628 * Create a [ComputeConstantDependenciesTask] based on the given [target] in 1962 * Create a [ComputeConstantDependenciesTask] based on the given [target] in
1629 * the given [context]. 1963 * the given [context].
1630 */ 1964 */
1631 static ComputeConstantDependenciesTask createTask( 1965 static ComputeConstantDependenciesTask createTask(
1632 AnalysisContext context, AnalysisTarget target) { 1966 AnalysisContext context, AnalysisTarget target) {
1633 return new ComputeConstantDependenciesTask(context, target); 1967 return new ComputeConstantDependenciesTask(context, target);
1634 } 1968 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1682 // cycle. 2016 // cycle.
1683 // 2017 //
1684 ConstantEvaluationEngine constantEvaluationEngine = 2018 ConstantEvaluationEngine constantEvaluationEngine =
1685 new ConstantEvaluationEngine(typeProvider, context.declaredVariables, 2019 new ConstantEvaluationEngine(typeProvider, context.declaredVariables,
1686 typeSystem: context.typeSystem); 2020 typeSystem: context.typeSystem);
1687 if (dependencyCycle == null) { 2021 if (dependencyCycle == null) {
1688 constantEvaluationEngine.computeConstantValue(constant); 2022 constantEvaluationEngine.computeConstantValue(constant);
1689 } else { 2023 } else {
1690 List<ConstantEvaluationTarget> constantsInCycle = 2024 List<ConstantEvaluationTarget> constantsInCycle =
1691 <ConstantEvaluationTarget>[]; 2025 <ConstantEvaluationTarget>[];
1692 for (WorkItem workItem in dependencyCycle) { 2026 int length = dependencyCycle.length;
2027 for (int i = 0; i < length; i++) {
2028 WorkItem workItem = dependencyCycle[i];
1693 if (workItem.descriptor == DESCRIPTOR) { 2029 if (workItem.descriptor == DESCRIPTOR) {
1694 constantsInCycle.add(workItem.target); 2030 constantsInCycle.add(workItem.target);
1695 } 2031 }
1696 } 2032 }
1697 assert(constantsInCycle.isNotEmpty); 2033 assert(constantsInCycle.isNotEmpty);
1698 constantEvaluationEngine.generateCycleError(constantsInCycle, constant); 2034 constantEvaluationEngine.generateCycleError(constantsInCycle, constant);
1699 } 2035 }
1700 // 2036 //
1701 // Record outputs. 2037 // Record outputs.
1702 // 2038 //
(...skipping 22 matching lines...) Expand all
1725 AnalysisContext context, AnalysisTarget target) { 2061 AnalysisContext context, AnalysisTarget target) {
1726 return new ComputeConstantValueTask(context, target); 2062 return new ComputeConstantValueTask(context, target);
1727 } 2063 }
1728 } 2064 }
1729 2065
1730 /** 2066 /**
1731 * A task that computes the [INFERABLE_STATIC_VARIABLE_DEPENDENCIES] for a 2067 * A task that computes the [INFERABLE_STATIC_VARIABLE_DEPENDENCIES] for a
1732 * static variable whose type should be inferred. 2068 * static variable whose type should be inferred.
1733 */ 2069 */
1734 class ComputeInferableStaticVariableDependenciesTask 2070 class ComputeInferableStaticVariableDependenciesTask
1735 extends ConstantEvaluationAnalysisTask { 2071 extends InferStaticVariableTask {
1736 /** 2072 /**
1737 * The name of the [RESOLVED_UNIT5] input. 2073 * The name of the [RESOLVED_UNIT7] input.
1738 */ 2074 */
1739 static const String UNIT_INPUT = 'UNIT_INPUT'; 2075 static const String UNIT_INPUT = 'UNIT_INPUT';
1740 2076
1741 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 2077 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
1742 'ComputeInferableStaticVariableDependenciesTask', 2078 'ComputeInferableStaticVariableDependenciesTask',
1743 createTask, 2079 createTask,
1744 buildInputs, 2080 buildInputs,
1745 <ResultDescriptor>[INFERABLE_STATIC_VARIABLE_DEPENDENCIES]); 2081 <ResultDescriptor>[INFERABLE_STATIC_VARIABLE_DEPENDENCIES]);
1746 2082
1747 ComputeInferableStaticVariableDependenciesTask( 2083 ComputeInferableStaticVariableDependenciesTask(
1748 InternalAnalysisContext context, VariableElement variable) 2084 InternalAnalysisContext context, VariableElement variable)
1749 : super(context, variable); 2085 : super(context, variable);
1750 2086
1751 @override 2087 @override
1752 TaskDescriptor get descriptor => DESCRIPTOR; 2088 TaskDescriptor get descriptor => DESCRIPTOR;
1753 2089
1754 @override 2090 @override
1755 void internalPerform() { 2091 void internalPerform() {
1756 // 2092 //
1757 // Prepare inputs. 2093 // Prepare inputs.
1758 // 2094 //
1759 VariableElement variable = target;
1760 CompilationUnit unit = getRequiredInput(UNIT_INPUT); 2095 CompilationUnit unit = getRequiredInput(UNIT_INPUT);
1761 // 2096 //
1762 // Compute dependencies. 2097 // Compute dependencies.
1763 // 2098 //
1764 NodeLocator locator = new NodeLocator(variable.nameOffset); 2099 VariableDeclaration declaration = getDeclaration(unit);
1765 AstNode node = locator.searchWithin(unit);
1766 VariableDeclaration declaration =
1767 node.getAncestor((AstNode ancestor) => ancestor is VariableDeclaration);
1768 if (declaration == null || declaration.name != node) {
1769 throw new AnalysisException(
1770 "NodeLocator failed to find a variable's declaration");
1771 }
1772 VariableGatherer gatherer = new VariableGatherer(_isInferableStatic); 2100 VariableGatherer gatherer = new VariableGatherer(_isInferableStatic);
1773 declaration.initializer.accept(gatherer); 2101 declaration.initializer.accept(gatherer);
1774 // 2102 //
1775 // Record outputs. 2103 // Record outputs.
1776 // 2104 //
1777 outputs[INFERABLE_STATIC_VARIABLE_DEPENDENCIES] = gatherer.results.toList(); 2105 outputs[INFERABLE_STATIC_VARIABLE_DEPENDENCIES] = gatherer.results.toList();
1778 } 2106 }
1779 2107
1780 /** 2108 /**
1781 * Return `true` if the given [variable] is a static variable whose type 2109 * Return `true` if the given [variable] is a static variable whose type
1782 * should be inferred. 2110 * should be inferred.
1783 */ 2111 */
1784 bool _isInferableStatic(VariableElement variable) => variable.isStatic && 2112 bool _isInferableStatic(VariableElement variable) =>
2113 variable.isStatic &&
1785 variable.hasImplicitType && 2114 variable.hasImplicitType &&
1786 variable.initializer != null; 2115 variable.initializer != null;
1787 2116
1788 /** 2117 /**
1789 * Return a map from the names of the inputs of this kind of task to the task 2118 * Return a map from the names of the inputs of this kind of task to the task
1790 * input descriptors describing those inputs for a task with the 2119 * input descriptors describing those inputs for a task with the
1791 * given [target]. 2120 * given [target].
1792 */ 2121 */
1793 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 2122 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
1794 if (target is VariableElement) { 2123 if (target is VariableElement) {
1795 CompilationUnitElementImpl unit = target 2124 CompilationUnitElementImpl unit = target
1796 .getAncestor((Element element) => element is CompilationUnitElement); 2125 .getAncestor((Element element) => element is CompilationUnitElement);
1797 return <String, TaskInput>{ 2126 return <String, TaskInput>{
1798 UNIT_INPUT: RESOLVED_UNIT5 2127 UNIT_INPUT: RESOLVED_UNIT7
1799 .of(new LibrarySpecificUnit(unit.librarySource, unit.source)) 2128 .of(new LibrarySpecificUnit(unit.librarySource, unit.source))
1800 }; 2129 };
1801 } 2130 }
1802 throw new AnalysisException( 2131 throw new AnalysisException(
1803 'Cannot build inputs for a ${target.runtimeType}'); 2132 'Cannot build inputs for a ${target.runtimeType}');
1804 } 2133 }
1805 2134
1806 /** 2135 /**
1807 * Create a [ComputeInferableStaticVariableDependenciesTask] based on the 2136 * Create a [ComputeInferableStaticVariableDependenciesTask] based on the
1808 * given [target] in the given [context]. 2137 * given [target] in the given [context].
(...skipping 26 matching lines...) Expand all
1835 2164
1836 ComputeLibraryCycleTask( 2165 ComputeLibraryCycleTask(
1837 InternalAnalysisContext context, AnalysisTarget target) 2166 InternalAnalysisContext context, AnalysisTarget target)
1838 : super(context, target); 2167 : super(context, target);
1839 2168
1840 @override 2169 @override
1841 TaskDescriptor get descriptor => DESCRIPTOR; 2170 TaskDescriptor get descriptor => DESCRIPTOR;
1842 2171
1843 @override 2172 @override
1844 void internalPerform() { 2173 void internalPerform() {
2174 // The computation of library cycles is necessarily non-local, since we
2175 // in general have to look at all of the reachable libraries
2176 // in order to find the strongly connected components. Repeating this
2177 // computation for every node would be quadratic. The libraryCycle getter
2178 // will avoid this by computing the library cycles for every reachable
2179 // library and recording it in the element model. This means that this
2180 // task implicitly produces the output for many other targets. This
2181 // can't be expressed in the task model right now: instead, we just
2182 // run tasks for those other targets, and they pick up the recorded
2183 // version off of the element model. Unfortunately, this means that
2184 // the task model will not handle the invalidation of the recorded
2185 // results for us. Instead, we must explicitly invalidate the recorded
2186 // library cycle information when we add or subtract edges from the
2187 // import/export graph. Any update that changes the
2188 // import/export graph will induce a recomputation of the LIBRARY_ELEMENT2
2189 // result for the changed node. This recomputation is responsible for
2190 // conservatively invalidating the library cycle information recorded
2191 // in the element model. The LIBRARY_CYCLE results that have been cached
2192 // by the task model are conservatively invalidated by the
2193 // IMPORT_EXPORT_SOURCE_CLOSURE dependency below. If anything reachable
2194 // from a node is changed, its LIBRARY_CYCLE results will be re-computed
2195 // here (possibly re-using the result from the element model if invalidation
2196 // did not cause it to be erased). In summary, task model dependencies
2197 // on the import/export source closure ensure that this method will be
2198 // re-run if anything reachable from this target has been invalidated,
2199 // and the invalidation code (invalidateLibraryCycles) will ensure that
2200 // element model results will be re-used here only if they are still valid.
1845 if (context.analysisOptions.strongMode) { 2201 if (context.analysisOptions.strongMode) {
1846 LibraryElementImpl library = getRequiredInput(LIBRARY_ELEMENT_INPUT); 2202 LibraryElement library = getRequiredInput(LIBRARY_ELEMENT_INPUT);
1847 List<LibraryElement> component = library.libraryCycle; 2203 List<LibraryElement> component = library.libraryCycle;
1848 Set<LibraryElement> filter = new Set<LibraryElement>.from(component); 2204 Set<LibraryElement> filter = component.toSet();
1849 Set<CompilationUnitElement> deps = new Set<CompilationUnitElement>(); 2205 Set<CompilationUnitElement> deps = new Set<CompilationUnitElement>();
1850 void addLibrary(l) { 2206 void addLibrary(LibraryElement l) {
1851 if (!filter.contains(l)) { 2207 if (!filter.contains(l)) {
1852 deps.addAll(l.units); 2208 deps.addAll(l.units);
1853 } 2209 }
1854 } 2210 }
1855 for (LibraryElement l in component) { 2211
1856 l.importedLibraries.forEach(addLibrary); 2212 int length = component.length;
1857 l.exportedLibraries.forEach(addLibrary); 2213 for (int i = 0; i < length; i++) {
2214 LibraryElement library = component[i];
2215 library.importedLibraries.forEach(addLibrary);
2216 library.exportedLibraries.forEach(addLibrary);
1858 } 2217 }
1859
1860 // 2218 //
1861 // Record outputs. 2219 // Record outputs.
1862 // 2220 //
2221 LibrarySpecificUnit unitToLSU(CompilationUnitElement unit) =>
2222 new LibrarySpecificUnit(unit.librarySource, unit.source);
1863 outputs[LIBRARY_CYCLE] = component; 2223 outputs[LIBRARY_CYCLE] = component;
1864 outputs[LIBRARY_CYCLE_UNITS] = component.expand((l) => l.units).toList(); 2224 outputs[LIBRARY_CYCLE_UNITS] =
1865 outputs[LIBRARY_CYCLE_DEPENDENCIES] = deps.toList(); 2225 component.expand((l) => l.units).map(unitToLSU).toList();
2226 outputs[LIBRARY_CYCLE_DEPENDENCIES] = deps.map(unitToLSU).toList();
1866 } else { 2227 } else {
1867 outputs[LIBRARY_CYCLE] = []; 2228 outputs[LIBRARY_CYCLE] = [];
1868 outputs[LIBRARY_CYCLE_UNITS] = []; 2229 outputs[LIBRARY_CYCLE_UNITS] = [];
1869 outputs[LIBRARY_CYCLE_DEPENDENCIES] = []; 2230 outputs[LIBRARY_CYCLE_DEPENDENCIES] = [];
1870 } 2231 }
1871 } 2232 }
1872 2233
1873 /** 2234 /**
1874 * Return a map from the names of the inputs of this kind of task to the task 2235 * Return a map from the names of the inputs of this kind of task to the task
1875 * input descriptors describing those inputs for a task with the 2236 * input descriptors describing those inputs for a task with the
1876 * given [target]. 2237 * given [target].
1877 */ 2238 */
1878 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 2239 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
1879 LibrarySpecificUnit unit = target; 2240 Source librarySource = target;
1880 return <String, TaskInput>{ 2241 return <String, TaskInput>{
1881 'resolveReachableLibraries': IMPORT_EXPORT_SOURCE_CLOSURE 2242 LIBRARY_ELEMENT_INPUT: LIBRARY_ELEMENT2.of(librarySource),
1882 .of(unit.library) 2243 'resolveReachableLibraries': READY_LIBRARY_ELEMENT2.of(librarySource),
1883 .toListOf(LIBRARY_ELEMENT2),
1884 LIBRARY_ELEMENT_INPUT: LIBRARY_ELEMENT2.of(unit.library)
1885 }; 2244 };
1886 } 2245 }
1887 2246
1888 /** 2247 /**
1889 * Create a [ComputeLibraryCycleTask] based on the 2248 * Create a [ComputeLibraryCycleTask] based on the
1890 * given [target] in the given [context]. 2249 * given [target] in the given [context].
1891 */ 2250 */
1892 static ComputeLibraryCycleTask createTask( 2251 static ComputeLibraryCycleTask createTask(
1893 AnalysisContext context, AnalysisTarget target) { 2252 AnalysisContext context, AnalysisTarget target) {
1894 return new ComputeLibraryCycleTask(context, target); 2253 return new ComputeLibraryCycleTask(context, target);
1895 } 2254 }
1896 } 2255 }
1897 2256
1898 /** 2257 /**
2258 * A task that builds [REQUIRED_CONSTANTS] for a unit.
2259 */
2260 class ComputeRequiredConstantsTask extends SourceBasedAnalysisTask {
2261 /**
2262 * The name of the [RESOLVED_UNIT] input.
2263 */
2264 static const String UNIT_INPUT = 'UNIT_INPUT';
2265
2266 /**
2267 * The task descriptor describing this kind of task.
2268 */
2269 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
2270 'ComputeRequiredConstantsTask',
2271 createTask,
2272 buildInputs,
2273 <ResultDescriptor>[PENDING_ERRORS, REQUIRED_CONSTANTS]);
2274
2275 ComputeRequiredConstantsTask(
2276 InternalAnalysisContext context, AnalysisTarget target)
2277 : super(context, target);
2278
2279 @override
2280 TaskDescriptor get descriptor => DESCRIPTOR;
2281
2282 @override
2283 void internalPerform() {
2284 Source source = getRequiredSource();
2285 //
2286 // Prepare inputs.
2287 //
2288 CompilationUnit unit = getRequiredInput(UNIT_INPUT);
2289 //
2290 // Use the ErrorVerifier to compute errors.
2291 //
2292 RequiredConstantsComputer computer = new RequiredConstantsComputer(source);
2293 unit.accept(computer);
2294 List<PendingError> pendingErrors = computer.pendingErrors;
2295 List<ConstantEvaluationTarget> requiredConstants =
2296 computer.requiredConstants;
2297 //
2298 // Record outputs.
2299 //
2300 outputs[PENDING_ERRORS] = pendingErrors;
2301 outputs[REQUIRED_CONSTANTS] = requiredConstants;
2302 }
2303
2304 /**
2305 * Return a map from the names of the inputs of this kind of task to the task
2306 * input descriptors describing those inputs for a task with the
2307 * given [target].
2308 */
2309 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
2310 LibrarySpecificUnit unit = target;
2311 return <String, TaskInput>{UNIT_INPUT: RESOLVED_UNIT.of(unit)};
2312 }
2313
2314 /**
2315 * Create a [ComputeRequiredConstantsTask] based on the given [target] in
2316 * the given [context].
2317 */
2318 static ComputeRequiredConstantsTask createTask(
2319 AnalysisContext context, AnalysisTarget target) {
2320 return new ComputeRequiredConstantsTask(context, target);
2321 }
2322 }
2323
2324 /**
1899 * A base class for analysis tasks whose target is expected to be a 2325 * A base class for analysis tasks whose target is expected to be a
1900 * [ConstantEvaluationTarget]. 2326 * [ConstantEvaluationTarget].
1901 */ 2327 */
1902 abstract class ConstantEvaluationAnalysisTask extends AnalysisTask { 2328 abstract class ConstantEvaluationAnalysisTask extends AnalysisTask {
1903 /** 2329 /**
1904 * Initialize a newly created task to perform analysis within the given 2330 * Initialize a newly created task to perform analysis within the given
1905 * [context] in order to produce results for the given [constant]. 2331 * [context] in order to produce results for the given [constant].
1906 */ 2332 */
1907 ConstantEvaluationAnalysisTask( 2333 ConstantEvaluationAnalysisTask(
1908 AnalysisContext context, ConstantEvaluationTarget constant) 2334 AnalysisContext context, ConstantEvaluationTarget constant)
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1973 static ContainingLibrariesTask createTask( 2399 static ContainingLibrariesTask createTask(
1974 AnalysisContext context, AnalysisTarget target) { 2400 AnalysisContext context, AnalysisTarget target) {
1975 return new ContainingLibrariesTask(context, target); 2401 return new ContainingLibrariesTask(context, target);
1976 } 2402 }
1977 } 2403 }
1978 2404
1979 /** 2405 /**
1980 * The description for a change in a Dart source. 2406 * The description for a change in a Dart source.
1981 */ 2407 */
1982 class DartDelta extends Delta { 2408 class DartDelta extends Delta {
1983 bool hasDirectiveChange = false;
1984
1985 final Set<String> addedNames = new Set<String>();
1986 final Set<String> changedNames = new Set<String>(); 2409 final Set<String> changedNames = new Set<String>();
1987 final Set<String> removedNames = new Set<String>(); 2410 final Map<Source, Set<String>> changedPrivateNames = <Source, Set<String>>{};
1988 2411
1989 final Set<Source> invalidatedSources = new Set<Source>(); 2412 final Map<String, ClassElementDelta> changedClasses =
1990 2413 <String, ClassElementDelta>{};
1991 DartDelta(Source source) : super(source) { 2414
1992 invalidatedSources.add(source); 2415 /**
1993 } 2416 * The cache of libraries in which all results are invalid.
1994 2417 */
1995 void elementAdded(Element element) { 2418 final Set<Source> librariesWithAllInvalidResults = new Set<Source>();
1996 addedNames.add(element.name); 2419
2420 /**
2421 * The cache of libraries in which all results are valid.
2422 */
2423 final Set<Source> librariesWithAllValidResults = new Set<Source>();
2424
2425 /**
2426 * The cache of libraries with all, but [HINTS] and [VERIFY_ERRORS] results
2427 * are valid.
2428 */
2429 final Set<Source> libraryWithInvalidErrors = new Set<Source>();
2430
2431 /**
2432 * This set is cleared in every [gatherEnd], and [gatherChanges] uses it
2433 * to find changes in every source only once per visit process.
2434 */
2435 final Set<Source> currentVisitUnits = new Set<Source>();
2436
2437 DartDelta(Source source) : super(source);
2438
2439 @override
2440 bool get shouldGatherChanges => true;
2441
2442 /**
2443 * Add names that are changed in the given [references].
2444 * Return `true` if any change was added.
2445 */
2446 bool addChangedElements(ReferencedNames references, Source refLibrary) {
2447 int numberOfChanges = 0;
2448 int lastNumberOfChange = -1;
2449 while (numberOfChanges != lastNumberOfChange) {
2450 lastNumberOfChange = numberOfChanges;
2451 // Classes that extend changed classes are also changed.
2452 // If there is a delta for a superclass, use it for the subclass.
2453 // Otherwise mark the subclass as "general name change".
2454 references.superToSubs.forEach((String superName, Set<String> subNames) {
2455 ClassElementDelta superDelta = changedClasses[superName];
2456 for (String subName in subNames) {
2457 if (superDelta != null) {
2458 ClassElementDelta subDelta = changedClasses.putIfAbsent(subName,
2459 () => new ClassElementDelta(null, refLibrary, subName));
2460 _log(() => '$subName in $refLibrary has delta because of its '
2461 'superclass $superName has delta');
2462 if (subDelta.superDeltas.add(superDelta)) {
2463 numberOfChanges++;
2464 }
2465 } else if (isChanged(refLibrary, superName)) {
2466 if (nameChanged(refLibrary, subName)) {
2467 _log(() => '$subName in $refLibrary is changed because its '
2468 'superclass $superName is changed');
2469 numberOfChanges++;
2470 }
2471 }
2472 }
2473 });
2474 // If a user element uses a changed top-level element, then the user is
2475 // also changed. Note that if a changed class with delta is used, this
2476 // does not make the user changed - classes with delta keep their
2477 // original elements, so resolution of their names does not change.
2478 references.userToDependsOn.forEach((user, dependencies) {
2479 for (String dependency in dependencies) {
2480 if (isChangedOrClassMember(refLibrary, dependency)) {
2481 if (nameChanged(refLibrary, user)) {
2482 _log(() => '$user in $refLibrary is changed because '
2483 'of $dependency in $dependencies');
2484 numberOfChanges++;
2485 }
2486 }
2487 }
2488 });
2489 }
2490 return numberOfChanges != 0;
2491 }
2492
2493 void classChanged(ClassElementDelta classDelta) {
2494 changedClasses[classDelta.name] = classDelta;
1997 } 2495 }
1998 2496
1999 void elementChanged(Element element) { 2497 void elementChanged(Element element) {
2000 changedNames.add(element.name); 2498 Source librarySource = element.library.source;
2001 } 2499 nameChanged(librarySource, element.name);
2002 2500 }
2003 void elementRemoved(Element element) { 2501
2004 removedNames.add(element.name); 2502 @override
2005 } 2503 bool gatherChanges(InternalAnalysisContext context, AnalysisTarget target,
2006 2504 ResultDescriptor descriptor, Object value) {
2007 bool isNameAffected(String name) { 2505 // Prepare target source.
2008 return addedNames.contains(name) || 2506 Source targetUnit = target.source;
2009 changedNames.contains(name) || 2507 Source targetLibrary = target.librarySource;
2010 removedNames.contains(name); 2508 if (target is Source) {
2011 } 2509 if (context.getKindOf(target) == SourceKind.LIBRARY) {
2012 2510 targetLibrary = target;
2013 bool nameChanged(String name) { 2511 }
2014 return changedNames.add(name); 2512 }
2513 // We don't know what to do with the given target.
2514 if (targetUnit == null || targetUnit != targetLibrary) {
2515 return false;
2516 }
2517 // Attempt to find new changed names for the unit only once.
2518 if (!currentVisitUnits.add(targetUnit)) {
2519 return false;
2520 }
2521 // Add changes.
2522 ReferencedNames referencedNames =
2523 context.getResult(targetUnit, REFERENCED_NAMES);
2524 if (referencedNames == null) {
2525 return false;
2526 }
2527 return addChangedElements(referencedNames, targetLibrary);
2528 }
2529
2530 @override
2531 void gatherEnd() {
2532 currentVisitUnits.clear();
2533 }
2534
2535 bool hasAffectedHintsVerifyErrors(
2536 ReferencedNames references, Source refLibrary) {
2537 for (String superName in references.superToSubs.keys) {
2538 if (isChangedOrClass(refLibrary, superName)) {
2539 _log(() => '$refLibrary hints/verify errors are affected because '
2540 '${references.superToSubs[superName]} subclasses $superName');
2541 return true;
2542 }
2543 }
2544 for (String name in references.names) {
2545 ClassElementDelta classDelta = changedClasses[name];
2546 if (classDelta != null && classDelta.hasAnnotationChanges) {
2547 _log(() => '$refLibrary hints/verify errors are affected because '
2548 '$name has a class delta with annotation changes');
2549 return true;
2550 }
2551 }
2552 return false;
2553 }
2554
2555 bool hasAffectedReferences(ReferencedNames references, Source refLibrary) {
2556 // Resolution must be performed when a referenced element changes.
2557 for (String name in references.names) {
2558 if (isChangedOrClassMember(refLibrary, name)) {
2559 _log(() => '$refLibrary is affected by $name');
2560 return true;
2561 }
2562 }
2563 // Resolution must be performed when the unnamed constructor of
2564 // an instantiated class is added/changed/removed.
2565 // TODO(scheglov) Use only instantiations with default constructor.
2566 for (String name in references.instantiatedNames) {
2567 for (ClassElementDelta classDelta in changedClasses.values) {
2568 if (classDelta.name == name && classDelta.hasUnnamedConstructorChange) {
2569 _log(() =>
2570 '$refLibrary is affected by the default constructor of $name');
2571 return true;
2572 }
2573 }
2574 }
2575 for (String name in references.extendedUsedUnnamedConstructorNames) {
2576 for (ClassElementDelta classDelta in changedClasses.values) {
2577 if (classDelta.name == name && classDelta.hasUnnamedConstructorChange) {
2578 _log(() =>
2579 '$refLibrary is affected by the default constructor of $name');
2580 return true;
2581 }
2582 }
2583 }
2584 return false;
2585 }
2586
2587 /**
2588 * Return `true` if the given [name], used in a unit of the [librarySource],
2589 * is affected by a changed top-level element, excluding classes.
2590 */
2591 bool isChanged(Source librarySource, String name) {
2592 if (_isPrivateName(name)) {
2593 if (changedPrivateNames[librarySource]?.contains(name) ?? false) {
2594 return true;
2595 }
2596 }
2597 return changedNames.contains(name);
2598 }
2599
2600 /**
2601 * Return `true` if the given [name], used in a unit of the [librarySource],
2602 * is affected by a changed top-level element or a class.
2603 */
2604 bool isChangedOrClass(Source librarySource, String name) {
2605 if (isChanged(librarySource, name)) {
2606 return true;
2607 }
2608 return changedClasses[name] != null;
2609 }
2610
2611 /**
2612 * Return `true` if the given [name], used in a unit of the [librarySource],
2613 * is affected by a changed top-level element or a class member.
2614 */
2615 bool isChangedOrClassMember(Source librarySource, String name) {
2616 if (isChanged(librarySource, name)) {
2617 return true;
2618 }
2619 // TODO(scheglov) Optimize this.
2620 for (ClassElementDelta classDelta in changedClasses.values) {
2621 if (classDelta.hasChanges(librarySource, name)) {
2622 return true;
2623 }
2624 }
2625 return false;
2626 }
2627
2628 /**
2629 * Register the fact that the given [name], defined in the [librarySource]
2630 * is changed. Return `true` if the [name] is a new name, not yet registered.
2631 */
2632 bool nameChanged(Source librarySource, String name) {
2633 if (_isPrivateName(name)) {
2634 return changedPrivateNames
2635 .putIfAbsent(librarySource, () => new Set<String>())
2636 .add(name);
2637 } else {
2638 return changedNames.add(name);
2639 }
2015 } 2640 }
2016 2641
2017 @override 2642 @override
2018 DeltaResult validate(InternalAnalysisContext context, AnalysisTarget target, 2643 DeltaResult validate(InternalAnalysisContext context, AnalysisTarget target,
2019 ResultDescriptor descriptor) { 2644 ResultDescriptor descriptor, Object value) {
2020 if (hasDirectiveChange) { 2645 // Always invalidate compounding results.
2646 if (descriptor == LIBRARY_ELEMENT4 ||
2647 descriptor == READY_LIBRARY_ELEMENT6 ||
2648 descriptor == READY_LIBRARY_ELEMENT7) {
2649 return DeltaResult.INVALIDATE_KEEP_DEPENDENCIES;
2650 }
2651 // Prepare target source.
2652 Source targetUnit = target.source;
2653 Source targetLibrary = target.librarySource;
2654 if (target is Source) {
2655 if (context.getKindOf(target) == SourceKind.LIBRARY) {
2656 targetLibrary = target;
2657 }
2658 }
2659 // We don't know what to do with the given target, invalidate it.
2660 if (targetUnit == null || targetUnit != targetLibrary) {
2021 return DeltaResult.INVALIDATE; 2661 return DeltaResult.INVALIDATE;
2022 } 2662 }
2023 // Prepare target source. 2663 // Keep results that don't change: any library.
2024 Source targetSource = null; 2664 if (_isTaskResult(ScanDartTask.DESCRIPTOR, descriptor) ||
2025 if (target is Source) { 2665 _isTaskResult(ParseDartTask.DESCRIPTOR, descriptor) ||
2026 targetSource = target; 2666 _isTaskResult(BuildCompilationUnitElementTask.DESCRIPTOR, descriptor) ||
2027 } 2667 _isTaskResult(BuildLibraryElementTask.DESCRIPTOR, descriptor) ||
2028 if (target is LibrarySpecificUnit) { 2668 _isTaskResult(BuildDirectiveElementsTask.DESCRIPTOR, descriptor) ||
2029 targetSource = target.library; 2669 _isTaskResult(ResolveDirectiveElementsTask.DESCRIPTOR, descriptor) ||
2030 } 2670 _isTaskResult(BuildEnumMemberElementsTask.DESCRIPTOR, descriptor) ||
2031 if (target is Element) { 2671 _isTaskResult(BuildSourceExportClosureTask.DESCRIPTOR, descriptor) ||
2032 targetSource = target.source; 2672 _isTaskResult(ReadyLibraryElement2Task.DESCRIPTOR, descriptor) ||
2033 } 2673 _isTaskResult(ComputeLibraryCycleTask.DESCRIPTOR, descriptor)) {
2034 // Keep results that are updated incrementally. 2674 return DeltaResult.KEEP_CONTINUE;
2035 // If we want to analyze only some references to the source being changed, 2675 }
2036 // we need to keep the same instances of CompilationUnitElement and 2676 // Keep results that don't change: changed library.
2037 // LibraryElement. 2677 if (targetUnit == source) {
2038 if (targetSource == source) { 2678 return DeltaResult.INVALIDATE;
2039 if (ParseDartTask.DESCRIPTOR.results.contains(descriptor)) { 2679 }
2680 // Keep results that don't change: dependent library.
2681 if (targetUnit != source) {
2682 if (_isTaskResult(BuildPublicNamespaceTask.DESCRIPTOR, descriptor)) {
2040 return DeltaResult.KEEP_CONTINUE; 2683 return DeltaResult.KEEP_CONTINUE;
2041 } 2684 }
2042 if (BuildCompilationUnitElementTask.DESCRIPTOR.results 2685 }
2043 .contains(descriptor)) { 2686 // Handle in-library results only for now.
2687 if (targetLibrary != null) {
2688 // Use cached library results.
2689 if (librariesWithAllInvalidResults.contains(targetLibrary)) {
2690 return DeltaResult.INVALIDATE;
2691 }
2692 if (librariesWithAllValidResults.contains(targetLibrary)) {
2044 return DeltaResult.KEEP_CONTINUE; 2693 return DeltaResult.KEEP_CONTINUE;
2045 } 2694 }
2046 if (BuildLibraryElementTask.DESCRIPTOR.results.contains(descriptor)) { 2695 // The library is almost, but not completely valid.
2696 // Some error results are invalid.
2697 if (libraryWithInvalidErrors.contains(targetLibrary)) {
2698 if (descriptor == HINTS || descriptor == VERIFY_ERRORS) {
2699 return DeltaResult.INVALIDATE_NO_DELTA;
2700 }
2047 return DeltaResult.KEEP_CONTINUE; 2701 return DeltaResult.KEEP_CONTINUE;
2048 } 2702 }
2049 return DeltaResult.INVALIDATE; 2703 // Compute the library result.
2050 } 2704 ReferencedNames referencedNames =
2051 // Use the target library dependency information to decide whether 2705 context.getResult(targetUnit, REFERENCED_NAMES);
2052 // the delta affects the library. 2706 if (referencedNames == null) {
2053 if (targetSource != null) { 2707 return DeltaResult.INVALIDATE_NO_DELTA;
2054 List<Source> librarySources = 2708 }
2055 context.getLibrariesContaining(targetSource); 2709 if (hasAffectedReferences(referencedNames, targetLibrary)) {
2056 for (Source librarySource in librarySources) { 2710 librariesWithAllInvalidResults.add(targetLibrary);
2057 AnalysisCache cache = context.analysisCache; 2711 return DeltaResult.INVALIDATE;
2058 ReferencedNames referencedNames = 2712 }
2059 cache.getValue(librarySource, REFERENCED_NAMES); 2713 if (hasAffectedHintsVerifyErrors(referencedNames, targetLibrary)) {
2060 if (referencedNames == null) { 2714 libraryWithInvalidErrors.add(targetLibrary);
2061 return DeltaResult.INVALIDATE; 2715 return DeltaResult.KEEP_CONTINUE;
2062 } 2716 }
2063 referencedNames.addChangedElements(this); 2717 librariesWithAllValidResults.add(targetLibrary);
2064 if (referencedNames.isAffectedBy(this)) { 2718 return DeltaResult.KEEP_CONTINUE;
2065 return DeltaResult.INVALIDATE;
2066 }
2067 }
2068 return DeltaResult.STOP;
2069 } 2719 }
2070 // We don't know what to do with the given target, invalidate it. 2720 // We don't know what to do with the given target, invalidate it.
2071 return DeltaResult.INVALIDATE; 2721 return DeltaResult.INVALIDATE;
2072 } 2722 }
2723
2724 void _log(String getMessage()) {
2725 // String message = getMessage();
2726 // print(message);
2727 }
2728
2729 static bool _isPrivateName(String name) => name.startsWith('_');
2730
2731 static bool _isTaskResult(
2732 TaskDescriptor taskDescriptor, ResultDescriptor result) {
2733 return taskDescriptor.results.contains(result);
2734 }
2073 } 2735 }
2074 2736
2075 /** 2737 /**
2076 * A task that merges all of the errors for a single source into a single list 2738 * A task that merges all of the errors for a single source into a single list
2077 * of errors. 2739 * of errors.
2078 */ 2740 */
2079 class DartErrorsTask extends SourceBasedAnalysisTask { 2741 class DartErrorsTask extends SourceBasedAnalysisTask {
2080 /** 2742 /**
2081 * The task descriptor describing this kind of task. 2743 * The task descriptor describing this kind of task.
2082 */ 2744 */
2083 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor('DartErrorsTask', 2745 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor('DartErrorsTask',
2084 createTask, buildInputs, <ResultDescriptor>[DART_ERRORS]); 2746 createTask, buildInputs, <ResultDescriptor>[DART_ERRORS]);
2085 2747
2748 /**
2749 * The name of the [IGNORE_INFO_INPUT] input.
2750 */
2751 static const String IGNORE_INFO_INPUT = 'IGNORE_INFO_INPUT';
2752
2753 /**
2754 * The name of the [LINE_INFO_INPUT] input.
2755 */
2756 static const String LINE_INFO_INPUT = 'LINE_INFO_INPUT';
2757
2086 DartErrorsTask(InternalAnalysisContext context, AnalysisTarget target) 2758 DartErrorsTask(InternalAnalysisContext context, AnalysisTarget target)
2087 : super(context, target); 2759 : super(context, target);
2088 2760
2089 @override 2761 @override
2090 TaskDescriptor get descriptor => DESCRIPTOR; 2762 TaskDescriptor get descriptor => DESCRIPTOR;
2091 2763
2092 @override 2764 @override
2093 void internalPerform() { 2765 void internalPerform() {
2094 List<List<AnalysisError>> errorLists = <List<AnalysisError>>[]; 2766 List<List<AnalysisError>> errorLists = <List<AnalysisError>>[];
2095 // 2767 //
2096 // Prepare inputs. 2768 // Prepare inputs.
2097 // 2769 //
2098 EnginePlugin enginePlugin = AnalysisEngine.instance.enginePlugin; 2770 EnginePlugin enginePlugin = AnalysisEngine.instance.enginePlugin;
2099 for (ResultDescriptor result in enginePlugin.dartErrorsForSource) { 2771 List<ResultDescriptor> errorsForSource = enginePlugin.dartErrorsForSource;
2772 int sourceLength = errorsForSource.length;
2773 for (int i = 0; i < sourceLength; i++) {
2774 ResultDescriptor result = errorsForSource[i];
2100 String inputName = result.name + '_input'; 2775 String inputName = result.name + '_input';
2101 errorLists.add(getRequiredInput(inputName)); 2776 errorLists.add(getRequiredInput(inputName));
2102 } 2777 }
2103 for (ResultDescriptor result in enginePlugin.dartErrorsForUnit) { 2778 List<ResultDescriptor> errorsForUnit = enginePlugin.dartErrorsForUnit;
2779 int unitLength = errorsForUnit.length;
2780 for (int i = 0; i < unitLength; i++) {
2781 ResultDescriptor result = errorsForUnit[i];
2104 String inputName = result.name + '_input'; 2782 String inputName = result.name + '_input';
2105 Map<Source, List<AnalysisError>> errorMap = getRequiredInput(inputName); 2783 Map<Source, List<AnalysisError>> errorMap = getRequiredInput(inputName);
2106 for (List<AnalysisError> errors in errorMap.values) { 2784 for (List<AnalysisError> errors in errorMap.values) {
2107 errorLists.add(errors); 2785 errorLists.add(errors);
2108 } 2786 }
2109 } 2787 }
2788
2789 //
2790 // Filter ignored errors.
2791 //
2792 List<AnalysisError> errors =
2793 _filterIgnores(AnalysisError.mergeLists(errorLists));
2794
2110 // 2795 //
2111 // Record outputs. 2796 // Record outputs.
2112 // 2797 //
2113 outputs[DART_ERRORS] = AnalysisError.mergeLists(errorLists); 2798 outputs[DART_ERRORS] = errors;
2799 }
2800
2801 List<AnalysisError> _filterIgnores(List<AnalysisError> errors) {
2802 if (errors.isEmpty) {
2803 return errors;
2804 }
2805
2806 IgnoreInfo ignoreInfo = getRequiredInput(IGNORE_INFO_INPUT);
2807 if (!ignoreInfo.hasIgnores) {
2808 return errors;
2809 }
2810
2811 LineInfo lineInfo = getRequiredInput(LINE_INFO_INPUT);
2812
2813 return filterIgnored(errors, ignoreInfo, lineInfo);
2114 } 2814 }
2115 2815
2116 /** 2816 /**
2117 * Return a map from the names of the inputs of this kind of task to the task 2817 * Return a map from the names of the inputs of this kind of task to the task
2118 * input descriptors describing those inputs for a task with the 2818 * input descriptors describing those inputs for a task with the
2119 * given [target]. 2819 * given [target].
2120 */ 2820 */
2121 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 2821 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
2122 Source source = target; 2822 Source source = target;
2123 Map<String, TaskInput> inputs = <String, TaskInput>{}; 2823 Map<String, TaskInput> inputs = <String, TaskInput>{};
2824 inputs[LINE_INFO_INPUT] = LINE_INFO.of(source);
2825 inputs[IGNORE_INFO_INPUT] = IGNORE_INFO.of(source);
2124 EnginePlugin enginePlugin = AnalysisEngine.instance.enginePlugin; 2826 EnginePlugin enginePlugin = AnalysisEngine.instance.enginePlugin;
2125 // for Source 2827 // for Source
2126 for (ResultDescriptor result in enginePlugin.dartErrorsForSource) { 2828 List<ResultDescriptor> errorsForSource = enginePlugin.dartErrorsForSource;
2829 int sourceLength = errorsForSource.length;
2830 for (int i = 0; i < sourceLength; i++) {
2831 ResultDescriptor result = errorsForSource[i];
2127 String inputName = result.name + '_input'; 2832 String inputName = result.name + '_input';
2128 inputs[inputName] = result.of(source); 2833 inputs[inputName] = result.of(source);
2129 } 2834 }
2130 // for LibrarySpecificUnit 2835 // for LibrarySpecificUnit
2131 for (ResultDescriptor result in enginePlugin.dartErrorsForUnit) { 2836 List<ResultDescriptor> errorsForUnit = enginePlugin.dartErrorsForUnit;
2837 int unitLength = errorsForUnit.length;
2838 for (int i = 0; i < unitLength; i++) {
2839 ResultDescriptor result = errorsForUnit[i];
2132 String inputName = result.name + '_input'; 2840 String inputName = result.name + '_input';
2133 inputs[inputName] = 2841 inputs[inputName] =
2134 CONTAINING_LIBRARIES.of(source).toMap((Source library) { 2842 CONTAINING_LIBRARIES.of(source).toMap((Source library) {
2135 LibrarySpecificUnit unit = new LibrarySpecificUnit(library, source); 2843 LibrarySpecificUnit unit = new LibrarySpecificUnit(library, source);
2136 return result.of(unit); 2844 return result.of(unit);
2137 }); 2845 });
2138 } 2846 }
2139 return inputs; 2847 return inputs;
2140 } 2848 }
2141 2849
2142 /** 2850 /**
2143 * Create a [DartErrorsTask] based on the given [target] in the given 2851 * Create a [DartErrorsTask] based on the given [target] in the given
2144 * [context]. 2852 * [context].
2145 */ 2853 */
2146 static DartErrorsTask createTask( 2854 static DartErrorsTask createTask(
2147 AnalysisContext context, AnalysisTarget target) { 2855 AnalysisContext context, AnalysisTarget target) {
2148 return new DartErrorsTask(context, target); 2856 return new DartErrorsTask(context, target);
2149 } 2857 }
2858
2859 /**
2860 * Return a new list with items from [errors] which are not filtered out by
2861 * the [ignoreInfo].
2862 */
2863 static List<AnalysisError> filterIgnored(
2864 List<AnalysisError> errors, IgnoreInfo ignoreInfo, LineInfo lineInfo) {
2865 if (errors.isEmpty || !ignoreInfo.hasIgnores) {
2866 return errors;
2867 }
2868
2869 bool isIgnored(AnalysisError error) {
2870 int errorLine = lineInfo.getLocation(error.offset).lineNumber;
2871 String errorCode = error.errorCode.name.toLowerCase();
2872 // Ignores can be on the line or just preceding the error.
2873 return ignoreInfo.ignoredAt(errorCode, errorLine) ||
2874 ignoreInfo.ignoredAt(errorCode, errorLine - 1);
2875 }
2876
2877 return errors.where((AnalysisError e) => !isIgnored(e)).toList();
2878 }
2150 } 2879 }
2151 2880
2152 /** 2881 /**
2153 * A task that builds [RESOLVED_UNIT10] for a unit. 2882 * A task that builds [RESOLVED_UNIT12] for a unit.
2154 */ 2883 */
2155 class EvaluateUnitConstantsTask extends SourceBasedAnalysisTask { 2884 class EvaluateUnitConstantsTask extends SourceBasedAnalysisTask {
2156 /** 2885 /**
2157 * The name of the [RESOLVED_UNIT9] input. 2886 * The name of the [RESOLVED_UNIT11] input.
2158 */ 2887 */
2159 static const String UNIT_INPUT = 'UNIT_INPUT'; 2888 static const String UNIT_INPUT = 'UNIT_INPUT';
2160 2889
2161 /** 2890 /**
2162 * The name of the [CONSTANT_VALUE] input. 2891 * The name of the [CONSTANT_VALUE] input.
2163 */ 2892 */
2164 static const String CONSTANT_VALUES = 'CONSTANT_VALUES'; 2893 static const String CONSTANT_VALUES = 'CONSTANT_VALUES';
2165 2894
2166 /** 2895 /**
2167 * The task descriptor describing this kind of task. 2896 * The task descriptor describing this kind of task.
2168 */ 2897 */
2169 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 2898 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
2170 'EvaluateUnitConstantsTask', 2899 'EvaluateUnitConstantsTask',
2171 createTask, 2900 createTask,
2172 buildInputs, 2901 buildInputs,
2173 <ResultDescriptor>[RESOLVED_UNIT10]); 2902 <ResultDescriptor>[CREATED_RESOLVED_UNIT12, RESOLVED_UNIT12]);
2174 2903
2175 EvaluateUnitConstantsTask(AnalysisContext context, LibrarySpecificUnit target) 2904 EvaluateUnitConstantsTask(AnalysisContext context, LibrarySpecificUnit target)
2176 : super(context, target); 2905 : super(context, target);
2177 2906
2178 @override 2907 @override
2179 TaskDescriptor get descriptor => DESCRIPTOR; 2908 TaskDescriptor get descriptor => DESCRIPTOR;
2180 2909
2181 @override 2910 @override
2182 void internalPerform() { 2911 void internalPerform() {
2183 // No actual work needs to be performed; the task manager will ensure that 2912 // No actual work needs to be performed; the task manager will ensure that
2184 // all constants are evaluated before this method is called. 2913 // all constants are evaluated before this method is called.
2185 CompilationUnit unit = getRequiredInput(UNIT_INPUT); 2914 CompilationUnit unit = getRequiredInput(UNIT_INPUT);
2186 outputs[RESOLVED_UNIT10] = unit; 2915 outputs[RESOLVED_UNIT12] = unit;
2916 outputs[CREATED_RESOLVED_UNIT12] = true;
2187 } 2917 }
2188 2918
2189 /** 2919 /**
2190 * Return a map from the names of the inputs of this kind of task to the task 2920 * Return a map from the names of the inputs of this kind of task to the task
2191 * input descriptors describing those inputs for a task with the 2921 * input descriptors describing those inputs for a task with the
2192 * given [target]. 2922 * given [target].
2193 */ 2923 */
2194 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 2924 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
2195 LibrarySpecificUnit unit = target; 2925 LibrarySpecificUnit unit = target;
2196 return <String, TaskInput>{ 2926 return <String, TaskInput>{
2197 'libraryElement': LIBRARY_ELEMENT.of(unit.library), 2927 'libraryElement': LIBRARY_ELEMENT9.of(unit.library),
2198 UNIT_INPUT: RESOLVED_UNIT9.of(unit), 2928 UNIT_INPUT: RESOLVED_UNIT11.of(unit),
2199 CONSTANT_VALUES: 2929 CONSTANT_VALUES:
2200 COMPILATION_UNIT_CONSTANTS.of(unit).toListOf(CONSTANT_VALUE) 2930 COMPILATION_UNIT_CONSTANTS.of(unit).toListOf(CONSTANT_VALUE),
2931 'constantExpressionsDependencies':
2932 CONSTANT_EXPRESSIONS_DEPENDENCIES.of(unit).toListOf(CONSTANT_VALUE)
2201 }; 2933 };
2202 } 2934 }
2203 2935
2204 /** 2936 /**
2205 * Create an [EvaluateUnitConstantsTask] based on the given [target] in 2937 * Create an [EvaluateUnitConstantsTask] based on the given [target] in
2206 * the given [context]. 2938 * the given [context].
2207 */ 2939 */
2208 static EvaluateUnitConstantsTask createTask( 2940 static EvaluateUnitConstantsTask createTask(
2209 AnalysisContext context, AnalysisTarget target) { 2941 AnalysisContext context, AnalysisTarget target) {
2210 return new EvaluateUnitConstantsTask(context, target); 2942 return new EvaluateUnitConstantsTask(context, target);
2211 } 2943 }
2212 } 2944 }
2213 2945
2214 /** 2946 /**
2215 * The helper for building the export [Namespace] of a [LibraryElement].
2216 */
2217 class ExportNamespaceBuilder {
2218 /**
2219 * Build the export [Namespace] of the given [LibraryElement].
2220 */
2221 Namespace build(LibraryElement library) {
2222 return new Namespace(
2223 _createExportMapping(library, new HashSet<LibraryElement>()));
2224 }
2225
2226 /**
2227 * Create a mapping table representing the export namespace of the given
2228 * [library].
2229 *
2230 * The given [visitedElements] a set of libraries that do not need to be
2231 * visited when processing the export directives of the given library because
2232 * all of the names defined by them will be added by another library.
2233 */
2234 HashMap<String, Element> _createExportMapping(
2235 LibraryElement library, HashSet<LibraryElement> visitedElements) {
2236 visitedElements.add(library);
2237 try {
2238 HashMap<String, Element> definedNames = new HashMap<String, Element>();
2239 // Add names of the export directives.
2240 for (ExportElement element in library.exports) {
2241 LibraryElement exportedLibrary = element.exportedLibrary;
2242 if (exportedLibrary != null &&
2243 !visitedElements.contains(exportedLibrary)) {
2244 //
2245 // The exported library will be null if the URI does not reference a
2246 // valid library.
2247 //
2248 HashMap<String, Element> exportedNames =
2249 _createExportMapping(exportedLibrary, visitedElements);
2250 exportedNames = _applyCombinators(exportedNames, element.combinators);
2251 definedNames.addAll(exportedNames);
2252 }
2253 }
2254 // Add names of the public namespace.
2255 {
2256 Namespace publicNamespace = library.publicNamespace;
2257 if (publicNamespace != null) {
2258 definedNames.addAll(publicNamespace.definedNames);
2259 }
2260 }
2261 return definedNames;
2262 } finally {
2263 visitedElements.remove(library);
2264 }
2265 }
2266
2267 /**
2268 * Apply the given [combinators] to all of the names in [definedNames].
2269 */
2270 static HashMap<String, Element> _applyCombinators(
2271 HashMap<String, Element> definedNames,
2272 List<NamespaceCombinator> combinators) {
2273 for (NamespaceCombinator combinator in combinators) {
2274 if (combinator is HideElementCombinator) {
2275 _hide(definedNames, combinator.hiddenNames);
2276 } else if (combinator is ShowElementCombinator) {
2277 definedNames = _show(definedNames, combinator.shownNames);
2278 }
2279 }
2280 return definedNames;
2281 }
2282
2283 /**
2284 * Hide all of the [hiddenNames] by removing them from the given
2285 * [definedNames].
2286 */
2287 static void _hide(
2288 HashMap<String, Element> definedNames, List<String> hiddenNames) {
2289 for (String name in hiddenNames) {
2290 definedNames.remove(name);
2291 definedNames.remove('$name=');
2292 }
2293 }
2294
2295 /**
2296 * Show only the given [shownNames] by removing all other names from the given
2297 * [definedNames].
2298 */
2299 static HashMap<String, Element> _show(
2300 HashMap<String, Element> definedNames, List<String> shownNames) {
2301 HashMap<String, Element> newNames = new HashMap<String, Element>();
2302 for (String name in shownNames) {
2303 Element element = definedNames[name];
2304 if (element != null) {
2305 newNames[name] = element;
2306 }
2307 String setterName = '$name=';
2308 element = definedNames[setterName];
2309 if (element != null) {
2310 newNames[setterName] = element;
2311 }
2312 }
2313 return newNames;
2314 }
2315 }
2316
2317 /**
2318 * A task that builds [USED_IMPORTED_ELEMENTS] for a unit. 2947 * A task that builds [USED_IMPORTED_ELEMENTS] for a unit.
2319 */ 2948 */
2320 class GatherUsedImportedElementsTask extends SourceBasedAnalysisTask { 2949 class GatherUsedImportedElementsTask extends SourceBasedAnalysisTask {
2321 /** 2950 /**
2322 * The name of the [RESOLVED_UNIT9] input. 2951 * The name of the [RESOLVED_UNIT11] input.
2323 */ 2952 */
2324 static const String UNIT_INPUT = 'UNIT_INPUT'; 2953 static const String UNIT_INPUT = 'UNIT_INPUT';
2325 2954
2326 /** 2955 /**
2327 * The task descriptor describing this kind of task. 2956 * The task descriptor describing this kind of task.
2328 */ 2957 */
2329 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 2958 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
2330 'GatherUsedImportedElementsTask', 2959 'GatherUsedImportedElementsTask',
2331 createTask, 2960 createTask,
2332 buildInputs, 2961 buildInputs,
(...skipping 23 matching lines...) Expand all
2356 outputs[USED_IMPORTED_ELEMENTS] = visitor.usedElements; 2985 outputs[USED_IMPORTED_ELEMENTS] = visitor.usedElements;
2357 } 2986 }
2358 2987
2359 /** 2988 /**
2360 * Return a map from the names of the inputs of this kind of task to the task 2989 * Return a map from the names of the inputs of this kind of task to the task
2361 * input descriptors describing those inputs for a task with the 2990 * input descriptors describing those inputs for a task with the
2362 * given [target]. 2991 * given [target].
2363 */ 2992 */
2364 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 2993 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
2365 LibrarySpecificUnit unit = target; 2994 LibrarySpecificUnit unit = target;
2366 return <String, TaskInput>{UNIT_INPUT: RESOLVED_UNIT9.of(unit)}; 2995 return <String, TaskInput>{UNIT_INPUT: RESOLVED_UNIT11.of(unit)};
2367 } 2996 }
2368 2997
2369 /** 2998 /**
2370 * Create a [GatherUsedImportedElementsTask] based on the given [target] in 2999 * Create a [GatherUsedImportedElementsTask] based on the given [target] in
2371 * the given [context]. 3000 * the given [context].
2372 */ 3001 */
2373 static GatherUsedImportedElementsTask createTask( 3002 static GatherUsedImportedElementsTask createTask(
2374 AnalysisContext context, AnalysisTarget target) { 3003 AnalysisContext context, AnalysisTarget target) {
2375 return new GatherUsedImportedElementsTask(context, target); 3004 return new GatherUsedImportedElementsTask(context, target);
2376 } 3005 }
2377 } 3006 }
2378 3007
2379 /** 3008 /**
2380 * A task that builds [USED_LOCAL_ELEMENTS] for a unit. 3009 * A task that builds [USED_LOCAL_ELEMENTS] for a unit.
2381 */ 3010 */
2382 class GatherUsedLocalElementsTask extends SourceBasedAnalysisTask { 3011 class GatherUsedLocalElementsTask extends SourceBasedAnalysisTask {
2383 /** 3012 /**
2384 * The name of the [RESOLVED_UNIT9] input. 3013 * The name of the [RESOLVED_UNIT11] input.
2385 */ 3014 */
2386 static const String UNIT_INPUT = 'UNIT_INPUT'; 3015 static const String UNIT_INPUT = 'UNIT_INPUT';
2387 3016
2388 /** 3017 /**
2389 * The task descriptor describing this kind of task. 3018 * The task descriptor describing this kind of task.
2390 */ 3019 */
2391 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 3020 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
2392 'GatherUsedLocalElementsTask', 3021 'GatherUsedLocalElementsTask',
2393 createTask, 3022 createTask,
2394 buildInputs, 3023 buildInputs,
(...skipping 23 matching lines...) Expand all
2418 outputs[USED_LOCAL_ELEMENTS] = visitor.usedElements; 3047 outputs[USED_LOCAL_ELEMENTS] = visitor.usedElements;
2419 } 3048 }
2420 3049
2421 /** 3050 /**
2422 * Return a map from the names of the inputs of this kind of task to the task 3051 * Return a map from the names of the inputs of this kind of task to the task
2423 * input descriptors describing those inputs for a task with the 3052 * input descriptors describing those inputs for a task with the
2424 * given [target]. 3053 * given [target].
2425 */ 3054 */
2426 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 3055 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
2427 LibrarySpecificUnit unit = target; 3056 LibrarySpecificUnit unit = target;
2428 return <String, TaskInput>{UNIT_INPUT: RESOLVED_UNIT9.of(unit)}; 3057 return <String, TaskInput>{UNIT_INPUT: RESOLVED_UNIT11.of(unit)};
2429 } 3058 }
2430 3059
2431 /** 3060 /**
2432 * Create a [GatherUsedLocalElementsTask] based on the given [target] in 3061 * Create a [GatherUsedLocalElementsTask] based on the given [target] in
2433 * the given [context]. 3062 * the given [context].
2434 */ 3063 */
2435 static GatherUsedLocalElementsTask createTask( 3064 static GatherUsedLocalElementsTask createTask(
2436 AnalysisContext context, AnalysisTarget target) { 3065 AnalysisContext context, AnalysisTarget target) {
2437 return new GatherUsedLocalElementsTask(context, target); 3066 return new GatherUsedLocalElementsTask(context, target);
2438 } 3067 }
2439 } 3068 }
2440 3069
2441 /** 3070 /**
2442 * A task that generates [HINTS] for a unit. 3071 * A task that generates [HINTS] for a unit.
2443 */ 3072 */
2444 class GenerateHintsTask extends SourceBasedAnalysisTask { 3073 class GenerateHintsTask extends SourceBasedAnalysisTask {
2445 /** 3074 /**
2446 * The name of the [RESOLVED_UNIT9] input. 3075 * The name of the [RESOLVED_UNIT11] input.
2447 */ 3076 */
2448 static const String RESOLVED_UNIT_INPUT = 'RESOLVED_UNIT'; 3077 static const String RESOLVED_UNIT_INPUT = 'RESOLVED_UNIT';
2449 3078
2450 /** 3079 /**
2451 * The name of a list of [USED_LOCAL_ELEMENTS] for each library unit input. 3080 * The name of a list of [USED_LOCAL_ELEMENTS] for each library unit input.
2452 */ 3081 */
2453 static const String USED_LOCAL_ELEMENTS_INPUT = 'USED_LOCAL_ELEMENTS'; 3082 static const String USED_LOCAL_ELEMENTS_INPUT = 'USED_LOCAL_ELEMENTS';
2454 3083
2455 /** 3084 /**
2456 * The name of a list of [USED_IMPORTED_ELEMENTS] for each library unit input. 3085 * The name of a list of [USED_IMPORTED_ELEMENTS] for each library unit input.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
2503 // Generate errors. 3132 // Generate errors.
2504 // 3133 //
2505 unit.accept(new DeadCodeVerifier(errorReporter, typeSystem: typeSystem)); 3134 unit.accept(new DeadCodeVerifier(errorReporter, typeSystem: typeSystem));
2506 // Verify imports. 3135 // Verify imports.
2507 { 3136 {
2508 ImportsVerifier verifier = new ImportsVerifier(); 3137 ImportsVerifier verifier = new ImportsVerifier();
2509 verifier.addImports(unit); 3138 verifier.addImports(unit);
2510 usedImportedElementsList.forEach(verifier.removeUsedElements); 3139 usedImportedElementsList.forEach(verifier.removeUsedElements);
2511 verifier.generateDuplicateImportHints(errorReporter); 3140 verifier.generateDuplicateImportHints(errorReporter);
2512 verifier.generateUnusedImportHints(errorReporter); 3141 verifier.generateUnusedImportHints(errorReporter);
3142 verifier.generateUnusedShownNameHints(errorReporter);
2513 } 3143 }
2514 // Unused local elements. 3144 // Unused local elements.
2515 { 3145 {
2516 UsedLocalElements usedElements = 3146 UsedLocalElements usedElements =
2517 new UsedLocalElements.merge(usedLocalElementsList); 3147 new UsedLocalElements.merge(usedLocalElementsList);
2518 UnusedLocalElementsVerifier visitor = 3148 UnusedLocalElementsVerifier visitor =
2519 new UnusedLocalElementsVerifier(errorListener, usedElements); 3149 new UnusedLocalElementsVerifier(errorListener, usedElements);
2520 unitElement.accept(visitor); 3150 unitElement.accept(visitor);
2521 } 3151 }
2522 // Dart2js analysis. 3152 // Dart2js analysis.
2523 if (analysisOptions.dart2jsHint) { 3153 if (analysisOptions.dart2jsHint) {
2524 unit.accept(new Dart2JSVerifier(errorReporter)); 3154 unit.accept(new Dart2JSVerifier(errorReporter));
2525 } 3155 }
2526 // Dart best practices. 3156 // Dart best practices.
2527 InheritanceManager inheritanceManager = 3157 InheritanceManager inheritanceManager = new InheritanceManager(
2528 new InheritanceManager(libraryElement); 3158 libraryElement,
3159 includeAbstractFromSuperclasses: true);
2529 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT); 3160 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT);
2530 3161
2531 unit.accept(new BestPracticesVerifier(errorReporter, typeProvider, 3162 unit.accept(new BestPracticesVerifier(
3163 errorReporter, typeProvider, libraryElement, inheritanceManager,
2532 typeSystem: typeSystem)); 3164 typeSystem: typeSystem));
2533 unit.accept(new OverrideVerifier(errorReporter, inheritanceManager)); 3165 unit.accept(new OverrideVerifier(errorReporter, inheritanceManager));
2534 // Find to-do comments. 3166 // Find to-do comments.
2535 new ToDoFinder(errorReporter).findIn(unit); 3167 new ToDoFinder(errorReporter).findIn(unit);
2536 // 3168 //
2537 // Record outputs. 3169 // Record outputs.
2538 // 3170 //
2539 outputs[HINTS] = errorListener.errors; 3171 outputs[HINTS] = errorListener.errors;
2540 } 3172 }
2541 3173
2542 /** 3174 /**
2543 * Return a map from the names of the inputs of this kind of task to the task 3175 * Return a map from the names of the inputs of this kind of task to the task
2544 * input descriptors describing those inputs for a task with the 3176 * input descriptors describing those inputs for a task with the
2545 * given [target]. 3177 * given [target].
2546 */ 3178 */
2547 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 3179 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
2548 LibrarySpecificUnit unit = target; 3180 LibrarySpecificUnit unit = target;
2549 Source libSource = unit.library; 3181 Source libSource = unit.library;
2550 return <String, TaskInput>{ 3182 return <String, TaskInput>{
2551 RESOLVED_UNIT_INPUT: RESOLVED_UNIT.of(unit), 3183 RESOLVED_UNIT_INPUT: RESOLVED_UNIT.of(unit),
2552 USED_LOCAL_ELEMENTS_INPUT: UNITS.of(libSource).toList((unit) { 3184 USED_LOCAL_ELEMENTS_INPUT:
2553 LibrarySpecificUnit target = new LibrarySpecificUnit(libSource, unit); 3185 LIBRARY_SPECIFIC_UNITS.of(libSource).toListOf(USED_LOCAL_ELEMENTS),
2554 return USED_LOCAL_ELEMENTS.of(target); 3186 USED_IMPORTED_ELEMENTS_INPUT:
2555 }), 3187 LIBRARY_SPECIFIC_UNITS.of(libSource).toListOf(USED_IMPORTED_ELEMENTS),
2556 USED_IMPORTED_ELEMENTS_INPUT: UNITS.of(libSource).toList((unit) {
2557 LibrarySpecificUnit target = new LibrarySpecificUnit(libSource, unit);
2558 return USED_IMPORTED_ELEMENTS.of(target);
2559 }),
2560 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request) 3188 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request)
2561 }; 3189 };
2562 } 3190 }
2563 3191
2564 /** 3192 /**
2565 * Create a [GenerateHintsTask] based on the given [target] in 3193 * Create a [GenerateHintsTask] based on the given [target] in
2566 * the given [context]. 3194 * the given [context].
2567 */ 3195 */
2568 static GenerateHintsTask createTask( 3196 static GenerateHintsTask createTask(
2569 AnalysisContext context, AnalysisTarget target) { 3197 AnalysisContext context, AnalysisTarget target) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
2606 Source source = getRequiredSource(); 3234 Source source = getRequiredSource();
2607 ErrorReporter errorReporter = new ErrorReporter(errorListener, source); 3235 ErrorReporter errorReporter = new ErrorReporter(errorListener, source);
2608 // 3236 //
2609 // Prepare inputs. 3237 // Prepare inputs.
2610 // 3238 //
2611 CompilationUnit unit = getRequiredInput(RESOLVED_UNIT_INPUT); 3239 CompilationUnit unit = getRequiredInput(RESOLVED_UNIT_INPUT);
2612 3240
2613 // 3241 //
2614 // Generate lints. 3242 // Generate lints.
2615 // 3243 //
3244 List<AstVisitor> visitors = <AstVisitor>[];
3245
3246 bool timeVisits = analysisOptions.enableTiming;
2616 List<Linter> linters = getLints(context); 3247 List<Linter> linters = getLints(context);
2617 linters.forEach((l) => l.reporter = errorReporter); 3248 int length = linters.length;
2618 Iterable<AstVisitor> visitors = linters.map((l) => l.getVisitor()).toList(); 3249 for (int i = 0; i < length; i++) {
2619 unit.accept(new DelegatingAstVisitor(visitors.where((v) => v != null))); 3250 Linter linter = linters[i];
3251 AstVisitor visitor = linter.getVisitor();
3252 if (visitor != null) {
3253 linter.reporter = errorReporter;
3254 if (timeVisits) {
3255 visitor = new TimedAstVisitor(visitor, lintRegistry.getTimer(linter));
3256 }
3257 visitors.add(visitor);
3258 }
3259 }
3260
3261 DelegatingAstVisitor dv = new DelegatingAstVisitor(visitors);
3262 unit.accept(dv);
2620 3263
2621 // 3264 //
2622 // Record outputs. 3265 // Record outputs.
2623 // 3266 //
2624 outputs[LINTS] = errorListener.errors; 3267 outputs[LINTS] = errorListener.errors;
2625 } 3268 }
2626 3269
2627 /** 3270 /**
2628 * Return a map from the names of the inputs of this kind of task to the task 3271 * Return a map from the names of the inputs of this kind of task to the task
2629 * input descriptors describing those inputs for a task with the 3272 * input descriptors describing those inputs for a task with the
2630 * given [target]. 3273 * given [target].
2631 */ 3274 */
2632 static Map<String, TaskInput> buildInputs(AnalysisTarget target) => 3275 static Map<String, TaskInput> buildInputs(AnalysisTarget target) =>
2633 <String, TaskInput>{RESOLVED_UNIT_INPUT: RESOLVED_UNIT.of(target)}; 3276 <String, TaskInput>{RESOLVED_UNIT_INPUT: RESOLVED_UNIT.of(target)};
2634 3277
2635 /** 3278 /**
2636 * Create a [GenerateLintsTask] based on the given [target] in 3279 * Create a [GenerateLintsTask] based on the given [target] in
2637 * the given [context]. 3280 * the given [context].
2638 */ 3281 */
2639 static GenerateLintsTask createTask( 3282 static GenerateLintsTask createTask(
2640 AnalysisContext context, AnalysisTarget target) { 3283 AnalysisContext context, AnalysisTarget target) {
2641 return new GenerateLintsTask(context, target); 3284 return new GenerateLintsTask(context, target);
2642 } 3285 }
2643 } 3286 }
2644 3287
2645 /** 3288 /**
2646 * A task that ensures that all of the inferrable instance members in a 3289 * Information about analysis `//ignore:` comments within a source file.
3290 */
3291 class IgnoreInfo {
3292 /**
3293 * Instance shared by all cases without matches.
3294 */
3295 static final IgnoreInfo _EMPTY_INFO = new IgnoreInfo();
3296
3297 /**
3298 * A regular expression for matching 'ignore' comments. Produces matches
3299 * containing 2 groups. For example:
3300 *
3301 * * ['//ignore: error_code', 'error_code']
3302 *
3303 * Resulting codes may be in a list ('error_code_1,error_code2').
3304 */
3305 static final RegExp _IGNORE_MATCHER =
3306 new RegExp(r'//[ ]*ignore:(.*)$', multiLine: true);
3307
3308 final Map<int, List<String>> _ignoreMap = new HashMap<int, List<String>>();
3309
3310 /**
3311 * Whether this info object defines any ignores.
3312 */
3313 bool get hasIgnores => ignores.isNotEmpty;
3314
3315 /**
3316 * Map of line numbers to associated ignored error codes.
3317 */
3318 Map<int, Iterable<String>> get ignores => _ignoreMap;
3319
3320 /**
3321 * Ignore this [errorCode] at [line].
3322 */
3323 void add(int line, String errorCode) {
3324 _ignoreMap.putIfAbsent(line, () => new List<String>()).add(errorCode);
3325 }
3326
3327 /**
3328 * Ignore these [errorCodes] at [line].
3329 */
3330 void addAll(int line, Iterable<String> errorCodes) {
3331 _ignoreMap.putIfAbsent(line, () => new List<String>()).addAll(errorCodes);
3332 }
3333
3334 /**
3335 * Test whether this [errorCode] is ignored at the given [line].
3336 */
3337 bool ignoredAt(String errorCode, int line) =>
3338 _ignoreMap[line]?.contains(errorCode) == true;
3339
3340 /**
3341 * Calculate ignores for the given [content] with line [info].
3342 */
3343 static IgnoreInfo calculateIgnores(String content, LineInfo info) {
3344 Iterable<Match> matches = _IGNORE_MATCHER.allMatches(content);
3345 if (matches.isEmpty) {
3346 return _EMPTY_INFO;
3347 }
3348
3349 IgnoreInfo ignoreInfo = new IgnoreInfo();
3350 for (Match match in matches) {
3351 // See _IGNORE_MATCHER for format --- note the possibility of error lists.
3352 Iterable<String> codes = match
3353 .group(1)
3354 .split(',')
3355 .map((String code) => code.trim().toLowerCase());
3356 ignoreInfo.addAll(info.getLocation(match.start).lineNumber, codes);
3357 }
3358 return ignoreInfo;
3359 }
3360 }
3361
3362 /**
3363 * A task that ensures that all of the inferable instance members in a
2647 * compilation unit have had their type inferred. 3364 * compilation unit have had their type inferred.
2648 */ 3365 */
2649 class InferInstanceMembersInUnitTask extends SourceBasedAnalysisTask { 3366 class InferInstanceMembersInUnitTask extends SourceBasedAnalysisTask {
2650 /** 3367 /**
2651 * The name of the [TYPE_PROVIDER] input. 3368 * The name of the [TYPE_PROVIDER] input.
2652 */ 3369 */
2653 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT'; 3370 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT';
2654 3371
2655 /** 3372 /**
2656 * The name of the input whose value is the [RESOLVED_UNIT6] for the 3373 * The name of the input whose value is the [RESOLVED_UNIT8] for the
2657 * compilation unit. 3374 * compilation unit.
2658 */ 3375 */
2659 static const String UNIT_INPUT = 'UNIT_INPUT'; 3376 static const String UNIT_INPUT = 'UNIT_INPUT';
2660 3377
2661 /** 3378 /**
2662 * The task descriptor describing this kind of task. 3379 * The task descriptor describing this kind of task.
2663 */ 3380 */
2664 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 3381 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
2665 'InferInstanceMembersInUnitTask', 3382 'InferInstanceMembersInUnitTask',
2666 createTask, 3383 createTask,
2667 buildInputs, 3384 buildInputs,
2668 <ResultDescriptor>[RESOLVED_UNIT8]); 3385 <ResultDescriptor>[CREATED_RESOLVED_UNIT10, RESOLVED_UNIT10]);
2669 3386
2670 /** 3387 /**
2671 * Initialize a newly created task to build a library element for the given 3388 * Initialize a newly created task to build a library element for the given
2672 * [unit] in the given [context]. 3389 * [unit] in the given [context].
2673 */ 3390 */
2674 InferInstanceMembersInUnitTask( 3391 InferInstanceMembersInUnitTask(
2675 InternalAnalysisContext context, LibrarySpecificUnit unit) 3392 InternalAnalysisContext context, LibrarySpecificUnit unit)
2676 : super(context, unit); 3393 : super(context, unit);
2677 3394
2678 @override 3395 @override
2679 TaskDescriptor get descriptor => DESCRIPTOR; 3396 TaskDescriptor get descriptor => DESCRIPTOR;
2680 3397
2681 @override 3398 @override
2682 void internalPerform() { 3399 void internalPerform() {
2683 // 3400 //
2684 // Prepare inputs. 3401 // Prepare inputs.
2685 // 3402 //
2686 CompilationUnit unit = getRequiredInput(UNIT_INPUT); 3403 CompilationUnit unit = getRequiredInput(UNIT_INPUT);
2687 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT); 3404 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT);
2688 // 3405 //
2689 // Infer instance members. 3406 // Infer instance members.
2690 // 3407 //
2691 if (context.analysisOptions.strongMode) { 3408 if (context.analysisOptions.strongMode) {
2692 InstanceMemberInferrer inferrer = new InstanceMemberInferrer(typeProvider, 3409 InstanceMemberInferrer inferrer = new InstanceMemberInferrer(
3410 typeProvider, new InheritanceManager(unit.element.library),
2693 typeSystem: context.typeSystem); 3411 typeSystem: context.typeSystem);
2694 inferrer.inferCompilationUnit(unit.element); 3412 inferrer.inferCompilationUnit(unit.element);
2695 } 3413 }
2696 // 3414 //
2697 // Record outputs. 3415 // Record outputs.
2698 // 3416 //
2699 outputs[RESOLVED_UNIT8] = unit; 3417 outputs[RESOLVED_UNIT10] = unit;
3418 outputs[CREATED_RESOLVED_UNIT10] = true;
2700 } 3419 }
2701 3420
2702 /** 3421 /**
2703 * Return a map from the names of the inputs of this kind of task to the task 3422 * Return a map from the names of the inputs of this kind of task to the task
2704 * input descriptors describing those inputs for a task with the given 3423 * input descriptors describing those inputs for a task with the given
2705 * [libSource]. 3424 * [libSource].
2706 */ 3425 */
2707 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 3426 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
2708 LibrarySpecificUnit unit = target; 3427 LibrarySpecificUnit unit = target;
2709 return <String, TaskInput>{ 3428 return <String, TaskInput>{
2710 UNIT_INPUT: RESOLVED_UNIT7.of(unit), 3429 UNIT_INPUT: RESOLVED_UNIT9.of(unit),
2711 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request), 3430 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request),
2712 // In strong mode, add additional dependencies to enforce inference 3431 // In strong mode, add additional dependencies to enforce inference
2713 // ordering. 3432 // ordering.
2714 3433
2715 // Require that field re-resolution be complete for all units in the 3434 // Require that field re-resolution be complete for all units in the
2716 // current library cycle. 3435 // current library cycle.
2717 'orderLibraryCycleTasks': LIBRARY_CYCLE_UNITS.of(unit).toList( 3436 'orderLibraryCycleTasks':
2718 (CompilationUnitElementImpl unit) => RESOLVED_UNIT7 3437 LIBRARY_CYCLE_UNITS.of(unit.library).toListOf(CREATED_RESOLVED_UNIT9),
2719 .of(new LibrarySpecificUnit(unit.librarySource, unit.source))),
2720 // Require that full inference be complete for all dependencies of the 3438 // Require that full inference be complete for all dependencies of the
2721 // current library cycle. 3439 // current library cycle.
2722 'orderLibraryCycles': LIBRARY_CYCLE_DEPENDENCIES.of(unit).toList( 3440 'orderLibraryCycles': LIBRARY_CYCLE_DEPENDENCIES
2723 (CompilationUnitElementImpl unit) => RESOLVED_UNIT8 3441 .of(unit.library)
2724 .of(new LibrarySpecificUnit(unit.librarySource, unit.source))) 3442 .toListOf(CREATED_RESOLVED_UNIT10)
2725 }; 3443 };
2726 } 3444 }
2727 3445
2728 /** 3446 /**
2729 * Create a [InferInstanceMembersInUnitTask] based on the given [target] in 3447 * Create a [InferInstanceMembersInUnitTask] based on the given [target] in
2730 * the given [context]. 3448 * the given [context].
2731 */ 3449 */
2732 static InferInstanceMembersInUnitTask createTask( 3450 static InferInstanceMembersInUnitTask createTask(
2733 AnalysisContext context, AnalysisTarget target) { 3451 AnalysisContext context, AnalysisTarget target) {
2734 return new InferInstanceMembersInUnitTask(context, target); 3452 return new InferInstanceMembersInUnitTask(context, target);
2735 } 3453 }
2736 } 3454 }
2737 3455
2738 /** 3456 /**
2739 * An abstract class that defines utility methods that are useful for tasks 3457 * An abstract class that defines utility methods that are useful for tasks
2740 * operating on static variables. 3458 * operating on static variables.
2741 */ 3459 */
2742 abstract class InferStaticVariableTask extends ConstantEvaluationAnalysisTask { 3460 abstract class InferStaticVariableTask extends ConstantEvaluationAnalysisTask {
2743 InferStaticVariableTask( 3461 InferStaticVariableTask(
2744 InternalAnalysisContext context, VariableElement variable) 3462 InternalAnalysisContext context, VariableElement variable)
2745 : super(context, variable); 3463 : super(context, variable);
2746 3464
2747 /** 3465 /**
2748 * Return the declaration of the target within the given compilation [unit]. 3466 * Return the declaration of the target within the given compilation [unit].
2749 * Throw an exception if the declaration cannot be found. 3467 * Throw an exception if the declaration cannot be found.
2750 */ 3468 */
2751 VariableDeclaration getDeclaration(CompilationUnit unit) { 3469 VariableDeclaration getDeclaration(CompilationUnit unit) {
2752 VariableElement variable = target; 3470 VariableElement variable = target;
2753 NodeLocator locator = new NodeLocator(variable.nameOffset); 3471 int offset = variable.nameOffset;
2754 AstNode node = locator.searchWithin(unit); 3472 AstNode node = new NodeLocator2(offset).searchWithin(unit);
3473 if (node == null) {
3474 Source variableSource = variable.source;
3475 Source unitSource = unit.element.source;
3476 if (variableSource != unitSource) {
3477 throw new AnalysisException(
3478 "Failed to find the AST node for the variable "
3479 "${variable.displayName} at $offset in $variableSource "
3480 "because we were looking in $unitSource");
3481 }
3482 throw new AnalysisException(
3483 "Failed to find the AST node for the variable "
3484 "${variable.displayName} at $offset in $variableSource");
3485 }
2755 VariableDeclaration declaration = 3486 VariableDeclaration declaration =
2756 node.getAncestor((AstNode ancestor) => ancestor is VariableDeclaration); 3487 node.getAncestor((AstNode ancestor) => ancestor is VariableDeclaration);
2757 if (declaration == null || declaration.name != node) { 3488 if (declaration == null || declaration.name != node) {
3489 Source variableSource = variable.source;
3490 Source unitSource = unit.element.source;
3491 if (variableSource != unitSource) {
3492 if (declaration == null) {
3493 throw new AnalysisException(
3494 "Failed to find the declaration of the variable "
3495 "${variable.displayName} at $offset in $variableSource "
3496 "because the node was not in a variable declaration "
3497 "possibly because we were looking in $unitSource");
3498 }
3499 throw new AnalysisException(
3500 "Failed to find the declaration of the variable "
3501 "${variable.displayName} at $offset in $variableSource "
3502 "because we were looking in $unitSource");
3503 }
3504 if (declaration == null) {
3505 throw new AnalysisException(
3506 "Failed to find the declaration of the variable "
3507 "${variable.displayName} at $offset in $variableSource "
3508 "because the node was not in a variable declaration");
3509 }
2758 throw new AnalysisException( 3510 throw new AnalysisException(
2759 "Failed to find the declaration of the variable ${variable.displayName } in ${variable.source}"); 3511 "Failed to find the declaration of the variable "
3512 "${variable.displayName} at $offset in $variableSource "
3513 "because the node was not the name in a variable declaration");
2760 } 3514 }
2761 return declaration; 3515 return declaration;
2762 } 3516 }
2763 } 3517 }
2764 3518
2765 /** 3519 /**
2766 * A task that ensures that all of the inferrable static variables in a 3520 * A task that ensures that all of the inferable static variables in a
2767 * compilation unit have had their type inferred. 3521 * compilation unit have had their type inferred.
2768 */ 3522 */
2769 class InferStaticVariableTypesInUnitTask extends SourceBasedAnalysisTask { 3523 class InferStaticVariableTypesInUnitTask extends SourceBasedAnalysisTask {
2770 /** 3524 /**
2771 * The name of the input whose value is the [RESOLVED_UNIT5] for the 3525 * The name of the input whose value is the [RESOLVED_UNIT8] for the
2772 * compilation unit. 3526 * compilation unit.
2773 */ 3527 */
2774 static const String UNIT_INPUT = 'UNIT_INPUT'; 3528 static const String UNIT_INPUT = 'UNIT_INPUT';
2775 3529
2776 /** 3530 /**
2777 * The name of the input whose value is a list of the inferrable static 3531 * The name of the [STATIC_VARIABLE_RESOLUTION_ERRORS] for all static
2778 * variables whose types have been computed. 3532 * variables in the compilation unit.
2779 */ 3533 */
2780 static const String INFERRED_VARIABLES_INPUT = 'INFERRED_VARIABLES_INPUT'; 3534 static const String ERRORS_LIST_INPUT = 'INFERRED_VARIABLES_INPUT';
2781 3535
2782 /** 3536 /**
2783 * The task descriptor describing this kind of task. 3537 * The task descriptor describing this kind of task.
2784 */ 3538 */
2785 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 3539 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
2786 'InferStaticVariableTypesInUnitTask', 3540 'InferStaticVariableTypesInUnitTask',
2787 createTask, 3541 createTask,
2788 buildInputs, 3542 buildInputs, <ResultDescriptor>[
2789 <ResultDescriptor>[RESOLVED_UNIT6]); 3543 CREATED_RESOLVED_UNIT8,
3544 RESOLVED_UNIT8,
3545 STATIC_VARIABLE_RESOLUTION_ERRORS_IN_UNIT
3546 ]);
2790 3547
2791 /** 3548 /**
2792 * Initialize a newly created task to build a library element for the given 3549 * Initialize a newly created task to build a library element for the given
2793 * [unit] in the given [context]. 3550 * [unit] in the given [context].
2794 */ 3551 */
2795 InferStaticVariableTypesInUnitTask( 3552 InferStaticVariableTypesInUnitTask(
2796 InternalAnalysisContext context, LibrarySpecificUnit unit) 3553 InternalAnalysisContext context, LibrarySpecificUnit unit)
2797 : super(context, unit); 3554 : super(context, unit);
2798 3555
2799 @override 3556 @override
2800 TaskDescriptor get descriptor => DESCRIPTOR; 3557 TaskDescriptor get descriptor => DESCRIPTOR;
2801 3558
2802 @override 3559 @override
2803 void internalPerform() { 3560 void internalPerform() {
2804 // 3561 //
2805 // Prepare inputs. 3562 // Prepare inputs.
2806 // 3563 //
2807 CompilationUnit unit = getRequiredInput(UNIT_INPUT); 3564 CompilationUnit unit = getRequiredInput(UNIT_INPUT);
3565 List<List<AnalysisError>> errorLists = getRequiredInput(ERRORS_LIST_INPUT);
2808 // 3566 //
2809 // Record outputs. There is no additional work to be done at this time 3567 // Record outputs. There is no additional work to be done at this time
2810 // because the work has implicitly been done by virtue of the task model 3568 // because the work has implicitly been done by virtue of the task model
2811 // preparing all of the inputs. 3569 // preparing all of the inputs.
2812 // 3570 //
2813 outputs[RESOLVED_UNIT6] = unit; 3571 outputs[RESOLVED_UNIT8] = unit;
3572 outputs[CREATED_RESOLVED_UNIT8] = true;
3573 outputs[STATIC_VARIABLE_RESOLUTION_ERRORS_IN_UNIT] =
3574 AnalysisError.mergeLists(errorLists);
2814 } 3575 }
2815 3576
2816 /** 3577 /**
2817 * Return a map from the names of the inputs of this kind of task to the task 3578 * Return a map from the names of the inputs of this kind of task to the task
2818 * input descriptors describing those inputs for a task with the given 3579 * input descriptors describing those inputs for a task with the given
2819 * [libSource]. 3580 * [libSource].
2820 */ 3581 */
2821 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 3582 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
2822 LibrarySpecificUnit unit = target; 3583 LibrarySpecificUnit unit = target;
2823 return <String, TaskInput>{ 3584 return <String, TaskInput>{
2824 INFERRED_VARIABLES_INPUT: INFERABLE_STATIC_VARIABLES_IN_UNIT 3585 'inferredTypes': INFERABLE_STATIC_VARIABLES_IN_UNIT
2825 .of(unit) 3586 .of(unit)
2826 .toListOf(INFERRED_STATIC_VARIABLE), 3587 .toListOf(INFERRED_STATIC_VARIABLE),
2827 UNIT_INPUT: RESOLVED_UNIT5.of(unit) 3588 ERRORS_LIST_INPUT: INFERABLE_STATIC_VARIABLES_IN_UNIT
3589 .of(unit)
3590 .toListOf(STATIC_VARIABLE_RESOLUTION_ERRORS),
3591 UNIT_INPUT: RESOLVED_UNIT7.of(unit)
2828 }; 3592 };
2829 } 3593 }
2830 3594
2831 /** 3595 /**
2832 * Create a [InferStaticVariableTypesInUnitTask] based on the given [target] 3596 * Create a [InferStaticVariableTypesInUnitTask] based on the given [target]
2833 * in the given [context]. 3597 * in the given [context].
2834 */ 3598 */
2835 static InferStaticVariableTypesInUnitTask createTask( 3599 static InferStaticVariableTypesInUnitTask createTask(
2836 AnalysisContext context, AnalysisTarget target) { 3600 AnalysisContext context, AnalysisTarget target) {
2837 return new InferStaticVariableTypesInUnitTask(context, target); 3601 return new InferStaticVariableTypesInUnitTask(context, target);
2838 } 3602 }
2839 } 3603 }
2840 3604
2841 /** 3605 /**
2842 * A task that computes the type of an inferrable static variable and 3606 * A task that computes the type of an inferable static variable and
2843 * stores it in the element model. 3607 * stores it in the element model.
2844 */ 3608 */
2845 class InferStaticVariableTypeTask extends InferStaticVariableTask { 3609 class InferStaticVariableTypeTask extends InferStaticVariableTask {
2846 /** 3610 /**
2847 * The name of the input which ensures that dependent values have their type 3611 * The name of the input which ensures that dependent values have their type
2848 * inferred before the target. 3612 * inferred before the target.
2849 */ 3613 */
2850 static const String DEPENDENCIES_INPUT = 'DEPENDENCIES_INPUT'; 3614 static const String DEPENDENCIES_INPUT = 'DEPENDENCIES_INPUT';
2851 3615
2852 /** 3616 /**
2853 * The name of the [TYPE_PROVIDER] input. 3617 * The name of the [TYPE_PROVIDER] input.
2854 */ 3618 */
2855 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT'; 3619 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT';
2856 3620
2857 /** 3621 /**
2858 * The name of the [RESOLVED_UNIT5] input. 3622 * The name of the [RESOLVED_UNIT8] input.
2859 */ 3623 */
2860 static const String UNIT_INPUT = 'UNIT_INPUT'; 3624 static const String UNIT_INPUT = 'UNIT_INPUT';
2861 3625
2862 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 3626 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
2863 'InferStaticVariableTypeTask', 3627 'InferStaticVariableTypeTask',
2864 createTask, 3628 createTask,
2865 buildInputs, 3629 buildInputs, <ResultDescriptor>[
2866 <ResultDescriptor>[INFERRED_STATIC_VARIABLE]); 3630 INFERRED_STATIC_VARIABLE,
3631 STATIC_VARIABLE_RESOLUTION_ERRORS
3632 ]);
2867 3633
2868 InferStaticVariableTypeTask( 3634 InferStaticVariableTypeTask(
2869 InternalAnalysisContext context, VariableElement variable) 3635 InternalAnalysisContext context, VariableElement variable)
2870 : super(context, variable); 3636 : super(context, variable);
2871 3637
2872 @override 3638 @override
2873 TaskDescriptor get descriptor => DESCRIPTOR; 3639 TaskDescriptor get descriptor => DESCRIPTOR;
2874 3640
2875 @override 3641 @override
2876 bool get handlesDependencyCycles => true; 3642 bool get handlesDependencyCycles => true;
2877 3643
2878 @override 3644 @override
2879 void internalPerform() { 3645 void internalPerform() {
2880 // 3646 //
2881 // Prepare inputs. 3647 // Prepare inputs.
2882 // 3648 //
2883 // Note: DEPENDENCIES_INPUT is not needed. It is merely a bookkeeping 3649 // Note: DEPENDENCIES_INPUT is not needed. It is merely a bookkeeping
2884 // dependency to ensure that the variables that this variable references 3650 // dependency to ensure that the variables that this variable references
2885 // have types inferred before inferring the type of this variable. 3651 // have types inferred before inferring the type of this variable.
2886 // 3652 //
2887 VariableElementImpl variable = target; 3653 VariableElementImpl variable = target;
2888 3654
2889 CompilationUnit unit = getRequiredInput(UNIT_INPUT); 3655 CompilationUnit unit = getRequiredInput(UNIT_INPUT);
2890 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT); 3656 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT);
2891 3657
2892 // If we're not in a dependency cycle, and we have no type annotation, 3658 // If we're not in a dependency cycle, and we have no type annotation,
2893 // re-resolve the right hand side and do inference. 3659 // re-resolve the right hand side and do inference.
3660 List<AnalysisError> errors = AnalysisError.NO_ERRORS;
2894 if (dependencyCycle == null && variable.hasImplicitType) { 3661 if (dependencyCycle == null && variable.hasImplicitType) {
2895 VariableDeclaration declaration = getDeclaration(unit); 3662 VariableDeclaration declaration = getDeclaration(unit);
2896 // 3663 //
2897 // Re-resolve the variable's initializer so that the inferred types 3664 // Re-resolve the variable's initializer so that the inferred types
2898 // of other variables will be propagated. 3665 // of other variables will be propagated.
2899 // 3666 //
3667 RecordingErrorListener errorListener = new RecordingErrorListener();
2900 Expression initializer = declaration.initializer; 3668 Expression initializer = declaration.initializer;
2901 ResolutionContext resolutionContext = ResolutionContextBuilder.contextFor( 3669 ResolutionContext resolutionContext =
2902 initializer, AnalysisErrorListener.NULL_LISTENER); 3670 ResolutionContextBuilder.contextFor(initializer);
2903 ResolverVisitor visitor = new ResolverVisitor(variable.library, 3671 ResolverVisitor visitor = new ResolverVisitor(
2904 variable.source, typeProvider, AnalysisErrorListener.NULL_LISTENER, 3672 variable.library, variable.source, typeProvider, errorListener,
2905 nameScope: resolutionContext.scope); 3673 nameScope: resolutionContext.scope);
2906 if (resolutionContext.enclosingClassDeclaration != null) { 3674 if (resolutionContext.enclosingClassDeclaration != null) {
2907 visitor.prepareToResolveMembersInClass( 3675 visitor.prepareToResolveMembersInClass(
2908 resolutionContext.enclosingClassDeclaration); 3676 resolutionContext.enclosingClassDeclaration);
2909 } 3677 }
2910 visitor.initForIncrementalResolution(); 3678 visitor.initForIncrementalResolution();
2911 initializer.accept(visitor); 3679 initializer.accept(visitor);
2912 3680
2913 // 3681 //
2914 // Record the type of the variable. 3682 // Record the type of the variable.
2915 // 3683 //
2916 DartType newType = initializer.staticType; 3684 DartType newType = initializer.staticType;
2917 if (newType == null || newType.isBottom) { 3685 if (newType == null || newType.isBottom) {
2918 newType = typeProvider.dynamicType; 3686 newType = typeProvider.dynamicType;
2919 } 3687 }
2920 variable.type = newType; 3688 setFieldType(variable, newType);
2921 (variable.initializer as ExecutableElementImpl).returnType = newType; 3689 errors = getUniqueErrors(errorListener.errors);
2922 if (variable is PropertyInducingElementImpl) {
2923 setReturnType(variable.getter, newType);
2924 if (!variable.isFinal && !variable.isConst) {
2925 setParameterType(variable.setter, newType);
2926 }
2927 }
2928 } else { 3690 } else {
2929 // TODO(brianwilkerson) For now we simply don't infer any type for 3691 // TODO(brianwilkerson) For now we simply don't infer any type for
2930 // variables or fields involved in a cycle. We could try to be smarter 3692 // variables or fields involved in a cycle. We could try to be smarter
2931 // by re-resolving the initializer in a context in which the types of all 3693 // by re-resolving the initializer in a context in which the types of all
2932 // of the variables in the cycle are assumed to be `null`, but it isn't 3694 // of the variables in the cycle are assumed to be `null`, but it isn't
2933 // clear to me that this would produce better results often enough to 3695 // clear to me that this would produce better results often enough to
2934 // warrant the extra effort. 3696 // warrant the extra effort.
2935 } 3697 }
2936 // 3698 //
2937 // Record outputs. 3699 // Record outputs.
2938 // 3700 //
2939 outputs[INFERRED_STATIC_VARIABLE] = variable; 3701 outputs[INFERRED_STATIC_VARIABLE] = variable;
3702 outputs[STATIC_VARIABLE_RESOLUTION_ERRORS] = errors;
2940 } 3703 }
2941 3704
2942 /** 3705 /**
2943 * Return a map from the names of the inputs of this kind of task to the task 3706 * Return a map from the names of the inputs of this kind of task to the task
2944 * input descriptors describing those inputs for a task with the given 3707 * input descriptors describing those inputs for a task with the given
2945 * [target]. 3708 * [target].
2946 */ 3709 */
2947 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 3710 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
2948 VariableElement variable = target; 3711 VariableElement variable = target;
2949 LibrarySpecificUnit unit = 3712 LibrarySpecificUnit unit =
2950 new LibrarySpecificUnit(variable.library.source, variable.source); 3713 new LibrarySpecificUnit(variable.library.source, variable.source);
2951 return <String, TaskInput>{ 3714 return <String, TaskInput>{
2952 DEPENDENCIES_INPUT: INFERABLE_STATIC_VARIABLE_DEPENDENCIES 3715 DEPENDENCIES_INPUT: INFERABLE_STATIC_VARIABLE_DEPENDENCIES
2953 .of(variable) 3716 .of(variable)
2954 .toListOf(INFERRED_STATIC_VARIABLE), 3717 .toListOf(INFERRED_STATIC_VARIABLE),
2955 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request), 3718 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request),
2956 UNIT_INPUT: RESOLVED_UNIT5.of(unit), 3719 UNIT_INPUT: RESOLVED_UNIT7.of(unit),
2957 // In strong mode, add additional dependencies to enforce inference 3720 // In strong mode, add additional dependencies to enforce inference
2958 // ordering. 3721 // ordering.
2959 3722
2960 // Require that full inference be complete for all dependencies of the 3723 // Require that full inference be complete for all dependencies of the
2961 // current library cycle. 3724 // current library cycle.
2962 'orderLibraryCycles': LIBRARY_CYCLE_DEPENDENCIES.of(unit).toList( 3725 'orderLibraryCycles': LIBRARY_CYCLE_DEPENDENCIES
2963 (CompilationUnitElementImpl unit) => RESOLVED_UNIT8 3726 .of(unit.library)
2964 .of(new LibrarySpecificUnit(unit.librarySource, unit.source))) 3727 .toListOf(CREATED_RESOLVED_UNIT10)
2965 }; 3728 };
2966 } 3729 }
2967 3730
2968 /** 3731 /**
2969 * Create a [InferStaticVariableTypeTask] based on the given [target] in the 3732 * Create a [InferStaticVariableTypeTask] based on the given [target] in the
2970 * given [context]. 3733 * given [context].
2971 */ 3734 */
2972 static InferStaticVariableTypeTask createTask( 3735 static InferStaticVariableTypeTask createTask(
2973 AnalysisContext context, AnalysisTarget target) { 3736 AnalysisContext context, AnalysisTarget target) {
2974 return new InferStaticVariableTypeTask(context, target); 3737 return new InferStaticVariableTypeTask(context, target);
(...skipping 21 matching lines...) Expand all
2996 TaskDescriptor get descriptor => DESCRIPTOR; 3759 TaskDescriptor get descriptor => DESCRIPTOR;
2997 3760
2998 @override 3761 @override
2999 void internalPerform() { 3762 void internalPerform() {
3000 outputs[LIBRARY_ERRORS_READY] = true; 3763 outputs[LIBRARY_ERRORS_READY] = true;
3001 } 3764 }
3002 3765
3003 /** 3766 /**
3004 * Return a map from the names of the inputs of this kind of task to the task 3767 * Return a map from the names of the inputs of this kind of task to the task
3005 * input descriptors describing those inputs for a task with the 3768 * input descriptors describing those inputs for a task with the
3006 * given [library]. 3769 * given [target].
3007 */ 3770 */
3008 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 3771 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
3009 Source source = target; 3772 Source source = target;
3010 return <String, TaskInput>{ 3773 return <String, TaskInput>{
3011 'allErrors': UNITS.of(source).toListOf(DART_ERRORS) 3774 'allErrors': UNITS.of(source).toListOf(DART_ERRORS),
3775 'libraryElement': LIBRARY_ELEMENT.of(source)
3012 }; 3776 };
3013 } 3777 }
3014 3778
3015 /** 3779 /**
3016 * Create a [LibraryErrorsReadyTask] based on the given [target] in the given 3780 * Create a [LibraryErrorsReadyTask] based on the given [target] in the given
3017 * [context]. 3781 * [context].
3018 */ 3782 */
3019 static LibraryErrorsReadyTask createTask( 3783 static LibraryErrorsReadyTask createTask(
3020 AnalysisContext context, AnalysisTarget target) { 3784 AnalysisContext context, AnalysisTarget target) {
3021 return new LibraryErrorsReadyTask(context, target); 3785 return new LibraryErrorsReadyTask(context, target);
(...skipping 19 matching lines...) Expand all
3041 * The name of the [HINTS] input. 3805 * The name of the [HINTS] input.
3042 */ 3806 */
3043 static const String HINTS_INPUT = 'HINTS'; 3807 static const String HINTS_INPUT = 'HINTS';
3044 3808
3045 /** 3809 /**
3046 * The name of the [LINTS] input. 3810 * The name of the [LINTS] input.
3047 */ 3811 */
3048 static const String LINTS_INPUT = 'LINTS'; 3812 static const String LINTS_INPUT = 'LINTS';
3049 3813
3050 /** 3814 /**
3815 * The name of the [STATIC_VARIABLE_RESOLUTION_ERRORS_IN_UNIT] input.
3816 */
3817 static const String STATIC_VARIABLE_RESOLUTION_ERRORS_INPUT =
3818 'STATIC_VARIABLE_RESOLUTION_ERRORS_INPUT';
3819
3820 /**
3051 * The name of the [STRONG_MODE_ERRORS] input. 3821 * The name of the [STRONG_MODE_ERRORS] input.
3052 */ 3822 */
3053 static const String STRONG_MODE_ERRORS_INPUT = 'STRONG_MODE_ERRORS'; 3823 static const String STRONG_MODE_ERRORS_INPUT = 'STRONG_MODE_ERRORS';
3054 3824
3055 /** 3825 /**
3056 * The name of the [RESOLVE_TYPE_NAMES_ERRORS] input. 3826 * The name of the [RESOLVE_TYPE_NAMES_ERRORS] input.
3057 */ 3827 */
3058 static const String RESOLVE_TYPE_NAMES_ERRORS_INPUT = 3828 static const String RESOLVE_TYPE_NAMES_ERRORS_INPUT =
3059 'RESOLVE_TYPE_NAMES_ERRORS'; 3829 'RESOLVE_TYPE_NAMES_ERRORS';
3060 3830
3061 /** 3831 /**
3832 * The name of the [RESOLVE_TYPE_BOUNDS_ERRORS] input.
3833 */
3834 static const String RESOLVE_TYPE_NAMES_ERRORS2_INPUT =
3835 'RESOLVE_TYPE_NAMES_ERRORS2';
3836
3837 /**
3062 * The name of the [RESOLVE_UNIT_ERRORS] input. 3838 * The name of the [RESOLVE_UNIT_ERRORS] input.
3063 */ 3839 */
3064 static const String RESOLVE_UNIT_ERRORS_INPUT = 'RESOLVE_UNIT_ERRORS'; 3840 static const String RESOLVE_UNIT_ERRORS_INPUT = 'RESOLVE_UNIT_ERRORS';
3065 3841
3066 /** 3842 /**
3067 * The name of the [VARIABLE_REFERENCE_ERRORS] input. 3843 * The name of the [VARIABLE_REFERENCE_ERRORS] input.
3068 */ 3844 */
3069 static const String VARIABLE_REFERENCE_ERRORS_INPUT = 3845 static const String VARIABLE_REFERENCE_ERRORS_INPUT =
3070 'VARIABLE_REFERENCE_ERRORS'; 3846 'VARIABLE_REFERENCE_ERRORS';
3071 3847
(...skipping 21 matching lines...) Expand all
3093 void internalPerform() { 3869 void internalPerform() {
3094 // 3870 //
3095 // Prepare inputs. 3871 // Prepare inputs.
3096 // 3872 //
3097 List<List<AnalysisError>> errorLists = <List<AnalysisError>>[]; 3873 List<List<AnalysisError>> errorLists = <List<AnalysisError>>[];
3098 errorLists.add(getRequiredInput(BUILD_DIRECTIVES_ERRORS_INPUT)); 3874 errorLists.add(getRequiredInput(BUILD_DIRECTIVES_ERRORS_INPUT));
3099 errorLists.add(getRequiredInput(BUILD_LIBRARY_ERRORS_INPUT)); 3875 errorLists.add(getRequiredInput(BUILD_LIBRARY_ERRORS_INPUT));
3100 errorLists.add(getRequiredInput(HINTS_INPUT)); 3876 errorLists.add(getRequiredInput(HINTS_INPUT));
3101 errorLists.add(getRequiredInput(LINTS_INPUT)); 3877 errorLists.add(getRequiredInput(LINTS_INPUT));
3102 errorLists.add(getRequiredInput(RESOLVE_TYPE_NAMES_ERRORS_INPUT)); 3878 errorLists.add(getRequiredInput(RESOLVE_TYPE_NAMES_ERRORS_INPUT));
3879 errorLists.add(getRequiredInput(RESOLVE_TYPE_NAMES_ERRORS2_INPUT));
3103 errorLists.add(getRequiredInput(RESOLVE_UNIT_ERRORS_INPUT)); 3880 errorLists.add(getRequiredInput(RESOLVE_UNIT_ERRORS_INPUT));
3881 errorLists.add(getRequiredInput(STATIC_VARIABLE_RESOLUTION_ERRORS_INPUT));
3104 errorLists.add(getRequiredInput(STRONG_MODE_ERRORS_INPUT)); 3882 errorLists.add(getRequiredInput(STRONG_MODE_ERRORS_INPUT));
3105 errorLists.add(getRequiredInput(VARIABLE_REFERENCE_ERRORS_INPUT)); 3883 errorLists.add(getRequiredInput(VARIABLE_REFERENCE_ERRORS_INPUT));
3106 errorLists.add(getRequiredInput(VERIFY_ERRORS_INPUT)); 3884 errorLists.add(getRequiredInput(VERIFY_ERRORS_INPUT));
3107 // 3885 //
3108 // Record outputs. 3886 // Record outputs.
3109 // 3887 //
3110 outputs[LIBRARY_UNIT_ERRORS] = AnalysisError.mergeLists(errorLists); 3888 outputs[LIBRARY_UNIT_ERRORS] = AnalysisError.mergeLists(errorLists);
3111 } 3889 }
3112 3890
3113 /** 3891 /**
3114 * Return a map from the names of the inputs of this kind of task to the task 3892 * Return a map from the names of the inputs of this kind of task to the task
3115 * input descriptors describing those inputs for a task with the 3893 * input descriptors describing those inputs for a task with the
3116 * given [unit]. 3894 * given [unit].
3117 */ 3895 */
3118 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 3896 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
3119 LibrarySpecificUnit unit = target; 3897 LibrarySpecificUnit unit = target;
3120 Map<String, TaskInput> inputs = <String, TaskInput>{ 3898 Map<String, TaskInput> inputs = <String, TaskInput>{
3121 HINTS_INPUT: HINTS.of(unit), 3899 HINTS_INPUT: HINTS.of(unit),
3122 LINTS_INPUT: LINTS.of(unit), 3900 LINTS_INPUT: LINTS.of(unit),
3123 RESOLVE_TYPE_NAMES_ERRORS_INPUT: RESOLVE_TYPE_NAMES_ERRORS.of(unit), 3901 RESOLVE_TYPE_NAMES_ERRORS_INPUT: RESOLVE_TYPE_NAMES_ERRORS.of(unit),
3902 RESOLVE_TYPE_NAMES_ERRORS2_INPUT: RESOLVE_TYPE_BOUNDS_ERRORS.of(unit),
3124 RESOLVE_UNIT_ERRORS_INPUT: RESOLVE_UNIT_ERRORS.of(unit), 3903 RESOLVE_UNIT_ERRORS_INPUT: RESOLVE_UNIT_ERRORS.of(unit),
3904 STATIC_VARIABLE_RESOLUTION_ERRORS_INPUT:
3905 STATIC_VARIABLE_RESOLUTION_ERRORS_IN_UNIT.of(unit),
3125 STRONG_MODE_ERRORS_INPUT: STRONG_MODE_ERRORS.of(unit), 3906 STRONG_MODE_ERRORS_INPUT: STRONG_MODE_ERRORS.of(unit),
3126 VARIABLE_REFERENCE_ERRORS_INPUT: VARIABLE_REFERENCE_ERRORS.of(unit), 3907 VARIABLE_REFERENCE_ERRORS_INPUT: VARIABLE_REFERENCE_ERRORS.of(unit),
3127 VERIFY_ERRORS_INPUT: VERIFY_ERRORS.of(unit) 3908 VERIFY_ERRORS_INPUT: VERIFY_ERRORS.of(unit)
3128 }; 3909 };
3129 Source source = unit.source; 3910 Source source = unit.source;
3130 if (unit.library == source) { 3911 if (unit.library == source) {
3131 inputs[BUILD_DIRECTIVES_ERRORS_INPUT] = 3912 inputs[BUILD_DIRECTIVES_ERRORS_INPUT] =
3132 BUILD_DIRECTIVES_ERRORS.of(source); 3913 BUILD_DIRECTIVES_ERRORS.of(source);
3133 inputs[BUILD_LIBRARY_ERRORS_INPUT] = BUILD_LIBRARY_ERRORS.of(source); 3914 inputs[BUILD_LIBRARY_ERRORS_INPUT] = BUILD_LIBRARY_ERRORS.of(source);
3134 } else { 3915 } else {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
3175 3956
3176 /** 3957 /**
3177 * The task descriptor describing this kind of task. 3958 * The task descriptor describing this kind of task.
3178 */ 3959 */
3179 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 3960 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
3180 'ParseDartTask', createTask, buildInputs, <ResultDescriptor>[ 3961 'ParseDartTask', createTask, buildInputs, <ResultDescriptor>[
3181 EXPLICITLY_IMPORTED_LIBRARIES, 3962 EXPLICITLY_IMPORTED_LIBRARIES,
3182 EXPORTED_LIBRARIES, 3963 EXPORTED_LIBRARIES,
3183 IMPORTED_LIBRARIES, 3964 IMPORTED_LIBRARIES,
3184 INCLUDED_PARTS, 3965 INCLUDED_PARTS,
3966 LIBRARY_SPECIFIC_UNITS,
3185 PARSE_ERRORS, 3967 PARSE_ERRORS,
3186 PARSED_UNIT, 3968 PARSED_UNIT,
3969 REFERENCED_NAMES,
3970 REFERENCED_SOURCES,
3187 SOURCE_KIND, 3971 SOURCE_KIND,
3188 UNITS 3972 UNITS,
3189 ]); 3973 ]);
3190 3974
3191 /** 3975 /**
3976 * The source that is being parsed.
3977 */
3978 Source _source;
3979
3980 /**
3981 * The [ErrorReporter] to report errors to.
3982 */
3983 ErrorReporter _errorReporter;
3984
3985 /**
3192 * Initialize a newly created task to parse the content of the Dart file 3986 * Initialize a newly created task to parse the content of the Dart file
3193 * associated with the given [target] in the given [context]. 3987 * associated with the given [target] in the given [context].
3194 */ 3988 */
3195 ParseDartTask(InternalAnalysisContext context, AnalysisTarget target) 3989 ParseDartTask(InternalAnalysisContext context, AnalysisTarget target)
3196 : super(context, target); 3990 : super(context, target);
3197 3991
3198 @override 3992 @override
3199 TaskDescriptor get descriptor => DESCRIPTOR; 3993 TaskDescriptor get descriptor => DESCRIPTOR;
3200 3994
3201 @override 3995 @override
3202 void internalPerform() { 3996 void internalPerform() {
3203 Source source = getRequiredSource(); 3997 _source = getRequiredSource();
3204 LineInfo lineInfo = getRequiredInput(LINE_INFO_INPUT_NAME); 3998 LineInfo lineInfo = getRequiredInput(LINE_INFO_INPUT_NAME);
3205 int modificationTime = getRequiredInput(MODIFICATION_TIME_INPUT_NAME); 3999 int modificationTime = getRequiredInput(MODIFICATION_TIME_INPUT_NAME);
3206 Token tokenStream = getRequiredInput(TOKEN_STREAM_INPUT_NAME); 4000 Token tokenStream = getRequiredInput(TOKEN_STREAM_INPUT_NAME);
3207 4001
3208 RecordingErrorListener errorListener = new RecordingErrorListener(); 4002 RecordingErrorListener errorListener = new RecordingErrorListener();
3209 Parser parser = new Parser(source, errorListener); 4003 _errorReporter = new ErrorReporter(errorListener, _source);
4004
4005 Parser parser = new Parser(_source, errorListener);
3210 AnalysisOptions options = context.analysisOptions; 4006 AnalysisOptions options = context.analysisOptions;
3211 parser.parseFunctionBodies = options.analyzeFunctionBodiesPredicate(source); 4007 parser.enableAssertInitializer = options.enableAssertInitializer;
4008 parser.parseFunctionBodies =
4009 options.analyzeFunctionBodiesPredicate(_source);
3212 parser.parseGenericMethods = options.enableGenericMethods; 4010 parser.parseGenericMethods = options.enableGenericMethods;
4011 parser.parseGenericMethodComments = options.strongMode;
3213 CompilationUnit unit = parser.parseCompilationUnit(tokenStream); 4012 CompilationUnit unit = parser.parseCompilationUnit(tokenStream);
3214 unit.lineInfo = lineInfo; 4013 unit.lineInfo = lineInfo;
3215 4014
3216 bool hasNonPartOfDirective = false; 4015 bool hasNonPartOfDirective = false;
3217 bool hasPartOfDirective = false; 4016 bool hasPartOfDirective = false;
3218 HashSet<Source> explicitlyImportedSourceSet = new HashSet<Source>(); 4017 HashSet<Source> explicitlyImportedSourceSet = new HashSet<Source>();
3219 HashSet<Source> exportedSourceSet = new HashSet<Source>(); 4018 HashSet<Source> exportedSourceSet = new HashSet<Source>();
3220 HashSet<Source> includedSourceSet = new HashSet<Source>(); 4019 HashSet<Source> includedSourceSet = new HashSet<Source>();
3221 for (Directive directive in unit.directives) { 4020 NodeList<Directive> directives = unit.directives;
4021 int length = directives.length;
4022 for (int i = 0; i < length; i++) {
4023 Directive directive = directives[i];
3222 if (directive is PartOfDirective) { 4024 if (directive is PartOfDirective) {
3223 hasPartOfDirective = true; 4025 hasPartOfDirective = true;
3224 } else { 4026 } else {
3225 hasNonPartOfDirective = true; 4027 hasNonPartOfDirective = true;
3226 if (directive is UriBasedDirective) { 4028 if (directive is UriBasedDirective) {
3227 Source referencedSource = 4029 Source referencedSource = _resolveDirective(directive);
3228 resolveDirective(context, source, directive, errorListener);
3229 if (referencedSource != null) { 4030 if (referencedSource != null) {
3230 if (directive is ExportDirective) { 4031 if (directive is ExportDirective) {
3231 exportedSourceSet.add(referencedSource); 4032 exportedSourceSet.add(referencedSource);
3232 } else if (directive is ImportDirective) { 4033 } else if (directive is ImportDirective) {
3233 explicitlyImportedSourceSet.add(referencedSource); 4034 explicitlyImportedSourceSet.add(referencedSource);
3234 } else if (directive is PartDirective) { 4035 } else if (directive is PartDirective) {
3235 includedSourceSet.add(referencedSource); 4036 includedSourceSet.add(referencedSource);
3236 } else { 4037 } else {
3237 throw new AnalysisException( 4038 throw new AnalysisException(
3238 '$runtimeType failed to handle a ${directive.runtimeType}'); 4039 '$runtimeType failed to handle a ${directive.runtimeType}');
3239 } 4040 }
3240 } 4041 }
3241 } 4042 }
3242 } 4043 }
3243 } 4044 }
3244 // 4045 //
3245 // Always include "dart:core" source. 4046 // Always include "dart:core" source.
3246 // 4047 //
3247 HashSet<Source> importedSourceSet = 4048 HashSet<Source> importedSourceSet =
3248 new HashSet.from(explicitlyImportedSourceSet); 4049 new HashSet.from(explicitlyImportedSourceSet);
3249 Source coreLibrarySource = context.sourceFactory.forUri(DartSdk.DART_CORE); 4050 Source coreLibrarySource = context.sourceFactory.forUri(DartSdk.DART_CORE);
4051 if (coreLibrarySource == null) {
4052 String message;
4053 DartSdk sdk = context.sourceFactory.dartSdk;
4054 if (sdk == null) {
4055 message = 'Could not resolve "dart:core": SDK not defined';
4056 } else {
4057 message = 'Could not resolve "dart:core": SDK incorrectly configured';
4058 }
4059 throw new AnalysisException(message);
4060 }
3250 importedSourceSet.add(coreLibrarySource); 4061 importedSourceSet.add(coreLibrarySource);
3251 // 4062 //
3252 // Compute kind. 4063 // Compute kind.
3253 // 4064 //
3254 SourceKind sourceKind = SourceKind.LIBRARY; 4065 SourceKind sourceKind = SourceKind.LIBRARY;
3255 if (modificationTime == -1) { 4066 if (modificationTime == -1) {
3256 sourceKind = SourceKind.UNKNOWN; 4067 sourceKind = SourceKind.UNKNOWN;
3257 } else if (hasPartOfDirective && !hasNonPartOfDirective) { 4068 } else if (hasPartOfDirective && !hasNonPartOfDirective) {
3258 sourceKind = SourceKind.PART; 4069 sourceKind = SourceKind.PART;
3259 } 4070 }
3260 // 4071 //
3261 // Record outputs. 4072 // Compute referenced names.
4073 //
4074 ReferencedNames referencedNames = new ReferencedNames(_source);
4075 new ReferencedNamesBuilder(referencedNames).build(unit);
4076 //
4077 // Compute source lists.
3262 // 4078 //
3263 List<Source> explicitlyImportedSources = 4079 List<Source> explicitlyImportedSources =
3264 explicitlyImportedSourceSet.toList(); 4080 explicitlyImportedSourceSet.toList();
3265 List<Source> exportedSources = exportedSourceSet.toList(); 4081 List<Source> exportedSources = exportedSourceSet.toList();
3266 List<Source> importedSources = importedSourceSet.toList(); 4082 List<Source> importedSources = importedSourceSet.toList();
3267 List<Source> includedSources = includedSourceSet.toList(); 4083 List<Source> includedSources = includedSourceSet.toList();
3268 List<AnalysisError> parseErrors = 4084 List<Source> unitSources = <Source>[_source]..addAll(includedSourceSet);
3269 removeDuplicateErrors(errorListener.errors); 4085 List<LibrarySpecificUnit> librarySpecificUnits =
3270 List<Source> unitSources = <Source>[source]..addAll(includedSourceSet); 4086 unitSources.map((s) => new LibrarySpecificUnit(_source, s)).toList();
4087 //
4088 // Compute referenced sources.
4089 //
4090 Set<Source> referencedSources = new Set<Source>();
4091 referencedSources.add(coreLibrarySource);
4092 referencedSources.addAll(unitSources);
4093 for (Directive directive in unit.directives) {
4094 if (directive is NamespaceDirective) {
4095 referencedSources.add(directive.uriSource);
4096 for (Configuration configuration in directive.configurations) {
4097 referencedSources.add(configuration.uriSource);
4098 }
4099 }
4100 }
4101 referencedSources.removeWhere((source) => source == null);
4102 //
4103 // Record outputs.
4104 //
4105 List<AnalysisError> parseErrors = getUniqueErrors(errorListener.errors);
3271 outputs[EXPLICITLY_IMPORTED_LIBRARIES] = explicitlyImportedSources; 4106 outputs[EXPLICITLY_IMPORTED_LIBRARIES] = explicitlyImportedSources;
3272 outputs[EXPORTED_LIBRARIES] = exportedSources; 4107 outputs[EXPORTED_LIBRARIES] = exportedSources;
3273 outputs[IMPORTED_LIBRARIES] = importedSources; 4108 outputs[IMPORTED_LIBRARIES] = importedSources;
3274 outputs[INCLUDED_PARTS] = includedSources; 4109 outputs[INCLUDED_PARTS] = includedSources;
4110 outputs[LIBRARY_SPECIFIC_UNITS] = librarySpecificUnits;
3275 outputs[PARSE_ERRORS] = parseErrors; 4111 outputs[PARSE_ERRORS] = parseErrors;
3276 outputs[PARSED_UNIT] = unit; 4112 outputs[PARSED_UNIT] = unit;
4113 outputs[REFERENCED_NAMES] = referencedNames;
4114 outputs[REFERENCED_SOURCES] = referencedSources.toList();
3277 outputs[SOURCE_KIND] = sourceKind; 4115 outputs[SOURCE_KIND] = sourceKind;
3278 outputs[UNITS] = unitSources; 4116 outputs[UNITS] = unitSources;
3279 } 4117 }
3280 4118
3281 /** 4119 /**
4120 * Return the result of resolving the URI of the given URI-based [directive]
4121 * against the URI of the given library, or `null` if the URI is not valid.
4122 */
4123 Source _resolveDirective(UriBasedDirective directive) {
4124 bool isImport = directive is ImportDirective;
4125
4126 // Resolve the default URI.
4127 Source defaultSource;
4128 {
4129 StringLiteral uriLiteral = directive.uri;
4130 String uriContent = uriLiteral.stringValue;
4131 if (uriContent != null) {
4132 uriContent = uriContent.trim();
4133 directive.uriContent = uriContent;
4134 }
4135 defaultSource = _resolveUri(isImport, uriLiteral, uriContent);
4136 directive.uriSource = defaultSource;
4137 }
4138
4139 // Resolve all configurations and try to choose one.
4140 if (directive is NamespaceDirectiveImpl) {
4141 String configuredUriContent;
4142 Source configuredSource;
4143 for (Configuration configuration in directive.configurations) {
4144 String uriContent = configuration.uri.stringValue;
4145 Source source = _resolveUri(isImport, configuration.uri, uriContent);
4146 configuration.uriSource = source;
4147 if (configuredSource == null) {
4148 String variableName =
4149 configuration.name.components.map((i) => i.name).join('.');
4150 String variableValue = context.declaredVariables.get(variableName);
4151 if (configuration.value != null &&
4152 variableValue == configuration.value.stringValue ||
4153 variableValue == 'true') {
4154 configuredUriContent = configuration.uri.stringValue;
4155 configuredSource = source;
4156 }
4157 }
4158 }
4159 String selectedContentUri = configuredUriContent ?? directive.uriContent;
4160 Source selectedSource = configuredSource ?? defaultSource;
4161 directive.selectedUriContent = selectedContentUri;
4162 directive.selectedSource = selectedSource;
4163 return selectedSource;
4164 }
4165 return defaultSource;
4166 }
4167
4168 /**
4169 * Return the result of resolve the given [uriContent], reporting errors
4170 * against the [uriLiteral].
4171 */
4172 Source _resolveUri(
4173 bool isImport, StringLiteral uriLiteral, String uriContent) {
4174 UriValidationCode code =
4175 UriBasedDirectiveImpl.validateUri(isImport, uriLiteral, uriContent);
4176 if (code == null) {
4177 String encodedUriContent = Uri.encodeFull(uriContent);
4178 return context.sourceFactory.resolveUri(_source, encodedUriContent);
4179 } else if (code == UriValidationCode.URI_WITH_DART_EXT_SCHEME) {
4180 return null;
4181 } else if (code == UriValidationCode.URI_WITH_INTERPOLATION) {
4182 _errorReporter.reportErrorForNode(
4183 CompileTimeErrorCode.URI_WITH_INTERPOLATION, uriLiteral);
4184 return null;
4185 } else if (code == UriValidationCode.INVALID_URI) {
4186 _errorReporter.reportErrorForNode(
4187 CompileTimeErrorCode.INVALID_URI, uriLiteral, [uriContent]);
4188 return null;
4189 }
4190 throw new AnalysisException('Failed to handle validation code: $code');
4191 }
4192
4193 /**
3282 * Return a map from the names of the inputs of this kind of task to the task 4194 * Return a map from the names of the inputs of this kind of task to the task
3283 * input descriptors describing those inputs for a task with the given 4195 * input descriptors describing those inputs for a task with the given
3284 * [source]. 4196 * [target].
3285 */ 4197 */
3286 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 4198 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
3287 return <String, TaskInput>{ 4199 return <String, TaskInput>{
3288 LINE_INFO_INPUT_NAME: LINE_INFO.of(target), 4200 LINE_INFO_INPUT_NAME: LINE_INFO.of(target),
3289 MODIFICATION_TIME_INPUT_NAME: MODIFICATION_TIME.of(target), 4201 MODIFICATION_TIME_INPUT_NAME: MODIFICATION_TIME.of(target),
3290 TOKEN_STREAM_INPUT_NAME: TOKEN_STREAM.of(target) 4202 TOKEN_STREAM_INPUT_NAME: TOKEN_STREAM.of(target, flushOnAccess: true)
3291 }; 4203 };
3292 } 4204 }
3293 4205
3294 /** 4206 /**
3295 * Create a [ParseDartTask] based on the given [target] in the given 4207 * Create a [ParseDartTask] based on the given [target] in the given
3296 * [context]. 4208 * [context].
3297 */ 4209 */
3298 static ParseDartTask createTask( 4210 static ParseDartTask createTask(
3299 AnalysisContext context, AnalysisTarget target) { 4211 AnalysisContext context, AnalysisTarget target) {
3300 return new ParseDartTask(context, target); 4212 return new ParseDartTask(context, target);
3301 } 4213 }
3302
3303 /**
3304 * Return the result of resolving the URI of the given URI-based [directive]
3305 * against the URI of the given library, or `null` if the URI is not valid.
3306 *
3307 * Resolution is to be performed in the given [context]. Errors should be
3308 * reported to the [errorListener].
3309 */
3310 static Source resolveDirective(AnalysisContext context, Source librarySource,
3311 UriBasedDirective directive, AnalysisErrorListener errorListener) {
3312 StringLiteral uriLiteral = directive.uri;
3313 String uriContent = uriLiteral.stringValue;
3314 if (uriContent != null) {
3315 uriContent = uriContent.trim();
3316 directive.uriContent = uriContent;
3317 }
3318 UriValidationCode code = directive.validate();
3319 if (code == null) {
3320 String encodedUriContent = Uri.encodeFull(uriContent);
3321 Source source =
3322 context.sourceFactory.resolveUri(librarySource, encodedUriContent);
3323 directive.source = source;
3324 return source;
3325 }
3326 if (code == UriValidationCode.URI_WITH_DART_EXT_SCHEME) {
3327 return null;
3328 }
3329 if (code == UriValidationCode.URI_WITH_INTERPOLATION) {
3330 errorListener.onError(new AnalysisError(librarySource, uriLiteral.offset,
3331 uriLiteral.length, CompileTimeErrorCode.URI_WITH_INTERPOLATION));
3332 return null;
3333 }
3334 if (code == UriValidationCode.INVALID_URI) {
3335 errorListener.onError(new AnalysisError(librarySource, uriLiteral.offset,
3336 uriLiteral.length, CompileTimeErrorCode.INVALID_URI, [uriContent]));
3337 return null;
3338 }
3339 throw new AnalysisException('Failed to handle validation code: $code');
3340 }
3341 } 4214 }
3342 4215
3343 /** 4216 /**
3344 * A task that builds [RESOLVED_UNIT5] for a unit. 4217 * A task that builds [RESOLVED_UNIT7] for a unit.
3345 */ 4218 */
3346 class PartiallyResolveUnitReferencesTask extends SourceBasedAnalysisTask { 4219 class PartiallyResolveUnitReferencesTask extends SourceBasedAnalysisTask {
3347 /** 4220 /**
3348 * The name of the [LIBRARY_ELEMENT5] input. 4221 * The name of the [LIBRARY_ELEMENT6] input.
3349 */ 4222 */
3350 static const String LIBRARY_INPUT = 'LIBRARY_INPUT'; 4223 static const String LIBRARY_INPUT = 'LIBRARY_INPUT';
3351 4224
3352 /** 4225 /**
3353 * The name of the [RESOLVED_UNIT4] input. 4226 * The name of the [RESOLVED_UNIT6] input.
3354 */ 4227 */
3355 static const String UNIT_INPUT = 'UNIT_INPUT'; 4228 static const String UNIT_INPUT = 'UNIT_INPUT';
3356 4229
3357 /** 4230 /**
3358 * The name of the [TYPE_PROVIDER] input. 4231 * The name of the [TYPE_PROVIDER] input.
3359 */ 4232 */
3360 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT'; 4233 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT';
3361 4234
3362 /** 4235 /**
3363 * The task descriptor describing this kind of task. 4236 * The task descriptor describing this kind of task.
3364 */ 4237 */
3365 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 4238 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
3366 'PartiallyResolveUnitReferencesTask', 4239 'PartiallyResolveUnitReferencesTask',
3367 createTask, 4240 createTask,
3368 buildInputs, 4241 buildInputs, <ResultDescriptor>[
3369 <ResultDescriptor>[INFERABLE_STATIC_VARIABLES_IN_UNIT, RESOLVED_UNIT5]); 4242 INFERABLE_STATIC_VARIABLES_IN_UNIT,
4243 CREATED_RESOLVED_UNIT7,
4244 RESOLVED_UNIT7
4245 ]);
3370 4246
3371 PartiallyResolveUnitReferencesTask( 4247 PartiallyResolveUnitReferencesTask(
3372 InternalAnalysisContext context, AnalysisTarget target) 4248 InternalAnalysisContext context, AnalysisTarget target)
3373 : super(context, target); 4249 : super(context, target);
3374 4250
3375 @override 4251 @override
3376 TaskDescriptor get descriptor => DESCRIPTOR; 4252 TaskDescriptor get descriptor => DESCRIPTOR;
3377 4253
3378 @override 4254 @override
3379 void internalPerform() { 4255 void internalPerform() {
3380 // 4256 //
3381 // Prepare inputs. 4257 // Prepare inputs.
3382 // 4258 //
3383 LibraryElement libraryElement = getRequiredInput(LIBRARY_INPUT); 4259 LibraryElement libraryElement = getRequiredInput(LIBRARY_INPUT);
3384 CompilationUnit unit = getRequiredInput(UNIT_INPUT); 4260 CompilationUnit unit = getRequiredInput(UNIT_INPUT);
3385 CompilationUnitElement unitElement = unit.element; 4261 CompilationUnitElement unitElement = unit.element;
3386 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT); 4262 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT);
3387 // 4263 //
3388 // Resolve references and record outputs. 4264 // Resolve references and record outputs.
3389 // 4265 //
4266 PartialResolverVisitor visitor = new PartialResolverVisitor(libraryElement,
4267 unitElement.source, typeProvider, AnalysisErrorListener.NULL_LISTENER);
4268 unit.accept(visitor);
4269 //
4270 // Record outputs.
4271 //
3390 if (context.analysisOptions.strongMode) { 4272 if (context.analysisOptions.strongMode) {
3391 InheritanceManager inheritanceManager = 4273 outputs[INFERABLE_STATIC_VARIABLES_IN_UNIT] = visitor.staticVariables;
3392 new InheritanceManager(libraryElement);
3393 PartialResolverVisitor visitor = new PartialResolverVisitor(
3394 libraryElement,
3395 unitElement.source,
3396 typeProvider,
3397 AnalysisErrorListener.NULL_LISTENER,
3398 inheritanceManager: inheritanceManager);
3399 unit.accept(visitor);
3400
3401 outputs[INFERABLE_STATIC_VARIABLES_IN_UNIT] = visitor.variablesAndFields;
3402 } else { 4274 } else {
3403 outputs[INFERABLE_STATIC_VARIABLES_IN_UNIT] = []; 4275 outputs[INFERABLE_STATIC_VARIABLES_IN_UNIT] = VariableElement.EMPTY_LIST;
3404 } 4276 }
3405 outputs[RESOLVED_UNIT5] = unit; 4277 outputs[RESOLVED_UNIT7] = unit;
4278 outputs[CREATED_RESOLVED_UNIT7] = true;
3406 } 4279 }
3407 4280
3408 /** 4281 /**
3409 * Return a map from the names of the inputs of this kind of task to the task 4282 * Return a map from the names of the inputs of this kind of task to the task
3410 * input descriptors describing those inputs for a task with the 4283 * input descriptors describing those inputs for a task with the
3411 * given [target]. 4284 * given [target].
3412 */ 4285 */
3413 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 4286 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
3414 LibrarySpecificUnit unit = target; 4287 LibrarySpecificUnit unit = target;
3415 return <String, TaskInput>{ 4288 return <String, TaskInput>{
3416 'fullyBuiltLibraryElements': IMPORT_EXPORT_SOURCE_CLOSURE 4289 'fullyBuiltLibraryElements': READY_LIBRARY_ELEMENT6.of(unit.library),
3417 .of(unit.library) 4290 LIBRARY_INPUT: LIBRARY_ELEMENT6.of(unit.library),
3418 .toListOf(LIBRARY_ELEMENT5), 4291 UNIT_INPUT: RESOLVED_UNIT6.of(unit),
3419 LIBRARY_INPUT: LIBRARY_ELEMENT5.of(unit.library),
3420 UNIT_INPUT: RESOLVED_UNIT4.of(unit),
3421 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request), 4292 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request),
3422 // In strong mode, add additional dependencies to enforce inference 4293 // In strong mode, add additional dependencies to enforce inference
3423 // ordering. 4294 // ordering.
3424 4295
3425 // Require that full inference be complete for all dependencies of the 4296 // Require that full inference be complete for all dependencies of the
3426 // current library cycle. 4297 // current library cycle.
3427 'orderLibraryCycles': LIBRARY_CYCLE_DEPENDENCIES.of(unit).toList( 4298 'orderLibraryCycles': LIBRARY_CYCLE_DEPENDENCIES
3428 (CompilationUnitElementImpl unit) => RESOLVED_UNIT8 4299 .of(unit.library)
3429 .of(new LibrarySpecificUnit(unit.librarySource, unit.source))) 4300 .toListOf(CREATED_RESOLVED_UNIT10)
3430 }; 4301 };
3431 } 4302 }
3432 4303
3433 /** 4304 /**
3434 * Create a [PartiallyResolveUnitReferencesTask] based on the given [target] 4305 * Create a [PartiallyResolveUnitReferencesTask] based on the given [target]
3435 * in the given [context]. 4306 * in the given [context].
3436 */ 4307 */
3437 static PartiallyResolveUnitReferencesTask createTask( 4308 static PartiallyResolveUnitReferencesTask createTask(
3438 AnalysisContext context, AnalysisTarget target) { 4309 AnalysisContext context, AnalysisTarget target) {
3439 return new PartiallyResolveUnitReferencesTask(context, target); 4310 return new PartiallyResolveUnitReferencesTask(context, target);
3440 } 4311 }
3441 } 4312 }
3442 4313
3443 /** 4314 /**
3444 * The helper for building the public [Namespace] of a [LibraryElement]. 4315 * A task that ensures that [LIBRARY_ELEMENT2] is ready for the target library
3445 */ 4316 * source and its import/export closure.
3446 class PublicNamespaceBuilder { 4317 */
3447 final HashMap<String, Element> definedNames = new HashMap<String, Element>(); 4318 class ReadyLibraryElement2Task extends SourceBasedAnalysisTask {
3448 4319 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
3449 /** 4320 'ReadyLibraryElement2Task',
3450 * Build a public [Namespace] of the given [library]. 4321 createTask,
3451 */ 4322 buildInputs,
3452 Namespace build(LibraryElement library) { 4323 <ResultDescriptor>[READY_LIBRARY_ELEMENT2]);
3453 definedNames.clear(); 4324
3454 _addPublicNames(library.definingCompilationUnit); 4325 ReadyLibraryElement2Task(
3455 library.parts.forEach(_addPublicNames); 4326 InternalAnalysisContext context, AnalysisTarget target)
3456 return new Namespace(definedNames); 4327 : super(context, target);
3457 } 4328
3458 4329 @override
3459 /** 4330 TaskDescriptor get descriptor => DESCRIPTOR;
3460 * Add the given [element] if it has a publicly visible name. 4331
3461 */ 4332 @override
3462 void _addIfPublic(Element element) { 4333 bool get handlesDependencyCycles => true;
3463 String name = element.name; 4334
3464 if (name != null && !Scope.isPrivateName(name)) { 4335 @override
3465 definedNames[name] = element; 4336 void internalPerform() {
3466 } 4337 outputs[READY_LIBRARY_ELEMENT2] = true;
3467 } 4338 }
3468 4339
3469 /** 4340 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
3470 * Add all of the public top-level names that are defined in the given 4341 Source source = target;
3471 * [compilationUnit]. 4342 return <String, TaskInput>{
3472 */ 4343 'thisLibraryElementReady': LIBRARY_ELEMENT2.of(source),
3473 void _addPublicNames(CompilationUnitElement compilationUnit) { 4344 'directlyImportedLibrariesReady':
3474 compilationUnit.accessors.forEach(_addIfPublic); 4345 IMPORTED_LIBRARIES.of(source).toListOf(READY_LIBRARY_ELEMENT2),
3475 compilationUnit.enums.forEach(_addIfPublic); 4346 'directlyExportedLibrariesReady':
3476 compilationUnit.functions.forEach(_addIfPublic); 4347 EXPORTED_LIBRARIES.of(source).toListOf(READY_LIBRARY_ELEMENT2),
3477 compilationUnit.functionTypeAliases.forEach(_addIfPublic); 4348 };
3478 compilationUnit.types.forEach(_addIfPublic); 4349 }
3479 } 4350
3480 } 4351 static ReadyLibraryElement2Task createTask(
3481 4352 AnalysisContext context, AnalysisTarget target) {
3482 /** 4353 return new ReadyLibraryElement2Task(context, target);
3483 * Information about a library - which names it uses, which names it defines 4354 }
3484 * with their externally visible dependencies. 4355 }
4356
4357 /**
4358 * A task that ensures that [LIBRARY_ELEMENT6] is ready for the target library
4359 * source and its import/export closure.
4360 */
4361 class ReadyLibraryElement5Task extends SourceBasedAnalysisTask {
4362 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
4363 'ReadyLibraryElement5Task',
4364 createTask,
4365 buildInputs,
4366 <ResultDescriptor>[READY_LIBRARY_ELEMENT6]);
4367
4368 ReadyLibraryElement5Task(
4369 InternalAnalysisContext context, AnalysisTarget target)
4370 : super(context, target);
4371
4372 @override
4373 TaskDescriptor get descriptor => DESCRIPTOR;
4374
4375 @override
4376 bool get handlesDependencyCycles => true;
4377
4378 @override
4379 void internalPerform() {
4380 outputs[READY_LIBRARY_ELEMENT6] = true;
4381 }
4382
4383 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
4384 Source source = target;
4385 return <String, TaskInput>{
4386 'thisLibraryElementReady': LIBRARY_ELEMENT6.of(source),
4387 'directlyImportedLibrariesReady':
4388 IMPORTED_LIBRARIES.of(source).toListOf(READY_LIBRARY_ELEMENT6),
4389 'directlyExportedLibrariesReady':
4390 EXPORTED_LIBRARIES.of(source).toListOf(READY_LIBRARY_ELEMENT6),
4391 };
4392 }
4393
4394 static ReadyLibraryElement5Task createTask(
4395 AnalysisContext context, AnalysisTarget target) {
4396 return new ReadyLibraryElement5Task(context, target);
4397 }
4398 }
4399
4400 /**
4401 * A task that ensures that [LIBRARY_ELEMENT7] is ready for the target library
4402 * source and its import/export closure.
4403 */
4404 class ReadyLibraryElement7Task extends SourceBasedAnalysisTask {
4405 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
4406 'ReadyLibraryElement7Task',
4407 createTask,
4408 buildInputs,
4409 <ResultDescriptor>[READY_LIBRARY_ELEMENT7]);
4410
4411 ReadyLibraryElement7Task(
4412 InternalAnalysisContext context, AnalysisTarget target)
4413 : super(context, target);
4414
4415 @override
4416 TaskDescriptor get descriptor => DESCRIPTOR;
4417
4418 @override
4419 bool get handlesDependencyCycles => true;
4420
4421 @override
4422 void internalPerform() {
4423 outputs[READY_LIBRARY_ELEMENT7] = true;
4424 }
4425
4426 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
4427 Source source = target;
4428 return <String, TaskInput>{
4429 'thisLibraryElementReady': LIBRARY_ELEMENT7.of(source),
4430 'directlyImportedLibrariesReady':
4431 IMPORTED_LIBRARIES.of(source).toListOf(READY_LIBRARY_ELEMENT7),
4432 'directlyExportedLibrariesReady':
4433 EXPORTED_LIBRARIES.of(source).toListOf(READY_LIBRARY_ELEMENT7),
4434 };
4435 }
4436
4437 static ReadyLibraryElement7Task createTask(
4438 AnalysisContext context, AnalysisTarget target) {
4439 return new ReadyLibraryElement7Task(context, target);
4440 }
4441 }
4442
4443 /**
4444 * A task that ensures that [RESOLVED_UNIT] is ready for every unit of the
4445 * target library source and its import/export closure.
4446 */
4447 class ReadyResolvedUnitTask extends SourceBasedAnalysisTask {
4448 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
4449 'ReadyResolvedUnitTask',
4450 createTask,
4451 buildInputs,
4452 <ResultDescriptor>[READY_RESOLVED_UNIT]);
4453
4454 ReadyResolvedUnitTask(InternalAnalysisContext context, AnalysisTarget target)
4455 : super(context, target);
4456
4457 @override
4458 TaskDescriptor get descriptor => DESCRIPTOR;
4459
4460 @override
4461 bool get handlesDependencyCycles => true;
4462
4463 @override
4464 void internalPerform() {
4465 outputs[READY_RESOLVED_UNIT] = true;
4466 }
4467
4468 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
4469 Source source = target;
4470 return <String, TaskInput>{
4471 'thisLibraryUnitsReady':
4472 LIBRARY_SPECIFIC_UNITS.of(source).toListOf(RESOLVED_UNIT),
4473 };
4474 }
4475
4476 static ReadyResolvedUnitTask createTask(
4477 AnalysisContext context, AnalysisTarget target) {
4478 return new ReadyResolvedUnitTask(context, target);
4479 }
4480 }
4481
4482 /**
4483 * Information about a Dart [source] - which names it uses, which names it
4484 * defines with their externally visible dependencies.
3485 */ 4485 */
3486 class ReferencedNames { 4486 class ReferencedNames {
4487 final Source source;
4488
4489 /**
4490 * The mapping from the name of a class to the set of names of other classes
4491 * that extend, mix-in, or implement it.
4492 *
4493 * If the set of member of a class is changed, these changes might change
4494 * the list of unimplemented inherited members in the class and classes that
4495 * extend, mix-in, or implement it. So, we might need to report (or stop
4496 * reporting) the corresponding warning.
4497 */
4498 final Map<String, Set<String>> superToSubs = <String, Set<String>>{};
4499
4500 /**
4501 * The names of extended classes for which the unnamed constructor is
4502 * invoked. Because we cannot use the name of the constructor to identify
4503 * whether the unit is affected, we need to use the class name.
4504 */
4505 final Set<String> extendedUsedUnnamedConstructorNames = new Set<String>();
4506
4507 /**
4508 * The names of instantiated classes.
4509 *
4510 * If one of these classes changes its set of members, it might change
4511 * its list of unimplemented inherited members. So, we might need to report
4512 * (or stop reporting) the corresponding warning.
4513 */
4514 final Set<String> instantiatedNames = new Set<String>();
4515
4516 /**
4517 * The set of names that are referenced by the library, both inside and
4518 * outside of method bodies.
4519 */
3487 final Set<String> names = new Set<String>(); 4520 final Set<String> names = new Set<String>();
4521
4522 /**
4523 * The mapping from the name of a top-level element to the set of names that
4524 * the element uses in a way that is visible outside of the element, e.g.
4525 * the return type, or a parameter type.
4526 */
3488 final Map<String, Set<String>> userToDependsOn = <String, Set<String>>{}; 4527 final Map<String, Set<String>> userToDependsOn = <String, Set<String>>{};
3489 4528
3490 /** 4529 ReferencedNames(this.source);
3491 * Updates [delta] by adding names that are changed in this library. 4530
3492 */ 4531 void addSubclass(String subName, String superName) {
3493 void addChangedElements(DartDelta delta) { 4532 superToSubs.putIfAbsent(superName, () => new Set<String>()).add(subName);
3494 bool hasProgress = true;
3495 while (hasProgress) {
3496 hasProgress = false;
3497 userToDependsOn.forEach((user, dependencies) {
3498 for (String dependency in dependencies) {
3499 if (delta.isNameAffected(dependency)) {
3500 if (delta.nameChanged(user)) {
3501 hasProgress = true;
3502 }
3503 }
3504 }
3505 });
3506 }
3507 }
3508
3509 /**
3510 * Returns `true` if the library described by this object is affected by
3511 * the given [delta].
3512 */
3513 bool isAffectedBy(DartDelta delta) {
3514 for (String name in names) {
3515 if (delta.isNameAffected(name)) {
3516 return true;
3517 }
3518 }
3519 return false;
3520 } 4533 }
3521 } 4534 }
3522 4535
3523 /** 4536 /**
3524 * A builder for creating [ReferencedNames]. 4537 * A builder for creating [ReferencedNames].
3525 * 4538 */
3526 * TODO(scheglov) Record dependencies for all other top-level declarations. 4539 class ReferencedNamesBuilder extends GeneralizingAstVisitor {
3527 */ 4540 final Set<String> importPrefixNames = new Set<String>();
3528 class ReferencedNamesBuilder extends RecursiveAstVisitor {
3529 final ReferencedNames names; 4541 final ReferencedNames names;
3530 int bodyLevel = 0; 4542
4543 String enclosingSuperClassName;
4544 ReferencedNamesScope scope = new ReferencedNamesScope(null);
4545
4546 int localLevel = 0;
3531 Set<String> dependsOn; 4547 Set<String> dependsOn;
3532 4548
3533 ReferencedNamesBuilder(this.names); 4549 ReferencedNamesBuilder(this.names);
3534 4550
3535 ReferencedNames build(CompilationUnit unit) { 4551 ReferencedNames build(CompilationUnit unit) {
3536 unit.accept(this); 4552 unit.accept(this);
3537 return names; 4553 return names;
3538 } 4554 }
3539 4555
3540 @override 4556 @override
3541 visitBlockFunctionBody(BlockFunctionBody node) { 4557 visitBlock(Block node) {
4558 ReferencedNamesScope outerScope = scope;
3542 try { 4559 try {
3543 bodyLevel++; 4560 scope = new ReferencedNamesScope.forBlock(scope, node);
3544 super.visitBlockFunctionBody(node); 4561 super.visitBlock(node);
3545 } finally { 4562 } finally {
3546 bodyLevel--; 4563 scope = outerScope;
3547 } 4564 }
3548 } 4565 }
3549 4566
3550 @override 4567 @override
3551 visitClassDeclaration(ClassDeclaration node) { 4568 visitClassDeclaration(ClassDeclaration node) {
3552 dependsOn = new Set<String>(); 4569 ReferencedNamesScope outerScope = scope;
3553 super.visitClassDeclaration(node); 4570 try {
3554 names.userToDependsOn[node.name.name] = dependsOn; 4571 scope = new ReferencedNamesScope.forClass(scope, node);
4572 dependsOn = new Set<String>();
4573 enclosingSuperClassName =
4574 _getSimpleName(node.extendsClause?.superclass?.name);
4575 super.visitClassDeclaration(node);
4576 String className = node.name.name;
4577 names.userToDependsOn[className] = dependsOn;
4578 _addSuperName(className, node.extendsClause?.superclass);
4579 _addSuperNames(className, node.withClause?.mixinTypes);
4580 _addSuperNames(className, node.implementsClause?.interfaces);
4581 } finally {
4582 enclosingSuperClassName = null;
4583 dependsOn = null;
4584 scope = outerScope;
4585 }
4586 }
4587
4588 @override
4589 visitClassTypeAlias(ClassTypeAlias node) {
4590 ReferencedNamesScope outerScope = scope;
4591 try {
4592 scope = new ReferencedNamesScope.forClassTypeAlias(scope, node);
4593 dependsOn = new Set<String>();
4594 super.visitClassTypeAlias(node);
4595 String className = node.name.name;
4596 names.userToDependsOn[className] = dependsOn;
4597 _addSuperName(className, node.superclass);
4598 _addSuperNames(className, node.withClause?.mixinTypes);
4599 _addSuperNames(className, node.implementsClause?.interfaces);
4600 } finally {
4601 dependsOn = null;
4602 scope = outerScope;
4603 }
4604 }
4605
4606 @override
4607 visitComment(Comment node) {
4608 try {
4609 localLevel++;
4610 super.visitComment(node);
4611 } finally {
4612 localLevel--;
4613 }
4614 }
4615
4616 @override
4617 visitConstructorName(ConstructorName node) {
4618 if (node.parent is! ConstructorDeclaration) {
4619 super.visitConstructorName(node);
4620 }
4621 }
4622
4623 @override
4624 visitFunctionBody(FunctionBody node) {
4625 try {
4626 localLevel++;
4627 super.visitFunctionBody(node);
4628 } finally {
4629 localLevel--;
4630 }
4631 }
4632
4633 @override
4634 visitFunctionDeclaration(FunctionDeclaration node) {
4635 if (localLevel == 0) {
4636 ReferencedNamesScope outerScope = scope;
4637 try {
4638 scope = new ReferencedNamesScope.forFunction(scope, node);
4639 dependsOn = new Set<String>();
4640 super.visitFunctionDeclaration(node);
4641 names.userToDependsOn[node.name.name] = dependsOn;
4642 } finally {
4643 dependsOn = null;
4644 scope = outerScope;
4645 }
4646 } else {
4647 super.visitFunctionDeclaration(node);
4648 }
4649 }
4650
4651 @override
4652 visitFunctionTypeAlias(FunctionTypeAlias node) {
4653 if (localLevel == 0) {
4654 ReferencedNamesScope outerScope = scope;
4655 try {
4656 scope = new ReferencedNamesScope.forFunctionTypeAlias(scope, node);
4657 dependsOn = new Set<String>();
4658 super.visitFunctionTypeAlias(node);
4659 names.userToDependsOn[node.name.name] = dependsOn;
4660 } finally {
4661 dependsOn = null;
4662 scope = outerScope;
4663 }
4664 } else {
4665 super.visitFunctionTypeAlias(node);
4666 }
4667 }
4668
4669 @override
4670 visitImportDirective(ImportDirective node) {
4671 if (node.prefix != null) {
4672 importPrefixNames.add(node.prefix.name);
4673 }
4674 super.visitImportDirective(node);
4675 }
4676
4677 @override
4678 visitInstanceCreationExpression(InstanceCreationExpression node) {
4679 ConstructorName constructorName = node.constructorName;
4680 Identifier typeName = constructorName.type.name;
4681 if (typeName is SimpleIdentifier) {
4682 names.instantiatedNames.add(typeName.name);
4683 }
4684 if (typeName is PrefixedIdentifier) {
4685 String prefixName = typeName.prefix.name;
4686 if (importPrefixNames.contains(prefixName)) {
4687 names.instantiatedNames.add(typeName.identifier.name);
4688 } else {
4689 names.instantiatedNames.add(prefixName);
4690 }
4691 }
4692 super.visitInstanceCreationExpression(node);
4693 }
4694
4695 @override
4696 visitMethodDeclaration(MethodDeclaration node) {
4697 ReferencedNamesScope outerScope = scope;
4698 try {
4699 scope = new ReferencedNamesScope.forMethod(scope, node);
4700 super.visitMethodDeclaration(node);
4701 } finally {
4702 scope = outerScope;
4703 }
4704 }
4705
4706 @override
4707 visitSimpleIdentifier(SimpleIdentifier node) {
4708 // Ignore all declarations.
4709 if (node.inDeclarationContext()) {
4710 return;
4711 }
4712 // Ignore class names references from constructors.
4713 AstNode parent = node.parent;
4714 if (parent is ConstructorDeclaration && parent.returnType == node) {
4715 return;
4716 }
4717 // Prepare name.
4718 String name = node.name;
4719 // Ignore unqualified names shadowed by local elements.
4720 if (!node.isQualified) {
4721 if (scope.contains(name)) {
4722 return;
4723 }
4724 if (importPrefixNames.contains(name)) {
4725 return;
4726 }
4727 }
4728 // Do add the dependency.
4729 names.names.add(name);
4730 if (dependsOn != null && localLevel == 0) {
4731 dependsOn.add(name);
4732 }
4733 }
4734
4735 @override
4736 visitSuperConstructorInvocation(SuperConstructorInvocation node) {
4737 if (node.constructorName == null && enclosingSuperClassName != null) {
4738 names.extendedUsedUnnamedConstructorNames.add(enclosingSuperClassName);
4739 }
4740 super.visitSuperConstructorInvocation(node);
4741 }
4742
4743 @override
4744 visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {
4745 VariableDeclarationList variableList = node.variables;
4746 // Prepare type dependencies.
4747 Set<String> typeDependencies = new Set<String>();
4748 dependsOn = typeDependencies;
4749 variableList.type?.accept(this);
4750 // Combine individual variable dependencies with the type dependencies.
4751 for (VariableDeclaration variable in variableList.variables) {
4752 dependsOn = new Set<String>();
4753 variable.accept(this);
4754 dependsOn.addAll(typeDependencies);
4755 names.userToDependsOn[variable.name.name] = dependsOn;
4756 }
3555 dependsOn = null; 4757 dependsOn = null;
3556 } 4758 }
3557 4759
3558 @override 4760 void _addSuperName(String className, TypeName type) {
3559 visitExpressionFunctionBody(ExpressionFunctionBody node) { 4761 if (type != null) {
3560 try { 4762 Identifier typeName = type.name;
3561 bodyLevel++; 4763 if (typeName is SimpleIdentifier) {
3562 super.visitExpressionFunctionBody(node); 4764 names.addSubclass(className, typeName.name);
3563 } finally { 4765 }
3564 bodyLevel--; 4766 if (typeName is PrefixedIdentifier) {
3565 } 4767 names.addSubclass(className, typeName.identifier.name);
3566 } 4768 }
3567 4769 }
3568 @override 4770 }
3569 visitSimpleIdentifier(SimpleIdentifier node) { 4771
3570 if (!node.inDeclarationContext()) { 4772 void _addSuperNames(String className, List<TypeName> types) {
3571 String name = node.name; 4773 types?.forEach((type) => _addSuperName(className, type));
3572 names.names.add(name); 4774 }
3573 if (dependsOn != null && bodyLevel == 0) { 4775
3574 dependsOn.add(name); 4776 static String _getSimpleName(Identifier identifier) {
3575 } 4777 if (identifier is SimpleIdentifier) {
3576 } 4778 return identifier.name;
4779 }
4780 if (identifier is PrefixedIdentifier) {
4781 return identifier.identifier.name;
4782 }
4783 return null;
3577 } 4784 }
3578 } 4785 }
3579 4786
4787 class ReferencedNamesScope {
4788 final ReferencedNamesScope enclosing;
4789 Set<String> names;
4790
4791 ReferencedNamesScope(this.enclosing);
4792
4793 factory ReferencedNamesScope.forBlock(
4794 ReferencedNamesScope enclosing, Block node) {
4795 ReferencedNamesScope scope = new ReferencedNamesScope(enclosing);
4796 for (Statement statement in node.statements) {
4797 if (statement is FunctionDeclarationStatement) {
4798 scope.add(statement.functionDeclaration.name.name);
4799 } else if (statement is VariableDeclarationStatement) {
4800 for (VariableDeclaration variable in statement.variables.variables) {
4801 scope.add(variable.name.name);
4802 }
4803 }
4804 }
4805 return scope;
4806 }
4807
4808 factory ReferencedNamesScope.forClass(
4809 ReferencedNamesScope enclosing, ClassDeclaration node) {
4810 ReferencedNamesScope scope = new ReferencedNamesScope(enclosing);
4811 scope._addTypeParameters(node.typeParameters);
4812 for (ClassMember member in node.members) {
4813 if (member is FieldDeclaration) {
4814 for (VariableDeclaration variable in member.fields.variables) {
4815 scope.add(variable.name.name);
4816 }
4817 } else if (member is MethodDeclaration) {
4818 scope.add(member.name.name);
4819 }
4820 }
4821 return scope;
4822 }
4823
4824 factory ReferencedNamesScope.forClassTypeAlias(
4825 ReferencedNamesScope enclosing, ClassTypeAlias node) {
4826 ReferencedNamesScope scope = new ReferencedNamesScope(enclosing);
4827 scope._addTypeParameters(node.typeParameters);
4828 return scope;
4829 }
4830
4831 factory ReferencedNamesScope.forFunction(
4832 ReferencedNamesScope enclosing, FunctionDeclaration node) {
4833 ReferencedNamesScope scope = new ReferencedNamesScope(enclosing);
4834 scope._addTypeParameters(node.functionExpression.typeParameters);
4835 scope._addFormalParameters(node.functionExpression.parameters);
4836 return scope;
4837 }
4838
4839 factory ReferencedNamesScope.forFunctionTypeAlias(
4840 ReferencedNamesScope enclosing, FunctionTypeAlias node) {
4841 ReferencedNamesScope scope = new ReferencedNamesScope(enclosing);
4842 scope._addTypeParameters(node.typeParameters);
4843 return scope;
4844 }
4845
4846 factory ReferencedNamesScope.forMethod(
4847 ReferencedNamesScope enclosing, MethodDeclaration node) {
4848 ReferencedNamesScope scope = new ReferencedNamesScope(enclosing);
4849 scope._addTypeParameters(node.typeParameters);
4850 scope._addFormalParameters(node.parameters);
4851 return scope;
4852 }
4853
4854 void add(String name) {
4855 names ??= new Set<String>();
4856 names.add(name);
4857 }
4858
4859 bool contains(String name) {
4860 if (names != null && names.contains(name)) {
4861 return true;
4862 }
4863 if (enclosing != null) {
4864 return enclosing.contains(name);
4865 }
4866 return false;
4867 }
4868
4869 void _addFormalParameters(FormalParameterList parameterList) {
4870 if (parameterList != null) {
4871 parameterList.parameters
4872 .map((p) => p is NormalFormalParameter ? p.identifier.name : '')
4873 .forEach(add);
4874 }
4875 }
4876
4877 void _addTypeParameters(TypeParameterList typeParameterList) {
4878 if (typeParameterList != null) {
4879 typeParameterList.typeParameters.map((p) => p.name.name).forEach(add);
4880 }
4881 }
4882 }
4883
3580 /** 4884 /**
3581 * A task that ensures that all of the inferrable instance members in a 4885 * A task that ensures that the expression AST for a constant is resolved and
4886 * sets the [CONSTANT_EXPRESSION_RESOLVED] result.
4887 */
4888 class ResolveConstantExpressionTask extends ConstantEvaluationAnalysisTask {
4889 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
4890 'ResolveConstantExpressionTask',
4891 createTask,
4892 buildInputs,
4893 <ResultDescriptor>[CONSTANT_EXPRESSION_RESOLVED]);
4894
4895 ResolveConstantExpressionTask(
4896 InternalAnalysisContext context, ConstantEvaluationTarget constant)
4897 : super(context, constant);
4898
4899 @override
4900 TaskDescriptor get descriptor => DESCRIPTOR;
4901
4902 @override
4903 void internalPerform() {
4904 //
4905 // Record outputs.
4906 //
4907 outputs[CONSTANT_EXPRESSION_RESOLVED] = true;
4908 }
4909
4910 /**
4911 * Return a map from the names of the inputs of this kind of task to the task
4912 * input descriptors describing those inputs for a task with the
4913 * given [target].
4914 */
4915 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
4916 Source librarySource;
4917 if (target is Element) {
4918 CompilationUnitElementImpl unit = target
4919 .getAncestor((Element element) => element is CompilationUnitElement);
4920 librarySource = unit.librarySource;
4921 } else if (target is ElementAnnotationImpl) {
4922 librarySource = target.librarySource;
4923 } else {
4924 throw new AnalysisException(
4925 'Cannot build inputs for a ${target.runtimeType}');
4926 }
4927 return <String, TaskInput>{
4928 'createdResolvedUnit': CREATED_RESOLVED_UNIT11
4929 .of(new LibrarySpecificUnit(librarySource, target.source))
4930 };
4931 }
4932
4933 /**
4934 * Create a [ResolveConstantExpressionTask] based on the given [target] in
4935 * the given [context].
4936 */
4937 static ResolveConstantExpressionTask createTask(
4938 AnalysisContext context, AnalysisTarget target) {
4939 return new ResolveConstantExpressionTask(context, target);
4940 }
4941 }
4942
4943 /**
4944 * A task that resolves imports and export directives to already built elements.
4945 */
4946 class ResolveDirectiveElementsTask extends SourceBasedAnalysisTask {
4947 /**
4948 * The name of the input whose value is the defining [LIBRARY_ELEMENT2].
4949 */
4950 static const String LIBRARY_INPUT = 'LIBRARY_INPUT';
4951
4952 /**
4953 * The name of the input for [RESOLVED_UNIT1] of a unit.
4954 */
4955 static const String UNIT_INPUT = 'UNIT_INPUT';
4956
4957 /**
4958 * The task descriptor describing this kind of task.
4959 */
4960 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
4961 'ResolveDirectiveElementsTask',
4962 createTask,
4963 buildInputs,
4964 <ResultDescriptor>[CREATED_RESOLVED_UNIT2, RESOLVED_UNIT2]);
4965
4966 ResolveDirectiveElementsTask(
4967 InternalAnalysisContext context, AnalysisTarget target)
4968 : super(context, target);
4969
4970 @override
4971 TaskDescriptor get descriptor => DESCRIPTOR;
4972
4973 @override
4974 void internalPerform() {
4975 LibrarySpecificUnit targetUnit = target;
4976 //
4977 // Prepare inputs.
4978 //
4979 CompilationUnit unit = getRequiredInput(UNIT_INPUT);
4980 //
4981 // Resolve directive AST nodes to elements.
4982 //
4983 if (targetUnit.unit == targetUnit.library) {
4984 DirectiveResolver resolver = new DirectiveResolver();
4985 unit.accept(resolver);
4986 }
4987 //
4988 // Record outputs.
4989 //
4990 outputs[CREATED_RESOLVED_UNIT2] = true;
4991 outputs[RESOLVED_UNIT2] = unit;
4992 }
4993
4994 /**
4995 * Return a map from the names of the inputs of this kind of task to the task
4996 * input descriptors describing those inputs for a task with the
4997 * given [target].
4998 */
4999 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
5000 LibrarySpecificUnit unit = target;
5001 return <String, TaskInput>{
5002 LIBRARY_INPUT: LIBRARY_ELEMENT2.of(unit.library),
5003 UNIT_INPUT: RESOLVED_UNIT1.of(unit)
5004 };
5005 }
5006
5007 /**
5008 * Create a [ResolveDirectiveElementsTask] based on the given [target] in
5009 * the given [context].
5010 */
5011 static ResolveDirectiveElementsTask createTask(
5012 AnalysisContext context, AnalysisTarget target) {
5013 return new ResolveDirectiveElementsTask(context, target);
5014 }
5015 }
5016
5017 /**
5018 * An artificial task that does nothing except to force [LIBRARY_ELEMENT7] for
5019 * the target library and its import/export closure.
5020 */
5021 class ResolvedUnit7InLibraryClosureTask extends SourceBasedAnalysisTask {
5022 /**
5023 * The name of the [LIBRARY_ELEMENT7] input.
5024 */
5025 static const String LIBRARY_INPUT = 'LIBRARY_INPUT';
5026
5027 /**
5028 * The task descriptor describing this kind of task.
5029 */
5030 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
5031 'ResolvedUnit7InLibraryClosureTask',
5032 createTask,
5033 buildInputs,
5034 <ResultDescriptor>[LIBRARY_ELEMENT8]);
5035
5036 ResolvedUnit7InLibraryClosureTask(
5037 InternalAnalysisContext context, AnalysisTarget target)
5038 : super(context, target);
5039
5040 @override
5041 TaskDescriptor get descriptor => DESCRIPTOR;
5042
5043 @override
5044 void internalPerform() {
5045 LibraryElement library = getRequiredInput(LIBRARY_INPUT);
5046 outputs[LIBRARY_ELEMENT8] = library;
5047 }
5048
5049 /**
5050 * Return a map from the names of the inputs of this kind of task to the task
5051 * input descriptors describing those inputs for a task with the
5052 * given [target].
5053 */
5054 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
5055 Source source = target;
5056 return <String, TaskInput>{
5057 'readyForClosure': READY_LIBRARY_ELEMENT7.of(source),
5058 LIBRARY_INPUT: LIBRARY_ELEMENT7.of(source),
5059 };
5060 }
5061
5062 /**
5063 * Create a [ResolvedUnit7InLibraryClosureTask] based on the given
5064 * [target] in the given [context].
5065 */
5066 static ResolvedUnit7InLibraryClosureTask createTask(
5067 AnalysisContext context, AnalysisTarget target) {
5068 return new ResolvedUnit7InLibraryClosureTask(context, target);
5069 }
5070 }
5071
5072 /**
5073 * An artificial task that does nothing except to force [LIBRARY_ELEMENT6] and
5074 * [RESOLVED_UNIT7] in the defining and part units of a library.
5075 */
5076 class ResolvedUnit7InLibraryTask extends SourceBasedAnalysisTask {
5077 /**
5078 * The name of the [LIBRARY_ELEMENT6] input.
5079 */
5080 static const String LIBRARY_INPUT = 'LIBRARY_INPUT';
5081
5082 /**
5083 * The task descriptor describing this kind of task.
5084 */
5085 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
5086 'ResolvedUnit7InLibraryTask',
5087 createTask,
5088 buildInputs,
5089 <ResultDescriptor>[LIBRARY_ELEMENT7]);
5090
5091 ResolvedUnit7InLibraryTask(
5092 InternalAnalysisContext context, AnalysisTarget target)
5093 : super(context, target);
5094
5095 @override
5096 TaskDescriptor get descriptor => DESCRIPTOR;
5097
5098 @override
5099 void internalPerform() {
5100 LibraryElement library = getRequiredInput(LIBRARY_INPUT);
5101 outputs[LIBRARY_ELEMENT7] = library;
5102 }
5103
5104 /**
5105 * Return a map from the names of the inputs of this kind of task to the task
5106 * input descriptors describing those inputs for a task with the
5107 * given [target].
5108 */
5109 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
5110 Source source = target;
5111 return <String, TaskInput>{
5112 'resolvedUnits':
5113 LIBRARY_SPECIFIC_UNITS.of(source).toListOf(RESOLVED_UNIT7),
5114 LIBRARY_INPUT: LIBRARY_ELEMENT6.of(source),
5115 };
5116 }
5117
5118 /**
5119 * Create a [ResolvedUnit7InLibraryTask] based on the given [target]
5120 * in the given [context].
5121 */
5122 static ResolvedUnit7InLibraryTask createTask(
5123 AnalysisContext context, AnalysisTarget target) {
5124 return new ResolvedUnit7InLibraryTask(context, target);
5125 }
5126 }
5127
5128 /**
5129 * A task that ensures that all of the inferable instance members in a
3582 * compilation unit have had their right hand sides re-resolved 5130 * compilation unit have had their right hand sides re-resolved
3583 */ 5131 */
3584 class ResolveInstanceFieldsInUnitTask extends SourceBasedAnalysisTask { 5132 class ResolveInstanceFieldsInUnitTask extends SourceBasedAnalysisTask {
3585 /** 5133 /**
3586 * The name of the [LIBRARY_ELEMENT5] input. 5134 * The name of the [LIBRARY_ELEMENT6] input.
3587 */ 5135 */
3588 static const String LIBRARY_INPUT = 'LIBRARY_INPUT'; 5136 static const String LIBRARY_INPUT = 'LIBRARY_INPUT';
3589 5137
3590 /** 5138 /**
3591 * The name of the [TYPE_PROVIDER] input. 5139 * The name of the [TYPE_PROVIDER] input.
3592 */ 5140 */
3593 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT'; 5141 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT';
3594 5142
3595 /** 5143 /**
3596 * The name of the input whose value is the [RESOLVED_UNIT6] for the 5144 * The name of the input whose value is the [RESOLVED_UNIT8] for the
3597 * compilation unit. 5145 * compilation unit.
3598 */ 5146 */
3599 static const String UNIT_INPUT = 'UNIT_INPUT'; 5147 static const String UNIT_INPUT = 'UNIT_INPUT';
3600 5148
3601 /** 5149 /**
3602 * The task descriptor describing this kind of task. 5150 * The task descriptor describing this kind of task.
3603 */ 5151 */
3604 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 5152 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
3605 'ResolveInstanceFieldsInUnitTask', 5153 'ResolveInstanceFieldsInUnitTask',
3606 createTask, 5154 createTask,
3607 buildInputs, 5155 buildInputs,
3608 <ResultDescriptor>[RESOLVED_UNIT7]); 5156 <ResultDescriptor>[CREATED_RESOLVED_UNIT9, RESOLVED_UNIT9]);
3609 5157
3610 /** 5158 /**
3611 * Initialize a newly created task to build a library element for the given 5159 * Initialize a newly created task to build a library element for the given
3612 * [unit] in the given [context]. 5160 * [unit] in the given [context].
3613 */ 5161 */
3614 ResolveInstanceFieldsInUnitTask( 5162 ResolveInstanceFieldsInUnitTask(
3615 InternalAnalysisContext context, LibrarySpecificUnit unit) 5163 InternalAnalysisContext context, LibrarySpecificUnit unit)
3616 : super(context, unit); 5164 : super(context, unit);
3617 5165
3618 @override 5166 @override
3619 TaskDescriptor get descriptor => DESCRIPTOR; 5167 TaskDescriptor get descriptor => DESCRIPTOR;
3620 5168
3621 @override 5169 @override
3622 void internalPerform() { 5170 void internalPerform() {
3623 // 5171 //
3624 // Prepare inputs. 5172 // Prepare inputs.
3625 // 5173 //
3626 LibraryElement libraryElement = getRequiredInput(LIBRARY_INPUT); 5174 LibraryElement libraryElement = getRequiredInput(LIBRARY_INPUT);
3627 CompilationUnit unit = getRequiredInput(UNIT_INPUT); 5175 CompilationUnit unit = getRequiredInput(UNIT_INPUT);
3628 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT); 5176 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT);
3629 5177
3630 CompilationUnitElement unitElement = unit.element; 5178 CompilationUnitElement unitElement = unit.element;
3631 if (context.analysisOptions.strongMode) { 5179 if (context.analysisOptions.strongMode) {
3632 // 5180 //
3633 // Resolve references. 5181 // Resolve references.
3634 // 5182 //
3635 // TODO(leafp): This code only needs to re-resolve the right hand sides of 5183 InstanceFieldResolverVisitor visitor = new InstanceFieldResolverVisitor(
3636 // instance fields. We could do incremental resolution on each field
3637 // only using the incremental resolver. However, this caused a massive
3638 // performance degredation on the large_class_declaration_test.dart test.
3639 // I would hypothesize that incremental resolution of field is linear in
3640 // the size of the enclosing class, and hence incrementally resolving each
3641 // field was quadratic. We may wish to revisit this if we can resolve
3642 // this performance issue.
3643 InheritanceManager inheritanceManager =
3644 new InheritanceManager(libraryElement);
3645 PartialResolverVisitor visitor = new PartialResolverVisitor(
3646 libraryElement, 5184 libraryElement,
3647 unitElement.source, 5185 unitElement.source,
3648 typeProvider, 5186 typeProvider,
3649 AnalysisErrorListener.NULL_LISTENER, 5187 AnalysisErrorListener.NULL_LISTENER);
3650 inheritanceManager: inheritanceManager); 5188 visitor.resolveCompilationUnit(unit);
3651 unit.accept(visitor);
3652 } 5189 }
3653 // 5190 //
3654 // Record outputs. 5191 // Record outputs.
3655 // 5192 //
3656 outputs[RESOLVED_UNIT7] = unit; 5193 outputs[RESOLVED_UNIT9] = unit;
5194 outputs[CREATED_RESOLVED_UNIT9] = true;
3657 } 5195 }
3658 5196
3659 /** 5197 /**
3660 * Return a map from the names of the inputs of this kind of task to the task 5198 * Return a map from the names of the inputs of this kind of task to the task
3661 * input descriptors describing those inputs for a task with the given 5199 * input descriptors describing those inputs for a task with the given
3662 * [libSource]. 5200 * [libSource].
3663 */ 5201 */
3664 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 5202 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
3665 LibrarySpecificUnit unit = target; 5203 LibrarySpecificUnit unit = target;
3666 return <String, TaskInput>{ 5204 return <String, TaskInput>{
3667 UNIT_INPUT: RESOLVED_UNIT6.of(unit), 5205 UNIT_INPUT: RESOLVED_UNIT8.of(unit),
3668 LIBRARY_INPUT: LIBRARY_ELEMENT5.of(unit.library), 5206 LIBRARY_INPUT: LIBRARY_ELEMENT6.of(unit.library),
3669 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request), 5207 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request),
3670 // In strong mode, add additional dependencies to enforce inference 5208 // In strong mode, add additional dependencies to enforce inference
3671 // ordering. 5209 // ordering.
3672 5210
3673 // Require that static variable inference be complete for all units in 5211 // Require that static variable inference be complete for all units in
3674 // the current library cycle. 5212 // the current library cycle.
3675 'orderLibraryCycleTasks': LIBRARY_CYCLE_UNITS.of(unit).toList( 5213 'orderLibraryCycleTasks':
3676 (CompilationUnitElementImpl unit) => RESOLVED_UNIT6 5214 LIBRARY_CYCLE_UNITS.of(unit.library).toListOf(CREATED_RESOLVED_UNIT8),
3677 .of(new LibrarySpecificUnit(unit.librarySource, unit.source))),
3678 // Require that full inference be complete for all dependencies of the 5215 // Require that full inference be complete for all dependencies of the
3679 // current library cycle. 5216 // current library cycle.
3680 'orderLibraryCycles': LIBRARY_CYCLE_DEPENDENCIES.of(unit).toList( 5217 'orderLibraryCycles': LIBRARY_CYCLE_DEPENDENCIES
3681 (CompilationUnitElementImpl unit) => RESOLVED_UNIT8 5218 .of(unit.library)
3682 .of(new LibrarySpecificUnit(unit.librarySource, unit.source))) 5219 .toListOf(CREATED_RESOLVED_UNIT10)
3683 }; 5220 };
3684 } 5221 }
3685 5222
3686 /** 5223 /**
3687 * Create a [ResolveInstanceFieldsInUnitTask] based on the given [target] in 5224 * Create a [ResolveInstanceFieldsInUnitTask] based on the given [target] in
3688 * the given [context]. 5225 * the given [context].
3689 */ 5226 */
3690 static ResolveInstanceFieldsInUnitTask createTask( 5227 static ResolveInstanceFieldsInUnitTask createTask(
3691 AnalysisContext context, AnalysisTarget target) { 5228 AnalysisContext context, AnalysisTarget target) {
3692 return new ResolveInstanceFieldsInUnitTask(context, target); 5229 return new ResolveInstanceFieldsInUnitTask(context, target);
3693 } 5230 }
3694 } 5231 }
3695 5232
3696 /** 5233 /**
3697 * A task that finishes resolution by requesting [RESOLVED_UNIT_NO_CONSTANTS] fo r every 5234 * A task that finishes resolution by requesting [RESOLVED_UNIT11] for every
3698 * unit in the libraries closure and produces [LIBRARY_ELEMENT]. 5235 * unit in the libraries closure and produces [LIBRARY_ELEMENT9].
3699 */ 5236 */
3700 class ResolveLibraryReferencesTask extends SourceBasedAnalysisTask { 5237 class ResolveLibraryReferencesTask extends SourceBasedAnalysisTask {
3701 /** 5238 /**
3702 * The name of the [LIBRARY_ELEMENT5] input. 5239 * The name of the [LIBRARY_ELEMENT8] input.
3703 */ 5240 */
3704 static const String LIBRARY_INPUT = 'LIBRARY_INPUT'; 5241 static const String LIBRARY_INPUT = 'LIBRARY_INPUT';
3705
3706 /**
3707 * The name of the list of [RESOLVED_UNIT9] input.
3708 */
3709 static const String UNITS_INPUT = 'UNITS_INPUT';
3710 5242
3711 /** 5243 /**
3712 * The task descriptor describing this kind of task. 5244 * The task descriptor describing this kind of task.
3713 */ 5245 */
3714 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 5246 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
3715 'ResolveLibraryReferencesTask', 5247 'ResolveLibraryReferencesTask',
3716 createTask, 5248 createTask,
3717 buildInputs, 5249 buildInputs,
3718 <ResultDescriptor>[LIBRARY_ELEMENT, REFERENCED_NAMES]); 5250 <ResultDescriptor>[LIBRARY_ELEMENT9]);
3719 5251
3720 ResolveLibraryReferencesTask( 5252 ResolveLibraryReferencesTask(
3721 InternalAnalysisContext context, AnalysisTarget target) 5253 InternalAnalysisContext context, AnalysisTarget target)
3722 : super(context, target); 5254 : super(context, target);
3723 5255
3724 @override 5256 @override
3725 TaskDescriptor get descriptor => DESCRIPTOR; 5257 TaskDescriptor get descriptor => DESCRIPTOR;
3726 5258
3727 @override 5259 @override
3728 void internalPerform() { 5260 void internalPerform() {
5261 LibraryElement library = getRequiredInput(LIBRARY_INPUT);
5262 outputs[LIBRARY_ELEMENT9] = library;
5263 }
5264
5265 /**
5266 * Return a map from the names of the inputs of this kind of task to the task
5267 * input descriptors describing those inputs for a task with the
5268 * given [target].
5269 */
5270 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
5271 Source source = target;
5272 return <String, TaskInput>{
5273 LIBRARY_INPUT: LIBRARY_ELEMENT8.of(source),
5274 'resolvedUnits':
5275 LIBRARY_SPECIFIC_UNITS.of(source).toListOf(RESOLVED_UNIT11),
5276 };
5277 }
5278
5279 /**
5280 * Create a [ResolveLibraryReferencesTask] based on the given [target] in
5281 * the given [context].
5282 */
5283 static ResolveLibraryReferencesTask createTask(
5284 AnalysisContext context, AnalysisTarget target) {
5285 return new ResolveLibraryReferencesTask(context, target);
5286 }
5287 }
5288
5289 /**
5290 * A task that finishes resolution by requesting [RESOLVED_UNIT12] for every
5291 * unit in the libraries closure and produces [LIBRARY_ELEMENT].
5292 */
5293 class ResolveLibraryTask extends SourceBasedAnalysisTask {
5294 /**
5295 * The name of the [LIBRARY_ELEMENT9] input.
5296 */
5297 static const String LIBRARY_INPUT = 'LIBRARY_INPUT';
5298
5299 /**
5300 * The name of the list of [RESOLVED_UNIT12] input.
5301 */
5302 static const String UNITS_INPUT = 'UNITS_INPUT';
5303
5304 /**
5305 * The task descriptor describing this kind of task.
5306 */
5307 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
5308 'ResolveLibraryTask',
5309 createTask,
5310 buildInputs,
5311 <ResultDescriptor>[LIBRARY_ELEMENT]);
5312
5313 ResolveLibraryTask(InternalAnalysisContext context, AnalysisTarget target)
5314 : super(context, target);
5315
5316 @override
5317 TaskDescriptor get descriptor => DESCRIPTOR;
5318
5319 @override
5320 void internalPerform() {
3729 // 5321 //
3730 // Prepare inputs. 5322 // Prepare inputs.
3731 // 5323 //
3732 LibraryElement library = getRequiredInput(LIBRARY_INPUT); 5324 LibraryElement library = getRequiredInput(LIBRARY_INPUT);
3733 List<CompilationUnit> units = getRequiredInput(UNITS_INPUT);
3734 // Compute referenced names.
3735 ReferencedNames referencedNames = new ReferencedNames();
3736 for (CompilationUnit unit in units) {
3737 new ReferencedNamesBuilder(referencedNames).build(unit);
3738 }
3739 // 5325 //
3740 // Record outputs. 5326 // Record outputs.
3741 // 5327 //
3742 outputs[LIBRARY_ELEMENT] = library; 5328 outputs[LIBRARY_ELEMENT] = library;
3743 outputs[REFERENCED_NAMES] = referencedNames; 5329 }
3744 } 5330
3745 5331 /**
3746 /** 5332 * Return a map from the names of the inputs of this kind of task to the task
5333 * input descriptors describing those inputs for a task with the
5334 * given [target].
5335 */
5336 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
5337 Source source = target;
5338 return <String, TaskInput>{
5339 LIBRARY_INPUT: LIBRARY_ELEMENT9.of(source),
5340 'thisLibraryClosureIsReady': READY_RESOLVED_UNIT.of(source),
5341 };
5342 }
5343
5344 /**
5345 * Create a [ResolveLibraryTask] based on the given [target] in the given
5346 * [context].
5347 */
5348 static ResolveLibraryTask createTask(
5349 AnalysisContext context, AnalysisTarget target) {
5350 return new ResolveLibraryTask(context, target);
5351 }
5352 }
5353
5354 /**
5355 * An artificial task that does nothing except to force type names resolution
5356 * for the defining and part units of a library.
5357 */
5358 class ResolveLibraryTypeNamesTask extends SourceBasedAnalysisTask {
5359 /**
5360 * The name of the [LIBRARY_ELEMENT5] input.
5361 */
5362 static const String LIBRARY_INPUT = 'LIBRARY_INPUT';
5363
5364 /**
5365 * The name of the [TYPE_PROVIDER] input.
5366 */
5367 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT';
5368
5369 /**
5370 * The task descriptor describing this kind of task.
5371 */
5372 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
5373 'ResolveLibraryTypeNamesTask',
5374 createTask,
5375 buildInputs,
5376 <ResultDescriptor>[LIBRARY_ELEMENT6]);
5377
5378 ResolveLibraryTypeNamesTask(
5379 InternalAnalysisContext context, AnalysisTarget target)
5380 : super(context, target);
5381
5382 @override
5383 TaskDescriptor get descriptor => DESCRIPTOR;
5384
5385 @override
5386 void internalPerform() {
5387 //
5388 // Prepare inputs.
5389 //
5390 LibraryElement library = getRequiredInput(LIBRARY_INPUT);
5391 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT);
5392 //
5393 // Create the synthetic element for `loadLibrary`.
5394 //
5395 (library as LibraryElementImpl).createLoadLibraryFunction(typeProvider);
5396 //
5397 // Record outputs.
5398 //
5399 outputs[LIBRARY_ELEMENT6] = library;
5400 }
5401
5402 /**
5403 * Return a map from the names of the inputs of this kind of task to the task
5404 * input descriptors describing those inputs for a task with the
5405 * given [target].
5406 */
5407 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
5408 Source source = target;
5409 return <String, TaskInput>{
5410 'resolvedUnit':
5411 LIBRARY_SPECIFIC_UNITS.of(source).toListOf(RESOLVED_UNIT5),
5412 LIBRARY_INPUT: LIBRARY_ELEMENT5.of(source),
5413 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request)
5414 };
5415 }
5416
5417 /**
5418 * Create a [ResolveLibraryTypeNamesTask] based on the given [target] in
5419 * the given [context].
5420 */
5421 static ResolveLibraryTypeNamesTask createTask(
5422 AnalysisContext context, AnalysisTarget target) {
5423 return new ResolveLibraryTypeNamesTask(context, target);
5424 }
5425 }
5426
5427 /**
5428 * An artificial task that does nothing except to force type parameter bounds
5429 * type names resolution for the defining and part units of a library.
5430 */
5431 class ResolveTopLevelLibraryTypeBoundsTask extends SourceBasedAnalysisTask {
5432 /**
5433 * The name of the [LIBRARY_ELEMENT4] input.
5434 */
5435 static const String LIBRARY_INPUT = 'LIBRARY_INPUT';
5436
5437 /**
5438 * The task descriptor describing this kind of task.
5439 */
5440 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
5441 'ResolveTopLevelLibraryTypeBoundsTask',
5442 createTask,
5443 buildInputs,
5444 <ResultDescriptor>[LIBRARY_ELEMENT5]);
5445
5446 ResolveTopLevelLibraryTypeBoundsTask(
5447 InternalAnalysisContext context, AnalysisTarget target)
5448 : super(context, target);
5449
5450 @override
5451 TaskDescriptor get descriptor => DESCRIPTOR;
5452
5453 @override
5454 bool get handlesDependencyCycles => true;
5455
5456 @override
5457 void internalPerform() {
5458 LibraryElement library = getRequiredInput(LIBRARY_INPUT);
5459 outputs[LIBRARY_ELEMENT5] = library;
5460 }
5461
5462 /**
3747 * Return a map from the names of the inputs of this kind of task to the task 5463 * Return a map from the names of the inputs of this kind of task to the task
3748 * input descriptors describing those inputs for a task with the 5464 * input descriptors describing those inputs for a task with the
3749 * given [target]. 5465 * given [target].
3750 */ 5466 */
3751 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 5467 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
3752 Source source = target; 5468 Source source = target;
3753 return <String, TaskInput>{ 5469 return <String, TaskInput>{
3754 LIBRARY_INPUT: LIBRARY_ELEMENT5.of(source), 5470 LIBRARY_INPUT: LIBRARY_ELEMENT4.of(source),
3755 UNITS_INPUT: UNITS.of(source).toList((Source unit) => 5471 'thisLibraryUnitsReady':
3756 RESOLVED_UNIT9.of(new LibrarySpecificUnit(source, unit))), 5472 LIBRARY_SPECIFIC_UNITS.of(source).toListOf(RESOLVED_UNIT4),
3757 'resolvedUnits': IMPORT_EXPORT_SOURCE_CLOSURE 5473 'directlyImportedLibrariesReady':
3758 .of(source) 5474 IMPORTED_LIBRARIES.of(source).toListOf(LIBRARY_ELEMENT5),
3759 .toMapOf(UNITS) 5475 'directlyExportedLibrariesReady':
3760 .toFlattenList((Source library, Source unit) => 5476 EXPORTED_LIBRARIES.of(source).toListOf(LIBRARY_ELEMENT5),
3761 RESOLVED_UNIT9.of(new LibrarySpecificUnit(library, unit))),
3762 }; 5477 };
3763 } 5478 }
3764 5479
3765 /** 5480 /**
3766 * Create a [ResolveLibraryReferencesTask] based on the given [target] in 5481 * Create a [ResolveTopLevelLibraryTypeBoundsTask] based on the given [target]
3767 * the given [context]. 5482 * in the given [context].
3768 */ 5483 */
3769 static ResolveLibraryReferencesTask createTask( 5484 static ResolveTopLevelLibraryTypeBoundsTask createTask(
3770 AnalysisContext context, AnalysisTarget target) { 5485 AnalysisContext context, AnalysisTarget target) {
3771 return new ResolveLibraryReferencesTask(context, target); 5486 return new ResolveTopLevelLibraryTypeBoundsTask(context, target);
3772 } 5487 }
3773 } 5488 }
3774 5489
3775 /** 5490 /**
3776 * An artifitial task that does nothing except to force type names resolution 5491 * A task that builds [RESOLVED_UNIT4] for a unit.
3777 * for the defining and part units of a library.
3778 */ 5492 */
3779 class ResolveLibraryTypeNamesTask extends SourceBasedAnalysisTask { 5493 class ResolveTopLevelUnitTypeBoundsTask extends SourceBasedAnalysisTask {
3780 /** 5494 /**
3781 * The name of the [LIBRARY_ELEMENT4] input. 5495 * The name of the input whose value is the defining [LIBRARY_ELEMENT4].
3782 */ 5496 */
3783 static const String LIBRARY_INPUT = 'LIBRARY_INPUT'; 5497 static const String LIBRARY_INPUT = 'LIBRARY_INPUT';
3784 5498
3785 /** 5499 /**
5500 * The name of the [RESOLVED_UNIT3] input.
5501 */
5502 static const String UNIT_INPUT = 'UNIT_INPUT';
5503
5504 /**
5505 * The name of the [TYPE_PROVIDER] input.
5506 */
5507 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT';
5508
5509 /**
3786 * The task descriptor describing this kind of task. 5510 * The task descriptor describing this kind of task.
3787 */ 5511 */
3788 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 5512 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
3789 'ResolveLibraryTypeNamesTask', 5513 'ResolveTopLevelUnitTypeBoundsTask',
3790 createTask, 5514 createTask,
3791 buildInputs, 5515 buildInputs, <ResultDescriptor>[
3792 <ResultDescriptor>[LIBRARY_ELEMENT5]); 5516 RESOLVE_TYPE_BOUNDS_ERRORS,
5517 CREATED_RESOLVED_UNIT4,
5518 RESOLVED_UNIT4
5519 ]);
3793 5520
3794 ResolveLibraryTypeNamesTask( 5521 ResolveTopLevelUnitTypeBoundsTask(
3795 InternalAnalysisContext context, AnalysisTarget target) 5522 InternalAnalysisContext context, AnalysisTarget target)
3796 : super(context, target); 5523 : super(context, target);
3797 5524
3798 @override 5525 @override
3799 TaskDescriptor get descriptor => DESCRIPTOR; 5526 TaskDescriptor get descriptor => DESCRIPTOR;
3800 5527
3801 @override 5528 @override
3802 void internalPerform() { 5529 void internalPerform() {
5530 //
5531 // Prepare inputs.
5532 //
3803 LibraryElement library = getRequiredInput(LIBRARY_INPUT); 5533 LibraryElement library = getRequiredInput(LIBRARY_INPUT);
3804 outputs[LIBRARY_ELEMENT5] = library; 5534 CompilationUnit unit = getRequiredInput(UNIT_INPUT);
5535 CompilationUnitElement unitElement = unit.element;
5536 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT);
5537 //
5538 // Resolve TypeName nodes.
5539 //
5540 RecordingErrorListener errorListener = new RecordingErrorListener();
5541 new TypeParameterBoundsResolver(
5542 typeProvider, library, unitElement.source, errorListener)
5543 .resolveTypeBounds(unit);
5544 //
5545 // Record outputs.
5546 //
5547 outputs[RESOLVE_TYPE_BOUNDS_ERRORS] =
5548 getTargetSourceErrors(errorListener, target);
5549 outputs[RESOLVED_UNIT4] = unit;
5550 outputs[CREATED_RESOLVED_UNIT4] = true;
3805 } 5551 }
3806 5552
3807 /** 5553 /**
3808 * Return a map from the names of the inputs of this kind of task to the task 5554 * Return a map from the names of the inputs of this kind of task to the task
3809 * input descriptors describing those inputs for a task with the 5555 * input descriptors describing those inputs for a task with the
3810 * given [target]. 5556 * given [target].
3811 */ 5557 */
3812 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 5558 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
3813 Source source = target; 5559 // TODO(brianwilkerson) This task updates the element model to have type
5560 // information and updates the class hierarchy. It should produce a new
5561 // version of the element model in order to record those changes.
5562 LibrarySpecificUnit unit = target;
3814 return <String, TaskInput>{ 5563 return <String, TaskInput>{
3815 'resolvedUnit': UNITS.of(source).toList((Source unit) => 5564 'importsExportNamespace':
3816 RESOLVED_UNIT3.of(new LibrarySpecificUnit(source, unit))), 5565 IMPORTED_LIBRARIES.of(unit.library).toMapOf(LIBRARY_ELEMENT4),
3817 LIBRARY_INPUT: LIBRARY_ELEMENT4.of(source) 5566 'dependOnAllExportedSources':
5567 IMPORTED_LIBRARIES.of(unit.library).toMapOf(EXPORT_SOURCE_CLOSURE),
5568 LIBRARY_INPUT: LIBRARY_ELEMENT4.of(unit.library),
5569 UNIT_INPUT: RESOLVED_UNIT3.of(unit),
5570 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request)
3818 }; 5571 };
3819 } 5572 }
3820 5573
3821 /** 5574 /**
3822 * Create a [ResolveLibraryTypeNamesTask] based on the given [target] in 5575 * Create a [ResolveTopLevelUnitTypeBoundsTask] based on the given [target] in
3823 * the given [context]. 5576 * the given [context].
3824 */ 5577 */
3825 static ResolveLibraryTypeNamesTask createTask( 5578 static ResolveTopLevelUnitTypeBoundsTask createTask(
3826 AnalysisContext context, AnalysisTarget target) { 5579 AnalysisContext context, AnalysisTarget target) {
3827 return new ResolveLibraryTypeNamesTask(context, target); 5580 return new ResolveTopLevelUnitTypeBoundsTask(context, target);
3828 } 5581 }
3829 } 5582 }
3830 5583
3831 /** 5584 /**
3832 * A task that resolves the bodies of top-level functions, constructors, and 5585 * A task that resolves the bodies of top-level functions, constructors, and
3833 * methods within a single compilation unit. 5586 * methods within a single compilation unit.
3834 */ 5587 */
3835 class ResolveUnitTask extends SourceBasedAnalysisTask { 5588 class ResolveUnitTask extends SourceBasedAnalysisTask {
3836 /** 5589 /**
3837 * The name of the input whose value is the defining [LIBRARY_ELEMENT5]. 5590 * The name of the input whose value is the defining [LIBRARY_ELEMENT8].
3838 */ 5591 */
3839 static const String LIBRARY_INPUT = 'LIBRARY_INPUT'; 5592 static const String LIBRARY_INPUT = 'LIBRARY_INPUT';
3840 5593
3841 /** 5594 /**
3842 * The name of the [TYPE_PROVIDER] input. 5595 * The name of the [TYPE_PROVIDER] input.
3843 */ 5596 */
3844 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT'; 5597 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT';
3845 5598
3846 /** 5599 /**
3847 * The name of the [RESOLVED_UNIT8] input. 5600 * The name of the [RESOLVED_UNIT10] input.
3848 */ 5601 */
3849 static const String UNIT_INPUT = 'UNIT_INPUT'; 5602 static const String UNIT_INPUT = 'UNIT_INPUT';
3850 5603
3851 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 5604 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
3852 'ResolveUnitTask', 5605 'ResolveUnitTask', createTask, buildInputs, <ResultDescriptor>[
3853 createTask, 5606 CONSTANT_EXPRESSIONS_DEPENDENCIES,
3854 buildInputs, 5607 RESOLVE_UNIT_ERRORS,
3855 <ResultDescriptor>[RESOLVE_UNIT_ERRORS, RESOLVED_UNIT9]); 5608 CREATED_RESOLVED_UNIT11,
5609 RESOLVED_UNIT11
5610 ]);
3856 5611
3857 ResolveUnitTask( 5612 ResolveUnitTask(
3858 InternalAnalysisContext context, LibrarySpecificUnit compilationUnit) 5613 InternalAnalysisContext context, LibrarySpecificUnit compilationUnit)
3859 : super(context, compilationUnit); 5614 : super(context, compilationUnit);
3860 5615
3861 @override 5616 @override
3862 TaskDescriptor get descriptor => DESCRIPTOR; 5617 TaskDescriptor get descriptor => DESCRIPTOR;
3863 5618
3864 @override 5619 @override
3865 void internalPerform() { 5620 void internalPerform() {
3866 // 5621 //
3867 // Prepare inputs. 5622 // Prepare inputs.
3868 // 5623 //
5624 LibrarySpecificUnit target = this.target;
3869 LibraryElement libraryElement = getRequiredInput(LIBRARY_INPUT); 5625 LibraryElement libraryElement = getRequiredInput(LIBRARY_INPUT);
3870 CompilationUnit unit = getRequiredInput(UNIT_INPUT); 5626 CompilationUnit unit = getRequiredInput(UNIT_INPUT);
3871 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT); 5627 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT);
3872 // 5628 //
3873 // Resolve everything. 5629 // Resolve everything.
3874 // 5630 //
3875 CompilationUnitElement unitElement = unit.element; 5631 CompilationUnitElement unitElement = unit.element;
3876 RecordingErrorListener errorListener = new RecordingErrorListener(); 5632 RecordingErrorListener errorListener = new RecordingErrorListener();
3877 ResolverVisitor visitor = new ResolverVisitor( 5633 ResolverVisitor visitor = new ResolverVisitor(
3878 libraryElement, unitElement.source, typeProvider, errorListener); 5634 libraryElement, unitElement.source, typeProvider, errorListener);
3879 unit.accept(visitor); 5635 unit.accept(visitor);
3880 // 5636 //
5637 // Compute constant expressions' dependencies.
5638 //
5639 List<ConstantEvaluationTarget> constExprDependencies;
5640 {
5641 ConstantExpressionsDependenciesFinder finder =
5642 new ConstantExpressionsDependenciesFinder();
5643 unit.accept(finder);
5644 constExprDependencies = finder.dependencies.toList();
5645 }
5646 //
3881 // Record outputs. 5647 // Record outputs.
3882 // 5648 //
3883 outputs[RESOLVE_UNIT_ERRORS] = errorListener.errors; 5649 // TODO(brianwilkerson) This task modifies the element model (by copying the
3884 outputs[RESOLVED_UNIT9] = unit; 5650 // AST's for constructor initializers into it) but does not produce an
5651 // updated version of the element model.
5652 //
5653 outputs[CONSTANT_EXPRESSIONS_DEPENDENCIES] = constExprDependencies;
5654 outputs[RESOLVE_UNIT_ERRORS] = getTargetSourceErrors(errorListener, target);
5655 outputs[RESOLVED_UNIT11] = unit;
5656 outputs[CREATED_RESOLVED_UNIT11] = true;
3885 } 5657 }
3886 5658
3887 /** 5659 /**
3888 * Return a map from the names of the inputs of this kind of task to the task 5660 * Return a map from the names of the inputs of this kind of task to the task
3889 * input descriptors describing those inputs for a task with the given 5661 * input descriptors describing those inputs for a task with the given
3890 * [target]. 5662 * [target].
3891 */ 5663 */
3892 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 5664 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
3893 LibrarySpecificUnit unit = target; 5665 LibrarySpecificUnit unit = target;
3894 return <String, TaskInput>{ 5666 return <String, TaskInput>{
3895 LIBRARY_INPUT: LIBRARY_ELEMENT5.of(unit.library), 5667 LIBRARY_INPUT: LIBRARY_ELEMENT8.of(unit.library),
3896 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request), 5668 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request),
3897 UNIT_INPUT: RESOLVED_UNIT8.of(unit), 5669 UNIT_INPUT: RESOLVED_UNIT10.of(unit),
3898 // In strong mode, add additional dependencies to enforce inference 5670 // In strong mode, add additional dependencies to enforce inference
3899 // ordering. 5671 // ordering.
3900 5672
3901 // Require that inference be complete for all units in the 5673 // Require that inference be complete for all units in the
3902 // current library cycle. 5674 // current library cycle.
3903 'orderLibraryCycleTasks': LIBRARY_CYCLE_UNITS.of(unit).toList( 5675 'orderLibraryCycleTasks':
3904 (CompilationUnitElementImpl unit) => RESOLVED_UNIT8 5676 LIBRARY_CYCLE_UNITS.of(unit.library).toListOf(CREATED_RESOLVED_UNIT10)
3905 .of(new LibrarySpecificUnit(unit.librarySource, unit.source)))
3906 }; 5677 };
3907 } 5678 }
3908 5679
3909 /** 5680 /**
3910 * Create a [ResolveUnitTask] based on the given [target] in 5681 * Create a [ResolveUnitTask] based on the given [target] in
3911 * the given [context]. 5682 * the given [context].
3912 */ 5683 */
3913 static ResolveUnitTask createTask( 5684 static ResolveUnitTask createTask(
3914 AnalysisContext context, AnalysisTarget target) { 5685 AnalysisContext context, AnalysisTarget target) {
3915 return new ResolveUnitTask(context, target); 5686 return new ResolveUnitTask(context, target);
3916 } 5687 }
3917 } 5688 }
3918 5689
3919 /** 5690 /**
3920 * A task that builds [RESOLVED_UNIT3] for a unit. 5691 * A task that builds [RESOLVED_UNIT5] for a unit.
3921 */ 5692 */
3922 class ResolveUnitTypeNamesTask extends SourceBasedAnalysisTask { 5693 class ResolveUnitTypeNamesTask extends SourceBasedAnalysisTask {
3923 /** 5694 /**
3924 * The name of the input whose value is the defining [LIBRARY_ELEMENT4]. 5695 * The name of the input whose value is the defining [LIBRARY_ELEMENT5].
3925 */ 5696 */
3926 static const String LIBRARY_INPUT = 'LIBRARY_INPUT'; 5697 static const String LIBRARY_INPUT = 'LIBRARY_INPUT';
3927 5698
3928 /** 5699 /**
3929 * The name of the [RESOLVED_UNIT2] input. 5700 * The name of the [RESOLVED_UNIT4] input.
3930 */ 5701 */
3931 static const String UNIT_INPUT = 'UNIT_INPUT'; 5702 static const String UNIT_INPUT = 'UNIT_INPUT';
3932 5703
3933 /** 5704 /**
3934 * The name of the [TYPE_PROVIDER] input. 5705 * The name of the [TYPE_PROVIDER] input.
3935 */ 5706 */
3936 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT'; 5707 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT';
3937 5708
3938 /** 5709 /**
3939 * The task descriptor describing this kind of task. 5710 * The task descriptor describing this kind of task.
3940 */ 5711 */
3941 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 5712 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
3942 'ResolveUnitTypeNamesTask', 5713 'ResolveUnitTypeNamesTask', createTask, buildInputs, <ResultDescriptor>[
3943 createTask, 5714 RESOLVE_TYPE_NAMES_ERRORS,
3944 buildInputs, 5715 CREATED_RESOLVED_UNIT5,
3945 <ResultDescriptor>[RESOLVE_TYPE_NAMES_ERRORS, RESOLVED_UNIT3]); 5716 RESOLVED_UNIT5
5717 ]);
3946 5718
3947 ResolveUnitTypeNamesTask( 5719 ResolveUnitTypeNamesTask(
3948 InternalAnalysisContext context, AnalysisTarget target) 5720 InternalAnalysisContext context, AnalysisTarget target)
3949 : super(context, target); 5721 : super(context, target);
3950 5722
3951 @override 5723 @override
3952 TaskDescriptor get descriptor => DESCRIPTOR; 5724 TaskDescriptor get descriptor => DESCRIPTOR;
3953 5725
3954 @override 5726 @override
3955 void internalPerform() { 5727 void internalPerform() {
3956 // 5728 //
3957 // Prepare inputs. 5729 // Prepare inputs.
3958 // 5730 //
3959 LibraryElement library = getRequiredInput(LIBRARY_INPUT); 5731 LibraryElement library = getRequiredInput(LIBRARY_INPUT);
3960 CompilationUnit unit = getRequiredInput(UNIT_INPUT); 5732 CompilationUnit unit = getRequiredInput(UNIT_INPUT);
3961 CompilationUnitElement unitElement = unit.element; 5733 CompilationUnitElement unitElement = unit.element;
3962 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT); 5734 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT);
3963 // 5735 //
3964 // Resolve TypeName nodes. 5736 // Resolve TypeName nodes.
3965 // 5737 //
3966 RecordingErrorListener errorListener = new RecordingErrorListener(); 5738 RecordingErrorListener errorListener = new RecordingErrorListener();
3967 TypeResolverVisitor visitor = new TypeResolverVisitor( 5739 TypeResolverVisitor visitor = new TypeResolverVisitor(
3968 library, unitElement.source, typeProvider, errorListener); 5740 library, unitElement.source, typeProvider, errorListener);
3969 unit.accept(visitor); 5741 unit.accept(visitor);
3970 // 5742 //
3971 // Record outputs. 5743 // Record outputs.
3972 // 5744 //
3973 outputs[RESOLVE_TYPE_NAMES_ERRORS] = 5745 outputs[RESOLVE_TYPE_NAMES_ERRORS] =
3974 removeDuplicateErrors(errorListener.errors); 5746 getTargetSourceErrors(errorListener, target);
3975 outputs[RESOLVED_UNIT3] = unit; 5747 outputs[RESOLVED_UNIT5] = unit;
5748 outputs[CREATED_RESOLVED_UNIT5] = true;
3976 } 5749 }
3977 5750
3978 /** 5751 /**
3979 * Return a map from the names of the inputs of this kind of task to the task 5752 * Return a map from the names of the inputs of this kind of task to the task
3980 * input descriptors describing those inputs for a task with the 5753 * input descriptors describing those inputs for a task with the
3981 * given [target]. 5754 * given [target].
3982 */ 5755 */
3983 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 5756 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
3984 // TODO(brianwilkerson) This task updates the element model to have type 5757 // TODO(brianwilkerson) This task updates the element model to have type
3985 // information and updates the class hierarchy. It should produce a new 5758 // information and updates the class hierarchy. It should produce a new
3986 // version of the element model in order to record those changes. 5759 // version of the element model in order to record those changes.
3987 LibrarySpecificUnit unit = target; 5760 LibrarySpecificUnit unit = target;
3988 return <String, TaskInput>{ 5761 return <String, TaskInput>{
3989 'importsExportNamespace': 5762 LIBRARY_INPUT: LIBRARY_ELEMENT5.of(unit.library),
3990 IMPORTED_LIBRARIES.of(unit.library).toMapOf(LIBRARY_ELEMENT4), 5763 UNIT_INPUT: RESOLVED_UNIT4.of(unit),
3991 LIBRARY_INPUT: LIBRARY_ELEMENT4.of(unit.library),
3992 UNIT_INPUT: RESOLVED_UNIT2.of(unit),
3993 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request) 5764 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request)
3994 }; 5765 };
3995 } 5766 }
3996 5767
3997 /** 5768 /**
3998 * Create a [ResolveUnitTypeNamesTask] based on the given [target] in 5769 * Create a [ResolveUnitTypeNamesTask] based on the given [target] in
3999 * the given [context]. 5770 * the given [context].
4000 */ 5771 */
4001 static ResolveUnitTypeNamesTask createTask( 5772 static ResolveUnitTypeNamesTask createTask(
4002 AnalysisContext context, AnalysisTarget target) { 5773 AnalysisContext context, AnalysisTarget target) {
4003 return new ResolveUnitTypeNamesTask(context, target); 5774 return new ResolveUnitTypeNamesTask(context, target);
4004 } 5775 }
4005 } 5776 }
4006 5777
4007 /** 5778 /**
4008 * A task that builds [RESOLVED_UNIT4] for a unit. 5779 * A task that builds [RESOLVED_UNIT6] for a unit.
4009 */ 5780 */
4010 class ResolveVariableReferencesTask extends SourceBasedAnalysisTask { 5781 class ResolveVariableReferencesTask extends SourceBasedAnalysisTask {
4011 /** 5782 /**
4012 * The name of the [LIBRARY_ELEMENT1] input. 5783 * The name of the [LIBRARY_ELEMENT1] input.
4013 */ 5784 */
4014 static const String LIBRARY_INPUT = 'LIBRARY_INPUT'; 5785 static const String LIBRARY_INPUT = 'LIBRARY_INPUT';
4015 5786
4016 /** 5787 /**
4017 * The name of the [RESOLVED_UNIT3] input. 5788 * The name of the [RESOLVED_UNIT5] input.
4018 */ 5789 */
4019 static const String UNIT_INPUT = 'UNIT_INPUT'; 5790 static const String UNIT_INPUT = 'UNIT_INPUT';
4020 5791
4021 /** 5792 /**
4022 * The name of the [TYPE_PROVIDER] input. 5793 * The name of the [TYPE_PROVIDER] input.
4023 */ 5794 */
4024 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT'; 5795 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT';
4025 5796
4026 /** 5797 /**
4027 * The task descriptor describing this kind of task. 5798 * The task descriptor describing this kind of task.
4028 */ 5799 */
4029 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 5800 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
4030 'ResolveVariableReferencesTask', 5801 'ResolveVariableReferencesTask',
4031 createTask, 5802 createTask,
4032 buildInputs, 5803 buildInputs, <ResultDescriptor>[
4033 <ResultDescriptor>[RESOLVED_UNIT4, VARIABLE_REFERENCE_ERRORS]); 5804 CREATED_RESOLVED_UNIT6,
5805 RESOLVED_UNIT6,
5806 VARIABLE_REFERENCE_ERRORS
5807 ]);
4034 5808
4035 ResolveVariableReferencesTask( 5809 ResolveVariableReferencesTask(
4036 InternalAnalysisContext context, AnalysisTarget target) 5810 InternalAnalysisContext context, AnalysisTarget target)
4037 : super(context, target); 5811 : super(context, target);
4038 5812
4039 @override 5813 @override
4040 TaskDescriptor get descriptor => DESCRIPTOR; 5814 TaskDescriptor get descriptor => DESCRIPTOR;
4041 5815
4042 @override 5816 @override
4043 void internalPerform() { 5817 void internalPerform() {
4044 // 5818 //
4045 // Prepare inputs. 5819 // Prepare inputs.
4046 // 5820 //
4047 LibraryElement libraryElement = getRequiredInput(LIBRARY_INPUT); 5821 LibraryElement libraryElement = getRequiredInput(LIBRARY_INPUT);
4048 CompilationUnit unit = getRequiredInput(UNIT_INPUT); 5822 CompilationUnit unit = getRequiredInput(UNIT_INPUT);
4049 CompilationUnitElement unitElement = unit.element; 5823 CompilationUnitElement unitElement = unit.element;
4050 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT); 5824 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT);
4051 // 5825 //
4052 // Resolve local variables. 5826 // Resolve local variables.
4053 // 5827 //
4054 RecordingErrorListener errorListener = new RecordingErrorListener(); 5828 RecordingErrorListener errorListener = new RecordingErrorListener();
4055 Scope nameScope = new LibraryScope(libraryElement, errorListener); 5829 Scope nameScope = new LibraryScope(libraryElement);
4056 VariableResolverVisitor visitor = new VariableResolverVisitor( 5830 VariableResolverVisitor visitor = new VariableResolverVisitor(
4057 libraryElement, unitElement.source, typeProvider, errorListener, 5831 libraryElement, unitElement.source, typeProvider, errorListener,
4058 nameScope: nameScope); 5832 nameScope: nameScope);
4059 unit.accept(visitor); 5833 unit.accept(visitor);
4060 // 5834 //
4061 // Record outputs. 5835 // Record outputs.
4062 // 5836 //
4063 outputs[RESOLVED_UNIT4] = unit; 5837 outputs[RESOLVED_UNIT6] = unit;
5838 outputs[CREATED_RESOLVED_UNIT6] = true;
4064 outputs[VARIABLE_REFERENCE_ERRORS] = 5839 outputs[VARIABLE_REFERENCE_ERRORS] =
4065 removeDuplicateErrors(errorListener.errors); 5840 getTargetSourceErrors(errorListener, target);
4066 } 5841 }
4067 5842
4068 /** 5843 /**
4069 * Return a map from the names of the inputs of this kind of task to the task 5844 * Return a map from the names of the inputs of this kind of task to the task
4070 * input descriptors describing those inputs for a task with the 5845 * input descriptors describing those inputs for a task with the
4071 * given [target]. 5846 * given [target].
4072 */ 5847 */
4073 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 5848 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
4074 LibrarySpecificUnit unit = target; 5849 LibrarySpecificUnit unit = target;
4075 return <String, TaskInput>{ 5850 return <String, TaskInput>{
4076 LIBRARY_INPUT: LIBRARY_ELEMENT1.of(unit.library), 5851 LIBRARY_INPUT: LIBRARY_ELEMENT1.of(unit.library),
4077 UNIT_INPUT: RESOLVED_UNIT3.of(unit), 5852 UNIT_INPUT: RESOLVED_UNIT5.of(unit),
4078 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request) 5853 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request)
4079 }; 5854 };
4080 } 5855 }
4081 5856
4082 /** 5857 /**
4083 * Create a [ResolveVariableReferencesTask] based on the given [target] in 5858 * Create a [ResolveVariableReferencesTask] based on the given [target] in
4084 * the given [context]. 5859 * the given [context].
4085 */ 5860 */
4086 static ResolveVariableReferencesTask createTask( 5861 static ResolveVariableReferencesTask createTask(
4087 AnalysisContext context, AnalysisTarget target) { 5862 AnalysisContext context, AnalysisTarget target) {
4088 return new ResolveVariableReferencesTask(context, target); 5863 return new ResolveVariableReferencesTask(context, target);
4089 } 5864 }
4090 } 5865 }
4091 5866
4092 /** 5867 /**
4093 * A task that scans the content of a Dart file, producing a stream of Dart 5868 * A task that scans the content of a Dart file, producing a stream of Dart
4094 * tokens, line information, and any lexical errors encountered in the process. 5869 * tokens, line information, and any lexical errors encountered in the process.
4095 */ 5870 */
4096 class ScanDartTask extends SourceBasedAnalysisTask { 5871 class ScanDartTask extends SourceBasedAnalysisTask {
4097 /** 5872 /**
4098 * The name of the input whose value is the content of the file. 5873 * The name of the input whose value is the content of the file.
4099 */ 5874 */
4100 static const String CONTENT_INPUT_NAME = 'CONTENT_INPUT_NAME'; 5875 static const String CONTENT_INPUT_NAME = 'CONTENT_INPUT_NAME';
4101 5876
4102 /** 5877 /**
5878 * The name of the input whose value is the modification time of the file.
5879 */
5880 static const String MODIFICATION_TIME_INPUT = 'MODIFICATION_TIME_INPUT';
5881
5882 /**
4103 * The task descriptor describing this kind of task. 5883 * The task descriptor describing this kind of task.
4104 */ 5884 */
4105 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 5885 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
4106 'ScanDartTask', 5886 'ScanDartTask',
4107 createTask, 5887 createTask,
4108 buildInputs, 5888 buildInputs,
4109 <ResultDescriptor>[LINE_INFO, SCAN_ERRORS, TOKEN_STREAM]); 5889 <ResultDescriptor>[IGNORE_INFO, LINE_INFO, SCAN_ERRORS, TOKEN_STREAM],
5890 suitabilityFor: suitabilityFor);
4110 5891
4111 /** 5892 /**
4112 * Initialize a newly created task to access the content of the source 5893 * Initialize a newly created task to access the content of the source
4113 * associated with the given [target] in the given [context]. 5894 * associated with the given [target] in the given [context].
4114 */ 5895 */
4115 ScanDartTask(InternalAnalysisContext context, AnalysisTarget target) 5896 ScanDartTask(InternalAnalysisContext context, AnalysisTarget target)
4116 : super(context, target); 5897 : super(context, target);
4117 5898
4118 @override 5899 @override
4119 TaskDescriptor get descriptor => DESCRIPTOR; 5900 TaskDescriptor get descriptor => DESCRIPTOR;
4120 5901
4121 @override 5902 @override
4122 void internalPerform() { 5903 void internalPerform() {
4123 Source source = getRequiredSource(); 5904 Source source = getRequiredSource();
5905 RecordingErrorListener errorListener = new RecordingErrorListener();
4124 5906
4125 RecordingErrorListener errorListener = new RecordingErrorListener(); 5907 int modificationTime = getRequiredInput(MODIFICATION_TIME_INPUT);
4126 if (context.getModificationStamp(target.source) < 0) { 5908 if (modificationTime < 0) {
4127 String message = 'Content could not be read'; 5909 String message = 'Content could not be read';
4128 if (context is InternalAnalysisContext) { 5910 if (context is InternalAnalysisContext) {
4129 CacheEntry entry = 5911 CacheEntry entry =
4130 (context as InternalAnalysisContext).getCacheEntry(target); 5912 (context as InternalAnalysisContext).getCacheEntry(target);
4131 CaughtException exception = entry.exception; 5913 CaughtException exception = entry.exception;
4132 if (exception != null) { 5914 if (exception != null) {
4133 message = exception.toString(); 5915 message = exception.toString();
4134 } 5916 }
4135 } 5917 }
4136 if (source.exists()) { 5918 if (source.exists()) {
(...skipping 11 matching lines...) Expand all
4148 'Cannot scan scripts with multiple fragments'); 5930 'Cannot scan scripts with multiple fragments');
4149 } 5931 }
4150 ScriptFragment fragment = fragments[0]; 5932 ScriptFragment fragment = fragments[0];
4151 5933
4152 Scanner scanner = new Scanner( 5934 Scanner scanner = new Scanner(
4153 source, 5935 source,
4154 new SubSequenceReader(fragment.content, fragment.offset), 5936 new SubSequenceReader(fragment.content, fragment.offset),
4155 errorListener); 5937 errorListener);
4156 scanner.setSourceStart(fragment.line, fragment.column); 5938 scanner.setSourceStart(fragment.line, fragment.column);
4157 scanner.preserveComments = context.analysisOptions.preserveComments; 5939 scanner.preserveComments = context.analysisOptions.preserveComments;
5940 scanner.scanGenericMethodComments = context.analysisOptions.strongMode;
5941 scanner.scanLazyAssignmentOperators =
5942 context.analysisOptions.enableLazyAssignmentOperators;
5943
5944 LineInfo lineInfo = new LineInfo(scanner.lineStarts);
4158 5945
4159 outputs[TOKEN_STREAM] = scanner.tokenize(); 5946 outputs[TOKEN_STREAM] = scanner.tokenize();
4160 outputs[LINE_INFO] = new LineInfo(scanner.lineStarts); 5947 outputs[LINE_INFO] = lineInfo;
4161 outputs[SCAN_ERRORS] = removeDuplicateErrors(errorListener.errors); 5948 outputs[IGNORE_INFO] =
5949 IgnoreInfo.calculateIgnores(fragment.content, lineInfo);
5950 outputs[SCAN_ERRORS] = getUniqueErrors(errorListener.errors);
4162 } else if (target is Source) { 5951 } else if (target is Source) {
4163 String content = getRequiredInput(CONTENT_INPUT_NAME); 5952 String content = getRequiredInput(CONTENT_INPUT_NAME);
4164 5953
4165 Scanner scanner = 5954 Scanner scanner =
4166 new Scanner(source, new CharSequenceReader(content), errorListener); 5955 new Scanner(source, new CharSequenceReader(content), errorListener);
4167 scanner.preserveComments = context.analysisOptions.preserveComments; 5956 scanner.preserveComments = context.analysisOptions.preserveComments;
5957 scanner.scanGenericMethodComments = context.analysisOptions.strongMode;
5958 scanner.scanLazyAssignmentOperators =
5959 context.analysisOptions.enableLazyAssignmentOperators;
5960
5961 LineInfo lineInfo = new LineInfo(scanner.lineStarts);
4168 5962
4169 outputs[TOKEN_STREAM] = scanner.tokenize(); 5963 outputs[TOKEN_STREAM] = scanner.tokenize();
4170 outputs[LINE_INFO] = new LineInfo(scanner.lineStarts); 5964 outputs[LINE_INFO] = lineInfo;
4171 outputs[SCAN_ERRORS] = removeDuplicateErrors(errorListener.errors); 5965 outputs[IGNORE_INFO] = IgnoreInfo.calculateIgnores(content, lineInfo);
5966 outputs[SCAN_ERRORS] = getUniqueErrors(errorListener.errors);
4172 } else { 5967 } else {
4173 throw new AnalysisException( 5968 throw new AnalysisException(
4174 'Cannot scan Dart code from a ${target.runtimeType}'); 5969 'Cannot scan Dart code from a ${target.runtimeType}');
4175 } 5970 }
4176 } 5971 }
4177 5972
4178 /** 5973 /**
4179 * Return a map from the names of the inputs of this kind of task to the task 5974 * Return a map from the names of the inputs of this kind of task to the task
4180 * input descriptors describing those inputs for a task with the given 5975 * input descriptors describing those inputs for a task with the given
4181 * [source]. 5976 * [target].
4182 */ 5977 */
4183 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 5978 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
4184 if (target is Source) { 5979 if (target is Source) {
4185 return <String, TaskInput>{CONTENT_INPUT_NAME: CONTENT.of(target)}; 5980 return <String, TaskInput>{
5981 CONTENT_INPUT_NAME: CONTENT.of(target, flushOnAccess: true),
5982 MODIFICATION_TIME_INPUT: MODIFICATION_TIME.of(target)
5983 };
4186 } else if (target is DartScript) { 5984 } else if (target is DartScript) {
4187 // This task does not use the following input; it is included only to add 5985 // This task does not use the following input; it is included only to add
4188 // a dependency between this value and the containing source so that when 5986 // a dependency between this value and the containing source so that when
4189 // the containing source is modified these results will be invalidated. 5987 // the containing source is modified these results will be invalidated.
4190 return <String, TaskInput>{'-': DART_SCRIPTS.of(target.source)}; 5988 Source source = target.source;
5989 return <String, TaskInput>{
5990 '-': DART_SCRIPTS.of(source),
5991 MODIFICATION_TIME_INPUT: MODIFICATION_TIME.of(source)
5992 };
4191 } 5993 }
4192 throw new AnalysisException( 5994 throw new AnalysisException(
4193 'Cannot build inputs for a ${target.runtimeType}'); 5995 'Cannot build inputs for a ${target.runtimeType}');
4194 } 5996 }
4195 5997
4196 /** 5998 /**
4197 * Create a [ScanDartTask] based on the given [target] in the given [context]. 5999 * Create a [ScanDartTask] based on the given [target] in the given [context].
4198 */ 6000 */
4199 static ScanDartTask createTask( 6001 static ScanDartTask createTask(
4200 AnalysisContext context, AnalysisTarget target) { 6002 AnalysisContext context, AnalysisTarget target) {
4201 return new ScanDartTask(context, target); 6003 return new ScanDartTask(context, target);
4202 } 6004 }
6005
6006 /**
6007 * Return an indication of how suitable this task is for the given [target].
6008 */
6009 static TaskSuitability suitabilityFor(AnalysisTarget target) {
6010 if (target is Source) {
6011 if (target.shortName.endsWith(AnalysisEngine.SUFFIX_DART)) {
6012 return TaskSuitability.HIGHEST;
6013 }
6014 return TaskSuitability.LOWEST;
6015 } else if (target is DartScript) {
6016 return TaskSuitability.HIGHEST;
6017 }
6018 return TaskSuitability.NONE;
6019 }
4203 } 6020 }
4204 6021
4205 /** 6022 /**
4206 * A task that builds [STRONG_MODE_ERRORS] for a unit. Also builds 6023 * A task that builds [STRONG_MODE_ERRORS] for a unit. Also builds
4207 * [RESOLVED_UNIT] for a unit. 6024 * [RESOLVED_UNIT] for a unit.
4208 */ 6025 */
4209 class StrongModeVerifyUnitTask extends SourceBasedAnalysisTask { 6026 class StrongModeVerifyUnitTask extends SourceBasedAnalysisTask {
4210 /** 6027 /**
4211 * The name of the [RESOLVED_UNIT10] input. 6028 * The name of the [RESOLVED_UNIT12] input.
4212 */ 6029 */
4213 static const String UNIT_INPUT = 'UNIT_INPUT'; 6030 static const String UNIT_INPUT = 'UNIT_INPUT';
4214 6031
4215 /** 6032 /**
4216 * The name of the [TYPE_PROVIDER] input. 6033 * The name of the [TYPE_PROVIDER] input.
4217 */ 6034 */
4218 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT'; 6035 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT';
4219 6036
4220 /** 6037 /**
4221 * The task descriptor describing this kind of task. 6038 * The task descriptor describing this kind of task.
4222 */ 6039 */
4223 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 6040 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
4224 'StrongModeVerifyUnitTask', 6041 'StrongModeVerifyUnitTask', createTask, buildInputs, <ResultDescriptor>[
4225 createTask, 6042 STRONG_MODE_ERRORS,
4226 buildInputs, 6043 CREATED_RESOLVED_UNIT,
4227 <ResultDescriptor>[STRONG_MODE_ERRORS, RESOLVED_UNIT]); 6044 RESOLVED_UNIT
6045 ]);
4228 6046
4229 StrongModeVerifyUnitTask( 6047 StrongModeVerifyUnitTask(
4230 InternalAnalysisContext context, AnalysisTarget target) 6048 InternalAnalysisContext context, AnalysisTarget target)
4231 : super(context, target); 6049 : super(context, target);
4232 6050
4233 @override 6051 @override
4234 TaskDescriptor get descriptor => DESCRIPTOR; 6052 TaskDescriptor get descriptor => DESCRIPTOR;
4235 6053
4236 @override 6054 @override
4237 void internalPerform() { 6055 void internalPerform() {
4238 RecordingErrorListener errorListener = new RecordingErrorListener(); 6056 RecordingErrorListener errorListener = new RecordingErrorListener();
4239 // 6057 //
4240 // Prepare inputs. 6058 // Prepare inputs.
4241 // 6059 //
4242 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT); 6060 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT);
4243 CompilationUnit unit = getRequiredInput(UNIT_INPUT); 6061 CompilationUnit unit = getRequiredInput(UNIT_INPUT);
4244 if (context.analysisOptions.strongMode) { 6062 AnalysisOptionsImpl options = context.analysisOptions;
4245 unit.accept(new CodeChecker(new TypeRules(typeProvider), errorListener)); 6063 if (options.strongMode) {
6064 CodeChecker checker = new CodeChecker(
6065 typeProvider,
6066 new StrongTypeSystemImpl(
6067 implicitCasts: options.implicitCasts,
6068 nonnullableTypes: options.nonnullableTypes),
6069 errorListener,
6070 options);
6071 checker.visitCompilationUnit(unit);
4246 } 6072 }
4247
4248 // 6073 //
4249 // Record outputs. 6074 // Record outputs.
4250 // 6075 //
4251 outputs[STRONG_MODE_ERRORS] = removeDuplicateErrors(errorListener.errors); 6076 outputs[STRONG_MODE_ERRORS] = getUniqueErrors(errorListener.errors);
6077 outputs[CREATED_RESOLVED_UNIT] = true;
4252 outputs[RESOLVED_UNIT] = unit; 6078 outputs[RESOLVED_UNIT] = unit;
4253 } 6079 }
4254 6080
4255 /** 6081 /**
4256 * Return a map from the names of the inputs of this kind of task to the task 6082 * Return a map from the names of the inputs of this kind of task to the task
4257 * input descriptors describing those inputs for a task with the 6083 * input descriptors describing those inputs for a task with the
4258 * given [target]. 6084 * given [target].
4259 */ 6085 */
4260 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 6086 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
4261 LibrarySpecificUnit unit = target; 6087 LibrarySpecificUnit unit = target;
4262 return <String, TaskInput>{ 6088 return <String, TaskInput>{
4263 'resolvedUnits': IMPORT_EXPORT_SOURCE_CLOSURE 6089 UNIT_INPUT: RESOLVED_UNIT12.of(unit),
4264 .of(unit.library) 6090 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request),
4265 .toMapOf(UNITS)
4266 .toFlattenList((Source library, Source unit) =>
4267 RESOLVED_UNIT10.of(new LibrarySpecificUnit(library, unit))),
4268 UNIT_INPUT: RESOLVED_UNIT10.of(unit),
4269 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request)
4270 }; 6091 };
4271 } 6092 }
4272 6093
4273 /** 6094 /**
4274 * Create a [StrongModeVerifyUnitTask] based on the given [target] in 6095 * Create a [StrongModeVerifyUnitTask] based on the given [target] in
4275 * the given [context]. 6096 * the given [context].
4276 */ 6097 */
4277 static StrongModeVerifyUnitTask createTask( 6098 static StrongModeVerifyUnitTask createTask(
4278 AnalysisContext context, AnalysisTarget target) { 6099 AnalysisContext context, AnalysisTarget target) {
4279 return new StrongModeVerifyUnitTask(context, target); 6100 return new StrongModeVerifyUnitTask(context, target);
4280 } 6101 }
4281 } 6102 }
4282 6103
4283 /** 6104 /**
4284 * A task that builds [VERIFY_ERRORS] for a unit. 6105 * A task that builds [VERIFY_ERRORS] for a unit.
4285 */ 6106 */
4286 class VerifyUnitTask extends SourceBasedAnalysisTask { 6107 class VerifyUnitTask extends SourceBasedAnalysisTask {
4287 /** 6108 /**
4288 * The name of the [RESOLVED_UNIT] input. 6109 * The name of the [PENDING_ERRORS] input.
4289 */ 6110 */
4290 static const String UNIT_INPUT = 'UNIT_INPUT'; 6111 static const String PENDING_ERRORS_INPUT = 'PENDING_ERRORS_INPUT';
6112
6113 /**
6114 * The name of the input of a mapping from [REFERENCED_SOURCES] to their
6115 * [MODIFICATION_TIME]s.
6116 */
6117 static const String REFERENCED_SOURCE_MODIFICATION_TIME_MAP_INPUT =
6118 'REFERENCED_SOURCE_MODIFICATION_TIME_MAP_INPUT';
4291 6119
4292 /** 6120 /**
4293 * The name of the [TYPE_PROVIDER] input. 6121 * The name of the [TYPE_PROVIDER] input.
4294 */ 6122 */
4295 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT'; 6123 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT';
4296 6124
4297 /** 6125 /**
6126 * The name of the [RESOLVED_UNIT] input.
6127 */
6128 static const String UNIT_INPUT = 'UNIT_INPUT';
6129
6130 /**
4298 * The task descriptor describing this kind of task. 6131 * The task descriptor describing this kind of task.
4299 */ 6132 */
4300 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor('VerifyUnitTask', 6133 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor('VerifyUnitTask',
4301 createTask, buildInputs, <ResultDescriptor>[VERIFY_ERRORS]); 6134 createTask, buildInputs, <ResultDescriptor>[VERIFY_ERRORS]);
4302 6135
4303 /** 6136 /**
4304 * The [ErrorReporter] to report errors to. 6137 * The [ErrorReporter] to report errors to.
4305 */ 6138 */
4306 ErrorReporter errorReporter; 6139 ErrorReporter errorReporter;
4307 6140
6141 /**
6142 * The mapping from the current library referenced sources to their
6143 * modification times.
6144 */
6145 Map<Source, int> sourceTimeMap;
6146
4308 VerifyUnitTask(InternalAnalysisContext context, AnalysisTarget target) 6147 VerifyUnitTask(InternalAnalysisContext context, AnalysisTarget target)
4309 : super(context, target); 6148 : super(context, target);
4310 6149
4311 @override 6150 @override
4312 TaskDescriptor get descriptor => DESCRIPTOR; 6151 TaskDescriptor get descriptor => DESCRIPTOR;
4313 6152
4314 @override 6153 @override
4315 void internalPerform() { 6154 void internalPerform() {
4316 RecordingErrorListener errorListener = new RecordingErrorListener(); 6155 RecordingErrorListener errorListener = new RecordingErrorListener();
4317 Source source = getRequiredSource(); 6156 Source source = getRequiredSource();
4318 errorReporter = new ErrorReporter(errorListener, source); 6157 errorReporter = new ErrorReporter(errorListener, source);
4319 // 6158 //
4320 // Prepare inputs. 6159 // Prepare inputs.
4321 // 6160 //
4322 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT);
4323 CompilationUnit unit = getRequiredInput(UNIT_INPUT); 6161 CompilationUnit unit = getRequiredInput(UNIT_INPUT);
4324 CompilationUnitElement unitElement = unit.element; 6162 CompilationUnitElement unitElement = unit.element;
4325 LibraryElement libraryElement = unitElement.library; 6163 LibraryElement libraryElement = unitElement.library;
6164 if (libraryElement == null) {
6165 throw new AnalysisException(
6166 'VerifyUnitTask verifying a unit with no library: '
6167 '${unitElement.source.fullName}');
6168 }
6169 List<PendingError> pendingErrors = getRequiredInput(PENDING_ERRORS_INPUT);
6170 sourceTimeMap =
6171 getRequiredInput(REFERENCED_SOURCE_MODIFICATION_TIME_MAP_INPUT);
6172 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT);
4326 // 6173 //
4327 // Validate the directives. 6174 // Validate the directives.
4328 // 6175 //
4329 validateDirectives(unit); 6176 validateDirectives(unit);
4330 // 6177 //
4331 // Use the ConstantVerifier to compute errors. 6178 // Use the ConstantVerifier to compute errors.
4332 // 6179 //
4333 ConstantVerifier constantVerifier = new ConstantVerifier( 6180 ConstantVerifier constantVerifier = new ConstantVerifier(
4334 errorReporter, libraryElement, typeProvider, context.declaredVariables); 6181 errorReporter, libraryElement, typeProvider, context.declaredVariables);
4335 unit.accept(constantVerifier); 6182 unit.accept(constantVerifier);
4336 // 6183 //
4337 // Use the ErrorVerifier to compute errors. 6184 // Use the ErrorVerifier to compute errors.
4338 // 6185 //
4339 ErrorVerifier errorVerifier = new ErrorVerifier( 6186 ErrorVerifier errorVerifier = new ErrorVerifier(
4340 errorReporter, 6187 errorReporter,
4341 libraryElement, 6188 libraryElement,
4342 typeProvider, 6189 typeProvider,
4343 new InheritanceManager(libraryElement), 6190 new InheritanceManager(libraryElement),
4344 context.analysisOptions.enableSuperMixins); 6191 context.analysisOptions.enableSuperMixins,
6192 context.analysisOptions.enableAssertMessage);
4345 unit.accept(errorVerifier); 6193 unit.accept(errorVerifier);
4346 6194 //
6195 // Convert the pending errors into actual errors.
6196 //
6197 for (PendingError pendingError in pendingErrors) {
6198 errorListener.onError(pendingError.toAnalysisError());
6199 }
4347 // 6200 //
4348 // Record outputs. 6201 // Record outputs.
4349 // 6202 //
4350 outputs[VERIFY_ERRORS] = removeDuplicateErrors(errorListener.errors); 6203 outputs[VERIFY_ERRORS] = getUniqueErrors(errorListener.errors);
4351 } 6204 }
4352 6205
4353 /** 6206 /**
4354 * Check each directive in the given [unit] to see if the referenced source 6207 * Check each directive in the given [unit] to see if the referenced source
4355 * exists and report an error if it does not. 6208 * exists and report an error if it does not.
4356 */ 6209 */
4357 void validateDirectives(CompilationUnit unit) { 6210 void validateDirectives(CompilationUnit unit) {
4358 for (Directive directive in unit.directives) { 6211 NodeList<Directive> directives = unit.directives;
6212 int length = directives.length;
6213 for (int i = 0; i < length; i++) {
6214 Directive directive = directives[i];
4359 if (directive is UriBasedDirective) { 6215 if (directive is UriBasedDirective) {
4360 validateReferencedSource(directive); 6216 validateReferencedSource(directive);
4361 } 6217 }
4362 } 6218 }
4363 } 6219 }
4364 6220
4365 /** 6221 /**
4366 * Check the given [directive] to see if the referenced source exists and 6222 * Check the given [directive] to see if the referenced source exists and
4367 * report an error if it does not. 6223 * report an error if it does not.
4368 */ 6224 */
4369 void validateReferencedSource(UriBasedDirective directive) { 6225 void validateReferencedSource(UriBasedDirectiveImpl directive) {
4370 Source source = directive.source; 6226 if (directive is NamespaceDirectiveImpl) {
6227 for (Configuration configuration in directive.configurations) {
6228 Source source = configuration.uriSource;
6229 StringLiteral uriLiteral = configuration.uri;
6230 String uriContent = uriLiteral?.stringValue?.trim();
6231 if (source != null) {
6232 int modificationTime = sourceTimeMap[source] ?? -1;
6233 if (modificationTime >= 0) {
6234 continue;
6235 }
6236 } else {
6237 // Don't report errors already reported by ParseDartTask.resolveDirect ive
6238 if (UriBasedDirectiveImpl.validateUri(
6239 directive is ImportDirective, uriLiteral, uriContent) !=
6240 null) {
6241 continue;
6242 }
6243 }
6244 CompileTimeErrorCode errorCode =
6245 CompileTimeErrorCode.URI_DOES_NOT_EXIST;
6246 if (_isGenerated(source)) {
6247 errorCode = CompileTimeErrorCode.URI_HAS_NOT_BEEN_GENERATED;
6248 }
6249 errorReporter.reportErrorForNode(errorCode, uriLiteral, [uriContent]);
6250 }
6251 }
6252 Source source = directive.uriSource;
4371 if (source != null) { 6253 if (source != null) {
4372 if (context.exists(source)) { 6254 int modificationTime = sourceTimeMap[source] ?? -1;
6255 if (modificationTime >= 0) {
4373 return; 6256 return;
4374 } 6257 }
4375 } else { 6258 } else {
4376 // Don't report errors already reported by ParseDartTask.resolveDirective 6259 // Don't report errors already reported by ParseDartTask.resolveDirective
4377 if (directive.validate() != null) { 6260 if (directive.validate() != null) {
4378 return; 6261 return;
4379 } 6262 }
4380 } 6263 }
4381 StringLiteral uriLiteral = directive.uri; 6264 StringLiteral uriLiteral = directive.uri;
4382 errorReporter.reportErrorForNode(CompileTimeErrorCode.URI_DOES_NOT_EXIST, 6265 CompileTimeErrorCode errorCode = CompileTimeErrorCode.URI_DOES_NOT_EXIST;
4383 uriLiteral, [directive.uriContent]); 6266 if (_isGenerated(source)) {
6267 errorCode = CompileTimeErrorCode.URI_HAS_NOT_BEEN_GENERATED;
6268 }
6269 errorReporter
6270 .reportErrorForNode(errorCode, uriLiteral, [directive.uriContent]);
4384 } 6271 }
4385 6272
4386 /** 6273 /**
6274 * Return `true` if the given [source] refers to a file that is assumed to be
6275 * generated.
6276 */
6277 bool _isGenerated(Source source) {
6278 if (source == null) {
6279 return false;
6280 }
6281 // TODO(brianwilkerson) Generalize this mechanism.
6282 const List<String> suffixes = const <String>[
6283 '.g.dart',
6284 '.pb.dart',
6285 '.pbenum.dart',
6286 '.pbserver.dart',
6287 '.pbjson.dart',
6288 '.template.dart'
6289 ];
6290 String fullName = source.fullName;
6291 for (String suffix in suffixes) {
6292 if (fullName.endsWith(suffix)) {
6293 return true;
6294 }
6295 }
6296 return false;
6297 }
6298
6299 /**
4387 * Return a map from the names of the inputs of this kind of task to the task 6300 * Return a map from the names of the inputs of this kind of task to the task
4388 * input descriptors describing those inputs for a task with the 6301 * input descriptors describing those inputs for a task with the
4389 * given [target]. 6302 * given [target].
4390 */ 6303 */
4391 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 6304 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
4392 LibrarySpecificUnit unit = target; 6305 LibrarySpecificUnit unit = target;
4393 return <String, TaskInput>{ 6306 return <String, TaskInput>{
4394 'resolvedUnits': IMPORT_EXPORT_SOURCE_CLOSURE 6307 'thisLibraryClosureIsReady': READY_RESOLVED_UNIT.of(unit.library),
4395 .of(unit.library)
4396 .toMapOf(UNITS)
4397 .toFlattenList((Source library, Source unit) =>
4398 RESOLVED_UNIT.of(new LibrarySpecificUnit(library, unit))),
4399 UNIT_INPUT: RESOLVED_UNIT.of(unit), 6308 UNIT_INPUT: RESOLVED_UNIT.of(unit),
6309 REFERENCED_SOURCE_MODIFICATION_TIME_MAP_INPUT:
6310 REFERENCED_SOURCES.of(unit.library).toMapOf(MODIFICATION_TIME),
6311 PENDING_ERRORS_INPUT: PENDING_ERRORS.of(unit),
6312 'requiredConstants': REQUIRED_CONSTANTS.of(unit).toListOf(CONSTANT_VALUE),
4400 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request) 6313 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request)
4401 }; 6314 };
4402 } 6315 }
4403 6316
4404 /** 6317 /**
4405 * Create a [VerifyUnitTask] based on the given [target] in 6318 * Create a [VerifyUnitTask] based on the given [target] in
4406 * the given [context]. 6319 * the given [context].
4407 */ 6320 */
4408 static VerifyUnitTask createTask( 6321 static VerifyUnitTask createTask(
4409 AnalysisContext context, AnalysisTarget target) { 6322 AnalysisContext context, AnalysisTarget target) {
(...skipping 14 matching lines...) Expand all
4424 6337
4425 _ExportSourceClosureTaskInput(this.target, this.resultDescriptor); 6338 _ExportSourceClosureTaskInput(this.target, this.resultDescriptor);
4426 6339
4427 @override 6340 @override
4428 TaskInputBuilder<List<Source>> createBuilder() => 6341 TaskInputBuilder<List<Source>> createBuilder() =>
4429 new _SourceClosureTaskInputBuilder( 6342 new _SourceClosureTaskInputBuilder(
4430 target, _SourceClosureKind.EXPORT, resultDescriptor); 6343 target, _SourceClosureKind.EXPORT, resultDescriptor);
4431 } 6344 }
4432 6345
4433 /** 6346 /**
4434 * A [TaskInput] whose value is a list of library sources imported or exported,
4435 * directly or indirectly by the target [Source].
4436 *
4437 * [resultDescriptor] is the type of result which should be produced for each
4438 * target [Source].
4439 */
4440 class _ImportExportSourceClosureTaskInput extends TaskInputImpl<List<Source>> {
4441 final Source target;
4442 final ResultDescriptor resultDescriptor;
4443
4444 _ImportExportSourceClosureTaskInput(this.target, this.resultDescriptor);
4445
4446 @override
4447 TaskInputBuilder<List<Source>> createBuilder() =>
4448 new _SourceClosureTaskInputBuilder(
4449 target, _SourceClosureKind.IMPORT_EXPORT, resultDescriptor);
4450 }
4451
4452 /**
4453 * A [TaskInput] whose value is a list of library sources imported directly 6347 * A [TaskInput] whose value is a list of library sources imported directly
4454 * or indirectly by the target [Source]. 6348 * or indirectly by the target [Source].
4455 * 6349 *
4456 * [resultDescriptor] is the type of result which should be produced for each 6350 * [resultDescriptor] is the type of result which should be produced for each
4457 * target [Source]. 6351 * target [Source].
4458 */ 6352 */
4459 class _ImportSourceClosureTaskInput extends TaskInputImpl<List<Source>> { 6353 class _ImportSourceClosureTaskInput extends TaskInputImpl<List<Source>> {
4460 final Source target; 6354 final Source target;
4461 final ResultDescriptor resultDescriptor; 6355 final ResultDescriptor resultDescriptor;
4462 6356
(...skipping 27 matching lines...) Expand all
4490 Source librarySource, this.kind, this.currentResult) { 6384 Source librarySource, this.kind, this.currentResult) {
4491 _newSources.add(librarySource); 6385 _newSources.add(librarySource);
4492 } 6386 }
4493 6387
4494 @override 6388 @override
4495 void set currentValue(Object value) { 6389 void set currentValue(Object value) {
4496 LibraryElement library = value; 6390 LibraryElement library = value;
4497 if (_libraries.add(library)) { 6391 if (_libraries.add(library)) {
4498 if (kind == _SourceClosureKind.IMPORT || 6392 if (kind == _SourceClosureKind.IMPORT ||
4499 kind == _SourceClosureKind.IMPORT_EXPORT) { 6393 kind == _SourceClosureKind.IMPORT_EXPORT) {
4500 for (ImportElement importElement in library.imports) { 6394 List<ImportElement> imports = library.imports;
4501 Source importedSource = importElement.importedLibrary.source; 6395 int length = imports.length;
4502 _newSources.add(importedSource); 6396 for (int i = 0; i < length; i++) {
6397 ImportElement importElement = imports[i];
6398 Source importedSource = importElement.importedLibrary?.source;
6399 if (importedSource != null) {
6400 _newSources.add(importedSource);
6401 }
4503 } 6402 }
4504 } 6403 }
4505 if (kind == _SourceClosureKind.EXPORT || 6404 if (kind == _SourceClosureKind.EXPORT ||
4506 kind == _SourceClosureKind.IMPORT_EXPORT) { 6405 kind == _SourceClosureKind.IMPORT_EXPORT) {
4507 for (ExportElement exportElement in library.exports) { 6406 List<ExportElement> exports = library.exports;
4508 Source exportedSource = exportElement.exportedLibrary.source; 6407 int length = exports.length;
4509 _newSources.add(exportedSource); 6408 for (int i = 0; i < length; i++) {
6409 ExportElement exportElement = exports[i];
6410 Source exportedSource = exportElement.exportedLibrary?.source;
6411 if (exportedSource != null) {
6412 _newSources.add(exportedSource);
6413 }
4510 } 6414 }
4511 } 6415 }
4512 } 6416 }
4513 } 6417 }
4514 6418
4515 @override 6419 @override
4516 bool get flushOnAccess => false; 6420 bool get flushOnAccess => false;
4517 6421
4518 @override 6422 @override
4519 List<Source> get inputValue { 6423 List<Source> get inputValue {
4520 return _libraries.map((LibraryElement library) => library.source).toList(); 6424 return _libraries.map((LibraryElement library) => library.source).toList();
4521 } 6425 }
4522 6426
4523 @override 6427 @override
4524 void currentValueNotAvailable() { 6428 void currentValueNotAvailable() {
4525 // Nothing needs to be done. moveNext() will simply go on to the next new 6429 // Nothing needs to be done. moveNext() will simply go on to the next new
4526 // source. 6430 // source.
4527 } 6431 }
4528 6432
4529 @override 6433 @override
4530 bool moveNext() { 6434 bool moveNext() {
4531 if (_newSources.isEmpty) { 6435 if (_newSources.isEmpty) {
4532 return false; 6436 return false;
4533 } 6437 }
4534 currentTarget = _newSources.removeLast(); 6438 currentTarget = _newSources.removeLast();
4535 return true; 6439 return true;
4536 } 6440 }
4537 } 6441 }
OLDNEW
« no previous file with comments | « packages/analyzer/lib/src/summary/summary_sdk.dart ('k') | packages/analyzer/lib/src/task/dart_work_manager.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698