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

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

Issue 1486663003: Ensure that a complete library element has constants evaluated (issue 24890) (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated after breaking changes Created 5 years 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';
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 * 299 *
300 * [LIBRARY_ELEMENT6] for the library and its import/export closure. 300 * [LIBRARY_ELEMENT6] for the library and its import/export closure.
301 * 301 *
302 * The result is only available for [Source]s representing a library. 302 * The result is only available for [Source]s representing a library.
303 */ 303 */
304 final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT7 = 304 final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT7 =
305 new ResultDescriptor<LibraryElement>('LIBRARY_ELEMENT7', null, 305 new ResultDescriptor<LibraryElement>('LIBRARY_ELEMENT7', null,
306 cachingPolicy: ELEMENT_CACHING_POLICY); 306 cachingPolicy: ELEMENT_CACHING_POLICY);
307 307
308 /** 308 /**
309 * The partial [LibraryElement] associated with a library.
310 *
311 * The same as a [LIBRARY_ELEMENT7].
312 *
313 * The result is only available for [Source]s representing a library.
314 */
315 final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT8 =
316 new ResultDescriptor<LibraryElement>('LIBRARY_ELEMENT8', null,
317 cachingPolicy: ELEMENT_CACHING_POLICY);
318
319 /**
309 * The flag specifying whether all analysis errors are computed in a specific 320 * The flag specifying whether all analysis errors are computed in a specific
310 * library. 321 * library.
311 * 322 *
312 * The result is only available for [Source]s representing a library. 323 * The result is only available for [Source]s representing a library.
313 */ 324 */
314 final ResultDescriptor<bool> LIBRARY_ERRORS_READY = 325 final ResultDescriptor<bool> LIBRARY_ERRORS_READY =
315 new ResultDescriptor<bool>('LIBRARY_ERRORS_READY', false); 326 new ResultDescriptor<bool>('LIBRARY_ERRORS_READY', false);
316 327
317 /** 328 /**
318 * The [LibrarySpecificUnit]s that a library consists of. 329 * The [LibrarySpecificUnit]s that a library consists of.
(...skipping 2065 matching lines...) Expand 10 before | Expand all | Expand 10 after
2384 } 2395 }
2385 2396
2386 /** 2397 /**
2387 * Return a map from the names of the inputs of this kind of task to the task 2398 * Return a map from the names of the inputs of this kind of task to the task
2388 * input descriptors describing those inputs for a task with the 2399 * input descriptors describing those inputs for a task with the
2389 * given [target]. 2400 * given [target].
2390 */ 2401 */
2391 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 2402 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
2392 LibrarySpecificUnit unit = target; 2403 LibrarySpecificUnit unit = target;
2393 return <String, TaskInput>{ 2404 return <String, TaskInput>{
2394 'libraryElement': LIBRARY_ELEMENT.of(unit.library), 2405 'libraryElement': LIBRARY_ELEMENT8.of(unit.library),
2395 UNIT_INPUT: RESOLVED_UNIT10.of(unit), 2406 UNIT_INPUT: RESOLVED_UNIT10.of(unit),
2396 CONSTANT_VALUES: 2407 CONSTANT_VALUES:
2397 COMPILATION_UNIT_CONSTANTS.of(unit).toListOf(CONSTANT_VALUE) 2408 COMPILATION_UNIT_CONSTANTS.of(unit).toListOf(CONSTANT_VALUE)
2398 }; 2409 };
2399 } 2410 }
2400 2411
2401 /** 2412 /**
2402 * Create an [EvaluateUnitConstantsTask] based on the given [target] in 2413 * Create an [EvaluateUnitConstantsTask] based on the given [target] in
2403 * the given [context]. 2414 * the given [context].
2404 */ 2415 */
(...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after
3194 } 3205 }
3195 3206
3196 /** 3207 /**
3197 * Return a map from the names of the inputs of this kind of task to the task 3208 * Return a map from the names of the inputs of this kind of task to the task
3198 * input descriptors describing those inputs for a task with the 3209 * input descriptors describing those inputs for a task with the
3199 * given [target]. 3210 * given [target].
3200 */ 3211 */
3201 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 3212 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
3202 Source source = target; 3213 Source source = target;
3203 return <String, TaskInput>{ 3214 return <String, TaskInput>{
3204 'allErrors': UNITS.of(source).toListOf(DART_ERRORS) 3215 'allErrors': UNITS.of(source).toListOf(DART_ERRORS),
3216 'libraryElement': LIBRARY_ELEMENT.of(source)
3205 }; 3217 };
3206 } 3218 }
3207 3219
3208 /** 3220 /**
3209 * Create a [LibraryErrorsReadyTask] based on the given [target] in the given 3221 * Create a [LibraryErrorsReadyTask] based on the given [target] in the given
3210 * [context]. 3222 * [context].
3211 */ 3223 */
3212 static LibraryErrorsReadyTask createTask( 3224 static LibraryErrorsReadyTask createTask(
3213 AnalysisContext context, AnalysisTarget target) { 3225 AnalysisContext context, AnalysisTarget target) {
3214 return new LibraryErrorsReadyTask(context, target); 3226 return new LibraryErrorsReadyTask(context, target);
(...skipping 1204 matching lines...) Expand 10 before | Expand all | Expand 10 after
4419 * the given [context]. 4431 * the given [context].
4420 */ 4432 */
4421 static ResolveInstanceFieldsInUnitTask createTask( 4433 static ResolveInstanceFieldsInUnitTask createTask(
4422 AnalysisContext context, AnalysisTarget target) { 4434 AnalysisContext context, AnalysisTarget target) {
4423 return new ResolveInstanceFieldsInUnitTask(context, target); 4435 return new ResolveInstanceFieldsInUnitTask(context, target);
4424 } 4436 }
4425 } 4437 }
4426 4438
4427 /** 4439 /**
4428 * A task that finishes resolution by requesting [RESOLVED_UNIT10] for every 4440 * A task that finishes resolution by requesting [RESOLVED_UNIT10] for every
4429 * unit in the libraries closure and produces [LIBRARY_ELEMENT]. 4441 * unit in the libraries closure and produces [LIBRARY_ELEMENT8].
4430 */ 4442 */
4431 class ResolveLibraryReferencesTask extends SourceBasedAnalysisTask { 4443 class ResolveLibraryReferencesTask extends SourceBasedAnalysisTask {
4432 /** 4444 /**
4433 * The name of the [LIBRARY_ELEMENT5] input. 4445 * The name of the [LIBRARY_ELEMENT7] input.
4434 */ 4446 */
4435 static const String LIBRARY_INPUT = 'LIBRARY_INPUT'; 4447 static const String LIBRARY_INPUT = 'LIBRARY_INPUT';
4436 4448
4437 /** 4449 /**
4438 * The name of the list of [RESOLVED_UNIT10] input. 4450 * The name of the list of [RESOLVED_UNIT10] input.
4439 */ 4451 */
4440 static const String UNITS_INPUT = 'UNITS_INPUT'; 4452 static const String UNITS_INPUT = 'UNITS_INPUT';
4441 4453
4442 /** 4454 /**
4443 * The task descriptor describing this kind of task. 4455 * The task descriptor describing this kind of task.
4444 */ 4456 */
4445 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 4457 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
4446 'ResolveLibraryReferencesTask', 4458 'ResolveLibraryReferencesTask',
4447 createTask, 4459 createTask,
4448 buildInputs, 4460 buildInputs,
4449 <ResultDescriptor>[LIBRARY_ELEMENT, REFERENCED_NAMES]); 4461 <ResultDescriptor>[LIBRARY_ELEMENT8, REFERENCED_NAMES]);
4450 4462
4451 ResolveLibraryReferencesTask( 4463 ResolveLibraryReferencesTask(
4452 InternalAnalysisContext context, AnalysisTarget target) 4464 InternalAnalysisContext context, AnalysisTarget target)
4453 : super(context, target); 4465 : super(context, target);
4454 4466
4455 @override 4467 @override
4456 TaskDescriptor get descriptor => DESCRIPTOR; 4468 TaskDescriptor get descriptor => DESCRIPTOR;
4457 4469
4458 @override 4470 @override
4459 void internalPerform() { 4471 void internalPerform() {
4460 // 4472 //
4461 // Prepare inputs. 4473 // Prepare inputs.
4462 // 4474 //
4463 LibraryElement library = getRequiredInput(LIBRARY_INPUT); 4475 LibraryElement library = getRequiredInput(LIBRARY_INPUT);
4464 List<CompilationUnit> units = getRequiredInput(UNITS_INPUT); 4476 List<CompilationUnit> units = getRequiredInput(UNITS_INPUT);
4465 // Compute referenced names. 4477 // Compute referenced names.
4466 ReferencedNames referencedNames = new ReferencedNames(); 4478 ReferencedNames referencedNames = new ReferencedNames();
4467 for (CompilationUnit unit in units) { 4479 for (CompilationUnit unit in units) {
4468 new ReferencedNamesBuilder(referencedNames).build(unit); 4480 new ReferencedNamesBuilder(referencedNames).build(unit);
4469 } 4481 }
4470 // 4482 //
4471 // Record outputs. 4483 // Record outputs.
4472 // 4484 //
4473 outputs[LIBRARY_ELEMENT] = library; 4485 outputs[LIBRARY_ELEMENT8] = library;
4474 outputs[REFERENCED_NAMES] = referencedNames; 4486 outputs[REFERENCED_NAMES] = referencedNames;
4475 } 4487 }
4476 4488
4477 /** 4489 /**
4478 * Return a map from the names of the inputs of this kind of task to the task 4490 * Return a map from the names of the inputs of this kind of task to the task
4479 * input descriptors describing those inputs for a task with the 4491 * input descriptors describing those inputs for a task with the
4480 * given [target]. 4492 * given [target].
4481 */ 4493 */
4482 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 4494 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
4483 Source source = target; 4495 Source source = target;
4484 return <String, TaskInput>{ 4496 return <String, TaskInput>{
4485 LIBRARY_INPUT: LIBRARY_ELEMENT5.of(source), 4497 LIBRARY_INPUT: LIBRARY_ELEMENT7.of(source),
4486 UNITS_INPUT: LIBRARY_SPECIFIC_UNITS.of(source).toListOf(RESOLVED_UNIT10), 4498 UNITS_INPUT: LIBRARY_SPECIFIC_UNITS.of(source).toListOf(RESOLVED_UNIT10),
4487 'thisLibraryClosureIsReady': READY_RESOLVED_UNIT10.of(source), 4499 'thisLibraryClosureIsReady': READY_RESOLVED_UNIT10.of(source),
4488 }; 4500 };
4489 } 4501 }
4490 4502
4491 /** 4503 /**
4492 * Create a [ResolveLibraryReferencesTask] based on the given [target] in 4504 * Create a [ResolveLibraryReferencesTask] based on the given [target] in
4493 * the given [context]. 4505 * the given [context].
4494 */ 4506 */
4495 static ResolveLibraryReferencesTask createTask( 4507 static ResolveLibraryReferencesTask createTask(
4496 AnalysisContext context, AnalysisTarget target) { 4508 AnalysisContext context, AnalysisTarget target) {
4497 return new ResolveLibraryReferencesTask(context, target); 4509 return new ResolveLibraryReferencesTask(context, target);
4498 } 4510 }
4499 } 4511 }
4500 4512
4501 /** 4513 /**
4514 * A task that finishes resolution by requesting [RESOLVED_UNIT11] for every
4515 * unit in the libraries closure and produces [LIBRARY_ELEMENT].
4516 */
4517 class ResolveLibraryTask extends SourceBasedAnalysisTask {
4518 /**
4519 * The name of the [LIBRARY_ELEMENT8] input.
4520 */
4521 static const String LIBRARY_INPUT = 'LIBRARY_INPUT';
4522
4523 /**
4524 * The name of the list of [RESOLVED_UNIT11] input.
4525 */
4526 static const String UNITS_INPUT = 'UNITS_INPUT';
4527
4528 /**
4529 * The task descriptor describing this kind of task.
4530 */
4531 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
4532 'ResolveLibraryTask',
4533 createTask,
4534 buildInputs,
4535 <ResultDescriptor>[LIBRARY_ELEMENT]);
4536
4537 ResolveLibraryTask(InternalAnalysisContext context, AnalysisTarget target)
4538 : super(context, target);
4539
4540 @override
4541 TaskDescriptor get descriptor => DESCRIPTOR;
4542
4543 @override
4544 void internalPerform() {
4545 //
4546 // Prepare inputs.
4547 //
4548 LibraryElement library = getRequiredInput(LIBRARY_INPUT);
4549 //
4550 // Record outputs.
4551 //
4552 outputs[LIBRARY_ELEMENT] = library;
4553 }
4554
4555 /**
4556 * Return a map from the names of the inputs of this kind of task to the task
4557 * input descriptors describing those inputs for a task with the
4558 * given [target].
4559 */
4560 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
4561 Source source = target;
4562 return <String, TaskInput>{
4563 LIBRARY_INPUT: LIBRARY_ELEMENT8.of(source),
4564 'thisLibraryClosureIsReady': READY_RESOLVED_UNIT.of(source),
4565 };
4566 }
4567
4568 /**
4569 * Create a [ResolveLibraryTask] based on the given [target] in the given
4570 * [context].
4571 */
4572 static ResolveLibraryTask createTask(
4573 AnalysisContext context, AnalysisTarget target) {
4574 return new ResolveLibraryTask(context, target);
4575 }
4576 }
4577
4578 /**
4502 * An artificial task that does nothing except to force type names resolution 4579 * An artificial task that does nothing except to force type names resolution
4503 * for the defining and part units of a library. 4580 * for the defining and part units of a library.
4504 */ 4581 */
4505 class ResolveLibraryTypeNamesTask extends SourceBasedAnalysisTask { 4582 class ResolveLibraryTypeNamesTask extends SourceBasedAnalysisTask {
4506 /** 4583 /**
4507 * The name of the [LIBRARY_ELEMENT4] input. 4584 * The name of the [LIBRARY_ELEMENT4] input.
4508 */ 4585 */
4509 static const String LIBRARY_INPUT = 'LIBRARY_INPUT'; 4586 static const String LIBRARY_INPUT = 'LIBRARY_INPUT';
4510 4587
4511 /** 4588 /**
(...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after
5252 5329
5253 @override 5330 @override
5254 bool moveNext() { 5331 bool moveNext() {
5255 if (_newSources.isEmpty) { 5332 if (_newSources.isEmpty) {
5256 return false; 5333 return false;
5257 } 5334 }
5258 currentTarget = _newSources.removeLast(); 5335 currentTarget = _newSources.removeLast();
5259 return true; 5336 return true;
5260 } 5337 }
5261 } 5338 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/plugin/engine_plugin.dart ('k') | pkg/analyzer/test/src/context/context_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698