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

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

Issue 887433002: Add simple Dart tasks (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add base class and general implementation of description Created 5 years, 10 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 | « pkg/analyzer/lib/src/task/dart.dart ('k') | pkg/analyzer/lib/task/model.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.general; 5 library analyzer.src.task.general;
6 6
7 import 'package:analyzer/src/generated/engine.dart' hide AnalysisTask; 7 import 'package:analyzer/src/generated/engine.dart' hide AnalysisTask;
8 import 'package:analyzer/src/generated/source.dart'; 8 import 'package:analyzer/src/generated/source.dart';
9 import 'package:analyzer/task/general.dart'; 9 import 'package:analyzer/task/general.dart';
10 import 'package:analyzer/task/model.dart'; 10 import 'package:analyzer/task/model.dart';
11 11
12 /** 12 /**
13 * A task that gets the contents of the source associated with an analysis 13 * A task that gets the contents of the source associated with an analysis
14 * target. 14 * target.
15 */ 15 */
16 class GetContentTask extends AnalysisTask { 16 class GetContentTask extends SourceBasedAnalysisTask {
17 /** 17 /**
18 * The task descriptor describing this kind of task. 18 * The task descriptor describing this kind of task.
19 */ 19 */
20 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 20 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
21 'GET_CONTENT', 21 'GET_CONTENT',
22 createTask, 22 createTask,
23 buildInputs, 23 buildInputs,
24 <ResultDescriptor>[CONTENT, MODIFICATION_TIME]); 24 <ResultDescriptor>[CONTENT, MODIFICATION_TIME]);
25 25
26 /** 26 /**
27 * Initialize a newly created task to access the content of the source 27 * Initialize a newly created task to access the content of the source
28 * associated with the given [target] in the given [context]. 28 * associated with the given [target] in the given [context].
29 */ 29 */
30 GetContentTask(InternalAnalysisContext context, AnalysisTarget target) 30 GetContentTask(InternalAnalysisContext context, AnalysisTarget target)
31 : super(context, target); 31 : super(context, target);
32 32
33 @override 33 @override
34 String get description {
35 Source source = target.source;
36 if (source == null) {
37 return "get contents of <unknown source>";
38 }
39 return "get contents of ${source.fullName}";
40 }
41
42 @override
43 TaskDescriptor get descriptor => DESCRIPTOR; 34 TaskDescriptor get descriptor => DESCRIPTOR;
44 35
45 @override 36 @override
46 internalPerform() { 37 internalPerform() {
47 Source source = getRequiredSource(); 38 Source source = getRequiredSource();
48 39
49 TimestampedData<String> data = context.getContents(source); 40 TimestampedData<String> data = context.getContents(source);
50 outputs[CONTENT] = data.data; 41 outputs[CONTENT] = data.data;
51 outputs[MODIFICATION_TIME] = data.modificationTime; 42 outputs[MODIFICATION_TIME] = data.modificationTime;
52 } 43 }
53 44
54 /** 45 /**
55 * Return a map from the names of the inputs of this kind of task to the task 46 * Return a map from the names of the inputs of this kind of task to the task
56 * input descriptors describing those inputs for a task with the given [target ]. 47 * input descriptors describing those inputs for a task with the given [target ].
57 */ 48 */
58 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 49 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
59 return <String, TaskInput>{}; 50 return <String, TaskInput>{};
60 } 51 }
61 52
62 /** 53 /**
63 * Create a [GetContentTask] based on the given [target] in the given 54 * Create a [GetContentTask] based on the given [target] in the given
64 * [context]. 55 * [context].
65 */ 56 */
66 static GetContentTask createTask(AnalysisContext context, 57 static GetContentTask createTask(AnalysisContext context,
67 AnalysisTarget target) { 58 AnalysisTarget target) {
68 return new GetContentTask(context, target); 59 return new GetContentTask(context, target);
69 } 60 }
70 } 61 }
62
63 /**
64 * A base class for analysis tasks whose target is expected to be a source.
65 */
66 abstract class SourceBasedAnalysisTask extends AnalysisTask {
67 /**
68 * Initialize a newly created task to perform analysis within the given
69 * [context] in order to produce results for the given [target].
70 */
71 SourceBasedAnalysisTask(AnalysisContext context, AnalysisTarget target)
72 : super(context, target);
73
74 @override
75 String get description {
76 Source source = target.source;
77 String sourceName =
78 target.source == null ? '<unknown source>' : source.fullName;
79 return '${descriptor.name} for source $sourceName';
80 }
81 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/task/dart.dart ('k') | pkg/analyzer/lib/task/model.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698