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

Side by Side Diff: pkg/analysis_server/lib/src/protocol.dart

Issue 479683005: Make more use of generated code in analysis server. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 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
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 protocol; 5 library protocol;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'dart:convert' show JsonDecoder; 8 import 'dart:convert' show JsonDecoder;
9 9
10 import 'package:analysis_server/src/services/json.dart'; 10 import 'package:analysis_server/src/services/json.dart';
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 final RequestError error; 148 final RequestError error;
149 149
150 /** 150 /**
151 * A table mapping the names of result fields to their values. Should be 151 * A table mapping the names of result fields to their values. Should be
152 * null if there is no result to send. 152 * null if there is no result to send.
153 */ 153 */
154 Map<String, Object> result; 154 Map<String, Object> result;
155 155
156 /** 156 /**
157 * Initialize a newly created instance to represent a response to a request 157 * Initialize a newly created instance to represent a response to a request
158 * with the given [id]. If an [error] is provided then the response will 158 * with the given [id]. If [result] is provided, it will be used as the
159 * represent an error condition. 159 * result; otherwise an empty result will be used. If an [error] is provided
160 * then the response will represent an error condition.
160 */ 161 */
161 Response(this.id, [this.error]); 162 Response(this.id, {this.result, this.error});
162 163
163 /** 164 /**
164 * Initialize a newly created instance to represent an error condition caused 165 * Initialize a newly created instance to represent an error condition caused
165 * by a [request] referencing a context that does not exist. 166 * by a [request] referencing a context that does not exist.
166 */ 167 */
167 Response.contextDoesNotExist(Request request) 168 Response.contextDoesNotExist(Request request)
168 : this(request.id, new RequestError('NONEXISTENT_CONTEXT', 'Context does not exist')); 169 : this(request.id, error: new RequestError('NONEXISTENT_CONTEXT', 'Context d oes not exist'));
169 170
170 /** 171 /**
171 * Initialize a newly created instance to represent an error condition caused 172 * Initialize a newly created instance to represent an error condition caused
172 * by a [request] that had invalid parameter. [path] is the path to the 173 * by a [request] that had invalid parameter. [path] is the path to the
173 * invalid parameter, in Javascript notation (e.g. "foo.bar" means that the 174 * invalid parameter, in Javascript notation (e.g. "foo.bar" means that the
174 * parameter "foo" contained a key "bar" whose value was the wrong type). 175 * parameter "foo" contained a key "bar" whose value was the wrong type).
175 * [expectation] is a description of the type of data that was expected. 176 * [expectation] is a description of the type of data that was expected.
176 */ 177 */
177 Response.invalidParameter(Request request, String path, String expectation) 178 Response.invalidParameter(Request request, String path, String expectation)
178 : this(request.id, new RequestError('INVALID_PARAMETER', 179 : this(request.id, error: new RequestError('INVALID_PARAMETER',
179 "Expected parameter $path to $expectation")); 180 "Expected parameter $path to $expectation"));
180 181
181 /** 182 /**
182 * Initialize a newly created instance to represent an error condition caused 183 * Initialize a newly created instance to represent an error condition caused
183 * by a malformed request. 184 * by a malformed request.
184 */ 185 */
185 Response.invalidRequestFormat() 186 Response.invalidRequestFormat()
186 : this('', new RequestError('INVALID_REQUEST', 'Invalid request')); 187 : this('', error: new RequestError('INVALID_REQUEST', 'Invalid request'));
187 188
188 /** 189 /**
189 * Initialize a newly created instance to represent an error condition caused 190 * Initialize a newly created instance to represent an error condition caused
190 * by a [request] that does not have a required parameter. 191 * by a [request] that does not have a required parameter.
191 */ 192 */
192 Response.missingRequiredParameter(Request request, String parameterName) 193 Response.missingRequiredParameter(Request request, String parameterName)
193 : this(request.id, new RequestError('MISSING_PARAMETER', 'Missing required p arameter: $parameterName')); 194 : this(request.id, error: new RequestError('MISSING_PARAMETER', 'Missing req uired parameter: $parameterName'));
194 195
195 /** 196 /**
196 * Initialize a newly created instance to represent an error condition caused 197 * Initialize a newly created instance to represent an error condition caused
197 * by a [request] that takes a set of analysis options but for which an 198 * by a [request] that takes a set of analysis options but for which an
198 * unknown analysis option was provided. 199 * unknown analysis option was provided.
199 */ 200 */
200 Response.unknownAnalysisOption(Request request, String optionName) 201 Response.unknownAnalysisOption(Request request, String optionName)
201 : this(request.id, new RequestError('UNKNOWN_ANALYSIS_OPTION', 'Unknown anal ysis option: "$optionName"')); 202 : this(request.id, error: new RequestError('UNKNOWN_ANALYSIS_OPTION', 'Unkno wn analysis option: "$optionName"'));
202 203
203 /** 204 /**
204 * Initialize a newly created instance to represent an error condition caused 205 * Initialize a newly created instance to represent an error condition caused
205 * by a [request] that cannot be handled by any known handlers. 206 * by a [request] that cannot be handled by any known handlers.
206 */ 207 */
207 Response.unknownRequest(Request request) 208 Response.unknownRequest(Request request)
208 : this(request.id, new RequestError('UNKNOWN_REQUEST', 'Unknown request')); 209 : this(request.id, error: new RequestError('UNKNOWN_REQUEST', 'Unknown reque st'));
209 210
210 Response.contextAlreadyExists(Request request) 211 Response.contextAlreadyExists(Request request)
211 : this(request.id, new RequestError('CONTENT_ALREADY_EXISTS', 'Context alrea dy exists')); 212 : this(request.id, error: new RequestError('CONTENT_ALREADY_EXISTS', 'Contex t already exists'));
212 213
213 Response.unsupportedFeature(String requestId, String message) 214 Response.unsupportedFeature(String requestId, String message)
214 : this(requestId, new RequestError('UNSUPPORTED_FEATURE', message)); 215 : this(requestId, error: new RequestError('UNSUPPORTED_FEATURE', message));
215 216
216 /** 217 /**
217 * Initialize a newly created instance to represent an error condition caused 218 * Initialize a newly created instance to represent an error condition caused
218 * by a `analysis.setSubscriptions` [request] that includes an unknown 219 * by a `analysis.setSubscriptions` [request] that includes an unknown
219 * analysis service name. 220 * analysis service name.
220 */ 221 */
221 Response.unknownAnalysisService(Request request, String name) 222 Response.unknownAnalysisService(Request request, String name)
222 : this(request.id, new RequestError('UNKNOWN_ANALYSIS_SERVICE', 'Unknown ana lysis service: "$name"')); 223 : this(request.id, error: new RequestError('UNKNOWN_ANALYSIS_SERVICE', 'Unkn own analysis service: "$name"'));
223 224
224 /** 225 /**
225 * Initialize a newly created instance to represent an error condition caused 226 * Initialize a newly created instance to represent an error condition caused
226 * by a `analysis.setPriorityFiles` [request] that includes one or more files 227 * by a `analysis.setPriorityFiles` [request] that includes one or more files
227 * that are not being analyzed. 228 * that are not being analyzed.
228 */ 229 */
229 Response.unanalyzedPriorityFiles(Request request, String fileNames) 230 Response.unanalyzedPriorityFiles(Request request, String fileNames)
230 : this(request.id, new RequestError('UNANALYZED_PRIORITY_FILES', "Unanalyzed files cannot be a priority: '$fileNames'")); 231 : this(request.id, error: new RequestError('UNANALYZED_PRIORITY_FILES', "Una nalyzed files cannot be a priority: '$fileNames'"));
231 232
232 /** 233 /**
233 * Initialize a newly created instance to represent an error condition caused 234 * Initialize a newly created instance to represent an error condition caused
234 * by a `analysis.updateOptions` [request] that includes an unknown analysis 235 * by a `analysis.updateOptions` [request] that includes an unknown analysis
235 * option. 236 * option.
236 */ 237 */
237 Response.unknownOptionName(Request request, String optionName) 238 Response.unknownOptionName(Request request, String optionName)
238 : this(request.id, new RequestError('UNKNOWN_OPTION_NAME', 'Unknown analysis option: "$optionName"')); 239 : this(request.id, error: new RequestError('UNKNOWN_OPTION_NAME', 'Unknown a nalysis option: "$optionName"'));
239 240
240 /** 241 /**
241 * Initialize a newly created instance to represent an error condition caused 242 * Initialize a newly created instance to represent an error condition caused
242 * by an error during `analysis.getErrors`. 243 * by an error during `analysis.getErrors`.
243 */ 244 */
244 Response.getErrorsError(Request request, String message) 245 Response.getErrorsError(Request request, String message)
245 : this( 246 : this(
246 request.id, 247 request.id,
247 new RequestError('GET_ERRORS_ERROR', 'Error during `analysis.getErrors`: $message.')); 248 error: new RequestError('GET_ERRORS_ERROR', 'Error during `analysis.getE rrors`: $message.'));
248 249
249 /** 250 /**
250 * Initialize a newly created instance based upon the given JSON data 251 * Initialize a newly created instance based upon the given JSON data
251 */ 252 */
252 factory Response.fromJson(Map<String, Object> json) { 253 factory Response.fromJson(Map<String, Object> json) {
253 try { 254 try {
254 Object id = json[Response.ID]; 255 Object id = json[Response.ID];
255 if (id is! String) { 256 if (id is! String) {
256 return null; 257 return null;
257 } 258 }
258 Object error = json[Response.ERROR]; 259 Object error = json[Response.ERROR];
259 Object result = json[Response.RESULT]; 260 Object result = json[Response.RESULT];
260 Response response; 261 Response response;
261 if (error is Map) { 262 if (error is Map) {
262 response = new Response(id, new RequestError.fromJson(error)); 263 response = new Response(id, error: new RequestError.fromJson(error));
263 } else { 264 } else {
264 response = new Response(id); 265 response = new Response(id);
265 } 266 }
266 if (result is Map) { 267 if (result is Map) {
267 result.forEach((String key, Object value) { 268 result.forEach((String key, Object value) {
268 response.setResult(key, value); 269 response.setResult(key, value);
269 }); 270 });
270 } 271 }
271 return response; 272 return response;
272 } catch (exception) { 273 } catch (exception) {
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 */ 596 */
596 _toJson(Object value) { 597 _toJson(Object value) {
597 if (value is HasToJson) { 598 if (value is HasToJson) {
598 return value.toJson(); 599 return value.toJson();
599 } 600 }
600 if (value is Iterable) { 601 if (value is Iterable) {
601 return value.map((item) => _toJson(item)).toList(); 602 return value.map((item) => _toJson(item)).toList();
602 } 603 }
603 return value; 604 return value;
604 } 605 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698