OLD | NEW |
---|---|
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library analyzer.src.task.dart; | 5 library analyzer.src.task.dart; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 | 8 |
9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
10 import 'package:analyzer/dart/ast/token.dart'; | 10 import 'package:analyzer/dart/ast/token.dart'; |
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
432 * | 432 * |
433 * The result is only available for [Source]s representing a library. | 433 * The result is only available for [Source]s representing a library. |
434 */ | 434 */ |
435 final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT1 = | 435 final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT1 = |
436 new ResultDescriptor<LibraryElement>('LIBRARY_ELEMENT1', null, | 436 new ResultDescriptor<LibraryElement>('LIBRARY_ELEMENT1', null, |
437 cachingPolicy: ELEMENT_CACHING_POLICY); | 437 cachingPolicy: ELEMENT_CACHING_POLICY); |
438 | 438 |
439 /** | 439 /** |
440 * The partial [LibraryElement] associated with a library. | 440 * The partial [LibraryElement] associated with a library. |
441 * | 441 * |
442 * In addition to [LIBRARY_ELEMENT1] [LibraryElement.imports] and | 442 * In addition to [LIBRARY_ELEMENT1] also [LibraryElement.imports] and |
443 * [LibraryElement.exports] are set. | 443 * [LibraryElement.exports] are set. |
444 * | 444 * |
445 * The result is only available for [Source]s representing a library. | 445 * The result is only available for [Source]s representing a library. |
446 */ | 446 */ |
447 final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT2 = | 447 final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT2 = |
448 new ResultDescriptor<LibraryElement>('LIBRARY_ELEMENT2', null, | 448 new ResultDescriptor<LibraryElement>('LIBRARY_ELEMENT2', null, |
449 cachingPolicy: ELEMENT_CACHING_POLICY); | 449 cachingPolicy: ELEMENT_CACHING_POLICY); |
450 | 450 |
451 /** | 451 /** |
452 * The partial [LibraryElement] associated with a library. | 452 * The partial [LibraryElement] associated with a library. |
(...skipping 1768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2221 outputs[LIBRARY_CYCLE_DEPENDENCIES] = []; | 2221 outputs[LIBRARY_CYCLE_DEPENDENCIES] = []; |
2222 } | 2222 } |
2223 } | 2223 } |
2224 | 2224 |
2225 /** | 2225 /** |
2226 * Return a map from the names of the inputs of this kind of task to the task | 2226 * Return a map from the names of the inputs of this kind of task to the task |
2227 * input descriptors describing those inputs for a task with the | 2227 * input descriptors describing those inputs for a task with the |
2228 * given [target]. | 2228 * given [target]. |
2229 */ | 2229 */ |
2230 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { | 2230 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { |
2231 // TODO(scheglov) Why the target is LibrarySpecificUnit? | |
Brian Wilkerson
2016/06/27 13:59:00
This is addressed by another CL.
| |
2231 LibrarySpecificUnit unit = target; | 2232 LibrarySpecificUnit unit = target; |
2232 return <String, TaskInput>{ | 2233 return <String, TaskInput>{ |
2233 LIBRARY_ELEMENT_INPUT: LIBRARY_ELEMENT2.of(unit.library), | 2234 LIBRARY_ELEMENT_INPUT: LIBRARY_ELEMENT2.of(unit.library), |
2234 'resolveReachableLibraries': READY_LIBRARY_ELEMENT2.of(unit.library), | 2235 'resolveReachableLibraries': READY_LIBRARY_ELEMENT2.of(unit.library), |
2235 }; | 2236 }; |
2236 } | 2237 } |
2237 | 2238 |
2238 /** | 2239 /** |
2239 * Create a [ComputeLibraryCycleTask] based on the | 2240 * Create a [ComputeLibraryCycleTask] based on the |
2240 * given [target] in the given [context]. | 2241 * given [target] in the given [context]. |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2541 Source targetSource = null; | 2542 Source targetSource = null; |
2542 if (target is Source) { | 2543 if (target is Source) { |
2543 targetSource = target; | 2544 targetSource = target; |
2544 } | 2545 } |
2545 if (target is LibrarySpecificUnit) { | 2546 if (target is LibrarySpecificUnit) { |
2546 targetSource = target.library; | 2547 targetSource = target.library; |
2547 } | 2548 } |
2548 if (target is Element) { | 2549 if (target is Element) { |
2549 targetSource = target.source; | 2550 targetSource = target.source; |
2550 } | 2551 } |
2551 // Keep results that are updated incrementally. | 2552 // Keep results that don't change: any library. |
2552 // If we want to analyze only some references to the source being changed, | 2553 if (_isTaskResult(BuildLibraryElementTask.DESCRIPTOR, descriptor) || |
2553 // we need to keep the same instances of CompilationUnitElement and | 2554 _isTaskResult(BuildDirectiveElementsTask.DESCRIPTOR, descriptor) || |
2554 // LibraryElement. | 2555 _isTaskResult(ResolveDirectiveElementsTask.DESCRIPTOR, descriptor) || |
2556 _isTaskResult(BuildEnumMemberElementsTask.DESCRIPTOR, descriptor) || | |
2557 _isTaskResult(BuildSourceExportClosureTask.DESCRIPTOR, descriptor) || | |
2558 _isTaskResult(ReadyLibraryElement2Task.DESCRIPTOR, descriptor) || | |
2559 _isTaskResult(ComputeLibraryCycleTask.DESCRIPTOR, descriptor)) { | |
2560 return DeltaResult.KEEP_CONTINUE; | |
2561 } | |
2562 // Keep results that don't change: changed library. | |
2555 if (targetSource == source) { | 2563 if (targetSource == source) { |
2556 if (ScanDartTask.DESCRIPTOR.results.contains(descriptor)) { | 2564 if (_isTaskResult(ScanDartTask.DESCRIPTOR, descriptor) || |
2557 return DeltaResult.KEEP_CONTINUE; | 2565 _isTaskResult(ParseDartTask.DESCRIPTOR, descriptor) || |
2558 } | 2566 _isTaskResult( |
2559 if (ParseDartTask.DESCRIPTOR.results.contains(descriptor)) { | 2567 BuildCompilationUnitElementTask.DESCRIPTOR, descriptor) || |
2560 return DeltaResult.KEEP_CONTINUE; | 2568 _isTaskResult(BuildLibraryElementTask.DESCRIPTOR, descriptor)) { |
2561 } | |
2562 if (BuildCompilationUnitElementTask.DESCRIPTOR.results | |
2563 .contains(descriptor)) { | |
2564 return DeltaResult.KEEP_CONTINUE; | |
2565 } | |
2566 if (BuildLibraryElementTask.DESCRIPTOR.results.contains(descriptor)) { | |
2567 return DeltaResult.KEEP_CONTINUE; | 2569 return DeltaResult.KEEP_CONTINUE; |
2568 } | 2570 } |
2569 return DeltaResult.INVALIDATE; | 2571 return DeltaResult.INVALIDATE; |
2570 } | 2572 } |
2573 // Keep results that don't change: dependent library. | |
2574 if (targetSource != source) { | |
2575 if (_isTaskResult(BuildPublicNamespaceTask.DESCRIPTOR, descriptor)) { | |
2576 return DeltaResult.KEEP_CONTINUE; | |
2577 } | |
2578 } | |
2571 // Use the target library dependency information to decide whether | 2579 // Use the target library dependency information to decide whether |
2572 // the delta affects the library. | 2580 // the delta affects the library. |
2573 if (targetSource != null) { | 2581 if (targetSource != null) { |
2574 List<Source> librarySources = | 2582 List<Source> librarySources = |
2575 context.getLibrariesContaining(targetSource); | 2583 context.getLibrariesContaining(targetSource); |
2576 int length = librarySources.length; | 2584 int length = librarySources.length; |
2577 for (int i = 0; i < length; i++) { | 2585 for (int i = 0; i < length; i++) { |
2578 Source librarySource = librarySources[i]; | 2586 Source librarySource = librarySources[i]; |
2579 AnalysisCache cache = context.analysisCache; | 2587 AnalysisCache cache = context.analysisCache; |
2580 ReferencedNames referencedNames = | 2588 ReferencedNames referencedNames = |
2581 cache.getValue(librarySource, REFERENCED_NAMES); | 2589 cache.getValue(librarySource, REFERENCED_NAMES); |
2582 if (referencedNames == null) { | 2590 if (referencedNames == null) { |
2583 return DeltaResult.INVALIDATE; | 2591 return DeltaResult.INVALIDATE; |
2584 } | 2592 } |
2585 referencedNames.addChangedElements(this); | 2593 referencedNames.addChangedElements(this); |
2586 if (referencedNames.isAffectedBy(this)) { | 2594 if (referencedNames.isAffectedBy(this)) { |
2587 return DeltaResult.INVALIDATE; | 2595 return DeltaResult.INVALIDATE; |
2588 } | 2596 } |
2589 } | 2597 } |
2590 return DeltaResult.STOP; | 2598 return DeltaResult.STOP; |
2591 } | 2599 } |
2592 // We don't know what to do with the given target, invalidate it. | 2600 // We don't know what to do with the given target, invalidate it. |
2593 return DeltaResult.INVALIDATE; | 2601 return DeltaResult.INVALIDATE; |
2594 } | 2602 } |
2595 | 2603 |
2596 static bool _isPrivateName(String name) => name.startsWith('_'); | 2604 static bool _isPrivateName(String name) => name.startsWith('_'); |
2605 | |
2606 static bool _isTaskResult( | |
2607 TaskDescriptor taskDescriptor, ResultDescriptor result) { | |
2608 return taskDescriptor.results.contains(result); | |
2609 } | |
2597 } | 2610 } |
2598 | 2611 |
2599 /** | 2612 /** |
2600 * A task that merges all of the errors for a single source into a single list | 2613 * A task that merges all of the errors for a single source into a single list |
2601 * of errors. | 2614 * of errors. |
2602 */ | 2615 */ |
2603 class DartErrorsTask extends SourceBasedAnalysisTask { | 2616 class DartErrorsTask extends SourceBasedAnalysisTask { |
2604 /** | 2617 /** |
2605 * The task descriptor describing this kind of task. | 2618 * The task descriptor describing this kind of task. |
2606 */ | 2619 */ |
(...skipping 3645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6252 | 6265 |
6253 @override | 6266 @override |
6254 bool moveNext() { | 6267 bool moveNext() { |
6255 if (_newSources.isEmpty) { | 6268 if (_newSources.isEmpty) { |
6256 return false; | 6269 return false; |
6257 } | 6270 } |
6258 currentTarget = _newSources.removeLast(); | 6271 currentTarget = _newSources.removeLast(); |
6259 return true; | 6272 return true; |
6260 } | 6273 } |
6261 } | 6274 } |
OLD | NEW |