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 import 'dart:math' as math; | 8 import 'dart:math' as math; |
9 | 9 |
10 import 'package:analyzer/src/context/cache.dart'; | 10 import 'package:analyzer/src/context/cache.dart'; |
(...skipping 3363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3374 */ | 3374 */ |
3375 ScanDartTask(InternalAnalysisContext context, AnalysisTarget target) | 3375 ScanDartTask(InternalAnalysisContext context, AnalysisTarget target) |
3376 : super(context, target); | 3376 : super(context, target); |
3377 | 3377 |
3378 @override | 3378 @override |
3379 TaskDescriptor get descriptor => DESCRIPTOR; | 3379 TaskDescriptor get descriptor => DESCRIPTOR; |
3380 | 3380 |
3381 @override | 3381 @override |
3382 void internalPerform() { | 3382 void internalPerform() { |
3383 Source source = getRequiredSource(); | 3383 Source source = getRequiredSource(); |
| 3384 |
| 3385 RecordingErrorListener errorListener = new RecordingErrorListener(); |
| 3386 if (context.getModificationStamp(target.source) < 0) { |
| 3387 String message = 'Content could not be read'; |
| 3388 if (context is InternalAnalysisContext) { |
| 3389 CacheEntry entry = (context as InternalAnalysisContext).getCacheEntry(ta
rget); |
| 3390 CaughtException exception = entry.exception; |
| 3391 if (exception != null) { |
| 3392 message = exception.toString(); |
| 3393 } |
| 3394 } |
| 3395 errorListener.onError(new AnalysisError( |
| 3396 source, 0, 0, ScannerErrorCode.UNABLE_GET_CONTENT, [message])); |
| 3397 } |
3384 if (target is DartScript) { | 3398 if (target is DartScript) { |
3385 DartScript script = target; | 3399 DartScript script = target; |
3386 List<ScriptFragment> fragments = script.fragments; | 3400 List<ScriptFragment> fragments = script.fragments; |
3387 if (fragments.length < 1) { | 3401 if (fragments.length < 1) { |
3388 throw new AnalysisException('Cannot scan scripts with no fragments'); | 3402 throw new AnalysisException('Cannot scan scripts with no fragments'); |
3389 } else if (fragments.length > 1) { | 3403 } else if (fragments.length > 1) { |
3390 throw new AnalysisException( | 3404 throw new AnalysisException( |
3391 'Cannot scan scripts with multiple fragments'); | 3405 'Cannot scan scripts with multiple fragments'); |
3392 } | 3406 } |
3393 ScriptFragment fragment = fragments[0]; | 3407 ScriptFragment fragment = fragments[0]; |
3394 | 3408 |
3395 RecordingErrorListener errorListener = new RecordingErrorListener(); | |
3396 Scanner scanner = new Scanner(source, | 3409 Scanner scanner = new Scanner(source, |
3397 new SubSequenceReader(fragment.content, fragment.offset), | 3410 new SubSequenceReader(fragment.content, fragment.offset), |
3398 errorListener); | 3411 errorListener); |
3399 scanner.setSourceStart(fragment.line, fragment.column); | 3412 scanner.setSourceStart(fragment.line, fragment.column); |
3400 scanner.preserveComments = context.analysisOptions.preserveComments; | 3413 scanner.preserveComments = context.analysisOptions.preserveComments; |
3401 scanner.enableNullAwareOperators = | 3414 scanner.enableNullAwareOperators = |
3402 context.analysisOptions.enableNullAwareOperators; | 3415 context.analysisOptions.enableNullAwareOperators; |
3403 | 3416 |
3404 outputs[TOKEN_STREAM] = scanner.tokenize(); | 3417 outputs[TOKEN_STREAM] = scanner.tokenize(); |
3405 outputs[LINE_INFO] = new LineInfo(scanner.lineStarts); | 3418 outputs[LINE_INFO] = new LineInfo(scanner.lineStarts); |
3406 outputs[SCAN_ERRORS] = removeDuplicateErrors(errorListener.errors); | 3419 outputs[SCAN_ERRORS] = removeDuplicateErrors(errorListener.errors); |
3407 } else if (target is Source) { | 3420 } else if (target is Source) { |
3408 String content = getRequiredInput(CONTENT_INPUT_NAME); | 3421 String content = getRequiredInput(CONTENT_INPUT_NAME); |
3409 | 3422 |
3410 RecordingErrorListener errorListener = new RecordingErrorListener(); | |
3411 Scanner scanner = | 3423 Scanner scanner = |
3412 new Scanner(source, new CharSequenceReader(content), errorListener); | 3424 new Scanner(source, new CharSequenceReader(content), errorListener); |
3413 scanner.preserveComments = context.analysisOptions.preserveComments; | 3425 scanner.preserveComments = context.analysisOptions.preserveComments; |
3414 scanner.enableNullAwareOperators = | 3426 scanner.enableNullAwareOperators = |
3415 context.analysisOptions.enableNullAwareOperators; | 3427 context.analysisOptions.enableNullAwareOperators; |
3416 | 3428 |
3417 outputs[TOKEN_STREAM] = scanner.tokenize(); | 3429 outputs[TOKEN_STREAM] = scanner.tokenize(); |
3418 outputs[LINE_INFO] = new LineInfo(scanner.lineStarts); | 3430 outputs[LINE_INFO] = new LineInfo(scanner.lineStarts); |
3419 outputs[SCAN_ERRORS] = removeDuplicateErrors(errorListener.errors); | 3431 outputs[SCAN_ERRORS] = removeDuplicateErrors(errorListener.errors); |
3420 } else { | 3432 } else { |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3675 | 3687 |
3676 @override | 3688 @override |
3677 bool moveNext() { | 3689 bool moveNext() { |
3678 if (_newSources.isEmpty) { | 3690 if (_newSources.isEmpty) { |
3679 return false; | 3691 return false; |
3680 } | 3692 } |
3681 currentTarget = _newSources.removeLast(); | 3693 currentTarget = _newSources.removeLast(); |
3682 return true; | 3694 return true; |
3683 } | 3695 } |
3684 } | 3696 } |
OLD | NEW |