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

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

Issue 1113103003: Use memento in ScanDartTask. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/analyzer/test/src/task/dart_test.dart » ('j') | 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.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/generated/ast.dart'; 10 import 'package:analyzer/src/generated/ast.dart';
(...skipping 2365 matching lines...) Expand 10 before | Expand all | Expand 10 after
2376 * Create a [ResolveVariableReferencesTask] based on the given [target] in 2376 * Create a [ResolveVariableReferencesTask] based on the given [target] in
2377 * the given [context]. 2377 * the given [context].
2378 */ 2378 */
2379 static ResolveVariableReferencesTask createTask( 2379 static ResolveVariableReferencesTask createTask(
2380 AnalysisContext context, AnalysisTarget target) { 2380 AnalysisContext context, AnalysisTarget target) {
2381 return new ResolveVariableReferencesTask(context, target); 2381 return new ResolveVariableReferencesTask(context, target);
2382 } 2382 }
2383 } 2383 }
2384 2384
2385 /** 2385 /**
2386 * The memento for [ScanDartTask].
2387 */
2388 class ScanDartMemento {
2389 final String content;
2390 final Token tokenStream;
2391 final LineInfo lineInfo;
2392 final List<AnalysisError> errors;
2393 ScanDartMemento(this.content, this.tokenStream, this.lineInfo, this.errors);
2394 }
2395
2396 /**
2386 * A task that scans the content of a file, producing a set of Dart tokens. 2397 * A task that scans the content of a file, producing a set of Dart tokens.
2387 */ 2398 */
2388 class ScanDartTask extends SourceBasedAnalysisTask { 2399 class ScanDartTask extends SourceBasedAnalysisTask {
2389 /** 2400 /**
2390 * The name of the input whose value is the content of the file. 2401 * The name of the input whose value is the content of the file.
2391 */ 2402 */
2392 static const String CONTENT_INPUT_NAME = 'CONTENT_INPUT_NAME'; 2403 static const String CONTENT_INPUT_NAME = 'CONTENT_INPUT_NAME';
2393 2404
2394 /** 2405 /**
2395 * The task descriptor describing this kind of task. 2406 * The task descriptor describing this kind of task.
(...skipping 13 matching lines...) Expand all
2409 : super(context, target); 2420 : super(context, target);
2410 2421
2411 @override 2422 @override
2412 TaskDescriptor get descriptor => DESCRIPTOR; 2423 TaskDescriptor get descriptor => DESCRIPTOR;
2413 2424
2414 @override 2425 @override
2415 void internalPerform() { 2426 void internalPerform() {
2416 Source source = getRequiredSource(); 2427 Source source = getRequiredSource();
2417 String content = getRequiredInput(CONTENT_INPUT_NAME); 2428 String content = getRequiredInput(CONTENT_INPUT_NAME);
2418 2429
2430 if (inputMemento is ScanDartMemento) {
2431 ScanDartMemento memento = inputMemento;
2432 if (memento.content == content) {
2433 outputMemento = memento;
2434 outputs[TOKEN_STREAM] = memento.tokenStream;
2435 outputs[LINE_INFO] = memento.lineInfo;
2436 outputs[SCAN_ERRORS] = memento.errors;
2437 return;
2438 }
2439 }
2440
2419 RecordingErrorListener errorListener = new RecordingErrorListener(); 2441 RecordingErrorListener errorListener = new RecordingErrorListener();
2420 Scanner scanner = 2442 Scanner scanner =
2421 new Scanner(source, new CharSequenceReader(content), errorListener); 2443 new Scanner(source, new CharSequenceReader(content), errorListener);
2422 scanner.preserveComments = context.analysisOptions.preserveComments; 2444 scanner.preserveComments = context.analysisOptions.preserveComments;
2423 scanner.enableNullAwareOperators = 2445 scanner.enableNullAwareOperators =
2424 context.analysisOptions.enableNullAwareOperators; 2446 context.analysisOptions.enableNullAwareOperators;
2425 outputs[TOKEN_STREAM] = scanner.tokenize(); 2447
2426 outputs[LINE_INFO] = new LineInfo(scanner.lineStarts); 2448 Token tokenStream = scanner.tokenize();
2427 outputs[SCAN_ERRORS] = errorListener.getErrorsForSource(source); 2449 LineInfo lineInfo = new LineInfo(scanner.lineStarts);
2450 List<AnalysisError> errors = errorListener.errors;
2451 outputs[TOKEN_STREAM] = tokenStream;
2452 outputs[LINE_INFO] = lineInfo;
2453 outputs[SCAN_ERRORS] = errors;
2454 outputMemento = new ScanDartMemento(content, tokenStream, lineInfo, errors);
2428 } 2455 }
2429 2456
2430 /** 2457 /**
2431 * Return a map from the names of the inputs of this kind of task to the task 2458 * Return a map from the names of the inputs of this kind of task to the task
2432 * input descriptors describing those inputs for a task with the given 2459 * input descriptors describing those inputs for a task with the given
2433 * [source]. 2460 * [source].
2434 */ 2461 */
2435 static Map<String, TaskInput> buildInputs(Source source) { 2462 static Map<String, TaskInput> buildInputs(Source source) {
2436 return <String, TaskInput>{CONTENT_INPUT_NAME: CONTENT.of(source)}; 2463 return <String, TaskInput>{CONTENT_INPUT_NAME: CONTENT.of(source)};
2437 } 2464 }
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
2607 @override 2634 @override
2608 bool moveNext() { 2635 bool moveNext() {
2609 if (_newSources.isEmpty) { 2636 if (_newSources.isEmpty) {
2610 return false; 2637 return false;
2611 } 2638 }
2612 currentTarget = _newSources.first; 2639 currentTarget = _newSources.first;
2613 _newSources.remove(currentTarget); 2640 _newSources.remove(currentTarget);
2614 return true; 2641 return true;
2615 } 2642 }
2616 } 2643 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/task/dart_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698