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

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

Issue 1645643002: Replace isAppropriateFor with suitabilityFor and start using it (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 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
« no previous file with comments | « pkg/analyzer/lib/src/task/options.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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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.yaml; 5 library analyzer.src.task.yaml;
6 6
7 import 'package:analyzer/src/context/cache.dart'; 7 import 'package:analyzer/src/context/cache.dart';
8 import 'package:analyzer/src/generated/engine.dart' hide AnalysisTask; 8 import 'package:analyzer/src/generated/engine.dart' hide AnalysisTask;
9 import 'package:analyzer/src/generated/error.dart'; 9 import 'package:analyzer/src/generated/error.dart';
10 import 'package:analyzer/src/generated/java_engine.dart'; 10 import 'package:analyzer/src/generated/java_engine.dart';
(...skipping 15 matching lines...) Expand all
26 */ 26 */
27 static const String CONTENT_INPUT_NAME = 'CONTENT_INPUT_NAME'; 27 static const String CONTENT_INPUT_NAME = 'CONTENT_INPUT_NAME';
28 28
29 /** 29 /**
30 * The task descriptor describing this kind of task. 30 * The task descriptor describing this kind of task.
31 */ 31 */
32 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 32 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
33 'ParseYamlTask', 33 'ParseYamlTask',
34 createTask, 34 createTask,
35 buildInputs, 35 buildInputs,
36 <ResultDescriptor>[YAML_DOCUMENT, YAML_ERRORS, YAML_LINE_INFO]); 36 <ResultDescriptor>[YAML_DOCUMENT, YAML_ERRORS, LINE_INFO],
37 suitabilityFor: suitabilityFor);
37 38
38 /** 39 /**
39 * Initialize a newly created task to access the content of the source 40 * Initialize a newly created task to access the content of the source
40 * associated with the given [target] in the given [context]. 41 * associated with the given [target] in the given [context].
41 */ 42 */
42 ParseYamlTask(InternalAnalysisContext context, AnalysisTarget target) 43 ParseYamlTask(InternalAnalysisContext context, AnalysisTarget target)
43 : super(context, target); 44 : super(context, target);
44 45
45 @override 46 @override
46 TaskDescriptor get descriptor => DESCRIPTOR; 47 TaskDescriptor get descriptor => DESCRIPTOR;
(...skipping 15 matching lines...) Expand all
62 } 63 }
63 } 64 }
64 // 65 //
65 // Record outputs. 66 // Record outputs.
66 // 67 //
67 outputs[YAML_DOCUMENT] = loadYamlDocument('', sourceUrl: uri); 68 outputs[YAML_DOCUMENT] = loadYamlDocument('', sourceUrl: uri);
68 outputs[YAML_ERRORS] = <AnalysisError>[ 69 outputs[YAML_ERRORS] = <AnalysisError>[
69 new AnalysisError( 70 new AnalysisError(
70 source, 0, 0, ScannerErrorCode.UNABLE_GET_CONTENT, [message]) 71 source, 0, 0, ScannerErrorCode.UNABLE_GET_CONTENT, [message])
71 ]; 72 ];
72 outputs[YAML_LINE_INFO] = new LineInfo(<int>[0]); 73 outputs[LINE_INFO] = new LineInfo(<int>[0]);
73 } else { 74 } else {
74 YamlDocument document; 75 YamlDocument document;
75 List<AnalysisError> errors = <AnalysisError>[]; 76 List<AnalysisError> errors = <AnalysisError>[];
76 try { 77 try {
77 document = loadYamlDocument(content, sourceUrl: uri); 78 document = loadYamlDocument(content, sourceUrl: uri);
78 } on YamlException catch (exception) { 79 } on YamlException catch (exception) {
79 SourceSpan span = exception.span; 80 SourceSpan span = exception.span;
80 int offset = span.start.offset; 81 int offset = span.start.offset;
81 int length = span.end.offset - offset; 82 int length = span.end.offset - offset;
82 errors.add(new AnalysisError(source, offset, length, 83 errors.add(new AnalysisError(source, offset, length,
83 YamlErrorCode.PARSE_ERROR, [exception.message])); 84 YamlErrorCode.PARSE_ERROR, [exception.message]));
84 } catch (exception, stackTrace) { 85 } catch (exception, stackTrace) {
85 throw new AnalysisException('Error while parsing ${source.fullName}', 86 throw new AnalysisException('Error while parsing ${source.fullName}',
86 new CaughtException(exception, stackTrace)); 87 new CaughtException(exception, stackTrace));
87 } 88 }
88 // 89 //
89 // Record outputs. 90 // Record outputs.
90 // 91 //
91 outputs[YAML_DOCUMENT] = document; 92 outputs[YAML_DOCUMENT] = document;
92 outputs[YAML_ERRORS] = errors; 93 outputs[YAML_ERRORS] = errors;
93 outputs[YAML_LINE_INFO] = new LineInfo.fromContent(content); 94 outputs[LINE_INFO] = new LineInfo.fromContent(content);
94 } 95 }
95 } 96 }
96 97
97 /** 98 /**
98 * Return a map from the names of the inputs of this kind of task to the task 99 * Return a map from the names of the inputs of this kind of task to the task
99 * input descriptors describing those inputs for a task with the given 100 * input descriptors describing those inputs for a task with the given
100 * [source]. 101 * [source].
101 */ 102 */
102 static Map<String, TaskInput> buildInputs(Source source) { 103 static Map<String, TaskInput> buildInputs(Source source) {
103 return <String, TaskInput>{CONTENT_INPUT_NAME: CONTENT.of(source)}; 104 return <String, TaskInput>{CONTENT_INPUT_NAME: CONTENT.of(source)};
104 } 105 }
105 106
106 /** 107 /**
107 * Create a [ParseYamlTask] based on the given [target] in the given [context] . 108 * Create a [ParseYamlTask] based on the given [target] in the given [context] .
108 */ 109 */
109 static ParseYamlTask createTask( 110 static ParseYamlTask createTask(
110 AnalysisContext context, AnalysisTarget target) { 111 AnalysisContext context, AnalysisTarget target) {
111 return new ParseYamlTask(context, target); 112 return new ParseYamlTask(context, target);
112 } 113 }
114
115 /**
116 * Return an indication of how suitable this task is for the given [target].
117 */
118 static TaskSuitability suitabilityFor(AnalysisTarget target) {
119 if (target is Source && target.shortName.endsWith('.yaml')) {
120 return TaskSuitability.HIGHEST;
121 }
122 return TaskSuitability.NONE;
123 }
113 } 124 }
114 125
115 /** 126 /**
116 * The error codes used for errors in YAML files. 127 * The error codes used for errors in YAML files.
117 */ 128 */
118 class YamlErrorCode extends ErrorCode { 129 class YamlErrorCode extends ErrorCode {
119 // TODO(brianwilkerson) Move this class to error.dart. 130 // TODO(brianwilkerson) Move this class to error.dart.
120 131
121 /** 132 /**
122 * An error code indicating that there is a syntactic error in the file. 133 * An error code indicating that there is a syntactic error in the file.
(...skipping 12 matching lines...) Expand all
135 */ 146 */
136 const YamlErrorCode(String name, String message, [String correction]) 147 const YamlErrorCode(String name, String message, [String correction])
137 : super(name, message, correction); 148 : super(name, message, correction);
138 149
139 @override 150 @override
140 ErrorSeverity get errorSeverity => ErrorSeverity.ERROR; 151 ErrorSeverity get errorSeverity => ErrorSeverity.ERROR;
141 152
142 @override 153 @override
143 ErrorType get type => ErrorType.COMPILE_TIME_ERROR; 154 ErrorType get type => ErrorType.COMPILE_TIME_ERROR;
144 } 155 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/task/options.dart ('k') | pkg/analyzer/lib/task/model.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698