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