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

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

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 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/src/context/cache.dart'; 9 import 'package:analyzer/src/context/cache.dart';
10 import 'package:analyzer/src/generated/ast.dart'; 10 import 'package:analyzer/src/generated/ast.dart';
11 import 'package:analyzer/src/generated/constant.dart'; 11 import 'package:analyzer/src/generated/constant.dart';
12 import 'package:analyzer/src/generated/element.dart'; 12 import 'package:analyzer/src/generated/element.dart';
13 import 'package:analyzer/src/generated/engine.dart' 13 import 'package:analyzer/src/generated/engine.dart'
14 hide AnalysisCache, AnalysisTask; 14 hide AnalysisCache, AnalysisTask;
15 import 'package:analyzer/src/generated/error.dart'; 15 import 'package:analyzer/src/generated/error.dart';
16 import 'package:analyzer/src/generated/error_verifier.dart'; 16 import 'package:analyzer/src/generated/error_verifier.dart';
17 import 'package:analyzer/src/generated/incremental_resolver.dart';
17 import 'package:analyzer/src/generated/java_engine.dart'; 18 import 'package:analyzer/src/generated/java_engine.dart';
18 import 'package:analyzer/src/generated/parser.dart'; 19 import 'package:analyzer/src/generated/parser.dart';
19 import 'package:analyzer/src/generated/resolver.dart'; 20 import 'package:analyzer/src/generated/resolver.dart';
20 import 'package:analyzer/src/generated/scanner.dart'; 21 import 'package:analyzer/src/generated/scanner.dart';
21 import 'package:analyzer/src/generated/sdk.dart'; 22 import 'package:analyzer/src/generated/sdk.dart';
22 import 'package:analyzer/src/generated/source.dart'; 23 import 'package:analyzer/src/generated/source.dart';
24 import 'package:analyzer/src/generated/visitors.dart';
25 import 'package:analyzer/src/plugin/engine_plugin.dart';
26 import 'package:analyzer/src/services/lint.dart';
23 import 'package:analyzer/src/task/driver.dart'; 27 import 'package:analyzer/src/task/driver.dart';
24 import 'package:analyzer/src/task/general.dart'; 28 import 'package:analyzer/src/task/general.dart';
25 import 'package:analyzer/src/task/html.dart'; 29 import 'package:analyzer/src/task/html.dart';
26 import 'package:analyzer/src/task/inputs.dart'; 30 import 'package:analyzer/src/task/inputs.dart';
27 import 'package:analyzer/src/task/model.dart'; 31 import 'package:analyzer/src/task/model.dart';
32 import 'package:analyzer/src/task/strong_mode.dart';
28 import 'package:analyzer/task/dart.dart'; 33 import 'package:analyzer/task/dart.dart';
29 import 'package:analyzer/task/general.dart'; 34 import 'package:analyzer/task/general.dart';
30 import 'package:analyzer/task/model.dart'; 35 import 'package:analyzer/task/model.dart';
31 36
32 /** 37 /**
33 * The [ResultCachingPolicy] for ASTs. 38 * The [ResultCachingPolicy] for ASTs.
34 */ 39 */
35 const ResultCachingPolicy AST_CACHING_POLICY = 40 const ResultCachingPolicy AST_CACHING_POLICY =
36 const SimpleResultCachingPolicy(8192, 8192); 41 const SimpleResultCachingPolicy(8192, 8192);
37 42
38 /** 43 /**
44 * The [ResultCachingPolicy] for [Element]s.
45 */
46 const ResultCachingPolicy ELEMENT_CACHING_POLICY =
47 const SimpleResultCachingPolicy(-1, -1);
48
49 /**
50 * The [ResultCachingPolicy] for [TOKEN_STREAM].
51 */
52 const ResultCachingPolicy TOKEN_STREAM_CACHING_POLICY =
53 const SimpleResultCachingPolicy(1, 1);
54
55 /**
39 * The errors produced while resolving a library directives. 56 * The errors produced while resolving a library directives.
40 * 57 *
41 * The list will be empty if there were no errors, but will not be `null`. 58 * The list will be empty if there were no errors, but will not be `null`.
42 * 59 *
43 * The result is only available for [Source]s representing a library. 60 * The result is only available for [Source]s representing a library.
44 */ 61 */
45 final ListResultDescriptor<AnalysisError> BUILD_DIRECTIVES_ERRORS = 62 final ListResultDescriptor<AnalysisError> BUILD_DIRECTIVES_ERRORS =
46 new ListResultDescriptor<AnalysisError>( 63 new ListResultDescriptor<AnalysisError>(
47 'BUILD_DIRECTIVES_ERRORS', AnalysisError.NO_ERRORS); 64 'BUILD_DIRECTIVES_ERRORS', AnalysisError.NO_ERRORS);
48 65
49 /** 66 /**
50 * The errors produced while building a library element. 67 * The errors produced while building a library element.
51 * 68 *
52 * The list will be empty if there were no errors, but will not be `null`. 69 * The list will be empty if there were no errors, but will not be `null`.
53 * 70 *
54 * The result is only available for [Source]s representing a library. 71 * The result is only available for [Source]s representing a library.
55 */ 72 */
56 final ListResultDescriptor<AnalysisError> BUILD_LIBRARY_ERRORS = 73 final ListResultDescriptor<AnalysisError> BUILD_LIBRARY_ERRORS =
57 new ListResultDescriptor<AnalysisError>( 74 new ListResultDescriptor<AnalysisError>(
58 'BUILD_LIBRARY_ERRORS', AnalysisError.NO_ERRORS); 75 'BUILD_LIBRARY_ERRORS', AnalysisError.NO_ERRORS);
59 76
60 /** 77 /**
61 * A list of the [ConstantEvaluationTarget]s defined in a unit. This includes 78 * A list of the [ConstantEvaluationTarget]s defined in a unit. This includes
62 * constants defined at top level, statically inside classes, and local to 79 * constants defined at top level, statically inside classes, and local to
63 * functions, as well as constant constructors, annotations, and default values 80 * functions, as well as constant constructors, annotations, and default values
64 * of parameters to constant constructors. 81 * of parameters to constant constructors.
82 *
83 * The result is only available for [LibrarySpecificUnit]s.
65 */ 84 */
66 final ListResultDescriptor<ConstantEvaluationTarget> COMPILATION_UNIT_CONSTANTS = 85 final ListResultDescriptor<
86 ConstantEvaluationTarget> COMPILATION_UNIT_CONSTANTS =
67 new ListResultDescriptor<ConstantEvaluationTarget>( 87 new ListResultDescriptor<ConstantEvaluationTarget>(
68 'COMPILATION_UNIT_CONSTANTS', null, 88 'COMPILATION_UNIT_CONSTANTS', null,
69 cachingPolicy: ELEMENT_CACHING_POLICY); 89 cachingPolicy: ELEMENT_CACHING_POLICY);
70 90
71 /** 91 /**
72 * The element model associated with a single compilation unit. 92 * The element model associated with a single compilation unit.
73 * 93 *
74 * The result is only available for [LibrarySpecificUnit]s. 94 * The result is only available for [LibrarySpecificUnit]s.
75 */ 95 */
76 final ResultDescriptor<CompilationUnitElement> COMPILATION_UNIT_ELEMENT = 96 final ResultDescriptor<CompilationUnitElement> COMPILATION_UNIT_ELEMENT =
(...skipping 10 matching lines...) Expand all
87 * constructor, or a parameter element with a default value). 107 * constructor, or a parameter element with a default value).
88 */ 108 */
89 final ListResultDescriptor<ConstantEvaluationTarget> CONSTANT_DEPENDENCIES = 109 final ListResultDescriptor<ConstantEvaluationTarget> CONSTANT_DEPENDENCIES =
90 new ListResultDescriptor<ConstantEvaluationTarget>( 110 new ListResultDescriptor<ConstantEvaluationTarget>(
91 'CONSTANT_DEPENDENCIES', const <ConstantEvaluationTarget>[]); 111 'CONSTANT_DEPENDENCIES', const <ConstantEvaluationTarget>[]);
92 112
93 /** 113 /**
94 * A [ConstantEvaluationTarget] that has been successfully constant-evaluated. 114 * A [ConstantEvaluationTarget] that has been successfully constant-evaluated.
95 * 115 *
96 * TODO(paulberry): is ELEMENT_CACHING_POLICY the correct caching policy? 116 * TODO(paulberry): is ELEMENT_CACHING_POLICY the correct caching policy?
117 *
118 * The result is only available for [ConstantEvaluationTarget]s.
119 *
97 */ 120 */
98 final ResultDescriptor<ConstantEvaluationTarget> CONSTANT_VALUE = 121 final ResultDescriptor<ConstantEvaluationTarget> CONSTANT_VALUE =
99 new ResultDescriptor<ConstantEvaluationTarget>('CONSTANT_VALUE', null, 122 new ResultDescriptor<ConstantEvaluationTarget>('CONSTANT_VALUE', null,
100 cachingPolicy: ELEMENT_CACHING_POLICY); 123 cachingPolicy: ELEMENT_CACHING_POLICY);
101 124
102 /** 125 /**
103 * The sources representing the libraries that include a given source as a part. 126 * The sources representing the libraries that include a given source as a part.
104 * 127 *
105 * The result is only available for [Source]s representing a compilation unit. 128 * The result is only available for [Source]s representing a compilation unit.
106 */ 129 */
107 final ListResultDescriptor<Source> CONTAINING_LIBRARIES = 130 final ListResultDescriptor<Source> CONTAINING_LIBRARIES =
108 new ListResultDescriptor<Source>('CONTAINING_LIBRARIES', Source.EMPTY_LIST); 131 new ListResultDescriptor<Source>('CONTAINING_LIBRARIES', Source.EMPTY_LIST);
109 132
110 /** 133 /**
111 * The [ResultCachingPolicy] for [Element]s.
112 */
113 const ResultCachingPolicy ELEMENT_CACHING_POLICY =
114 const SimpleResultCachingPolicy(-1, -1);
115
116 /**
117 * The sources representing the export closure of a library. 134 * The sources representing the export closure of a library.
118 * The [Source]s include only library sources, not their units. 135 * The [Source]s include only library sources, not their units.
119 * 136 *
120 * The result is only available for [Source]s representing a library. 137 * The result is only available for [Source]s representing a library.
121 */ 138 */
122 final ListResultDescriptor<Source> EXPORT_SOURCE_CLOSURE = 139 final ListResultDescriptor<Source> EXPORT_SOURCE_CLOSURE =
123 new ListResultDescriptor<Source>('EXPORT_SOURCE_CLOSURE', null); 140 new ListResultDescriptor<Source>('EXPORT_SOURCE_CLOSURE', null);
124 141
125 /** 142 /**
126 * The errors produced while generating hints a compilation unit. 143 * The errors produced while generating hints a compilation unit.
127 * 144 *
128 * The list will be empty if there were no errors, but will not be `null`. 145 * The list will be empty if there were no errors, but will not be `null`.
129 * 146 *
130 * The result is only available for [LibrarySpecificUnit]s. 147 * The result is only available for [LibrarySpecificUnit]s.
131 */ 148 */
132 final ListResultDescriptor<AnalysisError> HINTS = 149 final ListResultDescriptor<AnalysisError> HINTS =
133 new ListResultDescriptor<AnalysisError>( 150 new ListResultDescriptor<AnalysisError>(
134 'HINT_ERRORS', AnalysisError.NO_ERRORS); 151 'HINT_ERRORS', AnalysisError.NO_ERRORS);
135 152
136 /** 153 /**
137 * The sources representing the combined import/export closure of a library. 154 * The sources representing the combined import/export closure of a library.
138 * The [Source]s include only library sources, not their units. 155 * The [Source]s include only library sources, not their units.
139 * 156 *
140 * The result is only available for [Source]s representing a library. 157 * The result is only available for [Source]s representing a library.
141 */ 158 */
142 final ListResultDescriptor<Source> IMPORT_EXPORT_SOURCE_CLOSURE = 159 final ListResultDescriptor<Source> IMPORT_EXPORT_SOURCE_CLOSURE =
143 new ListResultDescriptor<Source>('IMPORT_EXPORT_SOURCE_CLOSURE', null); 160 new ListResultDescriptor<Source>('IMPORT_EXPORT_SOURCE_CLOSURE', null);
144 161
145 /** 162 /**
163 * A list of the [LibraryElement]s that make up the strongly connected
164 * component in the import/export graph in which the target resides.
165 *
166 * Only non-empty in strongMode
167 *
168 * The result is only available for [LibrarySpecificUnit]s.
169 */
170 final ListResultDescriptor<LibraryElement> LIBRARY_CYCLE =
171 new ListResultDescriptor<LibraryElement>('LIBRARY_CYCLE', null);
172
173 /**
174 * A list of the [CompilationUnitElement]s (including all parts) that make up
175 * the strongly connected component in the import/export graph in which the
176 * target resides.
177 *
178 * Only non-empty in strongMode
179 *
180 * The result is only available for [LibrarySpecificUnit]s.
181 */
182 final ListResultDescriptor<CompilationUnitElement> LIBRARY_CYCLE_UNITS =
183 new ListResultDescriptor<CompilationUnitElement>(
184 'LIBRARY_CYCLE_UNITS', null);
185
186 /**
187 * A list of the [CompilationUnitElement]s that comprise all of the parts and
188 * libraries in the direct import/export dependencies of the library cycle
189 * of the target, with the intra-component dependencies excluded.
190 *
191 * Only non-empty in strongMode
192 *
193 * The result is only available for [LibrarySpecificUnit]s.
194 */
195 final ListResultDescriptor<CompilationUnitElement> LIBRARY_CYCLE_DEPENDENCIES =
196 new ListResultDescriptor<CompilationUnitElement>(
197 'LIBRARY_CYCLE_DEPENDENCIES', null);
198
199 /**
200 * A list of the [VariableElement]s whose type should be inferred that another
201 * inferable static variable (the target) depends on.
202 *
203 * The result is only available for [VariableElement]s, and only when strong
204 * mode is enabled.
205 */
206 final ListResultDescriptor<
207 VariableElement> INFERABLE_STATIC_VARIABLE_DEPENDENCIES =
208 new ListResultDescriptor<VariableElement>(
209 'INFERABLE_STATIC_VARIABLE_DEPENDENCIES', null);
210
211 /**
212 * A list of the [VariableElement]s defined in a unit whose type should be
213 * inferred. This includes variables defined at the library level as well as
214 * static members inside classes.
215 *
216 * The result is only available for [LibrarySpecificUnit]s, and only when strong
217 * mode is enabled.
218 */
219 final ListResultDescriptor<VariableElement> INFERABLE_STATIC_VARIABLES_IN_UNIT =
220 new ListResultDescriptor<VariableElement>(
221 'INFERABLE_STATIC_VARIABLES_IN_UNIT', null);
222
223 /**
224 * An inferrable static variable ([VariableElement]) whose type has been
225 * inferred.
226 *
227 * The result is only available for [VariableElement]s, and only when strong
228 * mode is enabled.
229 */
230 final ResultDescriptor<VariableElement> INFERRED_STATIC_VARIABLE =
231 new ResultDescriptor<VariableElement>('INFERRED_STATIC_VARIABLE', null,
232 cachingPolicy: ELEMENT_CACHING_POLICY);
233
234 /**
146 * The partial [LibraryElement] associated with a library. 235 * The partial [LibraryElement] associated with a library.
147 * 236 *
148 * The [LibraryElement] and its [CompilationUnitElement]s are attached to each 237 * The [LibraryElement] and its [CompilationUnitElement]s are attached to each
149 * other. Directives 'library', 'part' and 'part of' are resolved. 238 * other. Directives 'library', 'part' and 'part of' are resolved.
150 * 239 *
151 * The result is only available for [Source]s representing a library. 240 * The result is only available for [Source]s representing a library.
152 */ 241 */
153 final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT1 = 242 final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT1 =
154 new ResultDescriptor<LibraryElement>('LIBRARY_ELEMENT1', null, 243 new ResultDescriptor<LibraryElement>('LIBRARY_ELEMENT1', null,
155 cachingPolicy: ELEMENT_CACHING_POLICY); 244 cachingPolicy: ELEMENT_CACHING_POLICY);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 /** 304 /**
216 * The analysis errors associated with a compilation unit in a specific library. 305 * The analysis errors associated with a compilation unit in a specific library.
217 * 306 *
218 * The result is only available for [LibrarySpecificUnit]s. 307 * The result is only available for [LibrarySpecificUnit]s.
219 */ 308 */
220 final ListResultDescriptor<AnalysisError> LIBRARY_UNIT_ERRORS = 309 final ListResultDescriptor<AnalysisError> LIBRARY_UNIT_ERRORS =
221 new ListResultDescriptor<AnalysisError>( 310 new ListResultDescriptor<AnalysisError>(
222 'LIBRARY_UNIT_ERRORS', AnalysisError.NO_ERRORS); 311 'LIBRARY_UNIT_ERRORS', AnalysisError.NO_ERRORS);
223 312
224 /** 313 /**
314 * The errors produced while generating lints for a compilation unit.
315 *
316 * The list will be empty if there were no errors, but will not be `null`.
317 *
318 * The result is only available for [LibrarySpecificUnit]s.
319 */
320 final ListResultDescriptor<AnalysisError> LINTS =
321 new ListResultDescriptor<AnalysisError>(
322 'LINT_ERRORS', AnalysisError.NO_ERRORS);
323
324 /**
225 * The errors produced while parsing a compilation unit. 325 * The errors produced while parsing a compilation unit.
226 * 326 *
227 * The list will be empty if there were no errors, but will not be `null`. 327 * The list will be empty if there were no errors, but will not be `null`.
228 * 328 *
229 * The result is only available for [Source]s representing a compilation unit. 329 * The result is only available for [Source]s representing a compilation unit.
230 */ 330 */
231 final ListResultDescriptor<AnalysisError> PARSE_ERRORS = 331 final ListResultDescriptor<AnalysisError> PARSE_ERRORS =
232 new ListResultDescriptor<AnalysisError>( 332 new ListResultDescriptor<AnalysisError>(
233 'PARSE_ERRORS', AnalysisError.NO_ERRORS); 333 'PARSE_ERRORS', AnalysisError.NO_ERRORS);
234 334
235 /** 335 /**
236 * The names (resolved and not) referenced by a unit. 336 * The names (resolved and not) referenced by a unit.
237 * 337 *
238 * The result is only available for [Source]s representing a compilation unit. 338 * The result is only available for [Source]s representing a compilation unit.
239 */ 339 */
240 final ResultDescriptor<ReferencedNames> REFERENCED_NAMES = 340 final ResultDescriptor<ReferencedNames> REFERENCED_NAMES =
241 new ResultDescriptor<ReferencedNames>('REFERENCED_NAMES', null); 341 new ResultDescriptor<ReferencedNames>('REFERENCED_NAMES', null);
242 342
243 /** 343 /**
244 * The errors produced while resolving references. 344 * The errors produced while resolving a full compilation unit.
245 * 345 *
246 * The list will be empty if there were no errors, but will not be `null`. 346 * The list will be empty if there were no errors, but will not be `null`.
247 * 347 *
248 * The result is only available for [LibrarySpecificUnit]s. 348 * The result is only available for [LibrarySpecificUnit]s.
249 */ 349 */
250 final ListResultDescriptor<AnalysisError> RESOLVE_REFERENCES_ERRORS = 350 final ListResultDescriptor<AnalysisError> RESOLVE_UNIT_ERRORS =
251 new ListResultDescriptor<AnalysisError>( 351 new ListResultDescriptor<AnalysisError>(
252 'RESOLVE_REFERENCES_ERRORS', AnalysisError.NO_ERRORS); 352 'RESOLVE_UNIT_ERRORS', AnalysisError.NO_ERRORS);
253 353
254 /** 354 /**
255 * The errors produced while resolving type names. 355 * The errors produced while resolving type names.
256 * 356 *
257 * The list will be empty if there were no errors, but will not be `null`. 357 * The list will be empty if there were no errors, but will not be `null`.
258 * 358 *
259 * The result is only available for [LibrarySpecificUnit]s. 359 * The result is only available for [LibrarySpecificUnit]s.
260 */ 360 */
261 final ListResultDescriptor<AnalysisError> RESOLVE_TYPE_NAMES_ERRORS = 361 final ListResultDescriptor<AnalysisError> RESOLVE_TYPE_NAMES_ERRORS =
262 new ListResultDescriptor<AnalysisError>( 362 new ListResultDescriptor<AnalysisError>(
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 * 400 *
301 * [RESOLVED_UNIT3] plus resolved local variables and formal parameters. 401 * [RESOLVED_UNIT3] plus resolved local variables and formal parameters.
302 * 402 *
303 * The result is only available for [LibrarySpecificUnit]s. 403 * The result is only available for [LibrarySpecificUnit]s.
304 */ 404 */
305 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT4 = 405 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT4 =
306 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT4', null, 406 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT4', null,
307 cachingPolicy: AST_CACHING_POLICY); 407 cachingPolicy: AST_CACHING_POLICY);
308 408
309 /** 409 /**
310 * The resolved [CompilationUnit] associated with a compilation unit, with 410 * The resolved [CompilationUnit] associated with a compilation unit in which
311 * constants not yet resolved. 411 * elements and types have been initially resolved outside of method bodies in
412 * addition to everything that is true of a [RESOLVED_UNIT4].
312 * 413 *
313 * The result is only available for [LibrarySpecificUnit]s. 414 * The result is only available for [LibrarySpecificUnit]s.
314 */ 415 */
315 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT5 = 416 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT5 =
316 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT5', null, 417 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT5', null,
317 cachingPolicy: AST_CACHING_POLICY); 418 cachingPolicy: AST_CACHING_POLICY);
318 419
319 /** 420 /**
421 * The resolved [CompilationUnit] associated with a compilation unit in which
422 * the types of static variables have been inferred in addition to everything
423 * that is true of a [RESOLVED_UNIT5].
424 *
425 * The result is only available for [LibrarySpecificUnit]s.
426 */
427 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT6 =
428 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT6', null,
429 cachingPolicy: AST_CACHING_POLICY);
430
431 /**
432 * The resolved [CompilationUnit] associated with a compilation unit in which
433 * the right hand sides of instance variables have been re-resolved in addition
434 * to everything that is true of a [RESOLVED_UNIT6].
435 *
436 * The result is only available for [LibrarySpecificUnit]s.
437 */
438 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT7 =
439 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT7', null,
440 cachingPolicy: AST_CACHING_POLICY);
441
442 /**
443 * The resolved [CompilationUnit] associated with a compilation unit in which
444 * the types of class members have been inferred in addition to everything that
445 * is true of a [RESOLVED_UNIT7].
446 *
447 * The result is only available for [LibrarySpecificUnit]s.
448 */
449 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT8 =
450 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT8', null,
451 cachingPolicy: AST_CACHING_POLICY);
452
453 /**
454 * The resolved [CompilationUnit] associated with a compilation unit, with
455 * constants not yet resolved.
456 *
457 * The result is only available for [LibrarySpecificUnit]s.
458 */
459 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT9 =
460 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT9', null,
461 cachingPolicy: AST_CACHING_POLICY);
462
463 /**
320 * The errors produced while scanning a compilation unit. 464 * The errors produced while scanning a compilation unit.
321 * 465 *
322 * The list will be empty if there were no errors, but will not be `null`. 466 * The list will be empty if there were no errors, but will not be `null`.
323 * 467 *
324 * The result is only available for [Source]s representing a compilation unit. 468 * The result is only available for [Source]s representing a compilation unit.
325 */ 469 */
326 final ListResultDescriptor<AnalysisError> SCAN_ERRORS = 470 final ListResultDescriptor<AnalysisError> SCAN_ERRORS =
327 new ListResultDescriptor<AnalysisError>( 471 new ListResultDescriptor<AnalysisError>(
328 'SCAN_ERRORS', AnalysisError.NO_ERRORS); 472 'SCAN_ERRORS', AnalysisError.NO_ERRORS);
329 473
330 /** 474 /**
331 * The [ResultCachingPolicy] for [TOKEN_STREAM].
332 */
333 const ResultCachingPolicy TOKEN_STREAM_CACHING_POLICY =
334 const SimpleResultCachingPolicy(1, 1);
335
336 /**
337 * The [TypeProvider] of the [AnalysisContext]. 475 * The [TypeProvider] of the [AnalysisContext].
338 */ 476 */
339 final ResultDescriptor<TypeProvider> TYPE_PROVIDER = 477 final ResultDescriptor<TypeProvider> TYPE_PROVIDER =
340 new ResultDescriptor<TypeProvider>('TYPE_PROVIDER', null); 478 new ResultDescriptor<TypeProvider>('TYPE_PROVIDER', null);
341 479
342 /** 480 /**
343 * The [UsedImportedElements] of a [LibrarySpecificUnit]. 481 * The [UsedImportedElements] of a [LibrarySpecificUnit].
344 */ 482 */
345 final ResultDescriptor<UsedImportedElements> USED_IMPORTED_ELEMENTS = 483 final ResultDescriptor<UsedImportedElements> USED_IMPORTED_ELEMENTS =
346 new ResultDescriptor<UsedImportedElements>('USED_IMPORTED_ELEMENTS', null, 484 new ResultDescriptor<UsedImportedElements>('USED_IMPORTED_ELEMENTS', null,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 class BuildCompilationUnitElementTask extends SourceBasedAnalysisTask { 530 class BuildCompilationUnitElementTask extends SourceBasedAnalysisTask {
393 /** 531 /**
394 * The name of the input whose value is the AST for the compilation unit. 532 * The name of the input whose value is the AST for the compilation unit.
395 */ 533 */
396 static const String PARSED_UNIT_INPUT_NAME = 'PARSED_UNIT_INPUT_NAME'; 534 static const String PARSED_UNIT_INPUT_NAME = 'PARSED_UNIT_INPUT_NAME';
397 535
398 /** 536 /**
399 * The task descriptor describing this kind of task. 537 * The task descriptor describing this kind of task.
400 */ 538 */
401 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 539 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
402 'BuildCompilationUnitElementTask', createTask, buildInputs, 540 'BuildCompilationUnitElementTask',
403 <ResultDescriptor>[ 541 createTask,
542 buildInputs, <ResultDescriptor>[
543 COMPILATION_UNIT_CONSTANTS,
404 COMPILATION_UNIT_ELEMENT, 544 COMPILATION_UNIT_ELEMENT,
405 RESOLVED_UNIT1, 545 RESOLVED_UNIT1
406 COMPILATION_UNIT_CONSTANTS
407 ]); 546 ]);
408 547
409 /** 548 /**
410 * Initialize a newly created task to build a compilation unit element for 549 * Initialize a newly created task to build a compilation unit element for
411 * the given [target] in the given [context]. 550 * the given [target] in the given [context].
412 */ 551 */
413 BuildCompilationUnitElementTask( 552 BuildCompilationUnitElementTask(
414 InternalAnalysisContext context, AnalysisTarget target) 553 InternalAnalysisContext context, AnalysisTarget target)
415 : super(context, target); 554 : super(context, target);
416 555
417 @override 556 @override
418 TaskDescriptor get descriptor => DESCRIPTOR; 557 TaskDescriptor get descriptor => DESCRIPTOR;
419 558
420 @override 559 @override
421 void internalPerform() { 560 void internalPerform() {
422 // 561 //
423 // Prepare inputs. 562 // Prepare inputs.
424 // 563 //
425 LibrarySpecificUnit librarySpecificUnit = target; 564 LibrarySpecificUnit librarySpecificUnit = target;
426 Source source = getRequiredSource(); 565 Source source = getRequiredSource();
427 CompilationUnit unit = getRequiredInput(PARSED_UNIT_INPUT_NAME); 566 CompilationUnit unit = getRequiredInput(PARSED_UNIT_INPUT_NAME);
428 // 567 //
429 // Build or reuse CompilationUnitElement. 568 // Build or reuse CompilationUnitElement.
430 // 569 //
431 unit = AstCloner.clone(unit); 570 // unit = AstCloner.clone(unit);
432 AnalysisCache analysisCache = 571 AnalysisCache analysisCache =
433 (context as InternalAnalysisContext).analysisCache; 572 (context as InternalAnalysisContext).analysisCache;
434 CompilationUnitElement element = 573 CompilationUnitElement element =
435 analysisCache.getValue(target, COMPILATION_UNIT_ELEMENT); 574 analysisCache.getValue(target, COMPILATION_UNIT_ELEMENT);
436 if (element == null) { 575 if (element == null) {
437 CompilationUnitBuilder builder = new CompilationUnitBuilder(); 576 CompilationUnitBuilder builder = new CompilationUnitBuilder();
438 element = builder.buildCompilationUnit( 577 element = builder.buildCompilationUnit(
439 source, unit, librarySpecificUnit.library); 578 source, unit, librarySpecificUnit.library);
440 } else { 579 } else {
441 new DeclarationResolver().resolve(unit, element); 580 new DeclarationResolver().resolve(unit, element);
442 } 581 }
443 // 582 //
444 // Prepare constants. 583 // Prepare constants.
445 // 584 //
446 ConstantFinder constantFinder = 585 ConstantFinder constantFinder =
447 new ConstantFinder(context, source, librarySpecificUnit.library); 586 new ConstantFinder(context, source, librarySpecificUnit.library);
448 unit.accept(constantFinder); 587 unit.accept(constantFinder);
449 List<ConstantEvaluationTarget> constants = 588 List<ConstantEvaluationTarget> constants = new List<
450 new List<ConstantEvaluationTarget>.from( 589 ConstantEvaluationTarget>.from(constantFinder.constantsToCompute);
451 constantFinder.constantsToCompute);
452 // 590 //
453 // Record outputs. 591 // Record outputs.
454 // 592 //
593 outputs[COMPILATION_UNIT_CONSTANTS] = constants;
455 outputs[COMPILATION_UNIT_ELEMENT] = element; 594 outputs[COMPILATION_UNIT_ELEMENT] = element;
456 outputs[RESOLVED_UNIT1] = unit; 595 outputs[RESOLVED_UNIT1] = unit;
457 outputs[COMPILATION_UNIT_CONSTANTS] = constants;
458 } 596 }
459 597
460 /** 598 /**
461 * Return a map from the names of the inputs of this kind of task to the task 599 * Return a map from the names of the inputs of this kind of task to the task
462 * input descriptors describing those inputs for a task with the given 600 * input descriptors describing those inputs for a task with the given
463 * [target]. 601 * [target].
464 */ 602 */
465 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 603 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
466 LibrarySpecificUnit unit = target; 604 LibrarySpecificUnit unit = target;
467 return <String, TaskInput>{ 605 return <String, TaskInput>{
468 PARSED_UNIT_INPUT_NAME: PARSED_UNIT.of(unit.unit) 606 PARSED_UNIT_INPUT_NAME: PARSED_UNIT.of(unit.unit, flushOnAccess: true)
469 }; 607 };
470 } 608 }
471 609
472 /** 610 /**
473 * Create a [BuildCompilationUnitElementTask] based on the given [target] in 611 * Create a [BuildCompilationUnitElementTask] based on the given [target] in
474 * the given [context]. 612 * the given [context].
475 */ 613 */
476 static BuildCompilationUnitElementTask createTask( 614 static BuildCompilationUnitElementTask createTask(
477 AnalysisContext context, AnalysisTarget target) { 615 AnalysisContext context, AnalysisTarget target) {
478 return new BuildCompilationUnitElementTask(context, target); 616 return new BuildCompilationUnitElementTask(context, target);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 /** 652 /**
515 * The input with a list of [SOURCE_KIND]s of exported libraries. 653 * The input with a list of [SOURCE_KIND]s of exported libraries.
516 */ 654 */
517 static const String EXPORTS_SOURCE_KIND_INPUT_NAME = 655 static const String EXPORTS_SOURCE_KIND_INPUT_NAME =
518 'EXPORTS_SOURCE_KIND_INPUT_NAME'; 656 'EXPORTS_SOURCE_KIND_INPUT_NAME';
519 657
520 /** 658 /**
521 * The task descriptor describing this kind of task. 659 * The task descriptor describing this kind of task.
522 */ 660 */
523 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 661 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
524 'BuildDirectiveElementsTask', createTask, buildInputs, <ResultDescriptor>[ 662 'BuildDirectiveElementsTask',
525 LIBRARY_ELEMENT2, 663 createTask,
526 BUILD_DIRECTIVES_ERRORS 664 buildInputs,
527 ]); 665 <ResultDescriptor>[LIBRARY_ELEMENT2, BUILD_DIRECTIVES_ERRORS]);
528 666
529 BuildDirectiveElementsTask( 667 BuildDirectiveElementsTask(
530 InternalAnalysisContext context, AnalysisTarget target) 668 InternalAnalysisContext context, AnalysisTarget target)
531 : super(context, target); 669 : super(context, target);
532 670
533 @override 671 @override
534 TaskDescriptor get descriptor => DESCRIPTOR; 672 TaskDescriptor get descriptor => DESCRIPTOR;
535 673
536 @override 674 @override
537 void internalPerform() { 675 void internalPerform() {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 if (uriLiteral != null) { 760 if (uriLiteral != null) {
623 exportElement.uriOffset = uriLiteral.offset; 761 exportElement.uriOffset = uriLiteral.offset;
624 exportElement.uriEnd = uriLiteral.end; 762 exportElement.uriEnd = uriLiteral.end;
625 } 763 }
626 exportElement.uri = exportDirective.uriContent; 764 exportElement.uri = exportDirective.uriContent;
627 exportElement.combinators = _buildCombinators(exportDirective); 765 exportElement.combinators = _buildCombinators(exportDirective);
628 exportElement.exportedLibrary = exportedLibrary; 766 exportElement.exportedLibrary = exportedLibrary;
629 directive.element = exportElement; 767 directive.element = exportElement;
630 exports.add(exportElement); 768 exports.add(exportElement);
631 if (exportSourceKindMap[exportedSource] != SourceKind.LIBRARY) { 769 if (exportSourceKindMap[exportedSource] != SourceKind.LIBRARY) {
632 errors.add(new AnalysisError(exportedSource, uriLiteral.offset, 770 errors.add(new AnalysisError(
633 uriLiteral.length, CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY, 771 exportedSource,
772 uriLiteral.offset,
773 uriLiteral.length,
774 CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY,
634 [uriLiteral.toSource()])); 775 [uriLiteral.toSource()]));
635 } 776 }
636 } 777 }
637 } 778 }
638 } 779 }
639 } 780 }
640 // 781 //
641 // Ensure "dart:core" import. 782 // Ensure "dart:core" import.
642 // 783 //
643 Source coreLibrarySource = context.sourceFactory.forUri(DartSdk.DART_CORE); 784 Source coreLibrarySource = context.sourceFactory.forUri(DartSdk.DART_CORE);
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 874
734 /** 875 /**
735 * The name of the [RESOLVED_UNIT1] input. 876 * The name of the [RESOLVED_UNIT1] input.
736 */ 877 */
737 static const String UNIT_INPUT = 'UNIT_INPUT'; 878 static const String UNIT_INPUT = 'UNIT_INPUT';
738 879
739 /** 880 /**
740 * The task descriptor describing this kind of task. 881 * The task descriptor describing this kind of task.
741 */ 882 */
742 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 883 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
743 'BuildEnumMemberElementsTask', createTask, buildInputs, 884 'BuildEnumMemberElementsTask',
885 createTask,
886 buildInputs,
744 <ResultDescriptor>[RESOLVED_UNIT2]); 887 <ResultDescriptor>[RESOLVED_UNIT2]);
745 888
746 BuildEnumMemberElementsTask( 889 BuildEnumMemberElementsTask(
747 InternalAnalysisContext context, AnalysisTarget target) 890 InternalAnalysisContext context, AnalysisTarget target)
748 : super(context, target); 891 : super(context, target);
749 892
750 @override 893 @override
751 TaskDescriptor get descriptor => DESCRIPTOR; 894 TaskDescriptor get descriptor => DESCRIPTOR;
752 895
753 @override 896 @override
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 class BuildExportNamespaceTask extends SourceBasedAnalysisTask { 937 class BuildExportNamespaceTask extends SourceBasedAnalysisTask {
795 /** 938 /**
796 * The name of the input for [LIBRARY_ELEMENT3] of a library. 939 * The name of the input for [LIBRARY_ELEMENT3] of a library.
797 */ 940 */
798 static const String LIBRARY_INPUT = 'LIBRARY_INPUT'; 941 static const String LIBRARY_INPUT = 'LIBRARY_INPUT';
799 942
800 /** 943 /**
801 * The task descriptor describing this kind of task. 944 * The task descriptor describing this kind of task.
802 */ 945 */
803 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 946 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
804 'BuildExportNamespaceTask', createTask, buildInputs, 947 'BuildExportNamespaceTask',
948 createTask,
949 buildInputs,
805 <ResultDescriptor>[LIBRARY_ELEMENT4]); 950 <ResultDescriptor>[LIBRARY_ELEMENT4]);
806 951
807 BuildExportNamespaceTask( 952 BuildExportNamespaceTask(
808 InternalAnalysisContext context, AnalysisTarget target) 953 InternalAnalysisContext context, AnalysisTarget target)
809 : super(context, target); 954 : super(context, target);
810 955
811 @override 956 @override
812 TaskDescriptor get descriptor => DESCRIPTOR; 957 TaskDescriptor get descriptor => DESCRIPTOR;
813 958
814 @override 959 @override
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
950 partElement.uriEnd = partUri.end; 1095 partElement.uriEnd = partUri.end;
951 partElement.uri = partDirective.uriContent; 1096 partElement.uri = partDirective.uriContent;
952 // 1097 //
953 // Validate that the part contains a part-of directive with the same 1098 // Validate that the part contains a part-of directive with the same
954 // name as the library. 1099 // name as the library.
955 // 1100 //
956 if (context.exists(partSource)) { 1101 if (context.exists(partSource)) {
957 String partLibraryName = 1102 String partLibraryName =
958 _getPartLibraryName(partSource, partUnit, directivesToResolve); 1103 _getPartLibraryName(partSource, partUnit, directivesToResolve);
959 if (partLibraryName == null) { 1104 if (partLibraryName == null) {
960 errors.add(new AnalysisError(librarySource, partUri.offset, 1105 errors.add(new AnalysisError(
961 partUri.length, CompileTimeErrorCode.PART_OF_NON_PART, 1106 librarySource,
1107 partUri.offset,
1108 partUri.length,
1109 CompileTimeErrorCode.PART_OF_NON_PART,
962 [partUri.toSource()])); 1110 [partUri.toSource()]));
963 } else if (libraryNameNode == null) { 1111 } else if (libraryNameNode == null) {
964 if (partsLibraryName == _UNKNOWN_LIBRARY_NAME) { 1112 if (partsLibraryName == _UNKNOWN_LIBRARY_NAME) {
965 partsLibraryName = partLibraryName; 1113 partsLibraryName = partLibraryName;
966 } else if (partsLibraryName != partLibraryName) { 1114 } else if (partsLibraryName != partLibraryName) {
967 partsLibraryName = null; 1115 partsLibraryName = null;
968 } 1116 }
969 } else if (libraryNameNode.name != partLibraryName) { 1117 } else if (libraryNameNode.name != partLibraryName) {
970 errors.add(new AnalysisError(librarySource, partUri.offset, 1118 errors.add(new AnalysisError(
971 partUri.length, StaticWarningCode.PART_OF_DIFFERENT_LIBRARY, [ 1119 librarySource,
972 libraryNameNode.name, 1120 partUri.offset,
973 partLibraryName 1121 partUri.length,
974 ])); 1122 StaticWarningCode.PART_OF_DIFFERENT_LIBRARY,
1123 [libraryNameNode.name, partLibraryName]));
975 } 1124 }
976 } 1125 }
977 if (entryPoint == null) { 1126 if (entryPoint == null) {
978 entryPoint = _findEntryPoint(partElement); 1127 entryPoint = _findEntryPoint(partElement);
979 } 1128 }
980 directive.element = partElement; 1129 directive.element = partElement;
981 sourcedCompilationUnits.add(partElement); 1130 sourcedCompilationUnits.add(partElement);
982 } 1131 }
983 } 1132 }
984 } 1133 }
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
1131 class BuildPublicNamespaceTask extends SourceBasedAnalysisTask { 1280 class BuildPublicNamespaceTask extends SourceBasedAnalysisTask {
1132 /** 1281 /**
1133 * The name of the input for [LIBRARY_ELEMENT2] of a library. 1282 * The name of the input for [LIBRARY_ELEMENT2] of a library.
1134 */ 1283 */
1135 static const String LIBRARY_INPUT = 'LIBRARY_INPUT'; 1284 static const String LIBRARY_INPUT = 'LIBRARY_INPUT';
1136 1285
1137 /** 1286 /**
1138 * The task descriptor describing this kind of task. 1287 * The task descriptor describing this kind of task.
1139 */ 1288 */
1140 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 1289 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
1141 'BuildPublicNamespaceTask', createTask, buildInputs, 1290 'BuildPublicNamespaceTask',
1291 createTask,
1292 buildInputs,
1142 <ResultDescriptor>[LIBRARY_ELEMENT3]); 1293 <ResultDescriptor>[LIBRARY_ELEMENT3]);
1143 1294
1144 BuildPublicNamespaceTask( 1295 BuildPublicNamespaceTask(
1145 InternalAnalysisContext context, AnalysisTarget target) 1296 InternalAnalysisContext context, AnalysisTarget target)
1146 : super(context, target); 1297 : super(context, target);
1147 1298
1148 @override 1299 @override
1149 TaskDescriptor get descriptor => DESCRIPTOR; 1300 TaskDescriptor get descriptor => DESCRIPTOR;
1150 1301
1151 @override 1302 @override
(...skipping 29 matching lines...) Expand all
1181 class BuildSourceExportClosureTask extends SourceBasedAnalysisTask { 1332 class BuildSourceExportClosureTask extends SourceBasedAnalysisTask {
1182 /** 1333 /**
1183 * The name of the export closure. 1334 * The name of the export closure.
1184 */ 1335 */
1185 static const String EXPORT_INPUT = 'EXPORT_INPUT'; 1336 static const String EXPORT_INPUT = 'EXPORT_INPUT';
1186 1337
1187 /** 1338 /**
1188 * The task descriptor describing this kind of task. 1339 * The task descriptor describing this kind of task.
1189 */ 1340 */
1190 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 1341 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
1191 'BuildSourceExportClosureTask', createTask, buildInputs, 1342 'BuildSourceExportClosureTask',
1343 createTask,
1344 buildInputs,
1192 <ResultDescriptor>[EXPORT_SOURCE_CLOSURE]); 1345 <ResultDescriptor>[EXPORT_SOURCE_CLOSURE]);
1193 1346
1194 BuildSourceExportClosureTask( 1347 BuildSourceExportClosureTask(
1195 InternalAnalysisContext context, AnalysisTarget target) 1348 InternalAnalysisContext context, AnalysisTarget target)
1196 : super(context, target); 1349 : super(context, target);
1197 1350
1198 @override 1351 @override
1199 TaskDescriptor get descriptor => DESCRIPTOR; 1352 TaskDescriptor get descriptor => DESCRIPTOR;
1200 1353
1201 @override 1354 @override
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1236 class BuildSourceImportExportClosureTask extends SourceBasedAnalysisTask { 1389 class BuildSourceImportExportClosureTask extends SourceBasedAnalysisTask {
1237 /** 1390 /**
1238 * The name of the import/export closure. 1391 * The name of the import/export closure.
1239 */ 1392 */
1240 static const String IMPORT_EXPORT_INPUT = 'IMPORT_EXPORT_INPUT'; 1393 static const String IMPORT_EXPORT_INPUT = 'IMPORT_EXPORT_INPUT';
1241 1394
1242 /** 1395 /**
1243 * The task descriptor describing this kind of task. 1396 * The task descriptor describing this kind of task.
1244 */ 1397 */
1245 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 1398 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
1246 'BuildSourceImportExportClosureTask', createTask, buildInputs, 1399 'BuildSourceImportExportClosureTask',
1400 createTask,
1401 buildInputs,
1247 <ResultDescriptor>[IMPORT_EXPORT_SOURCE_CLOSURE, IS_CLIENT]); 1402 <ResultDescriptor>[IMPORT_EXPORT_SOURCE_CLOSURE, IS_CLIENT]);
1248 1403
1249 BuildSourceImportExportClosureTask( 1404 BuildSourceImportExportClosureTask(
1250 InternalAnalysisContext context, AnalysisTarget target) 1405 InternalAnalysisContext context, AnalysisTarget target)
1251 : super(context, target); 1406 : super(context, target);
1252 1407
1253 @override 1408 @override
1254 TaskDescriptor get descriptor => DESCRIPTOR; 1409 TaskDescriptor get descriptor => DESCRIPTOR;
1255 1410
1256 @override 1411 @override
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1298 1453
1299 /** 1454 /**
1300 * The [PUBLIC_NAMESPACE] input of the `dart:async` library. 1455 * The [PUBLIC_NAMESPACE] input of the `dart:async` library.
1301 */ 1456 */
1302 static const String ASYNC_INPUT = 'ASYNC_INPUT'; 1457 static const String ASYNC_INPUT = 'ASYNC_INPUT';
1303 1458
1304 /** 1459 /**
1305 * The task descriptor describing this kind of task. 1460 * The task descriptor describing this kind of task.
1306 */ 1461 */
1307 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 1462 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
1308 'BuildTypeProviderTask', createTask, buildInputs, 1463 'BuildTypeProviderTask',
1464 createTask,
1465 buildInputs,
1309 <ResultDescriptor>[TYPE_PROVIDER]); 1466 <ResultDescriptor>[TYPE_PROVIDER]);
1310 1467
1311 BuildTypeProviderTask( 1468 BuildTypeProviderTask(
1312 InternalAnalysisContext context, AnalysisContextTarget target) 1469 InternalAnalysisContext context, AnalysisContextTarget target)
1313 : super(context, target); 1470 : super(context, target);
1314 1471
1315 @override 1472 @override
1316 TaskDescriptor get descriptor => DESCRIPTOR; 1473 TaskDescriptor get descriptor => DESCRIPTOR;
1317 1474
1318 @override 1475 @override
(...skipping 29 matching lines...) Expand all
1348 AnalysisContext context, AnalysisTarget target) { 1505 AnalysisContext context, AnalysisTarget target) {
1349 return new BuildTypeProviderTask(context, target); 1506 return new BuildTypeProviderTask(context, target);
1350 } 1507 }
1351 } 1508 }
1352 1509
1353 /** 1510 /**
1354 * A task that computes [CONSTANT_DEPENDENCIES] for a constant. 1511 * A task that computes [CONSTANT_DEPENDENCIES] for a constant.
1355 */ 1512 */
1356 class ComputeConstantDependenciesTask extends ConstantEvaluationAnalysisTask { 1513 class ComputeConstantDependenciesTask extends ConstantEvaluationAnalysisTask {
1357 /** 1514 /**
1358 * The name of the [RESOLVED_UNIT5] input. 1515 * The name of the [RESOLVED_UNIT9] input.
1359 */ 1516 */
1360 static const String UNIT_INPUT = 'UNIT_INPUT'; 1517 static const String UNIT_INPUT = 'UNIT_INPUT';
1361 1518
1362 /** 1519 /**
1363 * The name of the [TYPE_PROVIDER] input. 1520 * The name of the [TYPE_PROVIDER] input.
1364 */ 1521 */
1365 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT'; 1522 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT';
1366 1523
1367 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 1524 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
1368 'ComputeConstantDependenciesTask', createTask, buildInputs, 1525 'ComputeConstantDependenciesTask',
1526 createTask,
1527 buildInputs,
1369 <ResultDescriptor>[CONSTANT_DEPENDENCIES]); 1528 <ResultDescriptor>[CONSTANT_DEPENDENCIES]);
1370 1529
1371 ComputeConstantDependenciesTask( 1530 ComputeConstantDependenciesTask(
1372 InternalAnalysisContext context, ConstantEvaluationTarget constant) 1531 InternalAnalysisContext context, ConstantEvaluationTarget constant)
1373 : super(context, constant); 1532 : super(context, constant);
1374 1533
1375 @override 1534 @override
1376 TaskDescriptor get descriptor => DESCRIPTOR; 1535 TaskDescriptor get descriptor => DESCRIPTOR;
1377 1536
1378 @override 1537 @override
1379 void internalPerform() { 1538 void internalPerform() {
1380 // 1539 //
1381 // Prepare inputs. 1540 // Prepare inputs.
1382 // 1541 //
1383 // Note: UNIT_INPUT is not needed. It is merely a bookkeeping dependency 1542 // Note: UNIT_INPUT is not needed. It is merely a bookkeeping dependency
1384 // to ensure that resolution has occurred before we attempt to determine 1543 // to ensure that resolution has occurred before we attempt to determine
1385 // constant dependencies. 1544 // constant dependencies.
1386 // 1545 //
1387 ConstantEvaluationTarget constant = target; 1546 ConstantEvaluationTarget constant = target;
1388 AnalysisContext context = constant.context;
1389 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT); 1547 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT);
1390 // 1548 //
1391 // Compute dependencies. 1549 // Compute dependencies.
1392 // 1550 //
1393 List<ConstantEvaluationTarget> dependencies = <ConstantEvaluationTarget>[]; 1551 List<ConstantEvaluationTarget> dependencies = <ConstantEvaluationTarget>[];
1394 new ConstantEvaluationEngine(typeProvider, context.declaredVariables) 1552 new ConstantEvaluationEngine(typeProvider, context.declaredVariables,
1553 typeSystem: context.typeSystem)
1395 .computeDependencies(constant, dependencies.add); 1554 .computeDependencies(constant, dependencies.add);
1396 // 1555 //
1397 // Record outputs. 1556 // Record outputs.
1398 // 1557 //
1399 outputs[CONSTANT_DEPENDENCIES] = dependencies; 1558 outputs[CONSTANT_DEPENDENCIES] = dependencies;
1400 } 1559 }
1401 1560
1402 /** 1561 /**
1403 * Return a map from the names of the inputs of this kind of task to the task 1562 * Return a map from the names of the inputs of this kind of task to the task
1404 * input descriptors describing those inputs for a task with the 1563 * input descriptors describing those inputs for a task with the
1405 * given [target]. 1564 * given [target].
1406 */ 1565 */
1407 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 1566 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
1408 if (target is Element) { 1567 if (target is Element) {
1409 CompilationUnitElementImpl unit = target 1568 CompilationUnitElementImpl unit = target
1410 .getAncestor((Element element) => element is CompilationUnitElement); 1569 .getAncestor((Element element) => element is CompilationUnitElement);
1411 return <String, TaskInput>{ 1570 return <String, TaskInput>{
1412 UNIT_INPUT: RESOLVED_UNIT5 1571 UNIT_INPUT: RESOLVED_UNIT9
1413 .of(new LibrarySpecificUnit(unit.librarySource, target.source)), 1572 .of(new LibrarySpecificUnit(unit.librarySource, target.source)),
1414 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request) 1573 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request)
1415 }; 1574 };
1416 } else if (target is ConstantEvaluationTarget_Annotation) { 1575 } else if (target is ConstantEvaluationTarget_Annotation) {
1417 return <String, TaskInput>{ 1576 return <String, TaskInput>{
1418 UNIT_INPUT: RESOLVED_UNIT5 1577 UNIT_INPUT: RESOLVED_UNIT9
1419 .of(new LibrarySpecificUnit(target.librarySource, target.source)), 1578 .of(new LibrarySpecificUnit(target.librarySource, target.source)),
1420 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request) 1579 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request)
1421 }; 1580 };
1422 } 1581 }
1423 throw new AnalysisException( 1582 throw new AnalysisException(
1424 'Cannot build inputs for a ${target.runtimeType}'); 1583 'Cannot build inputs for a ${target.runtimeType}');
1425 } 1584 }
1426 1585
1427 /** 1586 /**
1428 * Create a [ResolveUnitReferencesTask] based on the given [target] in 1587 * Create a [ComputeConstantDependenciesTask] based on the given [target] in
1429 * the given [context]. 1588 * the given [context].
1430 */ 1589 */
1431 static ComputeConstantDependenciesTask createTask( 1590 static ComputeConstantDependenciesTask createTask(
1432 AnalysisContext context, AnalysisTarget target) { 1591 AnalysisContext context, AnalysisTarget target) {
1433 return new ComputeConstantDependenciesTask(context, target); 1592 return new ComputeConstantDependenciesTask(context, target);
1434 } 1593 }
1435 } 1594 }
1436 1595
1437 /** 1596 /**
1438 * A task that computes the value of a constant ([CONSTANT_VALUE]) and 1597 * A task that computes the value of a constant ([CONSTANT_VALUE]) and
1439 * stores it in the element model. 1598 * stores it in the element model.
1440 */ 1599 */
1441 class ComputeConstantValueTask extends ConstantEvaluationAnalysisTask { 1600 class ComputeConstantValueTask extends ConstantEvaluationAnalysisTask {
1442 /** 1601 /**
1443 * The name of the input which ensures that dependent constants are evaluated 1602 * The name of the input which ensures that dependent constants are evaluated
1444 * before the target. 1603 * before the target.
1445 */ 1604 */
1446 static const String DEPENDENCIES_INPUT = 'DEPENDENCIES_INPUT'; 1605 static const String DEPENDENCIES_INPUT = 'DEPENDENCIES_INPUT';
1447 1606
1448 /** 1607 /**
1449 * The name of the [TYPE_PROVIDER] input. 1608 * The name of the [TYPE_PROVIDER] input.
1450 */ 1609 */
1451 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT'; 1610 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT';
1452 1611
1453 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 1612 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
1454 'ComputeConstantValueTask', createTask, buildInputs, 1613 'ComputeConstantValueTask',
1614 createTask,
1615 buildInputs,
1455 <ResultDescriptor>[CONSTANT_VALUE]); 1616 <ResultDescriptor>[CONSTANT_VALUE]);
1456 1617
1457 ComputeConstantValueTask( 1618 ComputeConstantValueTask(
1458 InternalAnalysisContext context, ConstantEvaluationTarget constant) 1619 InternalAnalysisContext context, ConstantEvaluationTarget constant)
1459 : super(context, constant); 1620 : super(context, constant);
1460 1621
1461 @override 1622 @override
1462 TaskDescriptor get descriptor => DESCRIPTOR; 1623 TaskDescriptor get descriptor => DESCRIPTOR;
1463 1624
1464 @override 1625 @override
1465 bool get handlesDependencyCycles => true; 1626 bool get handlesDependencyCycles => true;
1466 1627
1467 @override 1628 @override
1468 void internalPerform() { 1629 void internalPerform() {
1469 // 1630 //
1470 // Prepare inputs. 1631 // Prepare inputs.
1471 // 1632 //
1472 // Note: DEPENDENCIES_INPUT is not needed. It is merely a bookkeeping 1633 // Note: DEPENDENCIES_INPUT is not needed. It is merely a bookkeeping
1473 // dependency to ensure that the constants that this constant depends on 1634 // dependency to ensure that the constants that this constant depends on
1474 // are computed first. 1635 // are computed first.
1475 ConstantEvaluationTarget constant = target; 1636 ConstantEvaluationTarget constant = target;
1476 AnalysisContext context = constant.context; 1637 AnalysisContext context = constant.context;
1477 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT); 1638 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT);
1478 // 1639 //
1479 // Compute the value of the constant, or report an error if there was a 1640 // Compute the value of the constant, or report an error if there was a
1480 // cycle. 1641 // cycle.
1481 // 1642 //
1482 ConstantEvaluationEngine constantEvaluationEngine = 1643 ConstantEvaluationEngine constantEvaluationEngine =
1483 new ConstantEvaluationEngine(typeProvider, context.declaredVariables); 1644 new ConstantEvaluationEngine(typeProvider, context.declaredVariables,
1645 typeSystem: context.typeSystem);
1484 if (dependencyCycle == null) { 1646 if (dependencyCycle == null) {
1485 constantEvaluationEngine.computeConstantValue(constant); 1647 constantEvaluationEngine.computeConstantValue(constant);
1486 } else { 1648 } else {
1487 List<ConstantEvaluationTarget> constantsInCycle = 1649 List<ConstantEvaluationTarget> constantsInCycle =
1488 <ConstantEvaluationTarget>[]; 1650 <ConstantEvaluationTarget>[];
1489 for (WorkItem workItem in dependencyCycle) { 1651 for (WorkItem workItem in dependencyCycle) {
1490 if (workItem.descriptor == DESCRIPTOR) { 1652 if (workItem.descriptor == DESCRIPTOR) {
1491 constantsInCycle.add(workItem.target); 1653 constantsInCycle.add(workItem.target);
1492 } 1654 }
1493 } 1655 }
(...skipping 24 matching lines...) Expand all
1518 * Create a [ComputeConstantValueTask] based on the given [target] in the 1680 * Create a [ComputeConstantValueTask] based on the given [target] in the
1519 * given [context]. 1681 * given [context].
1520 */ 1682 */
1521 static ComputeConstantValueTask createTask( 1683 static ComputeConstantValueTask createTask(
1522 AnalysisContext context, AnalysisTarget target) { 1684 AnalysisContext context, AnalysisTarget target) {
1523 return new ComputeConstantValueTask(context, target); 1685 return new ComputeConstantValueTask(context, target);
1524 } 1686 }
1525 } 1687 }
1526 1688
1527 /** 1689 /**
1690 * A task that computes the [INFERABLE_STATIC_VARIABLE_DEPENDENCIES] for a
1691 * static variable whose type should be inferred.
1692 */
1693 class ComputeInferableStaticVariableDependenciesTask
1694 extends ConstantEvaluationAnalysisTask {
1695 /**
1696 * The name of the [RESOLVED_UNIT5] input.
1697 */
1698 static const String UNIT_INPUT = 'UNIT_INPUT';
1699
1700 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
1701 'ComputeInferableStaticVariableDependenciesTask',
1702 createTask,
1703 buildInputs,
1704 <ResultDescriptor>[INFERABLE_STATIC_VARIABLE_DEPENDENCIES]);
1705
1706 ComputeInferableStaticVariableDependenciesTask(
1707 InternalAnalysisContext context, VariableElement variable)
1708 : super(context, variable);
1709
1710 @override
1711 TaskDescriptor get descriptor => DESCRIPTOR;
1712
1713 @override
1714 void internalPerform() {
1715 //
1716 // Prepare inputs.
1717 //
1718 VariableElement variable = target;
1719 CompilationUnit unit = getRequiredInput(UNIT_INPUT);
1720 //
1721 // Compute dependencies.
1722 //
1723 NodeLocator locator = new NodeLocator(variable.nameOffset);
1724 AstNode node = locator.searchWithin(unit);
1725 VariableDeclaration declaration =
1726 node.getAncestor((AstNode ancestor) => ancestor is VariableDeclaration);
1727 if (declaration == null || declaration.name != node) {
1728 throw new AnalysisException(
1729 "NodeLocator failed to find a variable's declaration");
1730 }
1731 VariableGatherer gatherer = new VariableGatherer(_isInferableStatic);
1732 declaration.initializer.accept(gatherer);
1733 //
1734 // Record outputs.
1735 //
1736 outputs[INFERABLE_STATIC_VARIABLE_DEPENDENCIES] = gatherer.results.toList();
1737 }
1738
1739 /**
1740 * Return `true` if the given [variable] is a static variable whose type
1741 * should be inferred.
1742 */
1743 bool _isInferableStatic(VariableElement variable) => variable.isStatic &&
1744 variable.hasImplicitType &&
1745 variable.initializer != null;
1746
1747 /**
1748 * Return a map from the names of the inputs of this kind of task to the task
1749 * input descriptors describing those inputs for a task with the
1750 * given [target].
1751 */
1752 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
1753 if (target is VariableElement) {
1754 CompilationUnitElementImpl unit = target
1755 .getAncestor((Element element) => element is CompilationUnitElement);
1756 return <String, TaskInput>{
1757 UNIT_INPUT: RESOLVED_UNIT5
1758 .of(new LibrarySpecificUnit(unit.librarySource, unit.source))
1759 };
1760 }
1761 throw new AnalysisException(
1762 'Cannot build inputs for a ${target.runtimeType}');
1763 }
1764
1765 /**
1766 * Create a [ComputeInferableStaticVariableDependenciesTask] based on the
1767 * given [target] in the given [context].
1768 */
1769 static ComputeInferableStaticVariableDependenciesTask createTask(
1770 AnalysisContext context, AnalysisTarget target) {
1771 return new ComputeInferableStaticVariableDependenciesTask(context, target);
1772 }
1773 }
1774
1775 /**
1776 * A task that computes the [LIBRARY_CYCLE] for a
1777 * library element. Also computes the [LIBRARY_CYCLE_UNITS] and the
1778 * [LIBRARY_CYCLE_DEPENDENCIES].
1779 */
1780 class ComputeLibraryCycleTask extends SourceBasedAnalysisTask {
1781 /**
1782 * The name of the [LIBRARY_ELEMENT2] input.
1783 */
1784 static const String LIBRARY_ELEMENT_INPUT = 'LIBRARY_ELEMENT_INPUT';
1785
1786 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
1787 'ComputeLibraryCycleForUnitTask',
1788 createTask,
1789 buildInputs, <ResultDescriptor>[
1790 LIBRARY_CYCLE,
1791 LIBRARY_CYCLE_UNITS,
1792 LIBRARY_CYCLE_DEPENDENCIES
1793 ]);
1794
1795 ComputeLibraryCycleTask(
1796 InternalAnalysisContext context, AnalysisTarget target)
1797 : super(context, target);
1798
1799 @override
1800 TaskDescriptor get descriptor => DESCRIPTOR;
1801
1802 @override
1803 void internalPerform() {
1804 if (context.analysisOptions.strongMode) {
1805 LibraryElementImpl library = getRequiredInput(LIBRARY_ELEMENT_INPUT);
1806 List<LibraryElement> component = library.libraryCycle;
1807 Set<LibraryElement> filter = new Set<LibraryElement>.from(component);
1808 Set<CompilationUnitElement> deps = new Set<CompilationUnitElement>();
1809 void addLibrary(l) {
1810 if (!filter.contains(l)) {
1811 deps.addAll(l.units);
1812 }
1813 }
1814 for (LibraryElement l in component) {
1815 l.importedLibraries.forEach(addLibrary);
1816 l.exportedLibraries.forEach(addLibrary);
1817 }
1818
1819 //
1820 // Record outputs.
1821 //
1822 outputs[LIBRARY_CYCLE] = component;
1823 outputs[LIBRARY_CYCLE_UNITS] = component.expand((l) => l.units).toList();
1824 outputs[LIBRARY_CYCLE_DEPENDENCIES] = deps.toList();
1825 } else {
1826 outputs[LIBRARY_CYCLE] = [];
1827 outputs[LIBRARY_CYCLE_UNITS] = [];
1828 outputs[LIBRARY_CYCLE_DEPENDENCIES] = [];
1829 }
1830 }
1831
1832 /**
1833 * Return a map from the names of the inputs of this kind of task to the task
1834 * input descriptors describing those inputs for a task with the
1835 * given [target].
1836 */
1837 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
1838 LibrarySpecificUnit unit = target;
1839 return <String, TaskInput>{
1840 'resolveReachableLibraries': IMPORT_EXPORT_SOURCE_CLOSURE
1841 .of(unit.library)
1842 .toListOf(LIBRARY_ELEMENT2),
1843 LIBRARY_ELEMENT_INPUT: LIBRARY_ELEMENT2.of(unit.library)
1844 };
1845 }
1846
1847 /**
1848 * Create a [ComputeLibraryCycleTask] based on the
1849 * given [target] in the given [context].
1850 */
1851 static ComputeLibraryCycleTask createTask(
1852 AnalysisContext context, AnalysisTarget target) {
1853 return new ComputeLibraryCycleTask(context, target);
1854 }
1855 }
1856
1857 /**
1528 * A base class for analysis tasks whose target is expected to be a 1858 * A base class for analysis tasks whose target is expected to be a
1529 * [ConstantEvaluationTarget]. 1859 * [ConstantEvaluationTarget].
1530 */ 1860 */
1531 abstract class ConstantEvaluationAnalysisTask extends AnalysisTask { 1861 abstract class ConstantEvaluationAnalysisTask extends AnalysisTask {
1532 /** 1862 /**
1533 * Initialize a newly created task to perform analysis within the given 1863 * Initialize a newly created task to perform analysis within the given
1534 * [context] in order to produce results for the given [constant]. 1864 * [context] in order to produce results for the given [constant].
1535 */ 1865 */
1536 ConstantEvaluationAnalysisTask( 1866 ConstantEvaluationAnalysisTask(
1537 AnalysisContext context, ConstantEvaluationTarget constant) 1867 AnalysisContext context, ConstantEvaluationTarget constant)
(...skipping 20 matching lines...) Expand all
1558 } 1888 }
1559 1889
1560 /** 1890 /**
1561 * A task that computes a list of the libraries containing the target source. 1891 * A task that computes a list of the libraries containing the target source.
1562 */ 1892 */
1563 class ContainingLibrariesTask extends SourceBasedAnalysisTask { 1893 class ContainingLibrariesTask extends SourceBasedAnalysisTask {
1564 /** 1894 /**
1565 * The task descriptor describing this kind of task. 1895 * The task descriptor describing this kind of task.
1566 */ 1896 */
1567 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 1897 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
1568 'ContainingLibrariesTask', createTask, buildInputs, 1898 'ContainingLibrariesTask',
1899 createTask,
1900 buildInputs,
1569 <ResultDescriptor>[CONTAINING_LIBRARIES]); 1901 <ResultDescriptor>[CONTAINING_LIBRARIES]);
1570 1902
1571 ContainingLibrariesTask( 1903 ContainingLibrariesTask(
1572 InternalAnalysisContext context, AnalysisTarget target) 1904 InternalAnalysisContext context, AnalysisTarget target)
1573 : super(context, target); 1905 : super(context, target);
1574 1906
1575 @override 1907 @override
1576 TaskDescriptor get descriptor => DESCRIPTOR; 1908 TaskDescriptor get descriptor => DESCRIPTOR;
1577 1909
1578 @override 1910 @override
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
1698 return DeltaResult.INVALIDATE; 2030 return DeltaResult.INVALIDATE;
1699 } 2031 }
1700 } 2032 }
1701 2033
1702 /** 2034 /**
1703 * A task that merges all of the errors for a single source into a single list 2035 * A task that merges all of the errors for a single source into a single list
1704 * of errors. 2036 * of errors.
1705 */ 2037 */
1706 class DartErrorsTask extends SourceBasedAnalysisTask { 2038 class DartErrorsTask extends SourceBasedAnalysisTask {
1707 /** 2039 /**
1708 * The name of the [BUILD_DIRECTIVES_ERRORS] input.
1709 */
1710 static const String BUILD_DIRECTIVES_ERRORS_INPUT = 'BUILD_DIRECTIVES_ERRORS';
1711
1712 /**
1713 * The name of the [BUILD_LIBRARY_ERRORS] input.
1714 */
1715 static const String BUILD_LIBRARY_ERRORS_INPUT = 'BUILD_LIBRARY_ERRORS';
1716
1717 /**
1718 * The name of the [LIBRARY_UNIT_ERRORS] input.
1719 */
1720 static const String LIBRARY_UNIT_ERRORS_INPUT = 'LIBRARY_UNIT_ERRORS';
1721
1722 /**
1723 * The name of the [PARSE_ERRORS] input.
1724 */
1725 static const String PARSE_ERRORS_INPUT = 'PARSE_ERRORS';
1726
1727 /**
1728 * The name of the [SCAN_ERRORS] input.
1729 */
1730 static const String SCAN_ERRORS_INPUT = 'SCAN_ERRORS';
1731
1732 /**
1733 * The task descriptor describing this kind of task. 2040 * The task descriptor describing this kind of task.
1734 */ 2041 */
1735 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor('DartErrorsTask', 2042 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor('DartErrorsTask',
1736 createTask, buildInputs, <ResultDescriptor>[DART_ERRORS]); 2043 createTask, buildInputs, <ResultDescriptor>[DART_ERRORS]);
1737 2044
1738 DartErrorsTask(InternalAnalysisContext context, AnalysisTarget target) 2045 DartErrorsTask(InternalAnalysisContext context, AnalysisTarget target)
1739 : super(context, target); 2046 : super(context, target);
1740 2047
1741 @override 2048 @override
1742 TaskDescriptor get descriptor => DESCRIPTOR; 2049 TaskDescriptor get descriptor => DESCRIPTOR;
1743 2050
1744 @override 2051 @override
1745 void internalPerform() { 2052 void internalPerform() {
2053 List<List<AnalysisError>> errorLists = <List<AnalysisError>>[];
1746 // 2054 //
1747 // Prepare inputs. 2055 // Prepare inputs.
1748 // 2056 //
1749 List<List<AnalysisError>> errorLists = <List<AnalysisError>>[]; 2057 EnginePlugin enginePlugin = AnalysisEngine.instance.enginePlugin;
1750 errorLists.add(getRequiredInput(BUILD_DIRECTIVES_ERRORS_INPUT)); 2058 for (ResultDescriptor result in enginePlugin.dartErrorsForSource) {
1751 errorLists.add(getRequiredInput(BUILD_LIBRARY_ERRORS_INPUT)); 2059 String inputName = result.name + '_input';
1752 errorLists.add(getRequiredInput(PARSE_ERRORS_INPUT)); 2060 errorLists.add(getRequiredInput(inputName));
1753 errorLists.add(getRequiredInput(SCAN_ERRORS_INPUT)); 2061 }
1754 Map<Source, List<AnalysisError>> unitErrors = 2062 for (ResultDescriptor result in enginePlugin.dartErrorsForUnit) {
1755 getRequiredInput(LIBRARY_UNIT_ERRORS_INPUT); 2063 String inputName = result.name + '_input';
1756 for (List<AnalysisError> errors in unitErrors.values) { 2064 Map<Source, List<AnalysisError>> errorMap = getRequiredInput(inputName);
1757 errorLists.add(errors); 2065 for (List<AnalysisError> errors in errorMap.values) {
2066 errorLists.add(errors);
2067 }
1758 } 2068 }
1759 // 2069 //
1760 // Record outputs. 2070 // Record outputs.
1761 // 2071 //
1762 outputs[DART_ERRORS] = AnalysisError.mergeLists(errorLists); 2072 outputs[DART_ERRORS] = AnalysisError.mergeLists(errorLists);
1763 } 2073 }
1764 2074
1765 /** 2075 /**
1766 * Return a map from the names of the inputs of this kind of task to the task 2076 * Return a map from the names of the inputs of this kind of task to the task
1767 * input descriptors describing those inputs for a task with the 2077 * input descriptors describing those inputs for a task with the
1768 * given [target]. 2078 * given [target].
1769 */ 2079 */
1770 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 2080 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
1771 Source source = target; 2081 Source source = target;
1772 return <String, TaskInput>{ 2082 Map<String, TaskInput> inputs = <String, TaskInput>{};
1773 BUILD_DIRECTIVES_ERRORS_INPUT: BUILD_DIRECTIVES_ERRORS.of(source), 2083 EnginePlugin enginePlugin = AnalysisEngine.instance.enginePlugin;
1774 BUILD_LIBRARY_ERRORS_INPUT: BUILD_LIBRARY_ERRORS.of(source), 2084 // for Source
1775 PARSE_ERRORS_INPUT: PARSE_ERRORS.of(source), 2085 for (ResultDescriptor result in enginePlugin.dartErrorsForSource) {
1776 SCAN_ERRORS_INPUT: SCAN_ERRORS.of(source), 2086 String inputName = result.name + '_input';
1777 LIBRARY_UNIT_ERRORS_INPUT: CONTAINING_LIBRARIES 2087 inputs[inputName] = result.of(source);
1778 .of(source) 2088 }
1779 .toMap((Source library) { 2089 // for LibrarySpecificUnit
2090 for (ResultDescriptor result in enginePlugin.dartErrorsForUnit) {
2091 String inputName = result.name + '_input';
2092 inputs[inputName] =
2093 CONTAINING_LIBRARIES.of(source).toMap((Source library) {
1780 LibrarySpecificUnit unit = new LibrarySpecificUnit(library, source); 2094 LibrarySpecificUnit unit = new LibrarySpecificUnit(library, source);
1781 return LIBRARY_UNIT_ERRORS.of(unit); 2095 return result.of(unit);
1782 }) 2096 });
1783 }; 2097 }
2098 return inputs;
1784 } 2099 }
1785 2100
1786 /** 2101 /**
1787 * Create a [DartErrorsTask] based on the given [target] in the given 2102 * Create a [DartErrorsTask] based on the given [target] in the given
1788 * [context]. 2103 * [context].
1789 */ 2104 */
1790 static DartErrorsTask createTask( 2105 static DartErrorsTask createTask(
1791 AnalysisContext context, AnalysisTarget target) { 2106 AnalysisContext context, AnalysisTarget target) {
1792 return new DartErrorsTask(context, target); 2107 return new DartErrorsTask(context, target);
1793 } 2108 }
1794 } 2109 }
1795 2110
1796 /** 2111 /**
1797 * A task that builds [RESOLVED_UNIT] for a unit. 2112 * A task that builds [RESOLVED_UNIT] for a unit.
1798 */ 2113 */
1799 class EvaluateUnitConstantsTask extends SourceBasedAnalysisTask { 2114 class EvaluateUnitConstantsTask extends SourceBasedAnalysisTask {
1800 /** 2115 /**
1801 * The name of the [RESOLVED_UNIT5] input. 2116 * The name of the [RESOLVED_UNIT9] input.
1802 */ 2117 */
1803 static const String UNIT_INPUT = 'UNIT_INPUT'; 2118 static const String UNIT_INPUT = 'UNIT_INPUT';
1804 2119
1805 /** 2120 /**
1806 * The name of the [CONSTANT_VALUE] input. 2121 * The name of the [CONSTANT_VALUE] input.
1807 */ 2122 */
1808 static const String CONSTANT_VALUES = 'CONSTANT_VALUES'; 2123 static const String CONSTANT_VALUES = 'CONSTANT_VALUES';
1809 2124
1810 /** 2125 /**
1811 * The task descriptor describing this kind of task. 2126 * The task descriptor describing this kind of task.
1812 */ 2127 */
1813 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 2128 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
1814 'EvaluateUnitConstantsTask', createTask, buildInputs, 2129 'EvaluateUnitConstantsTask',
2130 createTask,
2131 buildInputs,
1815 <ResultDescriptor>[RESOLVED_UNIT]); 2132 <ResultDescriptor>[RESOLVED_UNIT]);
1816 2133
1817 EvaluateUnitConstantsTask(AnalysisContext context, LibrarySpecificUnit target) 2134 EvaluateUnitConstantsTask(AnalysisContext context, LibrarySpecificUnit target)
1818 : super(context, target); 2135 : super(context, target);
1819 2136
1820 @override 2137 @override
1821 TaskDescriptor get descriptor => DESCRIPTOR; 2138 TaskDescriptor get descriptor => DESCRIPTOR;
1822 2139
1823 @override 2140 @override
1824 void internalPerform() { 2141 void internalPerform() {
1825 // No actual work needs to be performed; the task manager will ensure that 2142 // No actual work needs to be performed; the task manager will ensure that
1826 // all constants are evaluated before this method is called. 2143 // all constants are evaluated before this method is called.
1827 CompilationUnit unit = getRequiredInput(UNIT_INPUT); 2144 CompilationUnit unit = getRequiredInput(UNIT_INPUT);
1828 outputs[RESOLVED_UNIT] = unit; 2145 outputs[RESOLVED_UNIT] = unit;
1829 } 2146 }
1830 2147
1831 /** 2148 /**
1832 * Return a map from the names of the inputs of this kind of task to the task 2149 * Return a map from the names of the inputs of this kind of task to the task
1833 * input descriptors describing those inputs for a task with the 2150 * input descriptors describing those inputs for a task with the
1834 * given [target]. 2151 * given [target].
1835 */ 2152 */
1836 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 2153 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
1837 LibrarySpecificUnit unit = target; 2154 LibrarySpecificUnit unit = target;
1838 return <String, TaskInput>{ 2155 return <String, TaskInput>{
1839 'libraryElement': LIBRARY_ELEMENT.of(unit.library), 2156 'libraryElement': LIBRARY_ELEMENT.of(unit.library),
1840 UNIT_INPUT: RESOLVED_UNIT5.of(unit), 2157 UNIT_INPUT: RESOLVED_UNIT9.of(unit),
1841 CONSTANT_VALUES: 2158 CONSTANT_VALUES:
1842 COMPILATION_UNIT_CONSTANTS.of(unit).toListOf(CONSTANT_VALUE) 2159 COMPILATION_UNIT_CONSTANTS.of(unit).toListOf(CONSTANT_VALUE)
1843 }; 2160 };
1844 } 2161 }
1845 2162
1846 /** 2163 /**
1847 * Create an [EvaluateUnitConstantsTask] based on the given [target] in 2164 * Create an [EvaluateUnitConstantsTask] based on the given [target] in
1848 * the given [context]. 2165 * the given [context].
1849 */ 2166 */
1850 static EvaluateUnitConstantsTask createTask( 2167 static EvaluateUnitConstantsTask createTask(
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1954 } 2271 }
1955 return newNames; 2272 return newNames;
1956 } 2273 }
1957 } 2274 }
1958 2275
1959 /** 2276 /**
1960 * A task that builds [USED_IMPORTED_ELEMENTS] for a unit. 2277 * A task that builds [USED_IMPORTED_ELEMENTS] for a unit.
1961 */ 2278 */
1962 class GatherUsedImportedElementsTask extends SourceBasedAnalysisTask { 2279 class GatherUsedImportedElementsTask extends SourceBasedAnalysisTask {
1963 /** 2280 /**
1964 * The name of the [RESOLVED_UNIT5] input. 2281 * The name of the [RESOLVED_UNIT9] input.
1965 */ 2282 */
1966 static const String UNIT_INPUT = 'UNIT_INPUT'; 2283 static const String UNIT_INPUT = 'UNIT_INPUT';
1967 2284
1968 /** 2285 /**
1969 * The task descriptor describing this kind of task. 2286 * The task descriptor describing this kind of task.
1970 */ 2287 */
1971 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 2288 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
1972 'GatherUsedImportedElementsTask', createTask, buildInputs, 2289 'GatherUsedImportedElementsTask',
2290 createTask,
2291 buildInputs,
1973 <ResultDescriptor>[USED_IMPORTED_ELEMENTS]); 2292 <ResultDescriptor>[USED_IMPORTED_ELEMENTS]);
1974 2293
1975 GatherUsedImportedElementsTask( 2294 GatherUsedImportedElementsTask(
1976 InternalAnalysisContext context, AnalysisTarget target) 2295 InternalAnalysisContext context, AnalysisTarget target)
1977 : super(context, target); 2296 : super(context, target);
1978 2297
1979 @override 2298 @override
1980 TaskDescriptor get descriptor => DESCRIPTOR; 2299 TaskDescriptor get descriptor => DESCRIPTOR;
1981 2300
1982 @override 2301 @override
(...skipping 13 matching lines...) Expand all
1996 outputs[USED_IMPORTED_ELEMENTS] = visitor.usedElements; 2315 outputs[USED_IMPORTED_ELEMENTS] = visitor.usedElements;
1997 } 2316 }
1998 2317
1999 /** 2318 /**
2000 * Return a map from the names of the inputs of this kind of task to the task 2319 * Return a map from the names of the inputs of this kind of task to the task
2001 * input descriptors describing those inputs for a task with the 2320 * input descriptors describing those inputs for a task with the
2002 * given [target]. 2321 * given [target].
2003 */ 2322 */
2004 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 2323 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
2005 LibrarySpecificUnit unit = target; 2324 LibrarySpecificUnit unit = target;
2006 return <String, TaskInput>{UNIT_INPUT: RESOLVED_UNIT5.of(unit)}; 2325 return <String, TaskInput>{UNIT_INPUT: RESOLVED_UNIT9.of(unit)};
2007 } 2326 }
2008 2327
2009 /** 2328 /**
2010 * Create a [GatherUsedImportedElementsTask] based on the given [target] in 2329 * Create a [GatherUsedImportedElementsTask] based on the given [target] in
2011 * the given [context]. 2330 * the given [context].
2012 */ 2331 */
2013 static GatherUsedImportedElementsTask createTask( 2332 static GatherUsedImportedElementsTask createTask(
2014 AnalysisContext context, AnalysisTarget target) { 2333 AnalysisContext context, AnalysisTarget target) {
2015 return new GatherUsedImportedElementsTask(context, target); 2334 return new GatherUsedImportedElementsTask(context, target);
2016 } 2335 }
2017 } 2336 }
2018 2337
2019 /** 2338 /**
2020 * A task that builds [USED_LOCAL_ELEMENTS] for a unit. 2339 * A task that builds [USED_LOCAL_ELEMENTS] for a unit.
2021 */ 2340 */
2022 class GatherUsedLocalElementsTask extends SourceBasedAnalysisTask { 2341 class GatherUsedLocalElementsTask extends SourceBasedAnalysisTask {
2023 /** 2342 /**
2024 * The name of the [RESOLVED_UNIT5] input. 2343 * The name of the [RESOLVED_UNIT9] input.
2025 */ 2344 */
2026 static const String UNIT_INPUT = 'UNIT_INPUT'; 2345 static const String UNIT_INPUT = 'UNIT_INPUT';
2027 2346
2028 /** 2347 /**
2029 * The task descriptor describing this kind of task. 2348 * The task descriptor describing this kind of task.
2030 */ 2349 */
2031 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 2350 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
2032 'GatherUsedLocalElementsTask', createTask, buildInputs, 2351 'GatherUsedLocalElementsTask',
2352 createTask,
2353 buildInputs,
2033 <ResultDescriptor>[USED_LOCAL_ELEMENTS]); 2354 <ResultDescriptor>[USED_LOCAL_ELEMENTS]);
2034 2355
2035 GatherUsedLocalElementsTask( 2356 GatherUsedLocalElementsTask(
2036 InternalAnalysisContext context, AnalysisTarget target) 2357 InternalAnalysisContext context, AnalysisTarget target)
2037 : super(context, target); 2358 : super(context, target);
2038 2359
2039 @override 2360 @override
2040 TaskDescriptor get descriptor => DESCRIPTOR; 2361 TaskDescriptor get descriptor => DESCRIPTOR;
2041 2362
2042 @override 2363 @override
(...skipping 13 matching lines...) Expand all
2056 outputs[USED_LOCAL_ELEMENTS] = visitor.usedElements; 2377 outputs[USED_LOCAL_ELEMENTS] = visitor.usedElements;
2057 } 2378 }
2058 2379
2059 /** 2380 /**
2060 * Return a map from the names of the inputs of this kind of task to the task 2381 * Return a map from the names of the inputs of this kind of task to the task
2061 * input descriptors describing those inputs for a task with the 2382 * input descriptors describing those inputs for a task with the
2062 * given [target]. 2383 * given [target].
2063 */ 2384 */
2064 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 2385 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
2065 LibrarySpecificUnit unit = target; 2386 LibrarySpecificUnit unit = target;
2066 return <String, TaskInput>{UNIT_INPUT: RESOLVED_UNIT5.of(unit)}; 2387 return <String, TaskInput>{UNIT_INPUT: RESOLVED_UNIT9.of(unit)};
2067 } 2388 }
2068 2389
2069 /** 2390 /**
2070 * Create a [GatherUsedLocalElementsTask] based on the given [target] in 2391 * Create a [GatherUsedLocalElementsTask] based on the given [target] in
2071 * the given [context]. 2392 * the given [context].
2072 */ 2393 */
2073 static GatherUsedLocalElementsTask createTask( 2394 static GatherUsedLocalElementsTask createTask(
2074 AnalysisContext context, AnalysisTarget target) { 2395 AnalysisContext context, AnalysisTarget target) {
2075 return new GatherUsedLocalElementsTask(context, target); 2396 return new GatherUsedLocalElementsTask(context, target);
2076 } 2397 }
2077 } 2398 }
2078 2399
2079 /** 2400 /**
2080 * A task that generates [HINTS] for a unit. 2401 * A task that generates [HINTS] for a unit.
2081 */ 2402 */
2082 class GenerateHintsTask extends SourceBasedAnalysisTask { 2403 class GenerateHintsTask extends SourceBasedAnalysisTask {
2083 /** 2404 /**
2084 * The name of the [RESOLVED_UNIT5] input. 2405 * The name of the [RESOLVED_UNIT9] input.
2085 */ 2406 */
2086 static const String RESOLVED_UNIT_INPUT = 'RESOLVED_UNIT'; 2407 static const String RESOLVED_UNIT_INPUT = 'RESOLVED_UNIT';
2087 2408
2088 /** 2409 /**
2089 * The name of a list of [USED_LOCAL_ELEMENTS] for each library unit input. 2410 * The name of a list of [USED_LOCAL_ELEMENTS] for each library unit input.
2090 */ 2411 */
2091 static const String USED_LOCAL_ELEMENTS_INPUT = 'USED_LOCAL_ELEMENTS'; 2412 static const String USED_LOCAL_ELEMENTS_INPUT = 'USED_LOCAL_ELEMENTS';
2092 2413
2093 /** 2414 /**
2094 * The name of a list of [USED_IMPORTED_ELEMENTS] for each library unit input. 2415 * The name of a list of [USED_IMPORTED_ELEMENTS] for each library unit input.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2128 // 2449 //
2129 // Prepare inputs. 2450 // Prepare inputs.
2130 // 2451 //
2131 CompilationUnit unit = getRequiredInput(RESOLVED_UNIT_INPUT); 2452 CompilationUnit unit = getRequiredInput(RESOLVED_UNIT_INPUT);
2132 List<UsedImportedElements> usedImportedElementsList = 2453 List<UsedImportedElements> usedImportedElementsList =
2133 getRequiredInput(USED_IMPORTED_ELEMENTS_INPUT); 2454 getRequiredInput(USED_IMPORTED_ELEMENTS_INPUT);
2134 List<UsedLocalElements> usedLocalElementsList = 2455 List<UsedLocalElements> usedLocalElementsList =
2135 getRequiredInput(USED_LOCAL_ELEMENTS_INPUT); 2456 getRequiredInput(USED_LOCAL_ELEMENTS_INPUT);
2136 CompilationUnitElement unitElement = unit.element; 2457 CompilationUnitElement unitElement = unit.element;
2137 LibraryElement libraryElement = unitElement.library; 2458 LibraryElement libraryElement = unitElement.library;
2459 TypeSystem typeSystem = context.typeSystem;
2460
2138 // 2461 //
2139 // Generate errors. 2462 // Generate errors.
2140 // 2463 //
2141 unit.accept(new DeadCodeVerifier(errorReporter)); 2464 unit.accept(new DeadCodeVerifier(errorReporter, typeSystem: typeSystem));
2142 // Verify imports. 2465 // Verify imports.
2143 { 2466 {
2144 ImportsVerifier verifier = new ImportsVerifier(); 2467 ImportsVerifier verifier = new ImportsVerifier();
2145 verifier.addImports(unit); 2468 verifier.addImports(unit);
2146 usedImportedElementsList.forEach(verifier.removeUsedElements); 2469 usedImportedElementsList.forEach(verifier.removeUsedElements);
2147 verifier.generateDuplicateImportHints(errorReporter); 2470 verifier.generateDuplicateImportHints(errorReporter);
2148 verifier.generateUnusedImportHints(errorReporter); 2471 verifier.generateUnusedImportHints(errorReporter);
2149 } 2472 }
2150 // Unused local elements. 2473 // Unused local elements.
2151 { 2474 {
2152 UsedLocalElements usedElements = 2475 UsedLocalElements usedElements =
2153 new UsedLocalElements.merge(usedLocalElementsList); 2476 new UsedLocalElements.merge(usedLocalElementsList);
2154 UnusedLocalElementsVerifier visitor = 2477 UnusedLocalElementsVerifier visitor =
2155 new UnusedLocalElementsVerifier(errorListener, usedElements); 2478 new UnusedLocalElementsVerifier(errorListener, usedElements);
2156 unitElement.accept(visitor); 2479 unitElement.accept(visitor);
2157 } 2480 }
2158 // Dart2js analysis. 2481 // Dart2js analysis.
2159 if (analysisOptions.dart2jsHint) { 2482 if (analysisOptions.dart2jsHint) {
2160 unit.accept(new Dart2JSVerifier(errorReporter)); 2483 unit.accept(new Dart2JSVerifier(errorReporter));
2161 } 2484 }
2162 // Dart best practices. 2485 // Dart best practices.
2163 InheritanceManager inheritanceManager = 2486 InheritanceManager inheritanceManager =
2164 new InheritanceManager(libraryElement); 2487 new InheritanceManager(libraryElement);
2165 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT); 2488 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT);
2166 unit.accept(new BestPracticesVerifier(errorReporter, typeProvider)); 2489
2490 unit.accept(new BestPracticesVerifier(errorReporter, typeProvider,
2491 typeSystem: typeSystem));
2167 unit.accept(new OverrideVerifier(errorReporter, inheritanceManager)); 2492 unit.accept(new OverrideVerifier(errorReporter, inheritanceManager));
2168 // Find to-do comments. 2493 // Find to-do comments.
2169 new ToDoFinder(errorReporter).findIn(unit); 2494 new ToDoFinder(errorReporter).findIn(unit);
2170 // 2495 //
2171 // Record outputs. 2496 // Record outputs.
2172 // 2497 //
2173 outputs[HINTS] = errorListener.errors; 2498 outputs[HINTS] = errorListener.errors;
2174 } 2499 }
2175 2500
2176 /** 2501 /**
(...skipping 22 matching lines...) Expand all
2199 * Create a [GenerateHintsTask] based on the given [target] in 2524 * Create a [GenerateHintsTask] based on the given [target] in
2200 * the given [context]. 2525 * the given [context].
2201 */ 2526 */
2202 static GenerateHintsTask createTask( 2527 static GenerateHintsTask createTask(
2203 AnalysisContext context, AnalysisTarget target) { 2528 AnalysisContext context, AnalysisTarget target) {
2204 return new GenerateHintsTask(context, target); 2529 return new GenerateHintsTask(context, target);
2205 } 2530 }
2206 } 2531 }
2207 2532
2208 /** 2533 /**
2534 * A task that generates [LINTS] for a unit.
2535 */
2536 class GenerateLintsTask extends SourceBasedAnalysisTask {
2537 /**
2538 * The name of the [RESOLVED_UNIT8] input.
2539 */
2540 static const String RESOLVED_UNIT_INPUT = 'RESOLVED_UNIT';
2541
2542 /**
2543 * The name of a list of [USED_LOCAL_ELEMENTS] for each library unit input.
2544 */
2545 static const String USED_LOCAL_ELEMENTS_INPUT = 'USED_LOCAL_ELEMENTS';
2546
2547 /**
2548 * The name of a list of [USED_IMPORTED_ELEMENTS] for each library unit input.
2549 */
2550 static const String USED_IMPORTED_ELEMENTS_INPUT = 'USED_IMPORTED_ELEMENTS';
2551
2552 /**
2553 * The name of the [TYPE_PROVIDER] input.
2554 */
2555 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT';
2556
2557 /**
2558 * The task descriptor describing this kind of task.
2559 */
2560 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
2561 'GenerateLintsTask', createTask, buildInputs, <ResultDescriptor>[LINTS]);
2562
2563 GenerateLintsTask(InternalAnalysisContext context, AnalysisTarget target)
2564 : super(context, target);
2565
2566 @override
2567 TaskDescriptor get descriptor => DESCRIPTOR;
2568
2569 @override
2570 void internalPerform() {
2571 AnalysisOptions analysisOptions = context.analysisOptions;
2572 if (!analysisOptions.lint) {
2573 outputs[LINTS] = AnalysisError.NO_ERRORS;
2574 return;
2575 }
2576 //
2577 // Prepare collectors.
2578 //
2579 RecordingErrorListener errorListener = new RecordingErrorListener();
2580 Source source = getRequiredSource();
2581 ErrorReporter errorReporter = new ErrorReporter(errorListener, source);
2582 //
2583 // Prepare inputs.
2584 //
2585 CompilationUnit unit = getRequiredInput(RESOLVED_UNIT_INPUT);
2586
2587 //
2588 // Generate lints.
2589 //
2590 LintGenerator.LINTERS.forEach((l) => l.reporter = errorReporter);
2591 Iterable<AstVisitor> visitors =
2592 LintGenerator.LINTERS.map((l) => l.getVisitor()).toList();
2593 unit.accept(new DelegatingAstVisitor(visitors.where((v) => v != null)));
2594
2595 //
2596 // Record outputs.
2597 //
2598 outputs[LINTS] = errorListener.errors;
2599 }
2600
2601 /**
2602 * Return a map from the names of the inputs of this kind of task to the task
2603 * input descriptors describing those inputs for a task with the
2604 * given [target].
2605 */
2606 static Map<String, TaskInput> buildInputs(AnalysisTarget target) =>
2607 <String, TaskInput>{RESOLVED_UNIT_INPUT: RESOLVED_UNIT.of(target)};
2608
2609 /**
2610 * Create a [GenerateLintsTask] based on the given [target] in
2611 * the given [context].
2612 */
2613 static GenerateLintsTask createTask(
2614 AnalysisContext context, AnalysisTarget target) {
2615 return new GenerateLintsTask(context, target);
2616 }
2617 }
2618
2619 /**
2620 * A task that ensures that all of the inferrable instance members in a
2621 * compilation unit have had their type inferred.
2622 */
2623 class InferInstanceMembersInUnitTask extends SourceBasedAnalysisTask {
2624 /**
2625 * The name of the [TYPE_PROVIDER] input.
2626 */
2627 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT';
2628
2629 /**
2630 * The name of the input whose value is the [RESOLVED_UNIT6] for the
2631 * compilation unit.
2632 */
2633 static const String UNIT_INPUT = 'UNIT_INPUT';
2634
2635 /**
2636 * The task descriptor describing this kind of task.
2637 */
2638 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
2639 'InferInstanceMembersInUnitTask',
2640 createTask,
2641 buildInputs,
2642 <ResultDescriptor>[RESOLVED_UNIT8]);
2643
2644 /**
2645 * Initialize a newly created task to build a library element for the given
2646 * [unit] in the given [context].
2647 */
2648 InferInstanceMembersInUnitTask(
2649 InternalAnalysisContext context, LibrarySpecificUnit unit)
2650 : super(context, unit);
2651
2652 @override
2653 TaskDescriptor get descriptor => DESCRIPTOR;
2654
2655 @override
2656 void internalPerform() {
2657 //
2658 // Prepare inputs.
2659 //
2660 CompilationUnit unit = getRequiredInput(UNIT_INPUT);
2661 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT);
2662 //
2663 // Infer instance members.
2664 //
2665 if (context.analysisOptions.strongMode) {
2666 InstanceMemberInferrer inferrer = new InstanceMemberInferrer(typeProvider,
2667 typeSystem: context.typeSystem);
2668 inferrer.inferCompilationUnit(unit.element);
2669 }
2670 //
2671 // Record outputs.
2672 //
2673 outputs[RESOLVED_UNIT8] = unit;
2674 }
2675
2676 /**
2677 * Return a map from the names of the inputs of this kind of task to the task
2678 * input descriptors describing those inputs for a task with the given
2679 * [libSource].
2680 */
2681 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
2682 LibrarySpecificUnit unit = target;
2683 return <String, TaskInput>{
2684 UNIT_INPUT: RESOLVED_UNIT7.of(unit),
2685 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request),
2686 // In strong mode, add additional dependencies to enforce inference
2687 // ordering.
2688
2689 // Require that field re-resolution be complete for all units in the
2690 // current library cycle.
2691 'orderLibraryCycleTasks': LIBRARY_CYCLE_UNITS.of(unit).toList(
2692 (CompilationUnitElementImpl unit) => RESOLVED_UNIT7
2693 .of(new LibrarySpecificUnit(unit.librarySource, unit.source))),
2694 // Require that full inference be complete for all dependencies of the
2695 // current library cycle.
2696 'orderLibraryCycles': LIBRARY_CYCLE_DEPENDENCIES.of(unit).toList(
2697 (CompilationUnitElementImpl unit) => RESOLVED_UNIT8
2698 .of(new LibrarySpecificUnit(unit.librarySource, unit.source)))
2699 };
2700 }
2701
2702 /**
2703 * Create a [InferInstanceMembersInUnitTask] based on the given [target] in
2704 * the given [context].
2705 */
2706 static InferInstanceMembersInUnitTask createTask(
2707 AnalysisContext context, AnalysisTarget target) {
2708 return new InferInstanceMembersInUnitTask(context, target);
2709 }
2710 }
2711
2712 /**
2713 * A task that ensures that all of the inferrable instance members in a
2714 * compilation unit have had their right hand sides re-resolved
2715 */
2716 class ResolveInstanceFieldsInUnitTask extends SourceBasedAnalysisTask {
2717 /**
2718 * The name of the [LIBRARY_ELEMENT5] input.
2719 */
2720 static const String LIBRARY_INPUT = 'LIBRARY_INPUT';
2721
2722 /**
2723 * The name of the [TYPE_PROVIDER] input.
2724 */
2725 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT';
2726
2727 /**
2728 * The name of the input whose value is the [RESOLVED_UNIT6] for the
2729 * compilation unit.
2730 */
2731 static const String UNIT_INPUT = 'UNIT_INPUT';
2732
2733 /**
2734 * The task descriptor describing this kind of task.
2735 */
2736 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
2737 'ResolveInstanceFieldsInUnitTask',
2738 createTask,
2739 buildInputs,
2740 <ResultDescriptor>[RESOLVED_UNIT7]);
2741
2742 /**
2743 * Initialize a newly created task to build a library element for the given
2744 * [unit] in the given [context].
2745 */
2746 ResolveInstanceFieldsInUnitTask(
2747 InternalAnalysisContext context, LibrarySpecificUnit unit)
2748 : super(context, unit);
2749
2750 @override
2751 TaskDescriptor get descriptor => DESCRIPTOR;
2752
2753 @override
2754 void internalPerform() {
2755 //
2756 // Prepare inputs.
2757 //
2758 LibraryElement libraryElement = getRequiredInput(LIBRARY_INPUT);
2759 CompilationUnit unit = getRequiredInput(UNIT_INPUT);
2760 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT);
2761
2762 CompilationUnitElement unitElement = unit.element;
2763 if (context.analysisOptions.strongMode) {
2764 //
2765 // Resolve references.
2766 //
2767 // TODO(leafp): This code only needs to re-resolve the right hand sides of
2768 // instance fields. We could do incremental resolution on each field
2769 // only using the incremental resolver. However, this caused a massive
2770 // performance degredation on the large_class_declaration_test.dart test.
2771 // I would hypothesize that incremental resolution of field is linear in
2772 // the size of the enclosing class, and hence incrementally resolving each
2773 // field was quadratic. We may wish to revisit this if we can resolve
2774 // this performance issue.
2775 InheritanceManager inheritanceManager =
2776 new InheritanceManager(libraryElement);
2777 PartialResolverVisitor visitor = new PartialResolverVisitor(
2778 libraryElement,
2779 unitElement.source,
2780 typeProvider,
2781 AnalysisErrorListener.NULL_LISTENER,
2782 inheritanceManager: inheritanceManager);
2783 unit.accept(visitor);
2784 }
2785 //
2786 // Record outputs.
2787 //
2788 outputs[RESOLVED_UNIT7] = unit;
2789 }
2790
2791 /**
2792 * Return a map from the names of the inputs of this kind of task to the task
2793 * input descriptors describing those inputs for a task with the given
2794 * [libSource].
2795 */
2796 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
2797 LibrarySpecificUnit unit = target;
2798 return <String, TaskInput>{
2799 UNIT_INPUT: RESOLVED_UNIT6.of(unit),
2800 LIBRARY_INPUT: LIBRARY_ELEMENT5.of(unit.library),
2801 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request),
2802 // In strong mode, add additional dependencies to enforce inference
2803 // ordering.
2804
2805 // Require that static variable inference be complete for all units in
2806 // the current library cycle.
2807 'orderLibraryCycleTasks': LIBRARY_CYCLE_UNITS.of(unit).toList(
2808 (CompilationUnitElementImpl unit) => RESOLVED_UNIT6
2809 .of(new LibrarySpecificUnit(unit.librarySource, unit.source))),
2810 // Require that full inference be complete for all dependencies of the
2811 // current library cycle.
2812 'orderLibraryCycles': LIBRARY_CYCLE_DEPENDENCIES.of(unit).toList(
2813 (CompilationUnitElementImpl unit) => RESOLVED_UNIT8
2814 .of(new LibrarySpecificUnit(unit.librarySource, unit.source)))
2815 };
2816 }
2817
2818 /**
2819 * Create a [ResolveInstanceFieldsInUnitTask] based on the given [target] in
2820 * the given [context].
2821 */
2822 static ResolveInstanceFieldsInUnitTask createTask(
2823 AnalysisContext context, AnalysisTarget target) {
2824 return new ResolveInstanceFieldsInUnitTask(context, target);
2825 }
2826 }
2827
2828 /**
2829 * An abstract class that defines utility methods that are useful for tasks
2830 * operating on static variables.
2831 */
2832 abstract class InferStaticVariableTask extends ConstantEvaluationAnalysisTask {
2833 InferStaticVariableTask(
2834 InternalAnalysisContext context, VariableElement variable)
2835 : super(context, variable);
2836
2837 /**
2838 * Return the declaration of the target within the given compilation [unit].
2839 * Throw an exception if the declaration cannot be found.
2840 */
2841 VariableDeclaration getDeclaration(CompilationUnit unit) {
2842 VariableElement variable = target;
2843 NodeLocator locator = new NodeLocator(variable.nameOffset);
2844 AstNode node = locator.searchWithin(unit);
2845 VariableDeclaration declaration =
2846 node.getAncestor((AstNode ancestor) => ancestor is VariableDeclaration);
2847 if (declaration == null || declaration.name != node) {
2848 throw new AnalysisException(
2849 "Failed to find the declaration of the variable ${variable.displayName } in ${variable.source}");
2850 }
2851 return declaration;
2852 }
2853 }
2854
2855 /**
2856 * A task that ensures that all of the inferrable static variables in a
2857 * compilation unit have had their type inferred.
2858 */
2859 class InferStaticVariableTypesInUnitTask extends SourceBasedAnalysisTask {
2860 /**
2861 * The name of the input whose value is the [RESOLVED_UNIT5] for the
2862 * compilation unit.
2863 */
2864 static const String UNIT_INPUT = 'UNIT_INPUT';
2865
2866 /**
2867 * The name of the input whose value is a list of the inferrable static
2868 * variables whose types have been computed.
2869 */
2870 static const String INFERRED_VARIABLES_INPUT = 'INFERRED_VARIABLES_INPUT';
2871
2872 /**
2873 * The task descriptor describing this kind of task.
2874 */
2875 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
2876 'InferStaticVariableTypesInUnitTask',
2877 createTask,
2878 buildInputs,
2879 <ResultDescriptor>[RESOLVED_UNIT6]);
2880
2881 /**
2882 * Initialize a newly created task to build a library element for the given
2883 * [unit] in the given [context].
2884 */
2885 InferStaticVariableTypesInUnitTask(
2886 InternalAnalysisContext context, LibrarySpecificUnit unit)
2887 : super(context, unit);
2888
2889 @override
2890 TaskDescriptor get descriptor => DESCRIPTOR;
2891
2892 @override
2893 void internalPerform() {
2894 //
2895 // Prepare inputs.
2896 //
2897 CompilationUnit unit = getRequiredInput(UNIT_INPUT);
2898 //
2899 // Record outputs. There is no additional work to be done at this time
2900 // because the work has implicitly been done by virtue of the task model
2901 // preparing all of the inputs.
2902 //
2903 outputs[RESOLVED_UNIT6] = unit;
2904 }
2905
2906 /**
2907 * Return a map from the names of the inputs of this kind of task to the task
2908 * input descriptors describing those inputs for a task with the given
2909 * [libSource].
2910 */
2911 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
2912 LibrarySpecificUnit unit = target;
2913 return <String, TaskInput>{
2914 INFERRED_VARIABLES_INPUT: INFERABLE_STATIC_VARIABLES_IN_UNIT
2915 .of(unit)
2916 .toListOf(INFERRED_STATIC_VARIABLE),
2917 UNIT_INPUT: RESOLVED_UNIT5.of(unit)
2918 };
2919 }
2920
2921 /**
2922 * Create a [InferStaticVariableTypesInUnitTask] based on the given [target]
2923 * in the given [context].
2924 */
2925 static InferStaticVariableTypesInUnitTask createTask(
2926 AnalysisContext context, AnalysisTarget target) {
2927 return new InferStaticVariableTypesInUnitTask(context, target);
2928 }
2929 }
2930
2931 /**
2932 * A task that computes the type of an inferrable static variable and
2933 * stores it in the element model.
2934 */
2935 class InferStaticVariableTypeTask extends InferStaticVariableTask {
2936 /**
2937 * The name of the input which ensures that dependent values have their type
2938 * inferred before the target.
2939 */
2940 static const String DEPENDENCIES_INPUT = 'DEPENDENCIES_INPUT';
2941
2942 /**
2943 * The name of the [TYPE_PROVIDER] input.
2944 */
2945 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT';
2946
2947 /**
2948 * The name of the [RESOLVED_UNIT5] input.
2949 */
2950 static const String UNIT_INPUT = 'UNIT_INPUT';
2951
2952 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
2953 'InferStaticVariableTypeTask',
2954 createTask,
2955 buildInputs,
2956 <ResultDescriptor>[INFERRED_STATIC_VARIABLE]);
2957
2958 InferStaticVariableTypeTask(
2959 InternalAnalysisContext context, VariableElement variable)
2960 : super(context, variable);
2961
2962 @override
2963 TaskDescriptor get descriptor => DESCRIPTOR;
2964
2965 @override
2966 bool get handlesDependencyCycles => true;
2967
2968 @override
2969 void internalPerform() {
2970 //
2971 // Prepare inputs.
2972 //
2973 // Note: DEPENDENCIES_INPUT is not needed. It is merely a bookkeeping
2974 // dependency to ensure that the variables that this variable references
2975 // have types inferred before inferring the type of this variable.
2976 //
2977 VariableElementImpl variable = target;
2978
2979 CompilationUnit unit = getRequiredInput(UNIT_INPUT);
2980 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT);
2981
2982 // If we're not in a dependency cycle, and we have no type annotation,
2983 // re-resolve the right hand side and do inference.
2984 if (dependencyCycle == null && variable.hasImplicitType) {
2985 VariableDeclaration declaration = getDeclaration(unit);
2986 //
2987 // Re-resolve the variable's initializer so that the inferred types
2988 // of other variables will be propagated.
2989 //
2990 Expression initializer = declaration.initializer;
2991 ResolutionContext resolutionContext = ResolutionContextBuilder.contextFor(
2992 initializer, AnalysisErrorListener.NULL_LISTENER);
2993 ResolverVisitor visitor = new ResolverVisitor(variable.library,
2994 variable.source, typeProvider, AnalysisErrorListener.NULL_LISTENER,
2995 nameScope: resolutionContext.scope);
2996 if (resolutionContext.enclosingClassDeclaration != null) {
2997 visitor.prepareToResolveMembersInClass(
2998 resolutionContext.enclosingClassDeclaration);
2999 }
3000 visitor.initForIncrementalResolution();
3001 initializer.accept(visitor);
3002
3003 //
3004 // Record the type of the variable.
3005 //
3006 DartType newType = initializer.staticType;
3007 if (newType == null || newType.isBottom) {
3008 newType = typeProvider.dynamicType;
3009 }
3010 variable.type = newType;
3011 (variable.initializer as ExecutableElementImpl).returnType = newType;
3012 if (variable is PropertyInducingElementImpl) {
3013 setReturnType(variable.getter, newType);
3014 if (!variable.isFinal && !variable.isConst) {
3015 setParameterType(variable.setter, newType);
3016 }
3017 }
3018 } else {
3019 // TODO(brianwilkerson) For now we simply don't infer any type for
3020 // variables or fields involved in a cycle. We could try to be smarter
3021 // by re-resolving the initializer in a context in which the types of all
3022 // of the variables in the cycle are assumed to be `null`, but it isn't
3023 // clear to me that this would produce better results often enough to
3024 // warrant the extra effort.
3025 }
3026 //
3027 // Record outputs.
3028 //
3029 outputs[INFERRED_STATIC_VARIABLE] = variable;
3030 }
3031
3032 /**
3033 * Return a map from the names of the inputs of this kind of task to the task
3034 * input descriptors describing those inputs for a task with the given
3035 * [target].
3036 */
3037 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
3038 VariableElement variable = target;
3039 LibrarySpecificUnit unit =
3040 new LibrarySpecificUnit(variable.library.source, variable.source);
3041 return <String, TaskInput>{
3042 DEPENDENCIES_INPUT: INFERABLE_STATIC_VARIABLE_DEPENDENCIES
3043 .of(variable)
3044 .toListOf(INFERRED_STATIC_VARIABLE),
3045 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request),
3046 UNIT_INPUT: RESOLVED_UNIT5.of(unit),
3047 // In strong mode, add additional dependencies to enforce inference
3048 // ordering.
3049
3050 // Require that full inference be complete for all dependencies of the
3051 // current library cycle.
3052 'orderLibraryCycles': LIBRARY_CYCLE_DEPENDENCIES.of(unit).toList(
3053 (CompilationUnitElementImpl unit) => RESOLVED_UNIT8
3054 .of(new LibrarySpecificUnit(unit.librarySource, unit.source)))
3055 };
3056 }
3057
3058 /**
3059 * Create a [InferStaticVariableTypeTask] based on the given [target] in the
3060 * given [context].
3061 */
3062 static InferStaticVariableTypeTask createTask(
3063 AnalysisContext context, AnalysisTarget target) {
3064 return new InferStaticVariableTypeTask(context, target);
3065 }
3066 }
3067
3068 /**
2209 * A task computes all of the errors of all of the units for a single 3069 * A task computes all of the errors of all of the units for a single
2210 * library source and sets the [LIBRARY_ERRORS_READY] flag. 3070 * library source and sets the [LIBRARY_ERRORS_READY] flag.
2211 */ 3071 */
2212 class LibraryErrorsReadyTask extends SourceBasedAnalysisTask { 3072 class LibraryErrorsReadyTask extends SourceBasedAnalysisTask {
2213 /** 3073 /**
2214 * The task descriptor describing this kind of task. 3074 * The task descriptor describing this kind of task.
2215 */ 3075 */
2216 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 3076 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
2217 'LibraryErrorsReadyTask', createTask, buildInputs, 3077 'LibraryErrorsReadyTask',
3078 createTask,
3079 buildInputs,
2218 <ResultDescriptor>[LIBRARY_ERRORS_READY]); 3080 <ResultDescriptor>[LIBRARY_ERRORS_READY]);
2219 3081
2220 LibraryErrorsReadyTask(InternalAnalysisContext context, AnalysisTarget target) 3082 LibraryErrorsReadyTask(InternalAnalysisContext context, AnalysisTarget target)
2221 : super(context, target); 3083 : super(context, target);
2222 3084
2223 @override 3085 @override
2224 TaskDescriptor get descriptor => DESCRIPTOR; 3086 TaskDescriptor get descriptor => DESCRIPTOR;
2225 3087
2226 @override 3088 @override
2227 void internalPerform() { 3089 void internalPerform() {
(...skipping 21 matching lines...) Expand all
2249 return new LibraryErrorsReadyTask(context, target); 3111 return new LibraryErrorsReadyTask(context, target);
2250 } 3112 }
2251 } 3113 }
2252 3114
2253 /** 3115 /**
2254 * A task that merges all of the errors for a single source into a single list 3116 * A task that merges all of the errors for a single source into a single list
2255 * of errors. 3117 * of errors.
2256 */ 3118 */
2257 class LibraryUnitErrorsTask extends SourceBasedAnalysisTask { 3119 class LibraryUnitErrorsTask extends SourceBasedAnalysisTask {
2258 /** 3120 /**
3121 * The name of the [BUILD_DIRECTIVES_ERRORS] input.
3122 */
3123 static const String BUILD_DIRECTIVES_ERRORS_INPUT = 'BUILD_DIRECTIVES_ERRORS';
3124
3125 /**
3126 * The name of the [BUILD_LIBRARY_ERRORS] input.
3127 */
3128 static const String BUILD_LIBRARY_ERRORS_INPUT = 'BUILD_LIBRARY_ERRORS';
3129
3130 /**
2259 * The name of the [HINTS] input. 3131 * The name of the [HINTS] input.
2260 */ 3132 */
2261 static const String HINTS_INPUT = 'HINTS'; 3133 static const String HINTS_INPUT = 'HINTS';
2262 3134
2263 /** 3135 /**
2264 * The name of the [RESOLVE_REFERENCES_ERRORS] input. 3136 * The name of the [LINTS] input.
2265 */ 3137 */
2266 static const String RESOLVE_REFERENCES_ERRORS_INPUT = 3138 static const String LINTS_INPUT = 'LINTS';
2267 'RESOLVE_REFERENCES_ERRORS';
2268 3139
2269 /** 3140 /**
2270 * The name of the [RESOLVE_TYPE_NAMES_ERRORS] input. 3141 * The name of the [RESOLVE_TYPE_NAMES_ERRORS] input.
2271 */ 3142 */
2272 static const String RESOLVE_TYPE_NAMES_ERRORS_INPUT = 3143 static const String RESOLVE_TYPE_NAMES_ERRORS_INPUT =
2273 'RESOLVE_TYPE_NAMES_ERRORS'; 3144 'RESOLVE_TYPE_NAMES_ERRORS';
2274 3145
2275 /** 3146 /**
3147 * The name of the [RESOLVE_UNIT_ERRORS] input.
3148 */
3149 static const String RESOLVE_UNIT_ERRORS_INPUT = 'RESOLVE_UNIT_ERRORS';
3150
3151 /**
2276 * The name of the [VARIABLE_REFERENCE_ERRORS] input. 3152 * The name of the [VARIABLE_REFERENCE_ERRORS] input.
2277 */ 3153 */
2278 static const String VARIABLE_REFERENCE_ERRORS_INPUT = 3154 static const String VARIABLE_REFERENCE_ERRORS_INPUT =
2279 'VARIABLE_REFERENCE_ERRORS'; 3155 'VARIABLE_REFERENCE_ERRORS';
2280 3156
2281 /** 3157 /**
2282 * The name of the [VERIFY_ERRORS] input. 3158 * The name of the [VERIFY_ERRORS] input.
2283 */ 3159 */
2284 static const String VERIFY_ERRORS_INPUT = 'VERIFY_ERRORS'; 3160 static const String VERIFY_ERRORS_INPUT = 'VERIFY_ERRORS';
2285 3161
2286 /** 3162 /**
2287 * The task descriptor describing this kind of task. 3163 * The task descriptor describing this kind of task.
2288 */ 3164 */
2289 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 3165 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
2290 'LibraryUnitErrorsTask', createTask, buildInputs, 3166 'LibraryUnitErrorsTask',
3167 createTask,
3168 buildInputs,
2291 <ResultDescriptor>[LIBRARY_UNIT_ERRORS]); 3169 <ResultDescriptor>[LIBRARY_UNIT_ERRORS]);
2292 3170
2293 LibraryUnitErrorsTask(InternalAnalysisContext context, AnalysisTarget target) 3171 LibraryUnitErrorsTask(InternalAnalysisContext context, AnalysisTarget target)
2294 : super(context, target); 3172 : super(context, target);
2295 3173
2296 @override 3174 @override
2297 TaskDescriptor get descriptor => DESCRIPTOR; 3175 TaskDescriptor get descriptor => DESCRIPTOR;
2298 3176
2299 @override 3177 @override
2300 void internalPerform() { 3178 void internalPerform() {
2301 // 3179 //
2302 // Prepare inputs. 3180 // Prepare inputs.
2303 // 3181 //
2304 List<List<AnalysisError>> errorLists = <List<AnalysisError>>[]; 3182 List<List<AnalysisError>> errorLists = <List<AnalysisError>>[];
3183 errorLists.add(getRequiredInput(BUILD_DIRECTIVES_ERRORS_INPUT));
3184 errorLists.add(getRequiredInput(BUILD_LIBRARY_ERRORS_INPUT));
2305 errorLists.add(getRequiredInput(HINTS_INPUT)); 3185 errorLists.add(getRequiredInput(HINTS_INPUT));
2306 errorLists.add(getRequiredInput(RESOLVE_REFERENCES_ERRORS_INPUT)); 3186 errorLists.add(getRequiredInput(LINTS_INPUT));
2307 errorLists.add(getRequiredInput(RESOLVE_TYPE_NAMES_ERRORS_INPUT)); 3187 errorLists.add(getRequiredInput(RESOLVE_TYPE_NAMES_ERRORS_INPUT));
3188 errorLists.add(getRequiredInput(RESOLVE_UNIT_ERRORS_INPUT));
2308 errorLists.add(getRequiredInput(VARIABLE_REFERENCE_ERRORS_INPUT)); 3189 errorLists.add(getRequiredInput(VARIABLE_REFERENCE_ERRORS_INPUT));
2309 errorLists.add(getRequiredInput(VERIFY_ERRORS_INPUT)); 3190 errorLists.add(getRequiredInput(VERIFY_ERRORS_INPUT));
2310 // 3191 //
2311 // Record outputs. 3192 // Record outputs.
2312 // 3193 //
2313 outputs[LIBRARY_UNIT_ERRORS] = AnalysisError.mergeLists(errorLists); 3194 outputs[LIBRARY_UNIT_ERRORS] = AnalysisError.mergeLists(errorLists);
2314 } 3195 }
2315 3196
2316 /** 3197 /**
2317 * Return a map from the names of the inputs of this kind of task to the task 3198 * Return a map from the names of the inputs of this kind of task to the task
2318 * input descriptors describing those inputs for a task with the 3199 * input descriptors describing those inputs for a task with the
2319 * given [unit]. 3200 * given [unit].
2320 */ 3201 */
2321 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 3202 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
2322 LibrarySpecificUnit unit = target; 3203 LibrarySpecificUnit unit = target;
2323 return <String, TaskInput>{ 3204 Map<String, TaskInput> inputs = <String, TaskInput>{
2324 HINTS_INPUT: HINTS.of(unit), 3205 HINTS_INPUT: HINTS.of(unit),
2325 RESOLVE_REFERENCES_ERRORS_INPUT: RESOLVE_REFERENCES_ERRORS.of(unit), 3206 LINTS_INPUT: LINTS.of(unit),
2326 RESOLVE_TYPE_NAMES_ERRORS_INPUT: RESOLVE_TYPE_NAMES_ERRORS.of(unit), 3207 RESOLVE_TYPE_NAMES_ERRORS_INPUT: RESOLVE_TYPE_NAMES_ERRORS.of(unit),
3208 RESOLVE_UNIT_ERRORS_INPUT: RESOLVE_UNIT_ERRORS.of(unit),
2327 VARIABLE_REFERENCE_ERRORS_INPUT: VARIABLE_REFERENCE_ERRORS.of(unit), 3209 VARIABLE_REFERENCE_ERRORS_INPUT: VARIABLE_REFERENCE_ERRORS.of(unit),
2328 VERIFY_ERRORS_INPUT: VERIFY_ERRORS.of(unit) 3210 VERIFY_ERRORS_INPUT: VERIFY_ERRORS.of(unit)
2329 }; 3211 };
3212 Source source = unit.source;
3213 if (unit.library == source) {
3214 inputs[BUILD_DIRECTIVES_ERRORS_INPUT] =
3215 BUILD_DIRECTIVES_ERRORS.of(source);
3216 inputs[BUILD_LIBRARY_ERRORS_INPUT] = BUILD_LIBRARY_ERRORS.of(source);
3217 } else {
3218 inputs[BUILD_DIRECTIVES_ERRORS_INPUT] =
3219 new ConstantTaskInput(AnalysisError.NO_ERRORS);
3220 inputs[BUILD_LIBRARY_ERRORS_INPUT] =
3221 new ConstantTaskInput(AnalysisError.NO_ERRORS);
3222 }
3223 return inputs;
2330 } 3224 }
2331 3225
2332 /** 3226 /**
2333 * Create a [LibraryUnitErrorsTask] based on the given [target] in the given 3227 * Create a [LibraryUnitErrorsTask] based on the given [target] in the given
2334 * [context]. 3228 * [context].
2335 */ 3229 */
2336 static LibraryUnitErrorsTask createTask( 3230 static LibraryUnitErrorsTask createTask(
2337 AnalysisContext context, AnalysisTarget target) { 3231 AnalysisContext context, AnalysisTarget target) {
2338 return new LibraryUnitErrorsTask(context, target); 3232 return new LibraryUnitErrorsTask(context, target);
2339 } 3233 }
(...skipping 16 matching lines...) Expand all
2356 'MODIFICATION_TIME_INPUT_NAME'; 3250 'MODIFICATION_TIME_INPUT_NAME';
2357 3251
2358 /** 3252 /**
2359 * The name of the input whose value is the token stream produced for the file . 3253 * The name of the input whose value is the token stream produced for the file .
2360 */ 3254 */
2361 static const String TOKEN_STREAM_INPUT_NAME = 'TOKEN_STREAM_INPUT_NAME'; 3255 static const String TOKEN_STREAM_INPUT_NAME = 'TOKEN_STREAM_INPUT_NAME';
2362 3256
2363 /** 3257 /**
2364 * The task descriptor describing this kind of task. 3258 * The task descriptor describing this kind of task.
2365 */ 3259 */
2366 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor('ParseDartTask', 3260 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
2367 createTask, buildInputs, <ResultDescriptor>[ 3261 'ParseDartTask', createTask, buildInputs, <ResultDescriptor>[
2368 EXPLICITLY_IMPORTED_LIBRARIES, 3262 EXPLICITLY_IMPORTED_LIBRARIES,
2369 EXPORTED_LIBRARIES, 3263 EXPORTED_LIBRARIES,
2370 IMPORTED_LIBRARIES, 3264 IMPORTED_LIBRARIES,
2371 INCLUDED_PARTS, 3265 INCLUDED_PARTS,
2372 PARSE_ERRORS, 3266 PARSE_ERRORS,
2373 PARSED_UNIT, 3267 PARSED_UNIT,
2374 SOURCE_KIND, 3268 SOURCE_KIND,
2375 UNITS 3269 UNITS
2376 ]); 3270 ]);
2377 3271
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
2521 if (code == UriValidationCode.INVALID_URI) { 3415 if (code == UriValidationCode.INVALID_URI) {
2522 errorListener.onError(new AnalysisError(librarySource, uriLiteral.offset, 3416 errorListener.onError(new AnalysisError(librarySource, uriLiteral.offset,
2523 uriLiteral.length, CompileTimeErrorCode.INVALID_URI, [uriContent])); 3417 uriLiteral.length, CompileTimeErrorCode.INVALID_URI, [uriContent]));
2524 return null; 3418 return null;
2525 } 3419 }
2526 throw new AnalysisException('Failed to handle validation code: $code'); 3420 throw new AnalysisException('Failed to handle validation code: $code');
2527 } 3421 }
2528 } 3422 }
2529 3423
2530 /** 3424 /**
3425 * A task that builds [RESOLVED_UNIT5] for a unit.
3426 */
3427 class PartiallyResolveUnitReferencesTask extends SourceBasedAnalysisTask {
3428 /**
3429 * The name of the [LIBRARY_ELEMENT5] input.
3430 */
3431 static const String LIBRARY_INPUT = 'LIBRARY_INPUT';
3432
3433 /**
3434 * The name of the [RESOLVED_UNIT4] input.
3435 */
3436 static const String UNIT_INPUT = 'UNIT_INPUT';
3437
3438 /**
3439 * The name of the [TYPE_PROVIDER] input.
3440 */
3441 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT';
3442
3443 /**
3444 * The task descriptor describing this kind of task.
3445 */
3446 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
3447 'PartiallyResolveUnitReferencesTask',
3448 createTask,
3449 buildInputs,
3450 <ResultDescriptor>[INFERABLE_STATIC_VARIABLES_IN_UNIT, RESOLVED_UNIT5]);
3451
3452 PartiallyResolveUnitReferencesTask(
3453 InternalAnalysisContext context, AnalysisTarget target)
3454 : super(context, target);
3455
3456 @override
3457 TaskDescriptor get descriptor => DESCRIPTOR;
3458
3459 @override
3460 void internalPerform() {
3461 //
3462 // Prepare inputs.
3463 //
3464 LibraryElement libraryElement = getRequiredInput(LIBRARY_INPUT);
3465 CompilationUnit unit = getRequiredInput(UNIT_INPUT);
3466 CompilationUnitElement unitElement = unit.element;
3467 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT);
3468 if (context.analysisOptions.strongMode) {
3469 //
3470 // Resolve references.
3471 //
3472 InheritanceManager inheritanceManager =
3473 new InheritanceManager(libraryElement);
3474 PartialResolverVisitor visitor = new PartialResolverVisitor(
3475 libraryElement,
3476 unitElement.source,
3477 typeProvider,
3478 AnalysisErrorListener.NULL_LISTENER,
3479 inheritanceManager: inheritanceManager);
3480 unit.accept(visitor);
3481 //
3482 // Record outputs.
3483 //
3484 outputs[INFERABLE_STATIC_VARIABLES_IN_UNIT] = visitor.variablesAndFields;
3485 } else {
3486 outputs[INFERABLE_STATIC_VARIABLES_IN_UNIT] = [];
3487 }
3488 outputs[RESOLVED_UNIT5] = unit;
3489 }
3490
3491 /**
3492 * Return a map from the names of the inputs of this kind of task to the task
3493 * input descriptors describing those inputs for a task with the
3494 * given [target].
3495 */
3496 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
3497 LibrarySpecificUnit unit = target;
3498 return <String, TaskInput>{
3499 'fullyBuiltLibraryElements': IMPORT_EXPORT_SOURCE_CLOSURE
3500 .of(unit.library)
3501 .toListOf(LIBRARY_ELEMENT5),
3502 LIBRARY_INPUT: LIBRARY_ELEMENT5.of(unit.library),
3503 UNIT_INPUT: RESOLVED_UNIT4.of(unit),
3504 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request),
3505 // In strong mode, add additional dependencies to enforce inference
3506 // ordering.
3507
3508 // Require that full inference be complete for all dependencies of the
3509 // current library cycle.
3510 'orderLibraryCycles': LIBRARY_CYCLE_DEPENDENCIES.of(unit).toList(
3511 (CompilationUnitElementImpl unit) => RESOLVED_UNIT8
3512 .of(new LibrarySpecificUnit(unit.librarySource, unit.source)))
3513 };
3514 }
3515
3516 /**
3517 * Create a [PartiallyResolveUnitReferencesTask] based on the given [target]
3518 * in the given [context].
3519 */
3520 static PartiallyResolveUnitReferencesTask createTask(
3521 AnalysisContext context, AnalysisTarget target) {
3522 return new PartiallyResolveUnitReferencesTask(context, target);
3523 }
3524 }
3525
3526 /**
2531 * The helper for building the public [Namespace] of a [LibraryElement]. 3527 * The helper for building the public [Namespace] of a [LibraryElement].
2532 */ 3528 */
2533 class PublicNamespaceBuilder { 3529 class PublicNamespaceBuilder {
2534 final HashMap<String, Element> definedNames = new HashMap<String, Element>(); 3530 final HashMap<String, Element> definedNames = new HashMap<String, Element>();
2535 3531
2536 /** 3532 /**
2537 * Build a public [Namespace] of the given [library]. 3533 * Build a public [Namespace] of the given [library].
2538 */ 3534 */
2539 Namespace build(LibraryElement library) { 3535 Namespace build(LibraryElement library) {
2540 definedNames.clear(); 3536 definedNames.clear();
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
2658 String name = node.name; 3654 String name = node.name;
2659 names.names.add(name); 3655 names.names.add(name);
2660 if (dependsOn != null && bodyLevel == 0) { 3656 if (dependsOn != null && bodyLevel == 0) {
2661 dependsOn.add(name); 3657 dependsOn.add(name);
2662 } 3658 }
2663 } 3659 }
2664 } 3660 }
2665 } 3661 }
2666 3662
2667 /** 3663 /**
3664 * A task that resolves the bodies of top-level functions, constructors, and
3665 * methods within a single compilation unit.
3666 */
3667 class ResolveUnitTask extends SourceBasedAnalysisTask {
3668 /**
3669 * The name of the input whose value is the defining [LIBRARY_ELEMENT5].
3670 */
3671 static const String LIBRARY_INPUT = 'LIBRARY_INPUT';
3672
3673 /**
3674 * The name of the [TYPE_PROVIDER] input.
3675 */
3676 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT';
3677
3678 /**
3679 * The name of the [RESOLVED_UNIT8] input.
3680 */
3681 static const String UNIT_INPUT = 'UNIT_INPUT';
3682
3683 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
3684 'ResolveUnitTask',
3685 createTask,
3686 buildInputs,
3687 <ResultDescriptor>[RESOLVE_UNIT_ERRORS, RESOLVED_UNIT9]);
3688
3689 ResolveUnitTask(
3690 InternalAnalysisContext context, LibrarySpecificUnit compilationUnit)
3691 : super(context, compilationUnit);
3692
3693 @override
3694 TaskDescriptor get descriptor => DESCRIPTOR;
3695
3696 @override
3697 void internalPerform() {
3698 //
3699 // Prepare inputs.
3700 //
3701 LibraryElement libraryElement = getRequiredInput(LIBRARY_INPUT);
3702 CompilationUnit unit = getRequiredInput(UNIT_INPUT);
3703 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT);
3704 //
3705 // Resolve everything
3706 //
3707 CompilationUnitElement unitElement = unit.element;
3708 RecordingErrorListener errorListener = new RecordingErrorListener();
3709 ResolverVisitor visitor = new ResolverVisitor(
3710 libraryElement, unitElement.source, typeProvider, errorListener);
3711 unit.accept(visitor);
3712 //
3713 // Record outputs.
3714 //
3715 outputs[RESOLVE_UNIT_ERRORS] = errorListener.errors;
3716 outputs[RESOLVED_UNIT9] = unit;
3717 }
3718
3719 /**
3720 * Return a map from the names of the inputs of this kind of task to the task
3721 * input descriptors describing those inputs for a task with the given
3722 * [target].
3723 */
3724 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
3725 LibrarySpecificUnit unit = target;
3726 return <String, TaskInput>{
3727 LIBRARY_INPUT: LIBRARY_ELEMENT5.of(unit.library),
3728 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request),
3729 UNIT_INPUT: RESOLVED_UNIT8.of(unit),
3730 // In strong mode, add additional dependencies to enforce inference
3731 // ordering.
3732
3733 // Require that inference be complete for all units in the
3734 // current library cycle.
3735 'orderLibraryCycleTasks': LIBRARY_CYCLE_UNITS.of(unit).toList(
3736 (CompilationUnitElementImpl unit) => RESOLVED_UNIT8
3737 .of(new LibrarySpecificUnit(unit.librarySource, unit.source)))
3738 };
3739 }
3740
3741 /**
3742 * Create a [ResolveUnitTask] based on the given [target] in
3743 * the given [context].
3744 */
3745 static ResolveUnitTask createTask(
3746 AnalysisContext context, AnalysisTarget target) {
3747 return new ResolveUnitTask(context, target);
3748 }
3749 }
3750
3751 /**
2668 * A task that finishes resolution by requesting [RESOLVED_UNIT_NO_CONSTANTS] fo r every 3752 * A task that finishes resolution by requesting [RESOLVED_UNIT_NO_CONSTANTS] fo r every
2669 * unit in the libraries closure and produces [LIBRARY_ELEMENT]. 3753 * unit in the libraries closure and produces [LIBRARY_ELEMENT].
2670 */ 3754 */
2671 class ResolveLibraryReferencesTask extends SourceBasedAnalysisTask { 3755 class ResolveLibraryReferencesTask extends SourceBasedAnalysisTask {
2672 /** 3756 /**
2673 * The name of the [LIBRARY_ELEMENT5] input. 3757 * The name of the [LIBRARY_ELEMENT5] input.
2674 */ 3758 */
2675 static const String LIBRARY_INPUT = 'LIBRARY_INPUT'; 3759 static const String LIBRARY_INPUT = 'LIBRARY_INPUT';
2676 3760
2677 /** 3761 /**
2678 * The name of the list of [RESOLVED_UNIT5] input. 3762 * The name of the list of [RESOLVED_UNIT9] input.
2679 */ 3763 */
2680 static const String UNITS_INPUT = 'UNITS_INPUT'; 3764 static const String UNITS_INPUT = 'UNITS_INPUT';
2681 3765
2682 /** 3766 /**
2683 * The task descriptor describing this kind of task. 3767 * The task descriptor describing this kind of task.
2684 */ 3768 */
2685 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 3769 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
2686 'ResolveLibraryReferencesTask', createTask, buildInputs, 3770 'ResolveLibraryReferencesTask',
3771 createTask,
3772 buildInputs,
2687 <ResultDescriptor>[LIBRARY_ELEMENT, REFERENCED_NAMES]); 3773 <ResultDescriptor>[LIBRARY_ELEMENT, REFERENCED_NAMES]);
2688 3774
2689 ResolveLibraryReferencesTask( 3775 ResolveLibraryReferencesTask(
2690 InternalAnalysisContext context, AnalysisTarget target) 3776 InternalAnalysisContext context, AnalysisTarget target)
2691 : super(context, target); 3777 : super(context, target);
2692 3778
2693 @override 3779 @override
2694 TaskDescriptor get descriptor => DESCRIPTOR; 3780 TaskDescriptor get descriptor => DESCRIPTOR;
2695 3781
2696 @override 3782 @override
(...skipping 18 matching lines...) Expand all
2715 /** 3801 /**
2716 * Return a map from the names of the inputs of this kind of task to the task 3802 * Return a map from the names of the inputs of this kind of task to the task
2717 * input descriptors describing those inputs for a task with the 3803 * input descriptors describing those inputs for a task with the
2718 * given [target]. 3804 * given [target].
2719 */ 3805 */
2720 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 3806 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
2721 Source source = target; 3807 Source source = target;
2722 return <String, TaskInput>{ 3808 return <String, TaskInput>{
2723 LIBRARY_INPUT: LIBRARY_ELEMENT5.of(source), 3809 LIBRARY_INPUT: LIBRARY_ELEMENT5.of(source),
2724 UNITS_INPUT: UNITS.of(source).toList((Source unit) => 3810 UNITS_INPUT: UNITS.of(source).toList((Source unit) =>
2725 RESOLVED_UNIT5.of(new LibrarySpecificUnit(source, unit))), 3811 RESOLVED_UNIT9.of(new LibrarySpecificUnit(source, unit))),
2726 'resolvedUnits': IMPORT_EXPORT_SOURCE_CLOSURE 3812 'resolvedUnits': IMPORT_EXPORT_SOURCE_CLOSURE
2727 .of(source) 3813 .of(source)
2728 .toMapOf(UNITS) 3814 .toMapOf(UNITS)
2729 .toFlattenList((Source library, Source unit) => 3815 .toFlattenList((Source library, Source unit) =>
2730 RESOLVED_UNIT5.of(new LibrarySpecificUnit(library, unit))), 3816 RESOLVED_UNIT9.of(new LibrarySpecificUnit(library, unit))),
2731 }; 3817 };
2732 } 3818 }
2733 3819
2734 /** 3820 /**
2735 * Create a [ResolveLibraryReferencesTask] based on the given [target] in 3821 * Create a [ResolveLibraryReferencesTask] based on the given [target] in
2736 * the given [context]. 3822 * the given [context].
2737 */ 3823 */
2738 static ResolveLibraryReferencesTask createTask( 3824 static ResolveLibraryReferencesTask createTask(
2739 AnalysisContext context, AnalysisTarget target) { 3825 AnalysisContext context, AnalysisTarget target) {
2740 return new ResolveLibraryReferencesTask(context, target); 3826 return new ResolveLibraryReferencesTask(context, target);
2741 } 3827 }
2742 } 3828 }
2743 3829
2744 /** 3830 /**
2745 * An artifitial task that does nothing except to force type names resolution 3831 * An artifitial task that does nothing except to force type names resolution
2746 * for the defining and part units of a library. 3832 * for the defining and part units of a library.
2747 */ 3833 */
2748 class ResolveLibraryTypeNamesTask extends SourceBasedAnalysisTask { 3834 class ResolveLibraryTypeNamesTask extends SourceBasedAnalysisTask {
2749 /** 3835 /**
2750 * The name of the [LIBRARY_ELEMENT4] input. 3836 * The name of the [LIBRARY_ELEMENT4] input.
2751 */ 3837 */
2752 static const String LIBRARY_INPUT = 'LIBRARY_INPUT'; 3838 static const String LIBRARY_INPUT = 'LIBRARY_INPUT';
2753 3839
2754 /** 3840 /**
2755 * The task descriptor describing this kind of task. 3841 * The task descriptor describing this kind of task.
2756 */ 3842 */
2757 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 3843 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
2758 'ResolveLibraryTypeNamesTask', createTask, buildInputs, 3844 'ResolveLibraryTypeNamesTask',
3845 createTask,
3846 buildInputs,
2759 <ResultDescriptor>[LIBRARY_ELEMENT5]); 3847 <ResultDescriptor>[LIBRARY_ELEMENT5]);
2760 3848
2761 ResolveLibraryTypeNamesTask( 3849 ResolveLibraryTypeNamesTask(
2762 InternalAnalysisContext context, AnalysisTarget target) 3850 InternalAnalysisContext context, AnalysisTarget target)
2763 : super(context, target); 3851 : super(context, target);
2764 3852
2765 @override 3853 @override
2766 TaskDescriptor get descriptor => DESCRIPTOR; 3854 TaskDescriptor get descriptor => DESCRIPTOR;
2767 3855
2768 @override 3856 @override
(...skipping 20 matching lines...) Expand all
2789 * Create a [ResolveLibraryTypeNamesTask] based on the given [target] in 3877 * Create a [ResolveLibraryTypeNamesTask] based on the given [target] in
2790 * the given [context]. 3878 * the given [context].
2791 */ 3879 */
2792 static ResolveLibraryTypeNamesTask createTask( 3880 static ResolveLibraryTypeNamesTask createTask(
2793 AnalysisContext context, AnalysisTarget target) { 3881 AnalysisContext context, AnalysisTarget target) {
2794 return new ResolveLibraryTypeNamesTask(context, target); 3882 return new ResolveLibraryTypeNamesTask(context, target);
2795 } 3883 }
2796 } 3884 }
2797 3885
2798 /** 3886 /**
2799 * A task that builds [RESOLVED_UNIT5] for a unit.
2800 */
2801 class ResolveUnitReferencesTask extends SourceBasedAnalysisTask {
2802 /**
2803 * The name of the [LIBRARY_ELEMENT5] input.
2804 */
2805 static const String LIBRARY_INPUT = 'LIBRARY_INPUT';
2806
2807 /**
2808 * The name of the [RESOLVED_UNIT4] input.
2809 */
2810 static const String UNIT_INPUT = 'UNIT_INPUT';
2811
2812 /**
2813 * The name of the [TYPE_PROVIDER] input.
2814 */
2815 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT';
2816
2817 /**
2818 * The task descriptor describing this kind of task.
2819 */
2820 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
2821 'ResolveUnitReferencesTask', createTask, buildInputs, <ResultDescriptor>[
2822 RESOLVE_REFERENCES_ERRORS,
2823 RESOLVED_UNIT5
2824 ]);
2825
2826 ResolveUnitReferencesTask(
2827 InternalAnalysisContext context, AnalysisTarget target)
2828 : super(context, target);
2829
2830 @override
2831 TaskDescriptor get descriptor => DESCRIPTOR;
2832
2833 @override
2834 void internalPerform() {
2835 RecordingErrorListener errorListener = new RecordingErrorListener();
2836 //
2837 // Prepare inputs.
2838 //
2839 LibraryElement libraryElement = getRequiredInput(LIBRARY_INPUT);
2840 CompilationUnit unit = getRequiredInput(UNIT_INPUT);
2841 CompilationUnitElement unitElement = unit.element;
2842 TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT);
2843 //
2844 // Resolve references.
2845 //
2846 InheritanceManager inheritanceManager =
2847 new InheritanceManager(libraryElement);
2848 AstVisitor visitor = new ResolverVisitor(
2849 libraryElement, unitElement.source, typeProvider, errorListener,
2850 inheritanceManager: inheritanceManager);
2851 unit.accept(visitor);
2852 //
2853 // Record outputs.
2854 //
2855 outputs[RESOLVE_REFERENCES_ERRORS] =
2856 removeDuplicateErrors(errorListener.errors);
2857 outputs[RESOLVED_UNIT5] = unit;
2858 }
2859
2860 /**
2861 * Return a map from the names of the inputs of this kind of task to the task
2862 * input descriptors describing those inputs for a task with the
2863 * given [target].
2864 */
2865 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
2866 LibrarySpecificUnit unit = target;
2867 return <String, TaskInput>{
2868 'fullyBuiltLibraryElements': IMPORT_EXPORT_SOURCE_CLOSURE
2869 .of(unit.library)
2870 .toListOf(LIBRARY_ELEMENT5),
2871 LIBRARY_INPUT: LIBRARY_ELEMENT5.of(unit.library),
2872 UNIT_INPUT: RESOLVED_UNIT4.of(unit),
2873 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request)
2874 };
2875 }
2876
2877 /**
2878 * Create a [ResolveUnitReferencesTask] based on the given [target] in
2879 * the given [context].
2880 */
2881 static ResolveUnitReferencesTask createTask(
2882 AnalysisContext context, AnalysisTarget target) {
2883 return new ResolveUnitReferencesTask(context, target);
2884 }
2885 }
2886
2887 /**
2888 * A task that builds [RESOLVED_UNIT3] for a unit. 3887 * A task that builds [RESOLVED_UNIT3] for a unit.
2889 */ 3888 */
2890 class ResolveUnitTypeNamesTask extends SourceBasedAnalysisTask { 3889 class ResolveUnitTypeNamesTask extends SourceBasedAnalysisTask {
2891 /** 3890 /**
2892 * The name of the input whose value is the defining [LIBRARY_ELEMENT4]. 3891 * The name of the input whose value is the defining [LIBRARY_ELEMENT4].
2893 */ 3892 */
2894 static const String LIBRARY_INPUT = 'LIBRARY_INPUT'; 3893 static const String LIBRARY_INPUT = 'LIBRARY_INPUT';
2895 3894
2896 /** 3895 /**
2897 * The name of the [RESOLVED_UNIT2] input. 3896 * The name of the [RESOLVED_UNIT2] input.
2898 */ 3897 */
2899 static const String UNIT_INPUT = 'UNIT_INPUT'; 3898 static const String UNIT_INPUT = 'UNIT_INPUT';
2900 3899
2901 /** 3900 /**
2902 * The name of the [TYPE_PROVIDER] input. 3901 * The name of the [TYPE_PROVIDER] input.
2903 */ 3902 */
2904 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT'; 3903 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT';
2905 3904
2906 /** 3905 /**
2907 * The task descriptor describing this kind of task. 3906 * The task descriptor describing this kind of task.
2908 */ 3907 */
2909 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 3908 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
2910 'ResolveUnitTypeNamesTask', createTask, buildInputs, <ResultDescriptor>[ 3909 'ResolveUnitTypeNamesTask',
2911 RESOLVE_TYPE_NAMES_ERRORS, 3910 createTask,
2912 RESOLVED_UNIT3 3911 buildInputs,
2913 ]); 3912 <ResultDescriptor>[RESOLVE_TYPE_NAMES_ERRORS, RESOLVED_UNIT3]);
2914 3913
2915 ResolveUnitTypeNamesTask( 3914 ResolveUnitTypeNamesTask(
2916 InternalAnalysisContext context, AnalysisTarget target) 3915 InternalAnalysisContext context, AnalysisTarget target)
2917 : super(context, target); 3916 : super(context, target);
2918 3917
2919 @override 3918 @override
2920 TaskDescriptor get descriptor => DESCRIPTOR; 3919 TaskDescriptor get descriptor => DESCRIPTOR;
2921 3920
2922 @override 3921 @override
2923 void internalPerform() { 3922 void internalPerform() {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
2985 3984
2986 /** 3985 /**
2987 * The name of the [TYPE_PROVIDER] input. 3986 * The name of the [TYPE_PROVIDER] input.
2988 */ 3987 */
2989 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT'; 3988 static const String TYPE_PROVIDER_INPUT = 'TYPE_PROVIDER_INPUT';
2990 3989
2991 /** 3990 /**
2992 * The task descriptor describing this kind of task. 3991 * The task descriptor describing this kind of task.
2993 */ 3992 */
2994 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 3993 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
2995 'ResolveVariableReferencesTask', createTask, buildInputs, 3994 'ResolveVariableReferencesTask',
3995 createTask,
3996 buildInputs,
2996 <ResultDescriptor>[RESOLVED_UNIT4, VARIABLE_REFERENCE_ERRORS]); 3997 <ResultDescriptor>[RESOLVED_UNIT4, VARIABLE_REFERENCE_ERRORS]);
2997 3998
2998 ResolveVariableReferencesTask( 3999 ResolveVariableReferencesTask(
2999 InternalAnalysisContext context, AnalysisTarget target) 4000 InternalAnalysisContext context, AnalysisTarget target)
3000 : super(context, target); 4001 : super(context, target);
3001 4002
3002 @override 4003 @override
3003 TaskDescriptor get descriptor => DESCRIPTOR; 4004 TaskDescriptor get descriptor => DESCRIPTOR;
3004 4005
3005 @override 4006 @override
(...skipping 24 matching lines...) Expand all
3030 4031
3031 /** 4032 /**
3032 * Return a map from the names of the inputs of this kind of task to the task 4033 * Return a map from the names of the inputs of this kind of task to the task
3033 * input descriptors describing those inputs for a task with the 4034 * input descriptors describing those inputs for a task with the
3034 * given [target]. 4035 * given [target].
3035 */ 4036 */
3036 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 4037 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
3037 LibrarySpecificUnit unit = target; 4038 LibrarySpecificUnit unit = target;
3038 return <String, TaskInput>{ 4039 return <String, TaskInput>{
3039 LIBRARY_INPUT: LIBRARY_ELEMENT1.of(unit.library), 4040 LIBRARY_INPUT: LIBRARY_ELEMENT1.of(unit.library),
3040 UNIT_INPUT: RESOLVED_UNIT1.of(unit), 4041 UNIT_INPUT: RESOLVED_UNIT3.of(unit),
3041 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request) 4042 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request)
3042 }; 4043 };
3043 } 4044 }
3044 4045
3045 /** 4046 /**
3046 * Create a [ResolveVariableReferencesTask] based on the given [target] in 4047 * Create a [ResolveVariableReferencesTask] based on the given [target] in
3047 * the given [context]. 4048 * the given [context].
3048 */ 4049 */
3049 static ResolveVariableReferencesTask createTask( 4050 static ResolveVariableReferencesTask createTask(
3050 AnalysisContext context, AnalysisTarget target) { 4051 AnalysisContext context, AnalysisTarget target) {
3051 return new ResolveVariableReferencesTask(context, target); 4052 return new ResolveVariableReferencesTask(context, target);
3052 } 4053 }
3053 } 4054 }
3054 4055
3055 /** 4056 /**
3056 * A task that scans the content of a file, producing a set of Dart tokens. 4057 * A task that scans the content of a file, producing a set of Dart tokens.
3057 */ 4058 */
3058 class ScanDartTask extends SourceBasedAnalysisTask { 4059 class ScanDartTask extends SourceBasedAnalysisTask {
3059 /** 4060 /**
3060 * The name of the input whose value is the content of the file. 4061 * The name of the input whose value is the content of the file.
3061 */ 4062 */
3062 static const String CONTENT_INPUT_NAME = 'CONTENT_INPUT_NAME'; 4063 static const String CONTENT_INPUT_NAME = 'CONTENT_INPUT_NAME';
3063 4064
3064 /** 4065 /**
3065 * The task descriptor describing this kind of task. 4066 * The task descriptor describing this kind of task.
3066 */ 4067 */
3067 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor('ScanDartTask', 4068 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
3068 createTask, buildInputs, <ResultDescriptor>[ 4069 'ScanDartTask',
3069 LINE_INFO, 4070 createTask,
3070 SCAN_ERRORS, 4071 buildInputs,
3071 TOKEN_STREAM 4072 <ResultDescriptor>[LINE_INFO, SCAN_ERRORS, TOKEN_STREAM]);
3072 ]);
3073 4073
3074 /** 4074 /**
3075 * Initialize a newly created task to access the content of the source 4075 * Initialize a newly created task to access the content of the source
3076 * associated with the given [target] in the given [context]. 4076 * associated with the given [target] in the given [context].
3077 */ 4077 */
3078 ScanDartTask(InternalAnalysisContext context, AnalysisTarget target) 4078 ScanDartTask(InternalAnalysisContext context, AnalysisTarget target)
3079 : super(context, target); 4079 : super(context, target);
3080 4080
3081 @override 4081 @override
3082 TaskDescriptor get descriptor => DESCRIPTOR; 4082 TaskDescriptor get descriptor => DESCRIPTOR;
3083 4083
3084 @override 4084 @override
3085 void internalPerform() { 4085 void internalPerform() {
3086 Source source = getRequiredSource(); 4086 Source source = getRequiredSource();
3087 4087
3088 RecordingErrorListener errorListener = new RecordingErrorListener(); 4088 RecordingErrorListener errorListener = new RecordingErrorListener();
3089 if (context.getModificationStamp(target.source) < 0) { 4089 if (context.getModificationStamp(target.source) < 0) {
3090 String message = 'Content could not be read'; 4090 String message = 'Content could not be read';
3091 if (context is InternalAnalysisContext) { 4091 if (context is InternalAnalysisContext) {
3092 CacheEntry entry = 4092 CacheEntry entry =
3093 (context as InternalAnalysisContext).getCacheEntry(target); 4093 (context as InternalAnalysisContext).getCacheEntry(target);
3094 CaughtException exception = entry.exception; 4094 CaughtException exception = entry.exception;
3095 if (exception != null) { 4095 if (exception != null) {
3096 message = exception.toString(); 4096 message = exception.toString();
3097 } 4097 }
3098 } 4098 }
3099 errorListener.onError(new AnalysisError( 4099 if (source.exists()) {
3100 source, 0, 0, ScannerErrorCode.UNABLE_GET_CONTENT, [message])); 4100 errorListener.onError(new AnalysisError(
4101 source, 0, 0, ScannerErrorCode.UNABLE_GET_CONTENT, [message]));
4102 }
3101 } 4103 }
3102 if (target is DartScript) { 4104 if (target is DartScript) {
3103 DartScript script = target; 4105 DartScript script = target;
3104 List<ScriptFragment> fragments = script.fragments; 4106 List<ScriptFragment> fragments = script.fragments;
3105 if (fragments.length < 1) { 4107 if (fragments.length < 1) {
3106 throw new AnalysisException('Cannot scan scripts with no fragments'); 4108 throw new AnalysisException('Cannot scan scripts with no fragments');
3107 } else if (fragments.length > 1) { 4109 } else if (fragments.length > 1) {
3108 throw new AnalysisException( 4110 throw new AnalysisException(
3109 'Cannot scan scripts with multiple fragments'); 4111 'Cannot scan scripts with multiple fragments');
3110 } 4112 }
3111 ScriptFragment fragment = fragments[0]; 4113 ScriptFragment fragment = fragments[0];
3112 4114
3113 Scanner scanner = new Scanner(source, 4115 Scanner scanner = new Scanner(
4116 source,
3114 new SubSequenceReader(fragment.content, fragment.offset), 4117 new SubSequenceReader(fragment.content, fragment.offset),
3115 errorListener); 4118 errorListener);
3116 scanner.setSourceStart(fragment.line, fragment.column); 4119 scanner.setSourceStart(fragment.line, fragment.column);
3117 scanner.preserveComments = context.analysisOptions.preserveComments; 4120 scanner.preserveComments = context.analysisOptions.preserveComments;
3118 4121
3119 outputs[TOKEN_STREAM] = scanner.tokenize(); 4122 outputs[TOKEN_STREAM] = scanner.tokenize();
3120 outputs[LINE_INFO] = new LineInfo(scanner.lineStarts); 4123 outputs[LINE_INFO] = new LineInfo(scanner.lineStarts);
3121 outputs[SCAN_ERRORS] = removeDuplicateErrors(errorListener.errors); 4124 outputs[SCAN_ERRORS] = removeDuplicateErrors(errorListener.errors);
3122 } else if (target is Source) { 4125 } else if (target is Source) {
3123 String content = getRequiredInput(CONTENT_INPUT_NAME); 4126 String content = getRequiredInput(CONTENT_INPUT_NAME);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
3211 validateDirectives(unit); 4214 validateDirectives(unit);
3212 // 4215 //
3213 // Use the ConstantVerifier to compute errors. 4216 // Use the ConstantVerifier to compute errors.
3214 // 4217 //
3215 ConstantVerifier constantVerifier = new ConstantVerifier( 4218 ConstantVerifier constantVerifier = new ConstantVerifier(
3216 errorReporter, libraryElement, typeProvider, context.declaredVariables); 4219 errorReporter, libraryElement, typeProvider, context.declaredVariables);
3217 unit.accept(constantVerifier); 4220 unit.accept(constantVerifier);
3218 // 4221 //
3219 // Use the ErrorVerifier to compute errors. 4222 // Use the ErrorVerifier to compute errors.
3220 // 4223 //
3221 ErrorVerifier errorVerifier = new ErrorVerifier(errorReporter, 4224 ErrorVerifier errorVerifier = new ErrorVerifier(
3222 libraryElement, typeProvider, new InheritanceManager(libraryElement)); 4225 errorReporter,
4226 libraryElement,
4227 typeProvider,
4228 new InheritanceManager(libraryElement),
4229 context.analysisOptions.enableSuperMixins);
3223 unit.accept(errorVerifier); 4230 unit.accept(errorVerifier);
3224 // 4231 //
3225 // Record outputs. 4232 // Record outputs.
3226 // 4233 //
3227 outputs[VERIFY_ERRORS] = removeDuplicateErrors(errorListener.errors); 4234 outputs[VERIFY_ERRORS] = removeDuplicateErrors(errorListener.errors);
3228 } 4235 }
3229 4236
3230 /** 4237 /**
3231 * Check each directive in the given [unit] to see if the referenced source 4238 * Check each directive in the given [unit] to see if the referenced source
3232 * exists and report an error if it does not. 4239 * exists and report an error if it does not.
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
3383 kind == _SourceClosureKind.IMPORT_EXPORT) { 4390 kind == _SourceClosureKind.IMPORT_EXPORT) {
3384 for (ExportElement exportElement in library.exports) { 4391 for (ExportElement exportElement in library.exports) {
3385 Source exportedSource = exportElement.exportedLibrary.source; 4392 Source exportedSource = exportElement.exportedLibrary.source;
3386 _newSources.add(exportedSource); 4393 _newSources.add(exportedSource);
3387 } 4394 }
3388 } 4395 }
3389 } 4396 }
3390 } 4397 }
3391 4398
3392 @override 4399 @override
4400 bool get flushOnAccess => false;
4401
4402 @override
3393 List<Source> get inputValue { 4403 List<Source> get inputValue {
3394 return _libraries.map((LibraryElement library) => library.source).toList(); 4404 return _libraries.map((LibraryElement library) => library.source).toList();
3395 } 4405 }
3396 4406
3397 @override 4407 @override
3398 void currentValueNotAvailable() { 4408 void currentValueNotAvailable() {
3399 // Nothing needs to be done. moveNext() will simply go on to the next new 4409 // Nothing needs to be done. moveNext() will simply go on to the next new
3400 // source. 4410 // source.
3401 } 4411 }
3402 4412
3403 @override 4413 @override
3404 bool moveNext() { 4414 bool moveNext() {
3405 if (_newSources.isEmpty) { 4415 if (_newSources.isEmpty) {
3406 return false; 4416 return false;
3407 } 4417 }
3408 currentTarget = _newSources.removeLast(); 4418 currentTarget = _newSources.removeLast();
3409 return true; 4419 return true;
3410 } 4420 }
3411 } 4421 }
OLDNEW
« no previous file with comments | « packages/analyzer/lib/src/string_source.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