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

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

Issue 1370323003: Fix computation of errors to not run extra tasks (Closed) Base URL: https://github.com/dart-lang/sdk.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
« no previous file with comments | « pkg/analyzer/lib/src/task/dart.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.inputs; 5 library analyzer.src.task.inputs;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/task/model.dart'; 9 import 'package:analyzer/task/model.dart';
10 10
11 /** 11 /**
12 * A function that converts an object of the type [B] into a [TaskInput]. 12 * A function that converts an object of the type [B] into a [TaskInput].
13 * This is used, for example, by a [ListToListTaskInput] to create task inputs 13 * This is used, for example, by a [ListToListTaskInput] to create task inputs
14 * for each value in a list of values. 14 * for each value in a list of values.
15 */ 15 */
16 typedef TaskInput<E> GenerateTaskInputs<B, E>(B object); 16 typedef TaskInput<E> GenerateTaskInputs<B, E>(B object);
17 17
18 /** 18 /**
19 * A function that maps one [value] to another value. 19 * A function that maps one [value] to another value.
20 */ 20 */
21 typedef R Mapper<P, R>(P value); 21 typedef R Mapper<P, R>(P value);
22 22
23 /** 23 /**
24 * An input to an [AnalysisTask] that is computed by accessing a single result 24 * An input to an [AnalysisTask] that is computed by accessing a single result
25 * defined on a single target. 25 * defined on a single target.
26 */ 26 */
27 class ConstantTaskInput<V> extends TaskInputImpl<V> {
28 final V value;
29
30 ConstantTaskInput(this.value);
31
32 @override
33 TaskInputBuilder<V> createBuilder() {
34 return new ConstantTaskInputBuilder<V>(this);
35 }
36 }
37
38 /**
39 * A [TaskInputBuilder] used to build an input based on a [ConstantTaskInput].
40 */
41 class ConstantTaskInputBuilder<V> implements TaskInputBuilder<V> {
42 final ConstantTaskInput input;
43
44 ConstantTaskInputBuilder(this.input);
45
46 @override
47 ResultDescriptor get currentResult => null;
48
49 @override
50 AnalysisTarget get currentTarget => null;
51
52 @override
53 void set currentValue(Object value) {
54 throw new StateError('Only supported after moveNext() returns true');
55 }
56
57 @override
58 V get inputValue => input.value;
59
60 @override
61 void currentValueNotAvailable() {
62 throw new StateError('Only supported after moveNext() returns true');
63 }
64
65 @override
66 bool moveNext() => false;
67 }
68
69 /**
70 * An input to an [AnalysisTask] that is computed by accessing a single result
71 * defined on a single target.
72 */
27 class ListTaskInputImpl<E> extends SimpleTaskInput<List<E>> 73 class ListTaskInputImpl<E> extends SimpleTaskInput<List<E>>
28 with ListTaskInputMixin<E> 74 with ListTaskInputMixin<E>
29 implements ListTaskInput<E> { 75 implements ListTaskInput<E> {
30 /** 76 /**
31 * Initialize a newly created task input that computes the input by accessing 77 * Initialize a newly created task input that computes the input by accessing
32 * the given [result] associated with the given [target]. 78 * the given [result] associated with the given [target].
33 */ 79 */
34 ListTaskInputImpl(AnalysisTarget target, ResultDescriptor<List<E>> result) 80 ListTaskInputImpl(AnalysisTarget target, ResultDescriptor<List<E>> result)
35 : super(target, result); 81 : super(target, result);
36 } 82 }
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 if (currentBuilder.inputValue != null) { 714 if (currentBuilder.inputValue != null) {
669 inputs[_currentName] = currentBuilder.inputValue; 715 inputs[_currentName] = currentBuilder.inputValue;
670 } 716 }
671 nameIndex++; 717 nameIndex++;
672 } 718 }
673 if (nameIndex >= inputNames.length) { 719 if (nameIndex >= inputNames.length) {
674 // There is no next value, so we're done. 720 // There is no next value, so we're done.
675 return false; 721 return false;
676 } 722 }
677 currentBuilder = inputDescriptors[_currentName].createBuilder(); 723 currentBuilder = inputDescriptors[_currentName].createBuilder();
678 // NOTE: This assumes that every builder will require at least one result 724 while (!currentBuilder.moveNext()) {
679 // value to be created. If that assumption is every broken, this method will 725 if (currentBuilder.inputValue != null) {
680 // need to be changed to advance until we find a builder that does require 726 inputs[_currentName] = currentBuilder.inputValue;
681 // a result to be computed (or run out of builders). 727 }
682 return currentBuilder.moveNext(); 728 nameIndex++;
729 if (nameIndex >= inputNames.length) {
730 // There is no next value, so we're done.
731 return false;
732 }
733 currentBuilder = inputDescriptors[_currentName].createBuilder();
734 }
735 return true;
scheglov 2015/09/29 21:55:32 Too bad that we have to duplicate logic here :-(
Brian Wilkerson 2015/09/29 22:11:00 Agreed. I couldn't think of a good way to restruct
683 } 736 }
684 } 737 }
685 738
686 /** 739 /**
687 * An input to an [AnalysisTask] that is computed by the following steps. First 740 * An input to an [AnalysisTask] that is computed by the following steps. First
688 * another (base) task input is used to compute a [List]-valued result. An input 741 * another (base) task input is used to compute a [List]-valued result. An input
689 * generator function is then used to map each element of that list to a task 742 * generator function is then used to map each element of that list to a task
690 * input. Finally, each of the task inputs are used to access analysis results, 743 * input. Finally, each of the task inputs are used to access analysis results,
691 * and a collection of the analysis results is used as the input to the task. 744 * and a collection of the analysis results is used as the input to the task.
692 */ 745 */
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 return false; 887 return false;
835 } 888 }
836 _baseListElement = _baseList[_baseListIndex]; 889 _baseListElement = _baseList[_baseListIndex];
837 currentBuilder = input.generateTaskInputs(_baseListElement).createBuilder(); 890 currentBuilder = input.generateTaskInputs(_baseListElement).createBuilder();
838 return currentBuilder.moveNext(); 891 return currentBuilder.moveNext();
839 } 892 }
840 893
841 void _addResultElement(B baseElement, E resultElement); 894 void _addResultElement(B baseElement, E resultElement);
842 void _initResultValue(); 895 void _initResultValue();
843 } 896 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/task/dart.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698