| 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 5075 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5086 * A task that scans the content of a Dart file, producing a stream of Dart | 5086 * A task that scans the content of a Dart file, producing a stream of Dart |
| 5087 * tokens, line information, and any lexical errors encountered in the process. | 5087 * tokens, line information, and any lexical errors encountered in the process. |
| 5088 */ | 5088 */ |
| 5089 class ScanDartTask extends SourceBasedAnalysisTask { | 5089 class ScanDartTask extends SourceBasedAnalysisTask { |
| 5090 /** | 5090 /** |
| 5091 * The name of the input whose value is the content of the file. | 5091 * The name of the input whose value is the content of the file. |
| 5092 */ | 5092 */ |
| 5093 static const String CONTENT_INPUT_NAME = 'CONTENT_INPUT_NAME'; | 5093 static const String CONTENT_INPUT_NAME = 'CONTENT_INPUT_NAME'; |
| 5094 | 5094 |
| 5095 /** | 5095 /** |
| 5096 * The name of the input whose value is the modification time of the file. |
| 5097 */ |
| 5098 static const String MODIFICATION_TIME_INPUT = 'MODIFICATION_TIME_INPUT'; |
| 5099 |
| 5100 /** |
| 5096 * The task descriptor describing this kind of task. | 5101 * The task descriptor describing this kind of task. |
| 5097 */ | 5102 */ |
| 5098 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( | 5103 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( |
| 5099 'ScanDartTask', | 5104 'ScanDartTask', |
| 5100 createTask, | 5105 createTask, |
| 5101 buildInputs, | 5106 buildInputs, |
| 5102 <ResultDescriptor>[LINE_INFO, SCAN_ERRORS, TOKEN_STREAM], | 5107 <ResultDescriptor>[LINE_INFO, SCAN_ERRORS, TOKEN_STREAM], |
| 5103 suitabilityFor: suitabilityFor); | 5108 suitabilityFor: suitabilityFor); |
| 5104 | 5109 |
| 5105 /** | 5110 /** |
| 5106 * Initialize a newly created task to access the content of the source | 5111 * Initialize a newly created task to access the content of the source |
| 5107 * associated with the given [target] in the given [context]. | 5112 * associated with the given [target] in the given [context]. |
| 5108 */ | 5113 */ |
| 5109 ScanDartTask(InternalAnalysisContext context, AnalysisTarget target) | 5114 ScanDartTask(InternalAnalysisContext context, AnalysisTarget target) |
| 5110 : super(context, target); | 5115 : super(context, target); |
| 5111 | 5116 |
| 5112 @override | 5117 @override |
| 5113 TaskDescriptor get descriptor => DESCRIPTOR; | 5118 TaskDescriptor get descriptor => DESCRIPTOR; |
| 5114 | 5119 |
| 5115 @override | 5120 @override |
| 5116 void internalPerform() { | 5121 void internalPerform() { |
| 5117 Source source = getRequiredSource(); | 5122 Source source = getRequiredSource(); |
| 5123 RecordingErrorListener errorListener = new RecordingErrorListener(); |
| 5118 | 5124 |
| 5119 RecordingErrorListener errorListener = new RecordingErrorListener(); | 5125 int modificationTime = getRequiredInput(MODIFICATION_TIME_INPUT); |
| 5120 if (context.getModificationStamp(target.source) < 0) { | 5126 if (modificationTime < 0) { |
| 5121 String message = 'Content could not be read'; | 5127 String message = 'Content could not be read'; |
| 5122 if (context is InternalAnalysisContext) { | 5128 if (context is InternalAnalysisContext) { |
| 5123 CacheEntry entry = | 5129 CacheEntry entry = |
| 5124 (context as InternalAnalysisContext).getCacheEntry(target); | 5130 (context as InternalAnalysisContext).getCacheEntry(target); |
| 5125 CaughtException exception = entry.exception; | 5131 CaughtException exception = entry.exception; |
| 5126 if (exception != null) { | 5132 if (exception != null) { |
| 5127 message = exception.toString(); | 5133 message = exception.toString(); |
| 5128 } | 5134 } |
| 5129 } | 5135 } |
| 5130 if (source.exists()) { | 5136 if (source.exists()) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5167 outputs[SCAN_ERRORS] = getUniqueErrors(errorListener.errors); | 5173 outputs[SCAN_ERRORS] = getUniqueErrors(errorListener.errors); |
| 5168 } else { | 5174 } else { |
| 5169 throw new AnalysisException( | 5175 throw new AnalysisException( |
| 5170 'Cannot scan Dart code from a ${target.runtimeType}'); | 5176 'Cannot scan Dart code from a ${target.runtimeType}'); |
| 5171 } | 5177 } |
| 5172 } | 5178 } |
| 5173 | 5179 |
| 5174 /** | 5180 /** |
| 5175 * Return a map from the names of the inputs of this kind of task to the task | 5181 * Return a map from the names of the inputs of this kind of task to the task |
| 5176 * input descriptors describing those inputs for a task with the given | 5182 * input descriptors describing those inputs for a task with the given |
| 5177 * [source]. | 5183 * [target]. |
| 5178 */ | 5184 */ |
| 5179 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { | 5185 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { |
| 5180 if (target is Source) { | 5186 if (target is Source) { |
| 5181 return <String, TaskInput>{CONTENT_INPUT_NAME: CONTENT.of(target)}; | 5187 return <String, TaskInput>{ |
| 5188 CONTENT_INPUT_NAME: CONTENT.of(target), |
| 5189 MODIFICATION_TIME_INPUT: MODIFICATION_TIME.of(target) |
| 5190 }; |
| 5182 } else if (target is DartScript) { | 5191 } else if (target is DartScript) { |
| 5183 // This task does not use the following input; it is included only to add | 5192 // This task does not use the following input; it is included only to add |
| 5184 // a dependency between this value and the containing source so that when | 5193 // a dependency between this value and the containing source so that when |
| 5185 // the containing source is modified these results will be invalidated. | 5194 // the containing source is modified these results will be invalidated. |
| 5186 return <String, TaskInput>{'-': DART_SCRIPTS.of(target.source)}; | 5195 Source source = target.source; |
| 5196 return <String, TaskInput>{ |
| 5197 '-': DART_SCRIPTS.of(source), |
| 5198 MODIFICATION_TIME_INPUT: MODIFICATION_TIME.of(source) |
| 5199 }; |
| 5187 } | 5200 } |
| 5188 throw new AnalysisException( | 5201 throw new AnalysisException( |
| 5189 'Cannot build inputs for a ${target.runtimeType}'); | 5202 'Cannot build inputs for a ${target.runtimeType}'); |
| 5190 } | 5203 } |
| 5191 | 5204 |
| 5192 /** | 5205 /** |
| 5193 * Create a [ScanDartTask] based on the given [target] in the given [context]. | 5206 * Create a [ScanDartTask] based on the given [target] in the given [context]. |
| 5194 */ | 5207 */ |
| 5195 static ScanDartTask createTask( | 5208 static ScanDartTask createTask( |
| 5196 AnalysisContext context, AnalysisTarget target) { | 5209 AnalysisContext context, AnalysisTarget target) { |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5521 | 5534 |
| 5522 @override | 5535 @override |
| 5523 bool moveNext() { | 5536 bool moveNext() { |
| 5524 if (_newSources.isEmpty) { | 5537 if (_newSources.isEmpty) { |
| 5525 return false; | 5538 return false; |
| 5526 } | 5539 } |
| 5527 currentTarget = _newSources.removeLast(); | 5540 currentTarget = _newSources.removeLast(); |
| 5528 return true; | 5541 return true; |
| 5529 } | 5542 } |
| 5530 } | 5543 } |
| OLD | NEW |