| OLD | NEW |
| 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 /** | 5 /** |
| 6 * Support for client code that needs to interact with the requests, responses | 6 * Support for client code that needs to interact with the requests, responses |
| 7 * and notifications that are part of the analysis server's wire protocol. | 7 * and notifications that are part of the analysis server's wire protocol. |
| 8 */ | 8 */ |
| 9 library analysis_server.plugin.protocol.protocol; | 9 library analysis_server.plugin.protocol.protocol; |
| 10 | 10 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 * Initialize a newly created [Notification] to have the given [event] name. | 80 * Initialize a newly created [Notification] to have the given [event] name. |
| 81 * If [_params] is provided, it will be used as the params; otherwise no | 81 * If [_params] is provided, it will be used as the params; otherwise no |
| 82 * params will be used. | 82 * params will be used. |
| 83 */ | 83 */ |
| 84 Notification(this.event, [this._params]); | 84 Notification(this.event, [this._params]); |
| 85 | 85 |
| 86 /** | 86 /** |
| 87 * Initialize a newly created instance based on the given JSON data. | 87 * Initialize a newly created instance based on the given JSON data. |
| 88 */ | 88 */ |
| 89 factory Notification.fromJson(Map<String, Object> json) { | 89 factory Notification.fromJson(Map<String, Object> json) { |
| 90 return new Notification( | 90 return new Notification(json[Notification.EVENT], |
| 91 json[Notification.EVENT], json[Notification.PARAMS]); | 91 json[Notification.PARAMS] as Map<String, Object>); |
| 92 } | 92 } |
| 93 | 93 |
| 94 /** | 94 /** |
| 95 * Return a table representing the structure of the Json object that will be | 95 * Return a table representing the structure of the Json object that will be |
| 96 * sent to the client to represent this response. | 96 * sent to the client to represent this response. |
| 97 */ | 97 */ |
| 98 Map<String, Object> toJson() { | 98 Map<String, Object> toJson() { |
| 99 Map<String, Object> jsonObject = {}; | 99 Map<String, Object> jsonObject = {}; |
| 100 jsonObject[EVENT] = event; | 100 jsonObject[EVENT] = event; |
| 101 if (_params != null) { | 101 if (_params != null) { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 var method = result[Request.METHOD]; | 187 var method = result[Request.METHOD]; |
| 188 if (id is! String || method is! String) { | 188 if (id is! String || method is! String) { |
| 189 return null; | 189 return null; |
| 190 } | 190 } |
| 191 var time = result[Request.CLIENT_REQUEST_TIME]; | 191 var time = result[Request.CLIENT_REQUEST_TIME]; |
| 192 if (time != null && time is! int) { | 192 if (time != null && time is! int) { |
| 193 return null; | 193 return null; |
| 194 } | 194 } |
| 195 var params = result[Request.PARAMS]; | 195 var params = result[Request.PARAMS]; |
| 196 if (params is Map || params == null) { | 196 if (params is Map || params == null) { |
| 197 return new Request(id, method, params, time); | 197 return new Request(id, method, params as Map<String, Object>, time); |
| 198 } else { | 198 } else { |
| 199 return null; | 199 return null; |
| 200 } | 200 } |
| 201 } | 201 } |
| 202 | 202 |
| 203 /** | 203 /** |
| 204 * Return a request parsed from the given [data], or `null` if the [data] is | 204 * Return a request parsed from the given [data], or `null` if the [data] is |
| 205 * not a valid json representation of a request. The [data] is expected to | 205 * not a valid json representation of a request. The [data] is expected to |
| 206 * have the following format: | 206 * have the following format: |
| 207 * | 207 * |
| 208 * { | 208 * { |
| 209 * 'clientRequestTime': millisecondsSinceEpoch | 209 * 'clientRequestTime': millisecondsSinceEpoch |
| 210 * 'id': String, | 210 * 'id': String, |
| 211 * 'method': methodName, | 211 * 'method': methodName, |
| 212 * 'params': { | 212 * 'params': { |
| 213 * paramter_name: value | 213 * paramter_name: value |
| 214 * } | 214 * } |
| 215 * } | 215 * } |
| 216 * | 216 * |
| 217 * where both the parameters and clientRequestTime are optional. | 217 * where both the parameters and clientRequestTime are optional. |
| 218 * | 218 * |
| 219 * The parameters can contain any number of name/value pairs. The | 219 * The parameters can contain any number of name/value pairs. The |
| 220 * clientRequestTime must be an int representing the time at which the client | 220 * clientRequestTime must be an int representing the time at which the client |
| 221 * issued the request (milliseconds since epoch). | 221 * issued the request (milliseconds since epoch). |
| 222 */ | 222 */ |
| 223 factory Request.fromString(String data) { | 223 factory Request.fromString(String data) { |
| 224 try { | 224 try { |
| 225 var result = JSON.decode(data); | 225 var result = JSON.decode(data); |
| 226 if (result is Map) { | 226 if (result is Map) { |
| 227 return new Request.fromJson(result); | 227 return new Request.fromJson(result as Map<String, dynamic>); |
| 228 } | 228 } |
| 229 return null; | 229 return null; |
| 230 } catch (exception) { | 230 } catch (exception) { |
| 231 return null; | 231 return null; |
| 232 } | 232 } |
| 233 } | 233 } |
| 234 | 234 |
| 235 /** | 235 /** |
| 236 * Return a table representing the structure of the Json object that will be | 236 * Return a table representing the structure of the Json object that will be |
| 237 * sent to the client to represent this response. | 237 * sent to the client to represent this response. |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 } | 376 } |
| 377 Object error = json[Response.ERROR]; | 377 Object error = json[Response.ERROR]; |
| 378 RequestError decodedError; | 378 RequestError decodedError; |
| 379 if (error is Map) { | 379 if (error is Map) { |
| 380 decodedError = new RequestError.fromJson( | 380 decodedError = new RequestError.fromJson( |
| 381 new ResponseDecoder(null), '.error', error); | 381 new ResponseDecoder(null), '.error', error); |
| 382 } | 382 } |
| 383 Object result = json[Response.RESULT]; | 383 Object result = json[Response.RESULT]; |
| 384 Map<String, Object> decodedResult; | 384 Map<String, Object> decodedResult; |
| 385 if (result is Map) { | 385 if (result is Map) { |
| 386 decodedResult = result; | 386 decodedResult = result as Map<String, Object>; |
| 387 } | 387 } |
| 388 return new Response(id, error: decodedError, result: decodedResult); | 388 return new Response(id, error: decodedError, result: decodedResult); |
| 389 } catch (exception) { | 389 } catch (exception) { |
| 390 return null; | 390 return null; |
| 391 } | 391 } |
| 392 } | 392 } |
| 393 | 393 |
| 394 /** | 394 /** |
| 395 * Initialize a newly created instance to represent the | 395 * Initialize a newly created instance to represent the |
| 396 * GET_ERRORS_INVALID_FILE error condition. | 396 * GET_ERRORS_INVALID_FILE error condition. |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 jsonObject[ID] = id; | 575 jsonObject[ID] = id; |
| 576 if (error != null) { | 576 if (error != null) { |
| 577 jsonObject[ERROR] = error.toJson(); | 577 jsonObject[ERROR] = error.toJson(); |
| 578 } | 578 } |
| 579 if (_result != null) { | 579 if (_result != null) { |
| 580 jsonObject[RESULT] = _result; | 580 jsonObject[RESULT] = _result; |
| 581 } | 581 } |
| 582 return jsonObject; | 582 return jsonObject; |
| 583 } | 583 } |
| 584 } | 584 } |
| OLD | NEW |